Fixed download of spotify playlists with null tracks

This fixes #8
This commit is contained in:
RemixDev 2020-07-30 18:46:34 +02:00
parent 7409fce337
commit e9418c8433
3 changed files with 15 additions and 11 deletions

View File

@ -1,3 +1,3 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
__version__ = "1.1.23" __version__ = "1.1.24"

View File

@ -195,11 +195,15 @@ class SpotifyHelper:
'cover'] = "https://e-cdns-images.dzcdn.net/images/cover/d41d8cd98f00b204e9800998ecf8427e/75x75-000000-80-0-0.jpg" 'cover'] = "https://e-cdns-images.dzcdn.net/images/cover/d41d8cd98f00b204e9800998ecf8427e/75x75-000000-80-0-0.jpg"
playlistAPI = self._convert_playlist_structure(spotify_playlist) playlistAPI = self._convert_playlist_structure(spotify_playlist)
playlistAPI['various_artist'] = dz.get_artist(5080) playlistAPI['various_artist'] = dz.get_artist(5080)
tracklist = spotify_playlist['tracks']['items'] tracklistTmp = spotify_playlist['tracks']['items']
result['collection'] = [] result['collection'] = []
tracklist = []
while spotify_playlist['tracks']['next']: while spotify_playlist['tracks']['next']:
spotify_playlist['tracks'] = self.sp.next(spotify_playlist['tracks']) 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) totalSize = len(tracklist)
if path.isfile(path.join(self.configFolder, 'spotifyCache.json')): if path.isfile(path.join(self.configFolder, 'spotifyCache.json')):
with open(path.join(self.configFolder, 'spotifyCache.json'), 'r') as spotifyCache: with open(path.join(self.configFolder, 'spotifyCache.json'), 'r') as spotifyCache:
@ -207,23 +211,23 @@ class SpotifyHelper:
else: else:
cache = {'tracks': {}, 'albums': {}} cache = {'tracks': {}, 'albums': {}}
for pos, track in enumerate(tracklist, start=1): for pos, track in enumerate(tracklist, start=1):
if str(track['track']['id']) in cache['tracks']: if str(track['id']) in cache['tracks']:
trackID = cache['tracks'][str(track['track']['id'])] trackID = cache['tracks'][str(track['id'])]
else: else:
trackID = self.get_trackid_spotify(dz, 0, settings['fallbackSearch'], track['track']) trackID = self.get_trackid_spotify(dz, 0, settings['fallbackSearch'], track)
cache['tracks'][str(track['track']['id'])] = trackID cache['tracks'][str(track['id'])] = trackID
if trackID == 0: if trackID == 0:
deezerTrack = { deezerTrack = {
'SNG_ID': 0, 'SNG_ID': 0,
'SNG_TITLE': track['track']['name'], 'SNG_TITLE': track['name'],
'DURATION': 0, 'DURATION': 0,
'MD5_ORIGIN': 0, 'MD5_ORIGIN': 0,
'MEDIA_VERSION': 0, 'MEDIA_VERSION': 0,
'FILESIZE': 0, 'FILESIZE': 0,
'ALB_TITLE': track['track']['album']['name'], 'ALB_TITLE': track['album']['name'],
'ALB_PICTURE': "", 'ALB_PICTURE': "",
'ART_ID': 0, 'ART_ID': 0,
'ART_NAME': track['track']['artists'][0]['name'] 'ART_NAME': track['artists'][0]['name']
} }
else: else:
deezerTrack = dz.get_track_gw(trackID) deezerTrack = dz.get_track_gw(trackID)

View File

@ -7,7 +7,7 @@ README = (HERE / "README.md").read_text()
setup( setup(
name="deemix", name="deemix",
version="1.1.23", version="1.1.24",
description="A barebone deezer downloader library", description="A barebone deezer downloader library",
long_description=README, long_description=README,
long_description_content_type="text/markdown", long_description_content_type="text/markdown",