Removed necessity to pass `settings` to track constructor
This commit is contained in:
parent
16e45dd013
commit
f893fef7db
|
@ -252,7 +252,6 @@ class DownloadJob:
|
||||||
logger.info(f"[{trackAPI_gw['ART_NAME']} - {trackAPI_gw['SNG_TITLE']}] Getting the tags")
|
logger.info(f"[{trackAPI_gw['ART_NAME']} - {trackAPI_gw['SNG_TITLE']}] Getting the tags")
|
||||||
try:
|
try:
|
||||||
track = Track(self.dz,
|
track = Track(self.dz,
|
||||||
settings=self.settings,
|
|
||||||
trackAPI_gw=trackAPI_gw,
|
trackAPI_gw=trackAPI_gw,
|
||||||
trackAPI=trackAPI_gw['_EXTRA_TRACK'] if '_EXTRA_TRACK' in trackAPI_gw else None,
|
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
|
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'])
|
track.album['dateString'] = formatDate(track.album['date'], self.settings['dateFormat'])
|
||||||
if track.playlist: track.playlist['dateString'] = formatDate(track.playlist['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
|
# Check if user wants the feat in the title
|
||||||
if str(self.settings['featuredToTitle']) == FeaturesOption.REMOVE_TITLE:
|
if str(self.settings['featuredToTitle']) == FeaturesOption.REMOVE_TITLE:
|
||||||
track.title = track.getCleanTitle()
|
track.title = track.getCleanTitle()
|
||||||
|
|
|
@ -13,7 +13,7 @@ logger = logging.getLogger('deemix')
|
||||||
VARIOUS_ARTISTS = 5080
|
VARIOUS_ARTISTS = 5080
|
||||||
|
|
||||||
class Track:
|
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.parseEssentialData(dz, trackAPI_gw)
|
||||||
|
|
||||||
self.title = trackAPI_gw['SNG_TITLE'].strip()
|
self.title = trackAPI_gw['SNG_TITLE'].strip()
|
||||||
|
@ -26,7 +26,7 @@ class Track:
|
||||||
if self.localTrack:
|
if self.localTrack:
|
||||||
self.parseLocalTrackData(trackAPI_gw)
|
self.parseLocalTrackData(trackAPI_gw)
|
||||||
else:
|
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
|
# Make sure there is at least one artist
|
||||||
if not 'Main' in self.artist:
|
if not 'Main' in self.artist:
|
||||||
|
@ -45,7 +45,7 @@ class Track:
|
||||||
# Add playlist data if track is in a playlist
|
# Add playlist data if track is in a playlist
|
||||||
self.playlist = None
|
self.playlist = None
|
||||||
if "_EXTRA_PLAYLIST" in trackAPI_gw:
|
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)
|
self.singleDownload = trackAPI_gw.get('SINGLE_TRACK', False)
|
||||||
|
|
||||||
|
@ -124,13 +124,12 @@ class Track:
|
||||||
self.replayGain = ""
|
self.replayGain = ""
|
||||||
self.trackNumber = "0"
|
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.discNumber = trackAPI_gw.get('DISK_NUMBER')
|
||||||
self.explicit = bool(int(trackAPI_gw.get('EXPLICIT_LYRICS', "0")))
|
self.explicit = bool(int(trackAPI_gw.get('EXPLICIT_LYRICS', "0")))
|
||||||
self.copyright = trackAPI_gw.get('COPYRIGHT')
|
self.copyright = trackAPI_gw.get('COPYRIGHT')
|
||||||
self.replayGain = ""
|
self.replayGain = ""
|
||||||
if 'GAIN' in trackAPI_gw:
|
if 'GAIN' in trackAPI_gw: self.replayGain = generateReplayGainString(trackAPI_gw['GAIN'])
|
||||||
self.replayGain = generateReplayGainString(trackAPI_gw['GAIN'])
|
|
||||||
self.ISRC = trackAPI_gw.get('ISRC')
|
self.ISRC = trackAPI_gw.get('ISRC')
|
||||||
self.trackNumber = trackAPI_gw['TRACK_NUMBER']
|
self.trackNumber = trackAPI_gw['TRACK_NUMBER']
|
||||||
self.contributors = trackAPI_gw['SNG_CONTRIBUTORS']
|
self.contributors = trackAPI_gw['SNG_CONTRIBUTORS']
|
||||||
|
@ -228,23 +227,22 @@ class Track:
|
||||||
|
|
||||||
self.album['artist'] = {}
|
self.album['artist'] = {}
|
||||||
self.album['artists'] = []
|
self.album['artists'] = []
|
||||||
|
self.album['variousArtists'] = None
|
||||||
for artist in albumAPI['contributors']:
|
for artist in albumAPI['contributors']:
|
||||||
isVariousArtists = artist['id'] == VARIOUS_ARTISTS
|
isVariousArtists = artist['id'] == VARIOUS_ARTISTS
|
||||||
isMainArtist = artist['role'] == "Main"
|
isMainArtist = artist['role'] == "Main"
|
||||||
|
|
||||||
if not isVariousArtists or settings['albumVariousArtists'] and isVariousArtists:
|
if isVariousArtists:
|
||||||
if artist['name'] not in self.album['artists']:
|
self.album['variousArtists'] = artist
|
||||||
self.album['artists'].append(artist['name'])
|
continue
|
||||||
|
|
||||||
if isMainArtist or artist['name'] not in self.album['artist']['Main'] and not isMainArtist:
|
if artist['name'] not in self.album['artists']:
|
||||||
if not artist['role'] in self.album['artist']:
|
self.album['artists'].append(artist['name'])
|
||||||
self.album['artist'][artist['role']] = []
|
|
||||||
self.album['artist'][artist['role']].append(artist['name'])
|
|
||||||
|
|
||||||
if settings['removeDuplicateArtists']:
|
if isMainArtist or artist['name'] not in self.album['artist']['Main'] and not isMainArtist:
|
||||||
self.album['artists'] = uniqueArray(self.album['artists'])
|
if not artist['role'] in self.album['artist']:
|
||||||
for role in self.album['artist'].keys():
|
self.album['artist'][artist['role']] = []
|
||||||
self.album['artist'][role] = uniqueArray(self.album['artist'][role])
|
self.album['artist'][artist['role']].append(artist['name'])
|
||||||
|
|
||||||
self.album['trackTotal'] = albumAPI['nb_tracks']
|
self.album['trackTotal'] = albumAPI['nb_tracks']
|
||||||
self.album['recordType'] = albumAPI['record_type']
|
self.album['recordType'] = albumAPI['record_type']
|
||||||
|
@ -315,8 +313,7 @@ class Track:
|
||||||
'year': albumAPI_gw["PHYSICAL_RELEASE_DATE"][0:4]
|
'year': albumAPI_gw["PHYSICAL_RELEASE_DATE"][0:4]
|
||||||
}
|
}
|
||||||
|
|
||||||
isAlbumArtistVariousArtists = self.album['mainArtist']['id'] == VARIOUS_ARTISTS
|
self.album['mainArtist']['isVariousArtists'] = self.album['mainArtist']['id'] == VARIOUS_ARTISTS
|
||||||
self.album['mainArtist']['save'] = not isAlbumArtistVariousArtists or settings['albumVariousArtists'] and isAlbumArtistVariousArtists
|
|
||||||
|
|
||||||
if self.album['date'] and not self.date:
|
if self.album['date'] and not self.date:
|
||||||
self.date = self.album['date']
|
self.date = self.album['date']
|
||||||
|
@ -339,19 +336,16 @@ class Track:
|
||||||
isVariousArtists = artist['id'] == VARIOUS_ARTISTS
|
isVariousArtists = artist['id'] == VARIOUS_ARTISTS
|
||||||
isMainArtist = artist['role'] == "Main"
|
isMainArtist = artist['role'] == "Main"
|
||||||
|
|
||||||
if not isVariousArtists or len(trackAPI['contributors']) == 1 and isVariousArtists:
|
if isVariousArtists or len(trackAPI['contributors']) == 1 and not isVariousArtists:
|
||||||
if artist['name'] not in self.artists:
|
continue
|
||||||
self.artists.append(artist['name'])
|
|
||||||
|
|
||||||
if isMainArtist or artist['name'] not in self.artist['Main'] and not isMainArtist:
|
if artist['name'] not in self.artists:
|
||||||
if not artist['role'] in self.artist:
|
self.artists.append(artist['name'])
|
||||||
self.artist[artist['role']] = []
|
|
||||||
self.artist[artist['role']].append(artist['name'])
|
|
||||||
|
|
||||||
if settings['removeDuplicateArtists']:
|
if isMainArtist or artist['name'] not in self.artist['Main'] and not isMainArtist:
|
||||||
self.artists = uniqueArray(self.artists)
|
if not artist['role'] in self.artist:
|
||||||
for role in self.artist.keys():
|
self.artist[artist['role']] = []
|
||||||
self.artist[role] = uniqueArray(self.artist[role])
|
self.artist[artist['role']].append(artist['name'])
|
||||||
|
|
||||||
if not self.album['discTotal']:
|
if not self.album['discTotal']:
|
||||||
if not albumAPI_gw:
|
if not albumAPI_gw:
|
||||||
|
@ -365,7 +359,7 @@ class Track:
|
||||||
albumAPI_gw = dz.gw.get_album(self.album['id'])
|
albumAPI_gw = dz.gw.get_album(self.album['id'])
|
||||||
self.copyright = albumAPI_gw['COPYRIGHT']
|
self.copyright = albumAPI_gw['COPYRIGHT']
|
||||||
|
|
||||||
def parsePlaylistData(self, playlist, settings):
|
def parsePlaylistData(self, playlist):
|
||||||
self.playlist = {}
|
self.playlist = {}
|
||||||
if 'dzcdn.net' in playlist['picture_small']:
|
if 'dzcdn.net' in playlist['picture_small']:
|
||||||
url = playlist['picture_small']
|
url = playlist['picture_small']
|
||||||
|
@ -394,12 +388,9 @@ class Track:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.playlist['rootArtist'] = None
|
self.playlist['rootArtist'] = None
|
||||||
if settings['albumVariousArtists']:
|
self.playlist['artist'] = {"Main": []}
|
||||||
self.playlist['artist'] = {"Main": [playlist['various_artist']['name'], ]}
|
self.playlist['artists'] = []
|
||||||
self.playlist['artists'] = [playlist['various_artist']['name'], ]
|
self.playlist['variousArtists'] = playlist['various_artist']
|
||||||
else:
|
|
||||||
self.playlist['artist'] = {"Main": []}
|
|
||||||
self.playlist['artists'] = []
|
|
||||||
self.playlist['trackTotal'] = playlist['nb_tracks']
|
self.playlist['trackTotal'] = playlist['nb_tracks']
|
||||||
self.playlist['recordType'] = "compile"
|
self.playlist['recordType'] = "compile"
|
||||||
self.playlist['barcode'] = ""
|
self.playlist['barcode'] = ""
|
||||||
|
@ -414,6 +405,15 @@ class Track:
|
||||||
self.playlist['playlistId'] = playlist['id']
|
self.playlist['playlistId'] = playlist['id']
|
||||||
self.playlist['owner'] = playlist['creator']
|
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
|
# Removes featuring from the title
|
||||||
def getCleanTitle(self):
|
def getCleanTitle(self):
|
||||||
return removeFeatures(self.title)
|
return removeFeatures(self.title)
|
||||||
|
|
Loading…
Reference in New Issue