Skip to content

Handle SongError in reinit_song to skip unavailable tracks instead of crashing#2625

Open
cpaczek wants to merge 1 commit intospotDL:masterfrom
cpaczek:fix/handle-deleted-track-songerror
Open

Handle SongError in reinit_song to skip unavailable tracks instead of crashing#2625
cpaczek wants to merge 1 commit intospotDL:masterfrom
cpaczek:fix/handle-deleted-track-songerror

Conversation

@cpaczek
Copy link
Copy Markdown

@cpaczek cpaczek commented Mar 13, 2026

Description

When downloading large playlists or liked songs, if a track has been removed from Spotify (duration_ms == 0 or empty name), reinit_song() raises SongError which propagates unhandled from search_and_download() and crashes the entire batch download via asyncio.gather(). All remaining songs in the queue are left unprocessed.

This wraps the reinit_song() call in a try/except for SongError so that unavailable tracks are logged as warnings, appended to the error list (visible with --print-errors and --save-errors), and skipped gracefully while the rest of the playlist continues downloading.

A possible future enhancement would be to still attempt a YouTube search for these tracks using whatever metadata is available (name, artists) rather than skipping entirely, since the audio may still exist on YouTube even if Spotify marks the track as unavailable.

Related Issue

No existing issue for this specific crash.

Motivation and Context

Users with large liked songs libraries or playlists that contain tracks removed from Spotify experience a full crash mid-download. The only current workaround is to manually identify and remove the deleted track from the playlist/library, which is impractical when you don't know which track is causing the crash ahead of time.

How Has This Been Tested?

Tested locally against a liked songs library (549 tracks) containing a removed track. Before the fix, spotdl crashed after processing 25 songs and never completed the remaining 524. After the fix, the unavailable track is logged as a warning and skipped, and all remaining songs download successfully.

used this song https://open.spotify.com/track/2SmBbMM5WuINMebN4CFHOl

spotdl download "https://open.spotify.com/track/2SmBbMM5WuINMebN4CFHOl" --print-errors

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

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

Disclosure: AI (Cursor) was used to help make this fix but I have manually reviewed all code and manually tested. Also my First PR on this, read the contributing md however I'm not super familar with the project so there might be a better way to solve this issue.

… crashing

When downloading large playlists or liked songs, if a track has been
removed from Spotify (duration_ms == 0 or empty name), reinit_song
raises SongError which propagates unhandled and crashes the entire
batch download. This leaves all remaining songs in the queue unprocessed.

Wrap the reinit_song call in a try/except for SongError so that
unavailable tracks are logged, added to the error list, and skipped
gracefully while the rest of the playlist continues downloading.

Made-with: Cursor
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