From 5103380cf54f6e211bcb7130172e9f3cf6c12245 Mon Sep 17 00:00:00 2001 From: RemixDev Date: Fri, 25 Sep 2020 20:24:35 +0200 Subject: [PATCH] Cleaned up playlsit section in track.py --- deemix/app/downloadjob.py | 23 +++++++++++++++----- deemix/app/track.py | 46 +++++++++++++++++++-------------------- 2 files changed, 40 insertions(+), 29 deletions(-) diff --git a/deemix/app/downloadjob.py b/deemix/app/downloadjob.py index 5e8e204..e77d4f5 100644 --- a/deemix/app/downloadjob.py +++ b/deemix/app/downloadjob.py @@ -298,6 +298,15 @@ class DownloadJob: track.trackNumber = track.position track.discNumber = "1" track.album = {**track.album, **track.playlist} + if 'picType' in track.playlist: + track.playlist['picUrl'] = "https://e-cdns-images.dzcdn.net/images/{}/{}/{}x{}-{}".format( + track.playlist['picType'], + track.playlist['pic'], + self.settings['embeddedArtworkSize'], self.settings['embeddedArtworkSize'], + 'none-100-0-0.png' if self.settings['embeddedArtworkPNG'] else f'000000-{self.settings["jpegImageQuality"]}-0-0.jpg' + ) + else: + track.playlist['picUrl'] = track.playlist['pic'] ext = track.playlist['picUrl'][-4:] if ext[0] != ".": ext = ".jpg" @@ -373,14 +382,15 @@ class DownloadJob: for format in self.settings['localArtworkFormat'].split(","): if format in ["png","jpg"]: if self.settings['tags']['savePlaylistAsCompilation'] and track.playlist: - if track.playlist['pic']: - url = "{}/{}x{}-{}".format( + if track.playlist['picType']: + url = "https://e-cdns-images.dzcdn.net/images/{}/{}/{}x{}-{}".format( + track.album['picType'], track.album['pic'], self.settings['localArtworkSize'], self.settings['localArtworkSize'], 'none-100-0-0.png' if format == "png" else f'000000-{self.settings["jpegImageQuality"]}-0-0.jpg' ) else: - url = track.album['picUrl'] + url = track.album['pic'] if format != "jpg": continue else: @@ -456,17 +466,18 @@ class DownloadJob: # Save playlist cover if track.playlist: if not len(self.playlistURLs): - if track.playlist['pic']: + if track.playlist['picType']: for format in self.settings['localArtworkFormat'].split(","): if format in ["png","jpg"]: - url = "{}/{}x{}-{}".format( + url = "https://e-cdns-images.dzcdn.net/images/{}/{}/{}x{}-{}".format( + track.playlist['picType'], track.playlist['pic'], self.settings['localArtworkSize'], self.settings['localArtworkSize'], 'none-100-0-0.png' if format == "png" else f'000000-{self.settings["jpegImageQuality"]}-0-0.jpg' ) self.playlistURLs.append({'url': url, 'ext': format}) else: - self.playlistURLs.append({'url': track.playlist['picUrl'], 'ext': 'jpg'}) + self.playlistURLs.append({'url': track.playlist['pic'], 'ext': 'jpg'}) if not self.playlistPath: track.playlist['id'] = "pl_" + str(trackAPI_gw['_EXTRA_PLAYLIST']['id']) track.playlist['genre'] = ["Compilation", ] diff --git a/deemix/app/track.py b/deemix/app/track.py index 4b35d49..6ee6d69 100644 --- a/deemix/app/track.py +++ b/deemix/app/track.py @@ -41,7 +41,7 @@ class Track: # Add playlist data if track is in a playlist self.playlist = None if "_EXTRA_PLAYLIST" in trackAPI_gw: - self.parsePlaylistData() + self.parsePlaylistData(trackAPI_gw["_EXTRA_PLAYLIST"], settings) self.generateMainFeatStrings() @@ -280,6 +280,7 @@ class Track: 'month': albumAPI_gw["PHYSICAL_RELEASE_DATE"][5:7], 'year': albumAPI_gw["PHYSICAL_RELEASE_DATE"][0:4] } + self.album['picType'] = 'cover' isAlbumArtistVariousArtists = self.album['mainArtist']['id'] == VARIOUS_ARTISTS self.album['mainArtist']['save'] = not isAlbumArtistVariousArtists or settings['albumVariousArtists'] and isAlbumArtistVariousArtists @@ -331,40 +332,39 @@ class Track: albumAPI_gw = dz.get_album_gw(self.album['id']) self.copyright = albumAPI_gw['COPYRIGHT'] - def parsePlaylistData(self): + def parsePlaylistData(self, playlist, settings): self.playlist = {} - if 'dzcdn.net' in trackAPI_gw["_EXTRA_PLAYLIST"]['picture_small']: - self.playlist['pic'] = trackAPI_gw["_EXTRA_PLAYLIST"]['picture_small'][:-24] - self.playlist['picUrl'] = "{}/{}x{}-{}".format( - self.playlist['pic'], - settings['embeddedArtworkSize'], settings['embeddedArtworkSize'], - 'none-100-0-0.png' if settings['embeddedArtworkPNG'] else f'000000-{settings["jpegImageQuality"]}-0-0.jpg' - ) + if 'dzcdn.net' in playlist['picture_small']: + url = playlist['picture_small'] + picType = url[url.find('images/')+7:] + picType = picType[:picType.find('/')] + self.playlist['pic'] = url[url.find(picType+'/') + len(picType)+1:-24] + self.playlist['picType'] = picType else: - self.playlist['pic'] = None - self.playlist['picUrl'] = trackAPI_gw["_EXTRA_PLAYLIST"]['picture_xl'] - self.playlist['title'] = trackAPI_gw["_EXTRA_PLAYLIST"]['title'] + self.playlist['pic'] = playlist['picture_xl'] + self.playlist['picType'] = None + self.playlist['title'] = playlist['title'] self.playlist['mainArtist'] = { - 'id': trackAPI_gw["_EXTRA_PLAYLIST"]['various_artist']['id'], - 'name': trackAPI_gw["_EXTRA_PLAYLIST"]['various_artist']['name'], - 'pic': trackAPI_gw["_EXTRA_PLAYLIST"]['various_artist']['picture_small'][ - trackAPI_gw["_EXTRA_PLAYLIST"]['various_artist']['picture_small'].find('artist/') + 7:-24] + 'id': playlist['various_artist']['id'], + 'name': playlist['various_artist']['name'], + 'pic': playlist['various_artist']['picture_small'][ + playlist['various_artist']['picture_small'].find('artist/') + 7:-24] } if settings['albumVariousArtists']: - self.playlist['artist'] = {"Main": [trackAPI_gw["_EXTRA_PLAYLIST"]['various_artist']['name'], ]} - self.playlist['artists'] = [trackAPI_gw["_EXTRA_PLAYLIST"]['various_artist']['name'], ] + self.playlist['artist'] = {"Main": [playlist['various_artist']['name'], ]} + self.playlist['artists'] = [playlist['various_artist']['name'], ] else: self.playlist['artist'] = {"Main": []} self.playlist['artists'] = [] - self.playlist['trackTotal'] = trackAPI_gw["_EXTRA_PLAYLIST"]['nb_tracks'] + self.playlist['trackTotal'] = playlist['nb_tracks'] self.playlist['recordType'] = "compile" self.playlist['barcode'] = "" self.playlist['label'] = "" - self.playlist['explicit'] = trackAPI_gw['_EXTRA_PLAYLIST']['explicit'] + self.playlist['explicit'] = playlist['explicit'] self.playlist['date'] = { - 'day': trackAPI_gw["_EXTRA_PLAYLIST"]["creation_date"][8:10], - 'month': trackAPI_gw["_EXTRA_PLAYLIST"]["creation_date"][5:7], - 'year': trackAPI_gw["_EXTRA_PLAYLIST"]["creation_date"][0:4] + 'day': playlist["creation_date"][8:10], + 'month': playlist["creation_date"][5:7], + 'year': playlist["creation_date"][0:4] } self.playlist['discTotal'] = "1"