From dfb29b23973b66b6c3887a9fc0b8d8ad145bfab4 Mon Sep 17 00:00:00 2001 From: RemixDev Date: Sat, 21 Mar 2020 13:47:34 +0100 Subject: [PATCH] Implemented multitagSeparator setting --- deemix/app/downloader.py | 49 ++++++++++++++++++++++++++++++++++++++++ deemix/utils/taggers.py | 12 ++++++++-- 2 files changed, 59 insertions(+), 2 deletions(-) diff --git a/deemix/app/downloader.py b/deemix/app/downloader.py index 913d7df..62f6542 100644 --- a/deemix/app/downloader.py +++ b/deemix/app/downloader.py @@ -266,6 +266,48 @@ def getTrackData(dz, trackAPI_gw, trackAPI = None, albumAPI_gw = None, albumAPI monthTemp = track['album']['date']['month'] track['album']['date']['month'] = track['album']['date']['day'] track['album']['date']['day'] = monthTemp + + # Remove featuring from the title + track['title_clean'] = track['title'] + if "(feat." in track['title_clean'].lower(): + pos = track['title_clean'].lower().find("(feat.") + tempTrack = track['title_clean'][:pos] + if ")" in track['title_clean']: + tempTrack += track['title_clean'][track['title_clean'].find(")",pos+1)+1:] + track['title_clean'] = tempTrack.strip() + + # Create artists strings + track['mainArtistsString'] = "" + tot = len(track['artist']['Main']) + if tot > 0: + for i, art in enumerate(track['artist']['Main']): + track['mainArtistsString'] += art + if tot != i+1: + if tot-1 == i+1: + track['mainArtistsString'] += " & " + else: + track['mainArtistsString'] += ", " + else: + track['mainArtistsString'] = track['mainArtist']['name'] + tot = len(track['artist']['Featured']) + if tot > 0: + track['featArtistsString'] = "feat. " + for i, art in enumerate(track['artist']['Featured']): + track['featArtistsString'] += art + if tot != i+1: + if tot-1 == i+1: + track['featArtistsString'] += " & " + else: + track['featArtistsString'] += ", " + + # Create title with feat + if "(feat." in track['title'].lower(): + track['title_feat'] = track['title'] + elif len(artists['Featured'])>0: + track['title_feat'] = track['title']+" ({})".format(track['featArtistsString']) + else: + track['title_feat'] = track['title'] + return track def downloadTrackObj(dz, trackAPI, settings, overwriteBitrate=False, extraTrack=None): @@ -333,6 +375,13 @@ def downloadTrackObj(dz, trackAPI, settings, overwriteBitrate=False, extraTrack= result['extrasPath'] = extrasPath result['playlistPosition'] = writepath[len(extrasPath):] + # Generate artist tag if needed + if settings['multitagSeparator'] != "default": + if settings['multitagSeparator'] == "andFeat": + track['artistsString'] = track['mainArtistsString'] + " " + track['featArtistsString'] + else: + track['artistsString'] = settings['multitagSeparator'].join(track[artists]) + track['downloadUrl'] = dz.get_track_stream_url(track['id'], track['MD5'], track['mediaVersion'], track['selectedFormat']) try: with open(writepath, 'wb') as stream: diff --git a/deemix/utils/taggers.py b/deemix/utils/taggers.py index 3722686..b54d86e 100644 --- a/deemix/utils/taggers.py +++ b/deemix/utils/taggers.py @@ -13,7 +13,11 @@ def tagID3(stream, track, save, id3v1=False, nullSeparator=True): if save['title']: tag.add(TIT2(text=track['title'])) if save['artist']: - tag.add(TPE1(text=track['artists'])) + if 'artistsString' in track: + tag.add(TPE1(text=track['artistsString'])) + tag.add(TXXX(desc="ARTISTS", text=track['artists'])) + else: + tag.add(TPE1(text=track['artists'])) if save['album']: tag.add(TALB(text=track['album']['title'])) if save['albumArtist']: @@ -67,7 +71,11 @@ def tagFLAC(stream, track, save): if save['title']: tag["TITLE"] = track['title'] if save['artist']: - tag["ARTIST"] = track['artists'] + if 'artistsString' in track: + tag["ARTIST"] = track['artistsString'] + tag["ARTISTS"] = track['artists'] + else: + tag["ARTIST"] = track['artists'] if save['album']: tag["ALBUM"] = track['album']['title'] if save['albumArtist']: