Skip to content

fix(deezer): harden metadata parsing against missing API fields#994

Open
berettavexee wants to merge 1 commit into
nathom:devfrom
berettavexee:fix/deezer-metadata-hardening
Open

fix(deezer): harden metadata parsing against missing API fields#994
berettavexee wants to merge 1 commit into
nathom:devfrom
berettavexee:fix/deezer-metadata-hardening

Conversation

@berettavexee

@berettavexee berettavexee commented Jun 14, 2026

Copy link
Copy Markdown

Problem

Two KeyError / IndexError cases in the Deezer metadata parsers cause downloads to fail silently on certain content:

1. resp["contributors"] — KeyError

AlbumMetadata.from_deezer() and TrackMetadata.from_deezer() access resp["contributors"] directly. This key is absent for some tracks and albums (singles, compilations, or responses from certain regional API endpoints), raising a KeyError that aborts the download.

2. resp["tracks"][-1] — IndexError

AlbumMetadata.from_deezer() uses resp["tracks"][-1]["disk_number"] to determine disctotal. On geo-restricted albums the tracks list can be empty, causing an IndexError.

Fix

# album.py / track.py — guard contributors
contributors = resp.get("contributors", [])
albumartist = ", ".join(
    c["name"] for c in contributors if c["type"] == "artist"
) or typed(safe_get(resp, "artist", "name"), str)

# album.py — guard empty track list
disctotal = typed(resp["tracks"][-1]["disk_number"], int) if resp["tracks"] else 1

Test plan

  • Album with contributors in response → artists joined correctly
  • Album without contributors key → falls back to resp["artist"]["name"]
  • Geo-restricted album with empty tracks list → disctotal defaults to 1, no crash
  • Normal album download unaffected

🤖 Generated with Claude Code

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 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant