Skip to content

Fix/song from url missing spotify fields#2627

Open
Joelsitovs wants to merge 2 commits intospotDL:masterfrom
Joelsitovs:fix/song-from-url-missing-spotify-fields
Open

Fix/song from url missing spotify fields#2627
Joelsitovs wants to merge 2 commits intospotDL:masterfrom
Joelsitovs:fix/song-from-url-missing-spotify-fields

Conversation

@Joelsitovs
Copy link

@Joelsitovs Joelsitovs commented Mar 15, 2026

Title

Handle missing optional Spotify metadata in Song.from_url

Description

This change makes Song.from_url() more defensive when Spotify returns partial
metadata for a track.

The current implementation assumes that fields such as genres, label, images,
and popularity are always present in the Spotify API response. In practice, some
valid tracks omit one or more of these optional fields, which causes spotdl to raise
KeyError and abort.

This patch replaces those direct dictionary accesses with safe defaults so valid
tracks can still be processed.

Related Issue

Related to the open issue reporting a KeyError in Song.from_url() when Spotify
metadata omits fields like genres.
#2619

Motivation and Context

How Has This Been Tested?

Spotify metadata responses are not always complete for every track.

Because Song.from_url() treats several optional fields as required, spotdl can
fail on otherwise valid Spotify track URLs. This patch makes the parsing more robust
and prevents crashes caused by missing optional metadata.

Screenshots (if appropriate)

Types of Changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • [x ] My code follows the code style of this project
  • My change requires a change to the documentation
  • I have updated the documentation accordingly
  • I have read the CONTRIBUTING document
  • I have added tests to cover my changes
  • All new and existing tests passed

@Joelsitovs Joelsitovs marked this pull request as draft March 17, 2026 15:47
@Joelsitovs Joelsitovs marked this pull request as ready for review March 17, 2026 15:52
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