SRGSSR / srgdataprovider-apple

A library to retrieve SRG SSR unified metadata
MIT License
0 stars 1 forks source link

Couldn't use RTS CMS image urls with Play SRG image service #47

Closed pyby closed 7 months ago

pyby commented 1 year ago

Issue type

Incorrect content result

Description of the problem

44 is moving the whole library to one common image service: Play SRG image service.

Issue found with image urls from rts.ch CMS.

With 18.0.0 library release, the current fix is to not used Play SRG image service for RTS CMS image urls. The business unit scaling image service is still used, using the convention of https:[BU].ch/[image path]/scale/width/[width].

Waiting an image service update from RTS in 2023 Q3 or Q4.

Environment information

Reproducibility

Always reproducible

Code sample

[[self.dataProvider mediaWithURN:@"urn:rts:audio:14145940" completionBlock:^(SRGMedia * _Nullable media, 
        // "imageUrl" = "https://www.rts.ch/2021/04/30/14/43/7978319.image/16x9"

        NSURL *imageURL = [self.dataProvider URLForImage:media.image withWidth:SRGImageWidth320];
        // Using Play SRG image service: "https://il.srgssr.ch/images/?imageUrl=https://www.rts.ch/2021/04/30/14/43/7978319.image/16x9&format=jpg&width=320"

        UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:imageURL]];
        // 16:9 ratio or a square ratio expected, but with correct content.
        // Currently, it's the raw image returns.

    }] resume];

RTS audio image urls has 16x9 in its path, but it's not used correctly by RTS CMS image service: internal SRG ticket created.

pyby commented 1 year ago

The related internal ticket for RTS as been tackled by @bgaudaen. Few image caches could exist but now, the RTS image urls are compatible with Play SRG image service.

The workaround introduced in #44 could be removed.

pyby commented 1 year ago

We'll try to clean RTS show image cache, by updating the image urls. Tested in Play RTS iOS, wrong ratio image still delivered.

Script to get all Play RTS main show images:

#!/bin/bash

# Initialize an empty array to store show image URLs
show_image_urls=()
# Initialize an empty array to store show image IDs
show_image_ids=()

# Define the URL to remove
url_to_remove="https://ws.srf.ch/asset/image/audio/8b32fd87-459e-40f1-9519-ba0cbb01f34e/NOT_SPECIFIED.jpg"

# Define the API URLs
api_urls=(
  "https://il.srgssr.ch/integrationlayer/2.0/rts/showList/tv/alphabetical?pageSize=unlimited"
  "https://il.srgssr.ch/integrationlayer/2.0/rts/showList/radio/alphabeticalByChannel/a9e7621504c6959e35c3ecbe7f6bed0446cdf8da?pageSize=unlimited"
  "https://il.srgssr.ch/integrationlayer/2.0/rts/showList/radio/alphabeticalByChannel/a83f29dee7a5d0d3f9fccdb9c92161b1afb512db?pageSize=unlimited"
  "https://il.srgssr.ch/integrationlayer/2.0/rts/showList/radio/alphabeticalByChannel/8ceb28d9b3f1dd876d1df1780f908578cbefc3d7?pageSize=unlimited"
  "https://il.srgssr.ch/integrationlayer/2.0/rts/showList/radio/alphabeticalByChannel/f8517e5319a515e013551eea15aa114fa5cfbc3a?pageSize=unlimited"
  "https://il.srgssr.ch/integrationlayer/2.0/rts/showList/radio/alphabeticalByChannel/123456789101112131415161718192021222324x?pageSize=unlimited"
)

# Loop through the API URLs
for url in "${api_urls[@]}"; do
  # Make a GET request using curl and parse the JSON response with jq
  response=$(curl -s "$url" | jq -r '.showList[]?.imageUrl')

  # Add the parsed image URLs to the show_image_urls array, excluding the URL to remove
  show_image_urls+=($(echo "$response" | grep -vF "$url_to_remove"))
done

# Extract and store only the image IDs from the URLs
for url in "${show_image_urls[@]}"; do
  image_id=$(echo "$url" | sed -n 's/.*\/\([0-9]*\).image\/.*/\1/p')
  show_image_ids+=("$image_id")
done

# Export the merged array of show image URLs to a CSV file
csv_file="show_image_urls.csv"
for url in "${show_image_urls[@]}"; do
  echo "$url" >> "$csv_file"
done

echo "CSV file '$csv_file' has been created with the show image URLs."

# Export the array of show image IDs to a second CSV file
csv_file_ids="show_image_ids.csv"
for id in "${show_image_ids[@]}"; do
  echo "$id" >> "$csv_file_ids"
done

echo "CSV file '$csv_file_ids' has been created with the show image IDs."