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,12 +1,40 @@
{
"pathSettings": {
"downloadLocation": ""
},
"appSettings": {
"maxBitrate": 3
},
"taggingSettings": {
"artworkSize": 800,
"downloadLocation": "",
"tracknameTemplate": "%artist% - %title%",
"albumTracknameTemplate": "%number% - %title%",
"playlistTracknameTemplate": "%position% - %artist% - %title%",
"playlistNameTemplate": "%name%",
"artistNameTemplate": "",
"albumNameTemplate": "%artist% - %album%",
"createCDFolder": true,
"createStructurePlaylist": false,
"createSingleFolder": false,
"saveFullArtists": false,
"padTrack": true,
"paddingSize": "0",
"illegalCharacterReplacer": "_",
"queueConcurrency": 3,
"maxBitrate": "3",
"fallbackBitrate": true,
"fallbackSearch": true,
"logErrors": false,
"logSearched": false,
"createM3U8File": false,
"syncedLyrics": false,
"embeddedArtworkSize": 800,
"localArtworkSize": 1000,
"coverImageTemplate": "",
"artistImageTemplate": "",
"multitagSeparator": "default",
"dateFormat": "0",
"dateFormatYear": "4",
"savePlaylistAsCompilation": false,
"removeAlbumVersion": false,
"moveFeaturedToTitle": false,
"useNullSeparator": false,
"saveID3v1": true,
"titleCasing": "nothing",
"artistCasing": "nothing",
"tags": {
"title": true,
"artist": true,
@ -33,4 +61,3 @@
"involvedPeople": false
}
}
}

View File

@ -188,7 +188,7 @@ def downloadTrackObj(trackAPI, settings, overwriteBitrate=False):
if overwriteBitrate:
bitrate = overwriteBitrate
else:
bitrate = settings['appSettings']['maxBitrate']
bitrate = settings['maxBitrate']
bitrateFound = False;
if int(bitrate) == 9:
track['selectedFormat'] = 9
@ -217,21 +217,21 @@ def downloadTrackObj(trackAPI, settings, overwriteBitrate=False):
track['selectedFormat'] = 8
track['selectedFilesize'] = track['filesize']['default']
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
filename = "{artist} - {title}".format(title=track['title'], artist=track['mainArtist']['name']) + extensions[
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['selectedFormat'])
with open(writepath, 'wb') as stream:
dz.stream_track(track['id'], track['downloadUrl'], stream)
if track['selectedFormat'] in [3, 1, 8]:
tagID3(writepath, track, settings['taggingSettings']['tags'])
tagID3(writepath, track, settings['tags'])
elif track['selectedFormat'] == 9:
tagFLAC(writepath, track, settings['taggingSettings']['tags'])
tagFLAC(writepath, track, settings['tags'])
def download_track(id, settings, overwriteBitrate=False):
trackAPI = dz.get_track_gw(id)

View File

@ -6,23 +6,27 @@ import json
import deemix.utils.localpaths as localpaths
settings = {}
defaultSettings = {}
def initSettings():
global settings
global defaultSettings
currentFolder = path.abspath(path.dirname(__file__))
if not path.isdir(localpaths.getConfigFolder()):
mkdir(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')):
with open(path.join(configFolder, 'config.json'), 'w') as f:
with open(path.join(currentFolder, 'default.json'), 'r') as d:
f.write(d.read())
f.write(json.dumps(defaultSettings))
with open(path.join(configFolder, 'config.json'), 'r') as configFile:
settings = json.load(configFile)
if settings['pathSettings']['downloadLocation'] == "":
settings['pathSettings']['downloadLocation'] = path.join(localpaths.getHomeFolder(), 'deemix Music')
settingsCheck()
if settings['downloadLocation'] == "":
settings['downloadLocation'] = path.join(localpaths.getHomeFolder(), 'deemix Music')
saveSettings(settings)
if not path.isdir(settings['pathSettings']['downloadLocation']):
if not path.isdir(settings['downloadLocation']):
mkdir(settings['pathSettings']['downloadLocation'])
return settings
@ -36,3 +40,18 @@ def saveSettings(newSettings):
with open(path.join(localpaths.getConfigFolder(), 'config.json'), 'w') as configFile:
json.dump(settings, configFile)
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)