From 03e0396ac08b8d04c221b381c499ff533be31be4 Mon Sep 17 00:00:00 2001 From: Johan Lindbergh <238111+jlindbergh@users.noreply.github.com> Date: Thu, 13 Feb 2025 22:50:00 +0100 Subject: [PATCH] Add another check to the spotify track sanity filter (#111) Discovered a crash when syncing a playlist with some random podcast episode. It crashed because both ['artists'][0]['name'] and ['album']['artists'][0]['name'] was None. I thought the episode would be caught by the track_filter, but apparently having the 'type': 'episode' isn't reliable enough :/ Not sure if the check should be in the sanity_filter or any of the _search_for... methods though. --- src/spotify_to_tidal/sync.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/spotify_to_tidal/sync.py b/src/spotify_to_tidal/sync.py index 1f2e403..4494dbf 100755 --- a/src/spotify_to_tidal/sync.py +++ b/src/spotify_to_tidal/sync.py @@ -184,7 +184,11 @@ async def get_tracks_from_spotify_playlist(spotify_session: spotipy.Spotify, spo print(f"Loading tracks from Spotify playlist '{spotify_playlist['name']}'") items = await repeat_on_request_error( _fetch_all_from_spotify_in_chunks, lambda offset: _get_tracks_from_spotify_playlist(offset=offset, playlist_id=spotify_playlist["id"])) track_filter = lambda item: item.get('type', 'track') == 'track' # type may be 'episode' also - sanity_filter = lambda item: 'album' in item and 'name' in item['album'] and 'artists' in item['album'] and len(item['album']['artists']) > 0 + sanity_filter = lambda item: ('album' in item + and 'name' in item['album'] + and 'artists' in item['album'] + and len(item['album']['artists']) > 0 + and item['album']['artists'][0]['name'] is not None) return list(filter(sanity_filter, filter(track_filter, items))) def populate_track_match_cache(spotify_tracks_: Sequence[t_spotify.SpotifyTrack], tidal_tracks_: Sequence[tidalapi.Track]):