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:
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):
"""Save the config state to file."""
@ -181,7 +188,7 @@ class Config:
return self.qobuz_creds
if source == "tidal":
return self.tidal_creds
if source == "deezer":
if source == "deezer" or source == 'soundcloud':
return dict()
raise InvalidSourceError(source)

View file

@ -114,27 +114,34 @@ class MusicDL(list):
item = MEDIA_CLASS[media_type](client=client, id=item_id)
self.append(item)
def _get_download_args(self) -> dict:
return {
"database": self.db,
"parent_folder": self.config.session["downloads"]["folder"],
"folder_format": self.config.session["path_format"]["folder"],
"track_format": self.config.session["path_format"]["track"],
"embed_cover": self.config.session["artwork"]["embed"],
"embed_cover_size": self.config.session["artwork"]["size"],
"keep_hires_cover": self.config.session["artwork"]["keep_hires_cover"],
"set_playlist_to_album": self.config.session["metadata"][
"set_playlist_to_album"
],
"stay_temp": self.config.session["conversion"]["enabled"],
"conversion": self.config.session["conversion"],
"concurrent_downloads": self.config.session["concurrent_downloads"],
"new_tracknumbers": self.config.session["metadata"][
"new_playlist_tracknumbers"
],
}
def download(self):
try:
arguments = {
"database": self.db,
"parent_folder": self.config.session["downloads"]["folder"],
"folder_format": self.config.session["path_format"]["folder"],
"track_format": self.config.session["path_format"]["track"],
"embed_cover": self.config.session["artwork"]["embed"],
"embed_cover_size": self.config.session["artwork"]["size"],
"keep_hires_cover": self.config.session["artwork"]["keep_hires_cover"],
"set_playlist_to_album": self.config.session["metadata"][
"set_playlist_to_album"
],
"stay_temp": self.config.session["conversion"]["enabled"],
"conversion": self.config.session["conversion"],
"concurrent_downloads": self.config.session["concurrent_downloads"],
"new_tracknumbers": self.config.session["metadata"][
"new_playlist_tracknumbers"
],
}
except KeyError as err:
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(
"There was a problem with your config file. This happens "
"sometimes after updates. Run ",