Skip to content

fix(song): handle missing genres in metadata#2630

Open
BillionClaw wants to merge 1 commit intospotDL:masterfrom
BillionClaw:clawoss/fix/handle-missing-genres-metadata
Open

fix(song): handle missing genres in metadata#2630
BillionClaw wants to merge 1 commit intospotDL:masterfrom
BillionClaw:clawoss/fix/handle-missing-genres-metadata

Conversation

@BillionClaw
Copy link

Issue

Fixes #2619

Problem

When the Spotify API doesn't return genres for albums or artists, spotDL crashes with KeyError: 'genres'.

This happens because the code directly accesses raw_album_meta["genres"] and raw_artist_meta["genres"] without checking if these keys exist.

Solution

Use .get("genres", []) instead of direct key access to safely handle cases where genres data is missing from the API response.

Changes

  • Line 117 in spotdl/types/song.py: Changed raw_album_meta["genres"] + raw_artist_meta["genres"] to raw_album_meta.get("genres", []) + raw_artist_meta.get("genres", [])

This follows the same pattern used elsewhere in the codebase (e.g., line 111 for album_type, line 125 for isrc).

Fix KeyError when Spotify API doesn't return genres for albums or artists.
Use .get() with empty list default instead of direct key access.

Fixes spotDL#2619
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.

KeyError: 'genres'

1 participant