Made settings more compatible with deezloader

This commit is contained in:
RemixDev 2020-02-22 12:59:42 +01:00
parent c0f419e1be
commit a4e4ecdb98
3 changed files with 91 additions and 45 deletions

View File

@ -1,36 +1,63 @@
{ {
"pathSettings": { "downloadLocation": "",
"downloadLocation": "" "tracknameTemplate": "%artist% - %title%",
}, "albumTracknameTemplate": "%number% - %title%",
"appSettings": { "playlistTracknameTemplate": "%position% - %artist% - %title%",
"maxBitrate": 3 "playlistNameTemplate": "%name%",
}, "artistNameTemplate": "",
"taggingSettings": { "albumNameTemplate": "%artist% - %album%",
"artworkSize": 800, "createCDFolder": true,
"tags": { "createStructurePlaylist": false,
"title": true, "createSingleFolder": false,
"artist": true, "saveFullArtists": false,
"album": true, "padTrack": true,
"cover": true, "paddingSize": "0",
"trackNumber": true, "illegalCharacterReplacer": "_",
"trackTotal": false, "queueConcurrency": 3,
"discNumber": true, "maxBitrate": "3",
"discTotal": false, "fallbackBitrate": true,
"albumArtist": true, "fallbackSearch": true,
"genre": true, "logErrors": false,
"year": true, "logSearched": false,
"date": true, "createM3U8File": false,
"explicit": false, "syncedLyrics": false,
"isrc": true, "embeddedArtworkSize": 800,
"length": false, "localArtworkSize": 1000,
"barcode": false, "coverImageTemplate": "",
"bpm": true, "artistImageTemplate": "",
"replayGain": false, "multitagSeparator": "default",
"label": true, "dateFormat": "0",
"lyrics": false, "dateFormatYear": "4",
"copyright": false, "savePlaylistAsCompilation": false,
"composer": false, "removeAlbumVersion": false,
"involvedPeople": false "moveFeaturedToTitle": false,
} "useNullSeparator": false,
"saveID3v1": true,
"titleCasing": "nothing",
"artistCasing": "nothing",
"tags": {
"title": true,
"artist": true,
"album": true,
"cover": true,
"trackNumber": true,
"trackTotal": false,
"discNumber": true,
"discTotal": false,
"albumArtist": true,
"genre": true,
"year": true,
"date": true,
"explicit": false,
"isrc": true,
"length": false,
"barcode": false,
"bpm": true,
"replayGain": false,
"label": true,
"lyrics": false,
"copyright": false,
"composer": false,
"involvedPeople": false
} }
} }

View File

@ -188,7 +188,7 @@ def downloadTrackObj(trackAPI, settings, overwriteBitrate=False):
if overwriteBitrate: if overwriteBitrate:
bitrate = overwriteBitrate bitrate = overwriteBitrate
else: else:
bitrate = settings['appSettings']['maxBitrate'] bitrate = settings['maxBitrate']
bitrateFound = False; bitrateFound = False;
if int(bitrate) == 9: if int(bitrate) == 9:
track['selectedFormat'] = 9 track['selectedFormat'] = 9
@ -217,21 +217,21 @@ def downloadTrackObj(trackAPI, settings, overwriteBitrate=False):
track['selectedFormat'] = 8 track['selectedFormat'] = 8
track['selectedFilesize'] = track['filesize']['default'] track['selectedFilesize'] = track['filesize']['default']
track['album']['bitrate'] = track['selectedFormat'] track['album']['bitrate'] = track['selectedFormat']
track['album']['picUrl'] = "http://e-cdn-images.deezer.com/images/cover/{}/{}x{}-000000-80-0-0.jpg".format(track['album']['pic'], settings['taggingSettings']['artworkSize'], settings['taggingSettings']['artworkSize']) track['album']['picUrl'] = "http://e-cdn-images.deezer.com/images/cover/{}/{}x{}-000000-80-0-0.jpg".format(track['album']['pic'], settings['embeddedArtworkSize'], settings['embeddedArtworkSize'])
# Create the filename # Create the filename
filename = "{artist} - {title}".format(title=track['title'], artist=track['mainArtist']['name']) + extensions[ filename = "{artist} - {title}".format(title=track['title'], artist=track['mainArtist']['name']) + extensions[
track['selectedFormat']] track['selectedFormat']]
writepath = os.path.join(settings['pathSettings']['downloadLocation'], filename) writepath = os.path.join(settings['downloadLocation'], filename)
track['downloadUrl'] = dz.get_track_stream_url(track['id'], track['MD5'], track['mediaVersion'], track['downloadUrl'] = dz.get_track_stream_url(track['id'], track['MD5'], track['mediaVersion'],
track['selectedFormat']) track['selectedFormat'])
with open(writepath, 'wb') as stream: with open(writepath, 'wb') as stream:
dz.stream_track(track['id'], track['downloadUrl'], stream) dz.stream_track(track['id'], track['downloadUrl'], stream)
if track['selectedFormat'] in [3, 1, 8]: if track['selectedFormat'] in [3, 1, 8]:
tagID3(writepath, track, settings['taggingSettings']['tags']) tagID3(writepath, track, settings['tags'])
elif track['selectedFormat'] == 9: elif track['selectedFormat'] == 9:
tagFLAC(writepath, track, settings['taggingSettings']['tags']) tagFLAC(writepath, track, settings['tags'])
def download_track(id, settings, overwriteBitrate=False): def download_track(id, settings, overwriteBitrate=False):
trackAPI = dz.get_track_gw(id) trackAPI = dz.get_track_gw(id)

