Added playlistFilenameTemplate setting

Variables are:
%title%, %artist%, %size%, %type%, %id%, %bitrate%
This commit is contained in:
RemixDev 2020-06-10 19:47:57 +02:00
parent cb4b7b6f63
commit 42e55b3f06
3 changed files with 20 additions and 7 deletions

View File

@ -24,6 +24,7 @@
"saveDownloadQueue": false,
"overwriteFile": "n",
"createM3U8File": false,
"playlistFilenameTemplate": "playlist",
"syncedLyrics": false,
"embeddedArtworkSize": 800,
"localArtworkSize": 1400,

View File

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

View File

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