Skip to content

Openverse is a search engine for openly-licensed media. This monorepo includes all application code.

Add trailing slash to Jamendo thumbnail URLs (#1038)

Madison Swain-Bowden261538cb366f
diff --git a/openverse_catalog/dags/providers/provider_api_scripts/jamendo.py b/openverse_catalog/dags/providers/provider_api_scripts/jamendo.py
index d0676afdc..aa90c2780 100644
--- a/openverse_catalog/dags/providers/provider_api_scripts/jamendo.py
+++ b/openverse_catalog/dags/providers/provider_api_scripts/jamendo.py
@@ -90,7 +90,24 @@ class JamendoDataIngester(ProviderDataIngester):
"""
if thumbnail_url is None:
return None
- return self._remove_param_from_url(thumbnail_url, "trackid")
+ return self._remove_param_from_url(
+ self._add_trailing_slash(thumbnail_url), "trackid"
+ )
+
+ @staticmethod
+ def _add_trailing_slash(url: str | None) -> str | None:
+ """
+ Jamendo image URLs are missing a trailing slash, which when viewed normally in
+ the browser get redirected to the correct URL. Example:
+ - https://usercontent.jamendo.com?type=album&id=100007&width=300 (before)
+ - https://usercontent.jamendo.com/?type=album&id=100007&width=300 (after)
+
+ Due to the way photon processes thumbnails, we need to add this trailing slash
+ to the url prior to the query params if it does not have one.
+ """
+ if url and "/?" not in url:
+ url = url.replace("?", "/?")
+ return url
def _get_audio_url(self, data):
"""
@@ -178,7 +195,7 @@ class JamendoDataIngester(ProviderDataIngester):
if duration:
duration = int(duration) * 1000
title = data.get("name")
- thumbnail = data.get("image")
+ thumbnail = self._add_trailing_slash(data.get("image"))
genres = data.get("musicinfo", {}).get("tags", {}).get("genres")
creator, creator_url = self._get_creator_data(data)
metadata = self._get_metadata(data)
diff --git a/tests/dags/providers/provider_api_scripts/test_jamendo.py b/tests/dags/providers/provider_api_scripts/test_jamendo.py
index 5e23c1a9e..14eb69510 100644
--- a/tests/dags/providers/provider_api_scripts/test_jamendo.py
+++ b/tests/dags/providers/provider_api_scripts/test_jamendo.py
@@ -92,9 +92,9 @@ def test_get_record_data():
"raw_tags": ["instrumental", "speed_medium"],
"set_foreign_id": "119",
"set_position": 6,
- "set_thumbnail": "https://usercontent.jamendo.com?type=album&id=119&width=200",
+ "set_thumbnail": "https://usercontent.jamendo.com/?type=album&id=119&width=200",
"set_url": "https://www.jamendo.com/album/119/opera-i",
- "thumbnail_url": "https://usercontent.jamendo.com?type=album&id=119&width=200&trackid=732",
+ "thumbnail_url": "https://usercontent.jamendo.com/?type=album&id=119&width=200&trackid=732",
"title": "Thoughtful",
}
assert actual == expected
@@ -152,3 +152,23 @@ def test_get_tags():
expected_tags = ["vocal", "male", "speed_medium", "engage"]
actual_tags = jamendo._get_tags(item_data)
assert expected_tags == actual_tags
+
+
+ "url, expected",
+ [
+ (None, None),
+ ("", ""),
+ (
+ "https://usercontent.jamendo.com?type=album&id=100007&width=300",
+ "https://usercontent.jamendo.com/?type=album&id=100007&width=300",
+ ),
+ (
+ "https://usercontent.jamendo.com/some-other-page/subpage?type=album&id=100007&width=300",
+ "https://usercontent.jamendo.com/some-other-page/subpage/?type=album&id=100007&width=300",
+ ),
+ ],
+)
+def test_add_trailing_slash(url, expected):
+ actual = jamendo._add_trailing_slash(url)
+ assert actual == expected