Cleaned up playlsit section in track.py

This commit is contained in:
RemixDev 2020-09-25 20:24:35 +02:00
parent 0c71827ba9
commit 5103380cf5
2 changed files with 40 additions and 29 deletions

View File

@ -298,6 +298,15 @@ class DownloadJob:
track.trackNumber = track.position track.trackNumber = track.position
track.discNumber = "1" track.discNumber = "1"
track.album = {**track.album, **track.playlist} 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:] ext = track.playlist['picUrl'][-4:]
if ext[0] != ".": if ext[0] != ".":
ext = ".jpg" ext = ".jpg"
@ -373,14 +382,15 @@ class DownloadJob:
for format in self.settings['localArtworkFormat'].split(","): for format in self.settings['localArtworkFormat'].split(","):
if format in ["png","jpg"]: if format in ["png","jpg"]:
if self.settings['tags']['savePlaylistAsCompilation'] and track.playlist: if self.settings['tags']['savePlaylistAsCompilation'] and track.playlist:
if track.playlist['pic']: if track.playlist['picType']:
url = "{}/{}x{}-{}".format( url = "https://e-cdns-images.dzcdn.net/images/{}/{}/{}x{}-{}".format(
track.album['picType'],
track.album['pic'], track.album['pic'],
self.settings['localArtworkSize'], self.settings['localArtworkSize'], self.settings['localArtworkSize'], self.settings['localArtworkSize'],
'none-100-0-0.png' if format == "png" else f'000000-{self.settings["jpegImageQuality"]}-0-0.jpg' 'none-100-0-0.png' if format == "png" else f'000000-{self.settings["jpegImageQuality"]}-0-0.jpg'
) )
else: else:
url = track.album['picUrl'] url = track.album['pic']
if format != "jpg": if format != "jpg":
continue continue
else: else:
@ -456,17 +466,18 @@ class DownloadJob:
# Save playlist cover # Save playlist cover
if track.playlist: if track.playlist:
if not len(self.playlistURLs): if not len(self.playlistURLs):
if track.playlist['pic']: if track.playlist['picType']:
for format in self.settings['localArtworkFormat'].split(","): for format in self.settings['localArtworkFormat'].split(","):
if format in ["png","jpg"]: if format in ["png","jpg"]:
url = "{}/{}x{}-{}".format( url = "https://e-cdns-images.dzcdn.net/images/{}/{}/{}x{}-{}".format(
track.playlist['picType'],
track.playlist['pic'], track.playlist['pic'],
self.settings['localArtworkSize'], self.settings['localArtworkSize'], self.settings['localArtworkSize'], self.settings['localArtworkSize'],
'none-100-0-0.png' if format == "png" else f'000000-{self.settings["jpegImageQuality"]}-0-0.jpg' 'none-100-0-0.png' if format == "png" else f'000000-{self.settings["jpegImageQuality"]}-0-0.jpg'
) )
self.playlistURLs.append({'url': url, 'ext': format}) self.playlistURLs.append({'url': url, 'ext': format})
else: else:
self.playlistURLs.append({'url': track.playlist['picUrl'], 'ext': 'jpg'}) self.playlistURLs.append({'url': track.playlist['pic'], 'ext': 'jpg'})
if not self.playlistPath: if not self.playlistPath:
track.playlist['id'] = "pl_" + str(trackAPI_gw['_EXTRA_PLAYLIST']['id']) track.playlist['id'] = "pl_" + str(trackAPI_gw['_EXTRA_PLAYLIST']['id'])
track.playlist['genre'] = ["Compilation", ] track.playlist['genre'] = ["Compilation", ]

View File

