From ff8b6da33ed1f7b7c52d4c9cb4a64ab909487e5e Mon Sep 17 00:00:00 2001 From: RemixDev Date: Sat, 21 Nov 2020 16:45:40 +0100 Subject: [PATCH] Added %root_artist% template variable --- deemix/api/__init__.py | 1 - deemix/app/downloadjob.py | 2 +- deemix/app/queuemanager.py | 15 ++++++++++++--- deemix/app/track.py | 1 + deemix/utils/pathtemplates.py | 19 +++++++++++++++---- 5 files changed, 29 insertions(+), 9 deletions(-) delete mode 100644 deemix/api/__init__.py diff --git a/deemix/api/__init__.py b/deemix/api/__init__.py deleted file mode 100644 index fb5d517..0000000 --- a/deemix/api/__init__.py +++ /dev/null @@ -1 +0,0 @@ -# Empty File diff --git a/deemix/app/downloadjob.py b/deemix/app/downloadjob.py index 61162ed..033df13 100644 --- a/deemix/app/downloadjob.py +++ b/deemix/app/downloadjob.py @@ -447,7 +447,7 @@ class DownloadJob: ) if url: result['artistURLs'].append({'url': url, 'ext': format}) result['artistPath'] = artistPath - result['artistFilename'] = f"{settingsRegexArtist(self.settings['artistImageTemplate'], track.album['mainArtist'], self.settings)}" + result['artistFilename'] = f"{settingsRegexArtist(self.settings['artistImageTemplate'], track.album['mainArtist'], self.settings, rootArtist=track.album['rootArtist'])}" # Remove subfolders from filename and add it to filepath if pathSep in filename: diff --git a/deemix/app/queuemanager.py b/deemix/app/queuemanager.py index f756a26..93ae82e 100644 --- a/deemix/app/queuemanager.py +++ b/deemix/app/queuemanager.py @@ -72,7 +72,7 @@ class QueueManager: single=trackAPI_gw, ) - def generateAlbumQueueItem(self, dz, id, settings, bitrate): + def generateAlbumQueueItem(self, dz, id, settings, bitrate, rootArtist=None): # Get essential album info try: albumAPI = dz.api.get_album(id) @@ -87,6 +87,7 @@ class QueueManager: albumAPI_gw = dz.gw.get_album(id) albumAPI['nb_disk'] = albumAPI_gw['NUMBER_DISK'] albumAPI['copyright'] = albumAPI_gw['COPYRIGHT'] + albumAPI['root_artist'] = rootArtist # If the album is a single download as a track if albumAPI['nb_tracks'] == 1: @@ -185,12 +186,16 @@ class QueueManager: return QueueError("https://deezer.com/artist/"+str(id), f"Wrong URL: {e['type']+': ' if 'type' in e else ''}{e['message'] if 'message' in e else ''}") if interface: interface.send("startAddingArtist", {'name': artistAPI['name'], 'id': artistAPI['id']}) + rootArtist = { + 'id': artistAPI['id'], + 'name': artistAPI['name'] + } artistDiscographyAPI = dz.gw.get_artist_discography_tabs(id, 100) allReleases = artistDiscographyAPI.pop('all', []) albumList = [] for album in allReleases: - albumList.append(self.generateAlbumQueueItem(dz, album['id'], settings, bitrate)) + albumList.append(self.generateAlbumQueueItem(dz, album['id'], settings, bitrate, rootArtist=rootArtist)) if interface: interface.send("finishAddingArtist", {'name': artistAPI['name'], 'id': artistAPI['id']}) return albumList @@ -204,13 +209,17 @@ class QueueManager: return QueueError("https://deezer.com/artist/"+str(id)+"/discography", f"Wrong URL: {e['type']+': ' if 'type' in e else ''}{e['message'] if 'message' in e else ''}") if interface: interface.send("startAddingArtist", {'name': artistAPI['name'], 'id': artistAPI['id']}) + rootArtist = { + 'id': artistAPI['id'], + 'name': artistAPI['name'] + } artistDiscographyAPI = dz.gw.get_artist_discography_tabs(id, 100) artistDiscographyAPI.pop('all', None) # all contains albums and singles, so its all duplicates. This removes them albumList = [] for type in artistDiscographyAPI: for album in artistDiscographyAPI[type]: - albumList.append(self.generateAlbumQueueItem(dz, album['id'], settings, bitrate)) + albumList.append(self.generateAlbumQueueItem(dz, album['id'], settings, bitrate, rootArtist=rootArtist)) if interface: interface.send("finishAddingArtist", {'name': artistAPI['name'], 'id': artistAPI['id']}) return albumList diff --git a/deemix/app/track.py b/deemix/app/track.py index 59b5dd4..eeaf6b1 100644 --- a/deemix/app/track.py +++ b/deemix/app/track.py @@ -204,6 +204,7 @@ class Track: 'name': albumAPI['artist']['name'], 'pic': artistPicture } + self.album['rootArtist'] = albumAPI.get('root_artist', None) self.album['artist'] = {} self.album['artists'] = [] diff --git a/deemix/utils/pathtemplates.py b/deemix/utils/pathtemplates.py index 20a47dc..5e64b11 100644 --- a/deemix/utils/pathtemplates.py +++ b/deemix/utils/pathtemplates.py @@ -85,7 +85,7 @@ def generateFilepath(track, settings): (settings['createArtistFolder'] and track.playlist and settings['tags']['savePlaylistAsCompilation']) or (settings['createArtistFolder'] and track.playlist and settings['createStructurePlaylist']) ): - filepath = filepath / settingsRegexArtist(settings['artistNameTemplate'], track.album['mainArtist'], settings) + filepath = filepath / settingsRegexArtist(settings['artistNameTemplate'], track.album['mainArtist'], settings, rootArtist=track.album['rootArtist']) artistPath = filepath if (settings['createAlbumFolder'] and @@ -168,9 +168,14 @@ def settingsRegexAlbum(foldername, album, settings, playlist=None): else: foldername = foldername.replace("%genre%", "Unknown") foldername = foldername.replace("%album%", fixName(album['title'], settings['illegalCharacterReplacer'])) - foldername = foldername.replace("%artist%", - fixName(album['mainArtist']['name'], settings['illegalCharacterReplacer'])) + foldername = foldername.replace("%artist%", fixName(album['mainArtist']['name'], settings['illegalCharacterReplacer'])) foldername = foldername.replace("%artist_id%", str(album['mainArtist']['id'])) + if album['rootArtist']: + foldername = foldername.replace("%root_artist%", fixName(album['rootArtist']['name'], settings['illegalCharacterReplacer'])) + foldername = foldername.replace("%root_artist_id%", str(album['rootArtist']['id'])) + else: + foldername = foldername.replace("%root_artist%", fixName(album['mainArtist']['name'], settings['illegalCharacterReplacer'])) + foldername = foldername.replace("%root_artist_id%", str(album['mainArtist']['id'])) foldername = foldername.replace("%tracktotal%", str(album['trackTotal'])) foldername = foldername.replace("%disctotal%", str(album['discTotal'])) foldername = foldername.replace("%type%", fixName(album['recordType'].capitalize(), settings['illegalCharacterReplacer'])) @@ -185,9 +190,15 @@ def settingsRegexAlbum(foldername, album, settings, playlist=None): return antiDot(fixLongName(foldername)) -def settingsRegexArtist(foldername, artist, settings): +def settingsRegexArtist(foldername, artist, settings, rootArtist=None): foldername = foldername.replace("%artist%", fixName(artist['name'], settings['illegalCharacterReplacer'])) foldername = foldername.replace("%artist_id%", str(artist['id'])) + if rootArtist: + foldername = foldername.replace("%root_artist%", fixName(rootArtist['name'], settings['illegalCharacterReplacer'])) + foldername = foldername.replace("%root_artist_id%", str(rootArtist['id'])) + else: + foldername = foldername.replace("%root_artist%", fixName(artist['name'], settings['illegalCharacterReplacer'])) + foldername = foldername.replace("%root_artist_id%", str(artist['id'])) foldername = foldername.replace('\\', pathSep).replace('/', pathSep) return antiDot(fixLongName(foldername))