diff --git a/deemix/app/default.json b/deemix/app/default.json index 51114d0..b6886d6 100644 --- a/deemix/app/default.json +++ b/deemix/app/default.json @@ -31,7 +31,7 @@ "artistImageTemplate": "folder", "PNGcovers": false, "multitagSeparator": "default", - "dateFormat": "YMD", + "dateFormat": "Y-M-D", "savePlaylistAsCompilation": false, "removeAlbumVersion": false, "moveFeaturedToTitle": false, diff --git a/deemix/app/downloader.py b/deemix/app/downloader.py index 1fa1be6..148c472 100644 --- a/deemix/app/downloader.py +++ b/deemix/app/downloader.py @@ -37,6 +37,23 @@ def downloadImage(url, path): else: return path +def formatDate(date, template): + if 'YYYY' in template: + template = template.replace('YYYY', str(date['year'])) + if 'YY' in template: + template = template.replace('YY', str(date['year'])) + if 'Y' in template: + template = template.replace('Y', str(date['year'])) + if 'MM' in template: + template = template.replace('MM', str(date['month'])) + if 'M' in template: + template = template.replace('M', str(date['month'])) + if 'DD' in template: + template = template.replace('DD', str(date['day'])) + if 'D' in template: + template = template.replace('D', str(date['day'])) + return template + def getPreferredBitrate(filesize, bitrate): formats = {'flac': 9, 'mp3_320': 3, 'mp3_128': 1} @@ -239,6 +256,16 @@ def getTrackData(dz, trackAPI_gw, trackAPI = None, albumAPI_gw = None, albumAPI if not albumAPI_gw: albumAPI_gw = dz.get_album_gw(track['album']['id']) track['copyright'] = albumAPI_gw['COPYRIGHT'] + + # Fix incorrect day month when detectable + if int(track['date']['month']) > 12: + monthTemp = track['date']['month'] + track['date']['month'] = track['date']['day'] + track['date']['day'] = monthTemp + if int(track['album']['date']['month']) > 12: + monthTemp = track['album']['date']['month'] + track['album']['date']['month'] = track['album']['date']['day'] + track['album']['date']['day'] = monthTemp return track def downloadTrackObj(dz, trackAPI, settings, overwriteBitrate=False, extraTrack=None): @@ -272,6 +299,8 @@ def downloadTrackObj(dz, trackAPI, settings, overwriteBitrate=False, extraTrack= track['selectedFilesize'] = filesize track['album']['bitrate'] = format track['album']['picUrl'] = "https://e-cdns-images.dzcdn.net/images/cover/{}/{}x{}-000000-80-0-0.{}".format(track['album']['pic'], settings['embeddedArtworkSize'], settings['embeddedArtworkSize'], 'png' if settings['PNGcovers'] else 'jpg') + track['dateString'] = formatDate(track['date'], settings['dateFormat']) + track['album']['dateString'] = formatDate(track['album']['date'], settings['dateFormat']) # Generate filename and filepath from metadata filename = generateFilename(track, trackAPI, settings) diff --git a/deemix/utils/pathtemplates.py b/deemix/utils/pathtemplates.py index 6a778dc..c7a21f9 100644 --- a/deemix/utils/pathtemplates.py +++ b/deemix/utils/pathtemplates.py @@ -108,7 +108,7 @@ def settingsRegex(filename, track, settings, playlist=None): else: filename = filename.replace("%genre%", "Unknown") filename = filename.replace("%year%", str(track['date']['year'])) - filename = filename.replace("%date%", "{}-{}-{}".format(str(track['date']['year']), str(track['date']['month']), str(track['date']['day']))) + filename = filename.replace("%date%", track['dateString']) filename = filename.replace("%bpm%", str(track['bpm'])) filename = filename.replace("%label%", fixName(track['album']['label'], settings['illegalCharacterReplacer'])) filename = filename.replace("%isrc%", track['ISRC']) @@ -141,7 +141,7 @@ def settingsRegexAlbum(foldername, album, settings): else: foldername = foldername.replace("%genre%", "Unknown") foldername = foldername.replace("%year%", str(album['date']['year'])) - foldername = foldername.replace("%date%", "{}-{}-{}".format(str(album['date']['year']), str(album['date']['month']), str(album['date']['day']))) + foldername = foldername.replace("%date%", album['dateString']) foldername = foldername.replace("%bitrate%", bitrateLabels[int(album['bitrate'])]) foldername = foldername.replace('\\', pathSep).replace('/', pathSep) diff --git a/deemix/utils/taggers.py b/deemix/utils/taggers.py index 655fdaa..3722686 100644 --- a/deemix/utils/taggers.py +++ b/deemix/utils/taggers.py @@ -85,7 +85,7 @@ def tagFLAC(stream, track, save): if save['year']: tag["YEAR"] = str(track['date']['year']) if save['date']: - tag["DATE"] = "{}-{}-{}".format(str(track['date']['year']), str(track['date']['month']), str(track['date']['day'])) + tag["DATE"] = track['dateString'] if save['length']: tag["LENGTH"] = str(track['duration']) if save['bpm']: