Added back option to save PNGs as embedded artwork

This commit is contained in:
RemixDev 2020-08-21 14:40:36 +02:00
parent 56ebc0aa0f
commit 240c133d57
3 changed files with 38 additions and 18 deletions

View File

@ -70,7 +70,7 @@ def downloadImage(url, path, overwrite="n"):
except: except:
sleep(1) sleep(1)
return downloadImage(url, path, overwrite) return downloadImage(url, path, overwrite)
remove(path) if os.path.isfile(path): remove(path)
return None return None
else: else:
return path return path
@ -266,16 +266,19 @@ 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}
track.album['picPath'] = os.path.join(TEMPDIR, f"pl{trackAPI_gw['_EXTRA_PLAYLIST']['id']}_{self.settings['embeddedArtworkSize']}.jpg") ext = track.playlist['picUrl'][-4:]
if ext[0] != ".":
ext = ".jpg"
track.album['picPath'] = os.path.join(TEMPDIR, f"pl{trackAPI_gw['_EXTRA_PLAYLIST']['id']}_{self.settings['embeddedArtworkSize']}{ext}")
else: else:
if track.album['date']: if track.album['date']:
track.date = track.album['date'] track.date = track.album['date']
track.album['picUrl'] = "https://e-cdns-images.dzcdn.net/images/cover/{}/{}x{}-{}".format( track.album['picUrl'] = "https://e-cdns-images.dzcdn.net/images/cover/{}/{}x{}-{}".format(
track.album['pic'], track.album['pic'],
self.settings['embeddedArtworkSize'], self.settings['embeddedArtworkSize'], self.settings['embeddedArtworkSize'], self.settings['embeddedArtworkSize'],
f'000000-{self.settings["jpegImageQuality"]}-0-0.jpg' 'none-100-0-0.png' if self.settings['embeddedArtworkPNG'] else f'000000-{self.settings["jpegImageQuality"]}-0-0.jpg'
) )
track.album['picPath'] = os.path.join(TEMPDIR, f"alb{track.album['id']}_{self.settings['embeddedArtworkSize']}.jpg") track.album['picPath'] = os.path.join(TEMPDIR, f"alb{track.album['id']}_{self.settings['embeddedArtworkSize']}{track.album['picUrl'][-4:]}")
track.album['bitrate'] = selectedFormat track.album['bitrate'] = selectedFormat
track.dateString = formatDate(track.date, self.settings['dateFormat']) track.dateString = formatDate(track.date, self.settings['dateFormat'])
@ -333,11 +336,23 @@ class DownloadJob:
result['albumURLs'] = [] result['albumURLs'] = []
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 = track.album['picUrl'].replace( if self.settings['tags']['savePlaylistAsCompilation'] and track.playlist:
f"{self.settings['embeddedArtworkSize']}x{self.settings['embeddedArtworkSize']}", if track.playlist['pic']:
f"{self.settings['localArtworkSize']}x{self.settings['localArtworkSize']}") url = "{}/{}x{}-{}".format(
if format == "png": track.album['pic'],
url = url[:url.find("000000-")]+"none-100-0-0.png" 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']
if format != "jpg":
continue
else:
url = "https://e-cdns-images.dzcdn.net/images/cover/{}/{}x{}-{}".format(
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'
)
result['albumURLs'].append({'url': url, 'ext': format}) result['albumURLs'].append({'url': url, 'ext': format})
result['albumPath'] = os.path.join(coverPath, result['albumPath'] = os.path.join(coverPath,
f"{settingsRegexAlbum(self.settings['coverImageTemplate'], track.album, self.settings, trackAPI_gw['_EXTRA_PLAYLIST'] if'_EXTRA_PLAYLIST' in trackAPI_gw else None)}") f"{settingsRegexAlbum(self.settings['coverImageTemplate'], track.album, self.settings, trackAPI_gw['_EXTRA_PLAYLIST'] if'_EXTRA_PLAYLIST' in trackAPI_gw else None)}")
@ -399,14 +414,14 @@ 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 'dzcdn.net' in track.playlist['picUrl']: if track.playlist['pic']:
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 = track.playlist['picUrl'].replace( url = "{}/{}x{}-{}".format(
f"{self.settings['embeddedArtworkSize']}x{self.settings['embeddedArtworkSize']}", track.playlist['pic'],
f"{self.settings['localArtworkSize']}x{self.settings['localArtworkSize']}") self.settings['localArtworkSize'], self.settings['localArtworkSize'],
if format == "png": 'none-100-0-0.png' if format == "png" else f'000000-{self.settings["jpegImageQuality"]}-0-0.jpg'
url = url[:url.find("000000-")]+"none-100-0-0.png" )
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['picUrl'], 'ext': 'jpg'})

View File

@ -47,6 +47,7 @@ class Settings:
"playlistFilenameTemplate": "playlist", "playlistFilenameTemplate": "playlist",
"syncedLyrics": False, "syncedLyrics": False,
"embeddedArtworkSize": 800, "embeddedArtworkSize": 800,
"embeddedArtworkPNG": False,
"localArtworkSize": 1400, "localArtworkSize": 1400,
"localArtworkFormat": "jpg", "localArtworkFormat": "jpg",
"saveArtwork": True, "saveArtwork": True,

View File

@ -41,10 +41,14 @@ class Track:
if "_EXTRA_PLAYLIST" in trackAPI_gw: if "_EXTRA_PLAYLIST" in trackAPI_gw:
self.playlist = {} self.playlist = {}
if 'dzcdn.net' in trackAPI_gw["_EXTRA_PLAYLIST"]['picture_small']: if 'dzcdn.net' in trackAPI_gw["_EXTRA_PLAYLIST"]['picture_small']:
self.playlist['picUrl'] = trackAPI_gw["_EXTRA_PLAYLIST"]['picture_small'][:-24] + "/{}x{}-{}".format( self.playlist['pic'] = trackAPI_gw["_EXTRA_PLAYLIST"]['picture_small'][:-24]
self.playlist['picUrl'] = "{}/{}x{}-{}".format(
self.playlist['pic'],
settings['embeddedArtworkSize'], settings['embeddedArtworkSize'], settings['embeddedArtworkSize'], settings['embeddedArtworkSize'],
f'000000-{settings["jpegImageQuality"]}-0-0.jpg') 'none-100-0-0.png' if settings['embeddedArtworkPNG'] else f'000000-{settings["jpegImageQuality"]}-0-0.jpg'
)
else: else:
self.playlist['pic'] = None
self.playlist['picUrl'] = trackAPI_gw["_EXTRA_PLAYLIST"]['picture_xl'] self.playlist['picUrl'] = trackAPI_gw["_EXTRA_PLAYLIST"]['picture_xl']
self.playlist['title'] = trackAPI_gw["_EXTRA_PLAYLIST"]['title'] self.playlist['title'] = trackAPI_gw["_EXTRA_PLAYLIST"]['title']
self.playlist['mainArtist'] = { self.playlist['mainArtist'] = {