From f893fef7dbd6ea7b381540008f7ccf5031dab7b7 Mon Sep 17 00:00:00 2001 From: RemixDev Date: Thu, 24 Dec 2020 16:28:12 +0100 Subject: [PATCH] Removed necessity to pass `settings` to track constructor --- deemix/app/downloadjob.py | 18 +++++++++- deemix/app/track.py | 74 +++++++++++++++++++-------------------- 2 files changed, 54 insertions(+), 38 deletions(-) diff --git a/deemix/app/downloadjob.py b/deemix/app/downloadjob.py index 95a8e57..3c84da6 100644 --- a/deemix/app/downloadjob.py +++ b/deemix/app/downloadjob.py @@ -252,7 +252,6 @@ class DownloadJob: logger.info(f"[{trackAPI_gw['ART_NAME']} - {trackAPI_gw['SNG_TITLE']}] Getting the tags") try: track = Track(self.dz, - settings=self.settings, trackAPI_gw=trackAPI_gw, trackAPI=trackAPI_gw['_EXTRA_TRACK'] if '_EXTRA_TRACK' in trackAPI_gw else None, albumAPI=trackAPI_gw['_EXTRA_ALBUM'] if '_EXTRA_ALBUM' in trackAPI_gw else None @@ -352,6 +351,23 @@ class DownloadJob: track.album['dateString'] = formatDate(track.album['date'], self.settings['dateFormat']) if track.playlist: track.playlist['dateString'] = formatDate(track.playlist['date'], self.settings['dateFormat']) + # Check various artist option + if self.settings['albumVariousArtists'] and track.album['variousArtists']: + artist = track.album['variousArtists'] + isMainArtist = artist['role'] == "Main" + + if artist['name'] not in track.album['artists']: + track.album['artists'].insert(0, artist['name']) + + if isMainArtist or artist['name'] not in track.album['artist']['Main'] and not isMainArtist: + if not artist['role'] in track.album['artist']: + track.album['artist'][artist['role']] = [] + track.album['artist'][artist['role']].insert(0, artist['name']) + track.album['mainArtist']['save'] = not track.album['mainArtist']['isVariousArtists'] or self.settings['albumVariousArtists'] and track.album['mainArtist']['isVariousArtists'] + + # Check removeDuplicateArtists + if self.settings['removeDuplicateArtists']: track.removeDuplicateArtists() + # Check if user wants the feat in the title if str(self.settings['featuredToTitle']) == FeaturesOption.REMOVE_TITLE: track.title = track.getCleanTitle() diff --git a/deemix/app/track.py b/deemix/app/track.py index f24961c..b99358d 100644 --- a/deemix/app/track.py +++ b/deemix/app/track.py @@ -13,7 +13,7 @@ logger = logging.getLogger('deemix') VARIOUS_ARTISTS = 5080 class Track: - def __init__(self, dz, settings, trackAPI_gw, trackAPI=None, albumAPI_gw=None, albumAPI=None): + def __init__(self, dz, trackAPI_gw, trackAPI=None, albumAPI_gw=None, albumAPI=None): self.parseEssentialData(dz, trackAPI_gw) self.title = trackAPI_gw['SNG_TITLE'].strip() @@ -26,7 +26,7 @@ class Track: if self.localTrack: self.parseLocalTrackData(trackAPI_gw) else: - self.parseData(dz, settings, trackAPI_gw, trackAPI, albumAPI_gw, albumAPI) + self.parseData(dz, trackAPI_gw, trackAPI, albumAPI_gw, albumAPI) # Make sure there is at least one artist if not 'Main' in self.artist: @@ -45,7 +45,7 @@ class Track: # Add playlist data if track is in a playlist self.playlist = None if "_EXTRA_PLAYLIST" in trackAPI_gw: - self.parsePlaylistData(trackAPI_gw["_EXTRA_PLAYLIST"], settings) + self.parsePlaylistData(trackAPI_gw["_EXTRA_PLAYLIST"]) self.singleDownload = trackAPI_gw.get('SINGLE_TRACK', False) @@ -124,13 +124,12 @@ class Track: self.replayGain = "" self.trackNumber = "0" - def parseData(self, dz, settings, trackAPI_gw, trackAPI, albumAPI_gw, albumAPI): + def parseData(self, dz, trackAPI_gw, trackAPI, albumAPI_gw, albumAPI): self.discNumber = trackAPI_gw.get('DISK_NUMBER') self.explicit = bool(int(trackAPI_gw.get('EXPLICIT_LYRICS', "0"))) self.copyright = trackAPI_gw.get('COPYRIGHT') self.replayGain = "" - if 'GAIN' in trackAPI_gw: - self.replayGain = generateReplayGainString(trackAPI_gw['GAIN']) + if 'GAIN' in trackAPI_gw: self.replayGain = generateReplayGainString(trackAPI_gw['GAIN']) self.ISRC = trackAPI_gw.get('ISRC') self.trackNumber = trackAPI_gw['TRACK_NUMBER'] self.contributors = trackAPI_gw['SNG_CONTRIBUTORS'] @@ -228,23 +227,22 @@ class Track: self.album['artist'] = {} self.album['artists'] = [] + self.album['variousArtists'] = None for artist in albumAPI['contributors']: isVariousArtists = artist['id'] == VARIOUS_ARTISTS isMainArtist = artist['role'] == "Main" - if not isVariousArtists or settings['albumVariousArtists'] and isVariousArtists: - if artist['name'] not in self.album['artists']: - self.album['artists'].append(artist['name']) + if isVariousArtists: + self.album['variousArtists'] = artist + continue - if isMainArtist or artist['name'] not in self.album['artist']['Main'] and not isMainArtist: - if not artist['role'] in self.album['artist']: - self.album['artist'][artist['role']] = [] - self.album['artist'][artist['role']].append(artist['name']) + if artist['name'] not in self.album['artists']: + self.album['artists'].append(artist['name']) - if settings['removeDuplicateArtists']: - self.album['artists'] = uniqueArray(self.album['artists']) - for role in self.album['artist'].keys(): - self.album['artist'][role] = uniqueArray(self.album['artist'][role]) + if isMainArtist or artist['name'] not in self.album['artist']['Main'] and not isMainArtist: + if not artist['role'] in self.album['artist']: + self.album['artist'][artist['role']] = [] + self.album['artist'][artist['role']].append(artist['name']) self.album['trackTotal'] = albumAPI['nb_tracks'] self.album['recordType'] = albumAPI['record_type'] @@ -315,8 +313,7 @@ class Track: 'year': albumAPI_gw["PHYSICAL_RELEASE_DATE"][0:4] } - isAlbumArtistVariousArtists = self.album['mainArtist']['id'] == VARIOUS_ARTISTS - self.album['mainArtist']['save'] = not isAlbumArtistVariousArtists or settings['albumVariousArtists'] and isAlbumArtistVariousArtists + self.album['mainArtist']['isVariousArtists'] = self.album['mainArtist']['id'] == VARIOUS_ARTISTS if self.album['date'] and not self.date: self.date = self.album['date'] @@ -339,19 +336,16 @@ class Track: isVariousArtists = artist['id'] == VARIOUS_ARTISTS isMainArtist = artist['role'] == "Main" - if not isVariousArtists or len(trackAPI['contributors']) == 1 and isVariousArtists: - if artist['name'] not in self.artists: - self.artists.append(artist['name']) + if isVariousArtists or len(trackAPI['contributors']) == 1 and not isVariousArtists: + continue - if isMainArtist or artist['name'] not in self.artist['Main'] and not isMainArtist: - if not artist['role'] in self.artist: - self.artist[artist['role']] = [] - self.artist[artist['role']].append(artist['name']) + if artist['name'] not in self.artists: + self.artists.append(artist['name']) - if settings['removeDuplicateArtists']: - self.artists = uniqueArray(self.artists) - for role in self.artist.keys(): - self.artist[role] = uniqueArray(self.artist[role]) + if isMainArtist or artist['name'] not in self.artist['Main'] and not isMainArtist: + if not artist['role'] in self.artist: + self.artist[artist['role']] = [] + self.artist[artist['role']].append(artist['name']) if not self.album['discTotal']: if not albumAPI_gw: @@ -365,7 +359,7 @@ class Track: albumAPI_gw = dz.gw.get_album(self.album['id']) self.copyright = albumAPI_gw['COPYRIGHT'] - def parsePlaylistData(self, playlist, settings): + def parsePlaylistData(self, playlist): self.playlist = {} if 'dzcdn.net' in playlist['picture_small']: url = playlist['picture_small'] @@ -394,12 +388,9 @@ class Track: } } self.playlist['rootArtist'] = None - if settings['albumVariousArtists']: - self.playlist['artist'] = {"Main": [playlist['various_artist']['name'], ]} - self.playlist['artists'] = [playlist['various_artist']['name'], ] - else: - self.playlist['artist'] = {"Main": []} - self.playlist['artists'] = [] + self.playlist['artist'] = {"Main": []} + self.playlist['artists'] = [] + self.playlist['variousArtists'] = playlist['various_artist'] self.playlist['trackTotal'] = playlist['nb_tracks'] self.playlist['recordType'] = "compile" self.playlist['barcode'] = "" @@ -414,6 +405,15 @@ class Track: self.playlist['playlistId'] = playlist['id'] self.playlist['owner'] = playlist['creator'] + def removeDuplicateArtists(self): + self.artists = uniqueArray(self.artists) + for role in self.artist.keys(): + self.artist[role] = uniqueArray(self.artist[role]) + + self.album['artists'] = uniqueArray(self.album['artists']) + for role in self.album['artist'].keys(): + self.album['artist'][role] = uniqueArray(self.album['artist'][role]) + # Removes featuring from the title def getCleanTitle(self): return removeFeatures(self.title)