View File

@ -6,23 +6,27 @@ import json
import deemix.utils.localpaths as localpaths import deemix.utils.localpaths as localpaths
settings = {} settings = {}
defaultSettings = {}
def initSettings(): def initSettings():
global settings global settings
global defaultSettings
currentFolder = path.abspath(path.dirname(__file__)) currentFolder = path.abspath(path.dirname(__file__))
if not path.isdir(localpaths.getConfigFolder()):
mkdir(localpaths.getConfigFolder())
configFolder = localpaths.getConfigFolder() configFolder = localpaths.getConfigFolder()
if not path.isdir(configFolder):
mkdir(configFolder)
with open(path.join(currentFolder, 'default.json'), 'r') as d:
defaultSettings = json.load(d)
if not path.isfile(path.join(configFolder, 'config.json')): if not path.isfile(path.join(configFolder, 'config.json')):
with open(path.join(configFolder, 'config.json'), 'w') as f: with open(path.join(configFolder, 'config.json'), 'w') as f:
with open(path.join(currentFolder, 'default.json'), 'r') as d: f.write(json.dumps(defaultSettings))
f.write(d.read())
with open(path.join(configFolder, 'config.json'), 'r') as configFile: with open(path.join(configFolder, 'config.json'), 'r') as configFile:
settings = json.load(configFile) settings = json.load(configFile)
if settings['pathSettings']['downloadLocation'] == "": settingsCheck()
settings['pathSettings']['downloadLocation'] = path.join(localpaths.getHomeFolder(), 'deemix Music') if settings['downloadLocation'] == "":
settings['downloadLocation'] = path.join(localpaths.getHomeFolder(), 'deemix Music')
saveSettings(settings) saveSettings(settings)
if not path.isdir(settings['pathSettings']['downloadLocation']): if not path.isdir(settings['downloadLocation']):
mkdir(settings['pathSettings']['downloadLocation']) mkdir(settings['pathSettings']['downloadLocation'])
return settings return settings
@ -36,3 +40,18 @@ def saveSettings(newSettings):
with open(path.join(localpaths.getConfigFolder(), 'config.json'), 'w') as configFile: with open(path.join(localpaths.getConfigFolder(), 'config.json'), 'w') as configFile:
json.dump(settings, configFile) json.dump(settings, configFile)
return True return True
def settingsCheck():
global settings
global defaultSettings
changes = 0
for x in defaultSettings:
if not x in settings or type(settings[x]) != type(defaultSettings[x]):
settings[x] = defaultSettings[x]
changes+=1
for x in defaultSettings['tags']:
if not x in settings['tags'] or type(settings['tags'][x]) != type(defaultSettings['tags'][x]):
settings['tags'][x] = defaultSettings['tags'][x]
changes+=1
if changes > 0:
saveSettings(settings)