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.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", ]

View File

@ -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"