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.
This commit is contained in:
Footsiefat 2021-10-14 17:50:55 +13:00 committed by GitHub
parent 545800a53b
commit 11e6323e41
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -45,7 +45,7 @@ def wait(seconds: int = 3):
time.sleep(1) time.sleep(1)
def sanitizeData(value): def sanitizeData(value):
return value.replace("\\", "").replace("/", "") return value.replace("\\", "").replace("/", "").replace(":", "").replace("*", "").replace("?", "").replace("'", "").replace("<", "").replace(">", "")
def splash(): def splash():
print("=================================\n" print("=================================\n"
@ -211,8 +211,9 @@ def search(searchTerm):
playlistChoice = playlists[position - totalTracks - totalAlbums - 1] playlistChoice = playlists[position - totalTracks - totalAlbums - 1]
playlistSongs = get_playlist_songs(token, playlistChoice['id']) playlistSongs = get_playlist_songs(token, playlistChoice['id'])
for song in playlistSongs: for song in playlistSongs:
downloadTrack(song['track']['id'], sanitizeData(playlistChoice['name'].strip()) + "/") if song['track']['id'] != None:
print("\n") downloadTrack(song['track']['id'], sanitizeData(playlistChoice['name'].strip()) + "/")
print("\n")
def getSongInfo(songId): def getSongInfo(songId):
token = session.tokens().get("user-read-email") token = session.tokens().get("user-read-email")
@ -422,8 +423,8 @@ def downloadFromOurPlaylists():
playlistChoice = input("SELECT A PLAYLIST BY ID: ") playlistChoice = input("SELECT A PLAYLIST BY ID: ")
playlistSongs = get_playlist_songs(token, playlists[int(playlistChoice) - 1]['id']) playlistSongs = get_playlist_songs(token, playlists[int(playlistChoice) - 1]['id'])
for song in playlistSongs: for song in playlistSongs:
if song['track']['id'] != None:
downloadTrack(song['track']['id'], sanitizeData(playlists[int(playlistChoice) - 1]['name'].strip()) + "/") downloadTrack(song['track']['id'], sanitizeData(playlists[int(playlistChoice) - 1]['name'].strip()) + "/")
print("\n") print("\n")