Update config files automatically; #46

This commit is contained in:
nathom 2021-04-16 14:24:59 -07:00
parent c115eae15f
commit b7659a39cf
2 changed files with 34 additions and 20 deletions

View file

@ -114,6 +114,13 @@ class Config:
else: else:
self.load() self.load()
def update(self):
self.reset()
temp = copy.deepcopy(self.defaults)
temp['qobuz'] = self.file['qobuz']
temp['tidal'] = self.file['tidal']
self.dump(temp)
def save(self): def save(self):
"""Save the config state to file.""" """Save the config state to file."""
@ -181,7 +188,7 @@ class Config:
return self.qobuz_creds return self.qobuz_creds
if source == "tidal": if source == "tidal":
return self.tidal_creds return self.tidal_creds
if source == "deezer": if source == "deezer" or source == 'soundcloud':
return dict() return dict()
raise InvalidSourceError(source) raise InvalidSourceError(source)

View file

@ -114,9 +114,8 @@ class MusicDL(list):
item = MEDIA_CLASS[media_type](client=client, id=item_id) item = MEDIA_CLASS[media_type](client=client, id=item_id)
self.append(item) self.append(item)
def download(self): def _get_download_args(self) -> dict:
try: return {
arguments = {
"database": self.db, "database": self.db,
"parent_folder": self.config.session["downloads"]["folder"], "parent_folder": self.config.session["downloads"]["folder"],
"folder_format": self.config.session["path_format"]["folder"], "folder_format": self.config.session["path_format"]["folder"],
@ -134,7 +133,15 @@ class MusicDL(list):
"new_playlist_tracknumbers" "new_playlist_tracknumbers"
], ],
} }
except KeyError as err:
def download(self):
try:
arguments = self._get_download_args()
except KeyError:
click.secho("Updating config file... Please run the command again.", fg='magenta')
self.config.update()
exit()
except Exception as err:
click.secho( click.secho(
"There was a problem with your config file. This happens " "There was a problem with your config file. This happens "
"sometimes after updates. Run ", "sometimes after updates. Run ",