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:
sleep(1)
return downloadImage(url, path, overwrite)
remove(path)
if os.path.isfile(path): remove(path)
return None
else:
return path
@ -266,16 +266,19 @@ class DownloadJob:
track.trackNumber = track.position
track.discNumber = "1"
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:
if track.album['date']:
track.date = track.album['date']
track.album['picUrl'] = "https://e-cdns-images.dzcdn.net/images/cover/{}/{}x{}-{}".format(
track.album['pic'],
self.settings['embeddedArtworkSize'], self.settings['embeddedArtworkSize'],
f'000000-{self.settings["jpegImageQuality"]}-0-0.jpg'
)
track.album['picPath'] = os.path.join(TEMPDIR, f"alb{track.album['id']}_{self.settings['embeddedArtworkSize']}.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']}{track.album['picUrl'][-4:]}")
track.album['bitrate'] = selectedFormat
track.dateString = formatDate(track.date, self.settings['dateFormat'])
@ -333,11 +336,23 @@ class DownloadJob:
result['albumURLs'] = []
for format in self.settings['localArtworkFormat'].split(","):
if format in ["png","jpg"]:
url = track.album['picUrl'].replace(
f"{self.settings['embeddedArtworkSize']}x{self.settings['embeddedArtworkSize']}",
f"{self.settings['localArtworkSize']}x{self.settings['localArtworkSize']}")
if format == "png":
url = url[:url.find("000000-")]+"none-100-0-0.png"
if self.settings['tags']['savePlaylistAsCompilation'] and track.playlist:
if track.playlist['pic']:
url = "{}/{}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'
)
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['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)}")
@ -399,14 +414,14 @@ class DownloadJob:
# Save playlist cover
if track.playlist:
if not len(self.playlistURLs):
if 'dzcdn.net' in track.playlist['picUrl']:
if track.playlist['pic']:
for format in self.settings['localArtworkFormat'].split(","):
if format in ["png","jpg"]:
url = track.playlist['picUrl'].replace(
f"{self.settings['embeddedArtworkSize']}x{self.settings['embeddedArtworkSize']}",
f"{self.settings['localArtworkSize']}x{self.settings['localArtworkSize']}")
if format == "png":
url = url[:url.find("000000-")]+"none-100-0-0.png"
url = "{}/{}x{}-{}".format(
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'})

View File

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

View File

@ -41,10 +41,14 @@ class Track:
if "_EXTRA_PLAYLIST" in trackAPI_gw:
self.playlist = {}
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'],
f'000000-{settings["jpegImageQuality"]}-0-0.jpg')
'none-100-0-0.png' if settings['embeddedArtworkPNG'] else f'000000-{settings["jpegImageQuality"]}-0-0.jpg'
)
else:
self.playlist['pic'] = None
self.playlist['picUrl'] = trackAPI_gw["_EXTRA_PLAYLIST"]['picture_xl']
self.playlist['title'] = trackAPI_gw["_EXTRA_PLAYLIST"]['title']
self.playlist['mainArtist'] = {