From 11e6323e410c693ad0a3d849a7354b5b6e70bf07 Mon Sep 17 00:00:00 2001 From: Footsiefat <12180913+Footsiefat@users.noreply.github.com> Date: Thu, 14 Oct 2021 17:50:55 +1300 Subject: [PATCH] Patched a bug which stopped some playlists from downloading Sometimes the spotify playlist API query will return None for some song id's which crashed my program further down the pipeline, fixed by added filter to skip those tracks. --- zspotify.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/zspotify.py b/zspotify.py index 5db13fca..7b56d0fa 100644 --- a/zspotify.py +++ b/zspotify.py @@ -45,7 +45,7 @@ def wait(seconds: int = 3): time.sleep(1) def sanitizeData(value): - return value.replace("\\", "").replace("/", "") + return value.replace("\\", "").replace("/", "").replace(":", "").replace("*", "").replace("?", "").replace("'", "").replace("<", "").replace(">", "") def splash(): print("=================================\n" @@ -211,8 +211,9 @@ def search(searchTerm): playlistChoice = playlists[position - totalTracks - totalAlbums - 1] playlistSongs = get_playlist_songs(token, playlistChoice['id']) for song in playlistSongs: - downloadTrack(song['track']['id'], sanitizeData(playlistChoice['name'].strip()) + "/") - print("\n") + if song['track']['id'] != None: + downloadTrack(song['track']['id'], sanitizeData(playlistChoice['name'].strip()) + "/") + print("\n") def getSongInfo(songId): token = session.tokens().get("user-read-email") @@ -422,8 +423,8 @@ def downloadFromOurPlaylists(): playlistChoice = input("SELECT A PLAYLIST BY ID: ") playlistSongs = get_playlist_songs(token, playlists[int(playlistChoice) - 1]['id']) for song in playlistSongs: - - downloadTrack(song['track']['id'], sanitizeData(playlists[int(playlistChoice) - 1]['name'].strip()) + "/") + if song['track']['id'] != None: + downloadTrack(song['track']['id'], sanitizeData(playlists[int(playlistChoice) - 1]['name'].strip()) + "/") print("\n")