From e9418c84332c5afcc315115df543dd7792472f14 Mon Sep 17 00:00:00 2001 From: RemixDev Date: Thu, 30 Jul 2020 18:46:34 +0200 Subject: [PATCH] Fixed download of spotify playlists with null tracks This fixes #8 --- deemix/__init__.py | 2 +- deemix/app/spotify.py | 22 +++++++++++++--------- setup.py | 2 +- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/deemix/__init__.py b/deemix/__init__.py index 27fa507..f4b8d2b 100644 --- a/deemix/__init__.py +++ b/deemix/__init__.py @@ -1,3 +1,3 @@ #!/usr/bin/env python3 -__version__ = "1.1.23" +__version__ = "1.1.24" diff --git a/deemix/app/spotify.py b/deemix/app/spotify.py index 1fe687d..19d2d70 100644 --- a/deemix/app/spotify.py +++ b/deemix/app/spotify.py @@ -195,11 +195,15 @@ class SpotifyHelper: 'cover'] = "https://e-cdns-images.dzcdn.net/images/cover/d41d8cd98f00b204e9800998ecf8427e/75x75-000000-80-0-0.jpg" playlistAPI = self._convert_playlist_structure(spotify_playlist) playlistAPI['various_artist'] = dz.get_artist(5080) - tracklist = spotify_playlist['tracks']['items'] + tracklistTmp = spotify_playlist['tracks']['items'] result['collection'] = [] + tracklist = [] while spotify_playlist['tracks']['next']: spotify_playlist['tracks'] = self.sp.next(spotify_playlist['tracks']) - tracklist += spotify_playlist['tracks']['items'] + tracklistTmp += spotify_playlist['tracks']['items'] + for item in tracklistTmp: + if item['track']: + tracklist.append(item['track']) totalSize = len(tracklist) if path.isfile(path.join(self.configFolder, 'spotifyCache.json')): with open(path.join(self.configFolder, 'spotifyCache.json'), 'r') as spotifyCache: @@ -207,23 +211,23 @@ class SpotifyHelper: else: cache = {'tracks': {}, 'albums': {}} for pos, track in enumerate(tracklist, start=1): - if str(track['track']['id']) in cache['tracks']: - trackID = cache['tracks'][str(track['track']['id'])] + if str(track['id']) in cache['tracks']: + trackID = cache['tracks'][str(track['id'])] else: - trackID = self.get_trackid_spotify(dz, 0, settings['fallbackSearch'], track['track']) - cache['tracks'][str(track['track']['id'])] = trackID + trackID = self.get_trackid_spotify(dz, 0, settings['fallbackSearch'], track) + cache['tracks'][str(track['id'])] = trackID if trackID == 0: deezerTrack = { 'SNG_ID': 0, - 'SNG_TITLE': track['track']['name'], + 'SNG_TITLE': track['name'], 'DURATION': 0, 'MD5_ORIGIN': 0, 'MEDIA_VERSION': 0, 'FILESIZE': 0, - 'ALB_TITLE': track['track']['album']['name'], + 'ALB_TITLE': track['album']['name'], 'ALB_PICTURE': "", 'ART_ID': 0, - 'ART_NAME': track['track']['artists'][0]['name'] + 'ART_NAME': track['artists'][0]['name'] } else: deezerTrack = dz.get_track_gw(trackID) diff --git a/setup.py b/setup.py index d09bc8b..e137f21 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ README = (HERE / "README.md").read_text() setup( name="deemix", - version="1.1.23", + version="1.1.24", description="A barebone deezer downloader library", long_description=README, long_description_content_type="text/markdown",