From 42e55b3f06fced952c0213f724b275e35fb50452 Mon Sep 17 00:00:00 2001 From: RemixDev Date: Wed, 10 Jun 2020 19:47:57 +0200 Subject: [PATCH] Added playlistFilenameTemplate setting Variables are: %title%, %artist%, %size%, %type%, %id%, %bitrate% --- deemix/app/default.json | 1 + deemix/app/downloader.py | 7 ++++--- deemix/utils/pathtemplates.py | 19 +++++++++++++++---- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/deemix/app/default.json b/deemix/app/default.json index 95c5fd7..a1ca69f 100644 --- a/deemix/app/default.json +++ b/deemix/app/default.json @@ -24,6 +24,7 @@ "saveDownloadQueue": false, "overwriteFile": "n", "createM3U8File": false, + "playlistFilenameTemplate": "playlist", "syncedLyrics": false, "embeddedArtworkSize": 800, "localArtworkSize": 1400, diff --git a/deemix/app/downloader.py b/deemix/app/downloader.py index dbc733a..0ac1002 100644 --- a/deemix/app/downloader.py +++ b/deemix/app/downloader.py @@ -13,7 +13,7 @@ from requests.exceptions import HTTPError, ConnectionError from deemix.api.deezer import APIError, USER_AGENT_HEADER from deemix.utils.misc import changeCase -from deemix.utils.pathtemplates import generateFilename, generateFilepath, settingsRegexAlbum, settingsRegexArtist +from deemix.utils.pathtemplates import generateFilename, generateFilepath, settingsRegexAlbum, settingsRegexArtist, settingsRegexPlaylistFile from deemix.utils.taggers import tagID3, tagFLAC import logging @@ -894,10 +894,11 @@ def after_download(tracks, settings, queueItem): f.write(searched.encode('utf-8')) chmod(os.path.join(extrasPath, 'searched.txt'), 0o770) if settings['createM3U8File']: - with open(os.path.join(extrasPath, 'playlist.m3u8'), 'wb') as f: + filename = settingsRegexPlaylistFile(settings['playlistFilenameTemplate'], queueItem, settings) or "playlist" + with open(os.path.join(extrasPath, filename+'.m3u8'), 'wb') as f: for line in playlist: f.write((line + "\n").encode('utf-8')) - chmod(os.path.join(extrasPath, 'playlist.m3u8'), 0o770) + chmod(os.path.join(extrasPath, filename+'.m3u8'), 0o770) if settings['executeCommand'] != "": execute(settings['executeCommand'].replace("%folder%", extrasPath)) return extrasPath diff --git a/deemix/utils/pathtemplates.py b/deemix/utils/pathtemplates.py index 885c8cd..6e47641 100644 --- a/deemix/utils/pathtemplates.py +++ b/deemix/utils/pathtemplates.py @@ -94,7 +94,8 @@ def generateFilepath(track, trackAPI, settings): '_EXTRA_PLAYLIST' in trackAPI and settings['createStructurePlaylist'])) ): filepath += antiDot( - settingsRegexAlbum(settings['albumNameTemplate'], track['album'], settings, trackAPI)) + pathSep + settingsRegexAlbum(settings['albumNameTemplate'], track['album'], settings, + trackAPI['_EXTRA_PLAYLIST'] if'_EXTRA_PLAYLIST' in trackAPI else None)) + pathSep coverPath = filepath if not ('_EXTRA_PLAYLIST' in trackAPI and not settings['tags']['savePlaylistAsCompilation']): @@ -154,9 +155,9 @@ def settingsRegex(filename, track, settings, playlist=None): return antiDot(fixLongName(filename)) -def settingsRegexAlbum(foldername, album, settings, trackAPI): - if trackAPI and '_EXTRA_PLAYLIST' in trackAPI and settings['tags']['savePlaylistAsCompilation']: - foldername = foldername.replace("%album_id%", "pl_" + str(trackAPI['_EXTRA_PLAYLIST']['id'])) +def settingsRegexAlbum(foldername, album, settings, playlist=None): + if playlist and settings['tags']['savePlaylistAsCompilation']: + foldername = foldername.replace("%album_id%", "pl_" + str(playlist['id'])) else: foldername = foldername.replace("%album_id%", str(album['id'])) foldername = foldername.replace("%album%", fixName(album['title'], settings['illegalCharacterReplacer'])) @@ -199,3 +200,13 @@ def settingsRegexPlaylist(foldername, playlist, settings): foldername = foldername.replace("%date%", str(playlist['creation_date'][:10])) foldername = foldername.replace('\\', pathSep).replace('/', pathSep) return antiDot(fixLongName(foldername)) + +def settingsRegexPlaylistFile(foldername, queueItem, settings): + foldername = foldername.replace("%title%", fixName(queueItem['title'], settings['illegalCharacterReplacer'])) + foldername = foldername.replace("%artist%", fixName(queueItem['artist'], settings['illegalCharacterReplacer'])) + foldername = foldername.replace("%size%", str(queueItem['size'])) + foldername = foldername.replace("%type%", fixName(queueItem['type'], settings['illegalCharacterReplacer'])) + foldername = foldername.replace("%id%", fixName(queueItem['id'], settings['illegalCharacterReplacer'])) + foldername = foldername.replace("%bitrate%", bitrateLabels[int(queueItem['bitrate'])]) + foldername = foldername.replace('\\', pathSep).replace('/', pathSep).replace(pathSep, settings['illegalCharacterReplacer']) + return antiDot(fixLongName(foldername))