Handle settings corruption issue
This commit is contained in:
parent
7e6202b7f0
commit
3b0763eeb1
|
@ -1,5 +1,6 @@
|
|||
from concurrent.futures import ThreadPoolExecutor
|
||||
import json
|
||||
from copy import deepcopy
|
||||
from pathlib import Path
|
||||
import re
|
||||
from urllib.request import urlopen
|
||||
|
@ -309,7 +310,15 @@ class Spotify(Plugin):
|
|||
json.dump({**self.credentials, **self.settings}, f, indent=2)
|
||||
|
||||
with open(self.configFolder / 'settings.json', 'r') as settingsFile:
|
||||
settings = json.load(settingsFile)
|
||||
try:
|
||||
settings = json.load(settingsFile)
|
||||
except json.decoder.JSONDecodeError:
|
||||
with open(self.configFolder / 'settings.json', 'w') as f:
|
||||
json.dump({**self.credentials, **self.settings}, f, indent=2)
|
||||
settings = deepcopy({**self.credentials, **self.settings})
|
||||
except Exception:
|
||||
settings = deepcopy({**self.credentials, **self.settings})
|
||||
|
||||
self.setSettings(settings)
|
||||
self.checkCredentials()
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import json
|
||||
from copy import deepcopy
|
||||
from pathlib import Path
|
||||
from os import makedirs
|
||||
from deezer import TrackFormats
|
||||
|
@ -113,7 +114,13 @@ def load(configFolder=None):
|
|||
|
||||
# Read config file
|
||||
with open(configFolder / 'config.json', 'r') as configFile:
|
||||
settings = json.load(configFile)
|
||||
try:
|
||||
settings = json.load(configFile)
|
||||
except json.decoder.JSONDecodeError:
|
||||
save(DEFAULTS, configFolder)
|
||||
settings = deepcopy(DEFAULTS)
|
||||
except Exception:
|
||||
settings = deepcopy(DEFAULTS)
|
||||
|
||||
if check(settings) > 0: save(settings, configFolder) # Check the settings and save them if something changed
|
||||
return settings
|
||||
|
|
Loading…
Reference in New Issue