@ -41,7 +41,7 @@ class Track:
# Add playlist data if track is in a playlist # Add playlist data if track is in a playlist
self.playlist = None self.playlist = None
if "_EXTRA_PLAYLIST" in trackAPI_gw: if "_EXTRA_PLAYLIST" in trackAPI_gw:
self.parsePlaylistData() self.parsePlaylistData(trackAPI_gw["_EXTRA_PLAYLIST"], settings)
self.generateMainFeatStrings() self.generateMainFeatStrings()
@ -280,6 +280,7 @@ class Track:
'month': albumAPI_gw["PHYSICAL_RELEASE_DATE"][5:7], 'month': albumAPI_gw["PHYSICAL_RELEASE_DATE"][5:7],
'year': albumAPI_gw["PHYSICAL_RELEASE_DATE"][0:4] 'year': albumAPI_gw["PHYSICAL_RELEASE_DATE"][0:4]
} }
self.album['picType'] = 'cover'
isAlbumArtistVariousArtists = self.album['mainArtist']['id'] == VARIOUS_ARTISTS isAlbumArtistVariousArtists = self.album['mainArtist']['id'] == VARIOUS_ARTISTS
self.album['mainArtist']['save'] = not isAlbumArtistVariousArtists or settings['albumVariousArtists'] and isAlbumArtistVariousArtists 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']) albumAPI_gw = dz.get_album_gw(self.album['id'])
self.copyright = albumAPI_gw['COPYRIGHT'] self.copyright = albumAPI_gw['COPYRIGHT']
def parsePlaylistData(self): def parsePlaylistData(self, playlist, settings):
self.playlist = {} self.playlist = {}
if 'dzcdn.net' in trackAPI_gw["_EXTRA_PLAYLIST"]['picture_small']: if 'dzcdn.net' in playlist['picture_small']:
self.playlist['pic'] = trackAPI_gw["_EXTRA_PLAYLIST"]['picture_small'][:-24] url = playlist['picture_small']
self.playlist['picUrl'] = "{}/{}x{}-{}".format( picType = url[url.find('images/')+7:]
self.playlist['pic'], picType = picType[:picType.find('/')]
settings['embeddedArtworkSize'], settings['embeddedArtworkSize'], self.playlist['pic'] = url[url.find(picType+'/') + len(picType)+1:-24]
'none-100-0-0.png' if settings['embeddedArtworkPNG'] else f'000000-{settings["jpegImageQuality"]}-0-0.jpg' self.playlist['picType'] = picType
)
else: else:
self.playlist['pic'] = None self.playlist['pic'] = playlist['picture_xl']
self.playlist['picUrl'] = trackAPI_gw["_EXTRA_PLAYLIST"]['picture_xl'] self.playlist['picType'] = None
self.playlist['title'] = trackAPI_gw["_EXTRA_PLAYLIST"]['title'] self.playlist['title'] = playlist['title']
self.playlist['mainArtist'] = { self.playlist['mainArtist'] = {
'id': trackAPI_gw["_EXTRA_PLAYLIST"]['various_artist']['id'], 'id': playlist['various_artist']['id'],
'name': trackAPI_gw["_EXTRA_PLAYLIST"]['various_artist']['name'], 'name': playlist['various_artist']['name'],
'pic': trackAPI_gw["_EXTRA_PLAYLIST"]['various_artist']['picture_small'][ 'pic': playlist['various_artist']['picture_small'][
trackAPI_gw["_EXTRA_PLAYLIST"]['various_artist']['picture_small'].find('artist/') + 7:-24] playlist['various_artist']['picture_small'].find('artist/') + 7:-24]
} }
if settings['albumVariousArtists']: if settings['albumVariousArtists']:
self.playlist['artist'] = {"Main": [trackAPI_gw["_EXTRA_PLAYLIST"]['various_artist']['name'], ]} self.playlist['artist'] = {"Main": [playlist['various_artist']['name'], ]}
self.playlist['artists'] = [trackAPI_gw["_EXTRA_PLAYLIST"]['various_artist']['name'], ] self.playlist['artists'] = [playlist['various_artist']['name'], ]
else: else:
self.playlist['artist'] = {"Main": []} self.playlist['artist'] = {"Main": []}
self.playlist['artists'] = [] self.playlist['artists'] = []
self.playlist['trackTotal'] = trackAPI_gw["_EXTRA_PLAYLIST"]['nb_tracks'] self.playlist['trackTotal'] = playlist['nb_tracks']
self.playlist['recordType'] = "compile" self.playlist['recordType'] = "compile"
self.playlist['barcode'] = "" self.playlist['barcode'] = ""
self.playlist['label'] = "" self.playlist['label'] = ""
self.playlist['explicit'] = trackAPI_gw['_EXTRA_PLAYLIST']['explicit'] self.playlist['explicit'] = playlist['explicit']
self.playlist['date'] = { self.playlist['date'] = {
'day': trackAPI_gw["_EXTRA_PLAYLIST"]["creation_date"][8:10], 'day': playlist["creation_date"][8:10],
'month': trackAPI_gw["_EXTRA_PLAYLIST"]["creation_date"][5:7], 'month': playlist["creation_date"][5:7],
'year': trackAPI_gw["_EXTRA_PLAYLIST"]["creation_date"][0:4] 'year': playlist["creation_date"][0:4]
} }
self.playlist['discTotal'] = "1" self.playlist['discTotal'] = "1"