Added playlist cover download, even when not saved as compilation
Added %explicit% to playlist folder template This fixes #41
This commit is contained in:
parent
f47f4b4979
commit
e478e5b031
|
@ -593,38 +593,42 @@ def downloadTrackObj(dz, trackAPI, settings, bitrate, queueItem, extraTrack=None
|
||||||
'error': "Track is not available in Reality Audio 360."})
|
'error': "Track is not available in Reality Audio 360."})
|
||||||
return result
|
return result
|
||||||
track['selectedFormat'] = format
|
track['selectedFormat'] = format
|
||||||
if settings['tags']['savePlaylistAsCompilation'] and "_EXTRA_PLAYLIST" in trackAPI:
|
if "_EXTRA_PLAYLIST" in trackAPI:
|
||||||
|
track['playlist'] = {}
|
||||||
if 'dzcdn.net' in trackAPI["_EXTRA_PLAYLIST"]['picture_small']:
|
if 'dzcdn.net' in trackAPI["_EXTRA_PLAYLIST"]['picture_small']:
|
||||||
track['album']['picUrl'] = trackAPI["_EXTRA_PLAYLIST"]['picture_small'][:-24] + "/{}x{}-{}".format(
|
track['playlist']['picUrl'] = trackAPI["_EXTRA_PLAYLIST"]['picture_small'][:-24] + "/{}x{}-{}".format(
|
||||||
settings['embeddedArtworkSize'], settings['embeddedArtworkSize'],
|
settings['embeddedArtworkSize'], settings['embeddedArtworkSize'],
|
||||||
'none-100-0-0.png' if settings['PNGcovers'] else f'000000-{settings["jpegImageQuality"]}-0-0.jpg')
|
'none-100-0-0.png' if settings['PNGcovers'] else f'000000-{settings["jpegImageQuality"]}-0-0.jpg')
|
||||||
else:
|
else:
|
||||||
track['album']['picUrl'] = trackAPI["_EXTRA_PLAYLIST"]['picture_xl']
|
track['playlist']['picUrl'] = trackAPI["_EXTRA_PLAYLIST"]['picture_xl']
|
||||||
track['album']['title'] = trackAPI["_EXTRA_PLAYLIST"]['title']
|
track['playlist']['title'] = trackAPI["_EXTRA_PLAYLIST"]['title']
|
||||||
track['album']['mainArtist'] = {
|
track['playlist']['mainArtist'] = {
|
||||||
'id': trackAPI["_EXTRA_PLAYLIST"]['various_artist']['id'],
|
'id': trackAPI["_EXTRA_PLAYLIST"]['various_artist']['id'],
|
||||||
'name': trackAPI["_EXTRA_PLAYLIST"]['various_artist']['name'],
|
'name': trackAPI["_EXTRA_PLAYLIST"]['various_artist']['name'],
|
||||||
'pic': trackAPI["_EXTRA_PLAYLIST"]['various_artist']['picture_small'][
|
'pic': trackAPI["_EXTRA_PLAYLIST"]['various_artist']['picture_small'][
|
||||||
trackAPI["_EXTRA_PLAYLIST"]['various_artist']['picture_small'].find('artist/') + 7:-24]
|
trackAPI["_EXTRA_PLAYLIST"]['various_artist']['picture_small'].find('artist/') + 7:-24]
|
||||||
}
|
}
|
||||||
if settings['albumVariousArtists']:
|
if settings['albumVariousArtists']:
|
||||||
track['album']['artist'] = {"Main": [trackAPI["_EXTRA_PLAYLIST"]['various_artist']['name'], ]}
|
track['playlist']['artist'] = {"Main": [trackAPI["_EXTRA_PLAYLIST"]['various_artist']['name'], ]}
|
||||||
track['album']['artists'] = [trackAPI["_EXTRA_PLAYLIST"]['various_artist']['name'], ]
|
track['playlist']['artists'] = [trackAPI["_EXTRA_PLAYLIST"]['various_artist']['name'], ]
|
||||||
else:
|
else:
|
||||||
track['album']['artist'] = {"Main": []}
|
track['playlist']['artist'] = {"Main": []}
|
||||||
track['album']['artists'] = []
|
track['playlist']['artists'] = []
|
||||||
track['trackNumber'] = trackAPI["POSITION"]
|
track['trackNumber'] = trackAPI["POSITION"]
|
||||||
track['album']['trackTotal'] = trackAPI["_EXTRA_PLAYLIST"]['nb_tracks']
|
track['playlist']['trackTotal'] = trackAPI["_EXTRA_PLAYLIST"]['nb_tracks']
|
||||||
track['album']['recordType'] = "Compilation"
|
track['playlist']['recordType'] = "Compilation"
|
||||||
track['album']['barcode'] = ""
|
track['playlist']['barcode'] = ""
|
||||||
track['album']['label'] = ""
|
track['playlist']['label'] = ""
|
||||||
track['album']['date'] = {
|
track['playlist']['explicit'] = trackAPI['_EXTRA_PLAYLIST']['explicit']
|
||||||
|
track['playlist']['date'] = {
|
||||||
'day': trackAPI["_EXTRA_PLAYLIST"]["creation_date"][8:10],
|
'day': trackAPI["_EXTRA_PLAYLIST"]["creation_date"][8:10],
|
||||||
'month': trackAPI["_EXTRA_PLAYLIST"]["creation_date"][5:7],
|
'month': trackAPI["_EXTRA_PLAYLIST"]["creation_date"][5:7],
|
||||||
'year': trackAPI["_EXTRA_PLAYLIST"]["creation_date"][0:4]
|
'year': trackAPI["_EXTRA_PLAYLIST"]["creation_date"][0:4]
|
||||||
}
|
}
|
||||||
track['discNumber'] = "1"
|
track['discNumber'] = "1"
|
||||||
track['album']['discTotal'] = "1"
|
track['playlist']['discTotal'] = "1"
|
||||||
|
if settings['tags']['savePlaylistAsCompilation'] and "playlist" in track:
|
||||||
|
track['album'] = {**track['album'], **track['playlist']}
|
||||||
else:
|
else:
|
||||||
if 'date' in track['album']:
|
if 'date' in track['album']:
|
||||||
track['date'] = track['album']['date']
|
track['date'] = track['album']['date']
|
||||||
|
@ -728,6 +732,18 @@ def downloadTrackObj(dz, trackAPI, settings, bitrate, queueItem, extraTrack=None
|
||||||
if extrasPath:
|
if extrasPath:
|
||||||
result['extrasPath'] = extrasPath
|
result['extrasPath'] = extrasPath
|
||||||
result['playlistPosition'] = writepath[len(extrasPath):]
|
result['playlistPosition'] = writepath[len(extrasPath):]
|
||||||
|
if "playlist" in track:
|
||||||
|
if 'dzcdn.net' in track['playlist']['picUrl']:
|
||||||
|
result['playlistURL'] = track['playlist']['picUrl'].replace(
|
||||||
|
f"{settings['embeddedArtworkSize']}x{settings['embeddedArtworkSize']}",
|
||||||
|
f"{settings['localArtworkSize']}x{settings['localArtworkSize']}")
|
||||||
|
else:
|
||||||
|
result['playlistURL'] = track['playlist']['picUrl']
|
||||||
|
track['playlist']['id'] = "pl_" + str(trackAPI['_EXTRA_PLAYLIST']['id'])
|
||||||
|
track['playlist']['genre'] = ["Compilation", ]
|
||||||
|
track['playlist']['bitrate'] = format
|
||||||
|
track['playlist']['dateString'] = formatDate(track['playlist']['date'], settings['dateFormat'])
|
||||||
|
result['playlistCover'] = f"{settingsRegexAlbum(settings['coverImageTemplate'], track['playlist'], settings, trackAPI['_EXTRA_PLAYLIST'])}.{'png' if settings['PNGcovers'] else 'jpg'}"
|
||||||
|
|
||||||
track['downloadUrl'] = dz.get_track_stream_url(track['id'], track['MD5'], track['mediaVersion'],
|
track['downloadUrl'] = dz.get_track_stream_url(track['id'], track['MD5'], track['mediaVersion'],
|
||||||
track['selectedFormat'])
|
track['selectedFormat'])
|
||||||
|
@ -895,6 +911,8 @@ def download(dz, queueItem, interface=None):
|
||||||
def after_download(tracks, settings, queueItem):
|
def after_download(tracks, settings, queueItem):
|
||||||
extrasPath = None
|
extrasPath = None
|
||||||
playlist = [None] * len(tracks)
|
playlist = [None] * len(tracks)
|
||||||
|
playlistCover = None
|
||||||
|
playlistURL = None
|
||||||
errors = ""
|
errors = ""
|
||||||
searched = ""
|
searched = ""
|
||||||
for index in range(len(tracks)):
|
for index in range(len(tracks)):
|
||||||
|
@ -909,6 +927,9 @@ def after_download(tracks, settings, queueItem):
|
||||||
searched += result['searched'] + "\r\n"
|
searched += result['searched'] + "\r\n"
|
||||||
if not extrasPath and 'extrasPath' in result:
|
if not extrasPath and 'extrasPath' in result:
|
||||||
extrasPath = result['extrasPath']
|
extrasPath = result['extrasPath']
|
||||||
|
if not playlistCover and 'playlistCover' in result:
|
||||||
|
playlistCover = result['playlistCover']
|
||||||
|
playlistURL = result['playlistURL']
|
||||||
if settings['saveArtwork'] and 'albumPath' in result:
|
if settings['saveArtwork'] and 'albumPath' in result:
|
||||||
downloadImage(result['albumURL'], result['albumPath'], settings['overwriteFile'])
|
downloadImage(result['albumURL'], result['albumPath'], settings['overwriteFile'])
|
||||||
if settings['saveArtworkArtist'] and 'artistPath' in result:
|
if settings['saveArtworkArtist'] and 'artistPath' in result:
|
||||||
|
@ -922,6 +943,8 @@ def after_download(tracks, settings, queueItem):
|
||||||
if settings['logErrors'] and errors != "":
|
if settings['logErrors'] and errors != "":
|
||||||
with open(os.path.join(extrasPath, 'errors.txt'), 'wb') as f:
|
with open(os.path.join(extrasPath, 'errors.txt'), 'wb') as f:
|
||||||
f.write(errors.encode('utf-8'))
|
f.write(errors.encode('utf-8'))
|
||||||
|
if settings['saveArtwork'] and playlistCover and not settings['tags']['savePlaylistAsCompilation']:
|
||||||
|
downloadImage(playlistURL, os.path.join(extrasPath, playlistCover), settings['overwriteFile'])
|
||||||
if settings['logSearched'] and searched != "":
|
if settings['logSearched'] and searched != "":
|
||||||
with open(os.path.join(extrasPath, 'searched.txt'), 'wb') as f:
|
with open(os.path.join(extrasPath, 'searched.txt'), 'wb') as f:
|
||||||
f.write(searched.encode('utf-8'))
|
f.write(searched.encode('utf-8'))
|
||||||
|
|
|
@ -187,11 +187,15 @@ def generateQueueItem(dz, sp, url, settings, bitrate=None, albumAPI=None, interf
|
||||||
totalSize = len(playlistTracksAPI)
|
totalSize = len(playlistTracksAPI)
|
||||||
result['collection'] = []
|
result['collection'] = []
|
||||||
for pos, trackAPI in enumerate(playlistTracksAPI, start=1):
|
for pos, trackAPI in enumerate(playlistTracksAPI, start=1):
|
||||||
|
if 'EXPLICIT_TRACK_CONTENT' in trackAPI and 'EXPLICIT_LYRICS_STATUS' in trackAPI['EXPLICIT_TRACK_CONTENT'] and trackAPI['EXPLICIT_TRACK_CONTENT']['EXPLICIT_LYRICS_STATUS'] in [1,4]:
|
||||||
|
playlistAPI['explicit'] = True
|
||||||
trackAPI['_EXTRA_PLAYLIST'] = playlistAPI
|
trackAPI['_EXTRA_PLAYLIST'] = playlistAPI
|
||||||
trackAPI['POSITION'] = pos
|
trackAPI['POSITION'] = pos
|
||||||
trackAPI['SIZE'] = totalSize
|
trackAPI['SIZE'] = totalSize
|
||||||
trackAPI['FILENAME_TEMPLATE'] = settings['playlistTracknameTemplate']
|
trackAPI['FILENAME_TEMPLATE'] = settings['playlistTracknameTemplate']
|
||||||
result['collection'].append(trackAPI)
|
result['collection'].append(trackAPI)
|
||||||
|
if not 'explicit' in playlistAPI:
|
||||||
|
playlistAPI['explicit'] = False
|
||||||
|
|
||||||
elif type == "artist":
|
elif type == "artist":
|
||||||
artistAPI = dz.get_artist(id)
|
artistAPI = dz.get_artist(id)
|
||||||
|
|
|
@ -227,11 +227,15 @@ class SpotifyHelper:
|
||||||
}
|
}
|
||||||
else:
|
else:
|
||||||
deezerTrack = dz.get_track_gw(trackID)
|
deezerTrack = dz.get_track_gw(trackID)
|
||||||
|
if 'EXPLICIT_LYRICS' in deezerTrack and deezerTrack['EXPLICIT_LYRICS'] == "1":
|
||||||
|
playlistAPI['explicit'] = True
|
||||||
deezerTrack['_EXTRA_PLAYLIST'] = playlistAPI
|
deezerTrack['_EXTRA_PLAYLIST'] = playlistAPI
|
||||||
deezerTrack['POSITION'] = pos
|
deezerTrack['POSITION'] = pos
|
||||||
deezerTrack['SIZE'] = totalSize
|
deezerTrack['SIZE'] = totalSize
|
||||||
deezerTrack['FILENAME_TEMPLATE'] = settings['playlistTracknameTemplate']
|
deezerTrack['FILENAME_TEMPLATE'] = settings['playlistTracknameTemplate']
|
||||||
result['collection'].append(deezerTrack)
|
result['collection'].append(deezerTrack)
|
||||||
|
if not 'explicit' in playlistAPI:
|
||||||
|
playlistAPI['explicit'] = False
|
||||||
with open(path.join(self.configFolder, 'spotifyCache.json'), 'w') as spotifyCache:
|
with open(path.join(self.configFolder, 'spotifyCache.json'), 'w') as spotifyCache:
|
||||||
json.dump(cache, spotifyCache)
|
json.dump(cache, spotifyCache)
|
||||||
return result
|
return result
|
||||||
|
|
|
@ -158,8 +158,13 @@ def settingsRegex(filename, track, settings, playlist=None):
|
||||||
def settingsRegexAlbum(foldername, album, settings, playlist=None):
|
def settingsRegexAlbum(foldername, album, settings, playlist=None):
|
||||||
if playlist and settings['tags']['savePlaylistAsCompilation']:
|
if playlist and settings['tags']['savePlaylistAsCompilation']:
|
||||||
foldername = foldername.replace("%album_id%", "pl_" + str(playlist['id']))
|
foldername = foldername.replace("%album_id%", "pl_" + str(playlist['id']))
|
||||||
|
foldername = foldername.replace("%genre%", "Compilation")
|
||||||
else:
|
else:
|
||||||
foldername = foldername.replace("%album_id%", str(album['id']))
|
foldername = foldername.replace("%album_id%", str(album['id']))
|
||||||
|
if len(album['genre']) > 0:
|
||||||
|
foldername = foldername.replace("%genre%", fixName(album['genre'][0], settings['illegalCharacterReplacer']))
|
||||||
|
else:
|
||||||
|
foldername = foldername.replace("%genre%", "Unknown")
|
||||||
foldername = foldername.replace("%album%", fixName(album['title'], settings['illegalCharacterReplacer']))
|
foldername = foldername.replace("%album%", fixName(album['title'], settings['illegalCharacterReplacer']))
|
||||||
foldername = foldername.replace("%artist%",
|
foldername = foldername.replace("%artist%",
|
||||||
fixName(album['mainArtist']['name'], settings['illegalCharacterReplacer']))
|
fixName(album['mainArtist']['name'], settings['illegalCharacterReplacer']))
|
||||||
|
@ -171,10 +176,6 @@ def settingsRegexAlbum(foldername, album, settings, playlist=None):
|
||||||
foldername = foldername.replace("%upc%", album['barcode'])
|
foldername = foldername.replace("%upc%", album['barcode'])
|
||||||
foldername = foldername.replace("%explicit%", "(Explicit)" if album['explicit'] else "")
|
foldername = foldername.replace("%explicit%", "(Explicit)" if album['explicit'] else "")
|
||||||
foldername = foldername.replace("%label%", fixName(album['label'], settings['illegalCharacterReplacer']))
|
foldername = foldername.replace("%label%", fixName(album['label'], settings['illegalCharacterReplacer']))
|
||||||
if len(album['genre']) > 0:
|
|
||||||
foldername = foldername.replace("%genre%", fixName(album['genre'][0], settings['illegalCharacterReplacer']))
|
|
||||||
else:
|
|
||||||
foldername = foldername.replace("%genre%", "Unknown")
|
|
||||||
foldername = foldername.replace("%year%", str(album['date']['year']))
|
foldername = foldername.replace("%year%", str(album['date']['year']))
|
||||||
foldername = foldername.replace("%date%", album['dateString'])
|
foldername = foldername.replace("%date%", album['dateString'])
|
||||||
foldername = foldername.replace("%bitrate%", bitrateLabels[int(album['bitrate'])])
|
foldername = foldername.replace("%bitrate%", bitrateLabels[int(album['bitrate'])])
|
||||||
|
@ -198,6 +199,7 @@ def settingsRegexPlaylist(foldername, playlist, settings):
|
||||||
foldername = foldername.replace("%owner_id%", str(playlist['creator']['id']))
|
foldername = foldername.replace("%owner_id%", str(playlist['creator']['id']))
|
||||||
foldername = foldername.replace("%year%", str(playlist['creation_date'][:4]))
|
foldername = foldername.replace("%year%", str(playlist['creation_date'][:4]))
|
||||||
foldername = foldername.replace("%date%", str(playlist['creation_date'][:10]))
|
foldername = foldername.replace("%date%", str(playlist['creation_date'][:10]))
|
||||||
|
foldername = foldername.replace("%explicit%", "(Explicit)" if playlist['explicit'] else "")
|
||||||
foldername = foldername.replace('\\', pathSep).replace('/', pathSep)
|
foldername = foldername.replace('\\', pathSep).replace('/', pathSep)
|
||||||
return antiDot(fixLongName(foldername))
|
return antiDot(fixLongName(foldername))
|
||||||
|
|
||||||
|
|
2
setup.py
2
setup.py
|
@ -7,7 +7,7 @@ README = (HERE / "README.md").read_text()
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="deemix",
|
name="deemix",
|
||||||
version="1.0.25",
|
version="1.0.26",
|
||||||
description="A barebone deezer downloader library",
|
description="A barebone deezer downloader library",
|
||||||
long_description=README,
|
long_description=README,
|
||||||
long_description_content_type="text/markdown",
|
long_description_content_type="text/markdown",
|
||||||
|
|
Loading…
Reference in New Issue