Handle SongError in reinit_song to skip unavailable tracks instead of crashing#2625
Open
cpaczek wants to merge 1 commit intospotDL:masterfrom
Open
Handle SongError in reinit_song to skip unavailable tracks instead of crashing#2625cpaczek wants to merge 1 commit intospotDL:masterfrom
cpaczek wants to merge 1 commit intospotDL:masterfrom
Conversation
… 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-errorsTypes of Changes
Checklist
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.