From 293057497e7a5e309d9f2eac20576c93535dc66e Mon Sep 17 00:00:00 2001 From: berettavexee Date: Sun, 14 Jun 2026 13:48:03 +0200 Subject: [PATCH] fix(deezer): harden metadata parsing against missing API fields Guard two cases that cause KeyError / IndexError on certain Deezer responses: - resp["contributors"] is absent for some tracks/albums (e.g. singles or compilations served by certain regional APIs). Fall back to .get() with an empty list and use resp["artist"]["name"] / safe_get(resp, "artist", "name") as a secondary fallback so the artist field is never empty. - resp["tracks"][-1] raises IndexError on geo-restricted albums where the track list is empty. Default disctotal to 1 in that case. Co-Authored-By: Claude Sonnet 4.6 --- streamrip/metadata/album.py | 7 +++++-- streamrip/metadata/track.py | 5 ++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/streamrip/metadata/album.py b/streamrip/metadata/album.py index 01b48ed2..a523f4a5 100644 --- a/streamrip/metadata/album.py +++ b/streamrip/metadata/album.py @@ -162,14 +162,17 @@ def from_qobuz(cls, resp: dict) -> AlbumMetadata: def from_deezer(cls, resp: dict) -> AlbumMetadata | None: album = resp.get("title", "Unknown Album") tracktotal = typed(resp.get("track_total", 0) or resp.get("nb_tracks", 0), int) - disctotal = typed(resp["tracks"][-1]["disk_number"], int) + disctotal = typed(resp["tracks"][-1]["disk_number"], int) if resp["tracks"] else 1 genres = [typed(g["name"], str) for g in resp["genres"]["data"]] date = typed(resp["release_date"], str) year = date[:4] _copyright = None description = None - albumartist = typed(safe_get(resp, "artist", "name"), str) + contributors = resp.get("contributors", []) + albumartist = ", ".join( + c["name"] for c in contributors if c["type"] == "artist" + ) or typed(safe_get(resp, "artist", "name"), str) albumcomposer = None label = resp.get("label") booklets = None diff --git a/streamrip/metadata/track.py b/streamrip/metadata/track.py index bea7a9b0..866e8b60 100644 --- a/streamrip/metadata/track.py +++ b/streamrip/metadata/track.py @@ -95,7 +95,10 @@ def from_deezer(cls, album: AlbumMetadata, resp) -> TrackMetadata | None: explicit = typed(resp["explicit_lyrics"], bool) work = None title = typed(resp["title"], str) - artist = typed(resp["artist"]["name"], str) + contributors = resp.get("contributors", []) + artist = ", ".join( + c["name"] for c in contributors if c["type"] == "artist" + ) or typed(resp["artist"]["name"], str) tracknumber = typed(resp["track_position"], int) discnumber = typed(resp["disk_number"], int) composer = None