diff --git a/scdl/__init__.py b/scdl/__init__.py index e25b934..6fb3be7 100644 --- a/scdl/__init__.py +++ b/scdl/__init__.py @@ -9,19 +9,21 @@ CLIENT_ID = 'a3e059563d7fd3372b49b37f00a00bcf' ALT_CLIENT_ID = '2t9loNQH90kzJcsFCODdigxfp325aq4z' ALT2_CLIENT_ID = 'NONE' -dir_path_to_conf = os.path.join(os.path.expanduser('~'), '.config/scdl') -if 'XDG_CONFIG_HOME' in os.environ: - dir_path_to_conf = os.environ['XDG_CONFIG_HOME'] - -file_path_to_conf = os.path.join(dir_path_to_conf, 'scdl.cfg') -text = """[scdl] +default_config = """[scdl] auth_token = path = . """ -if not os.path.exists(dir_path_to_conf): - os.makedirs(dir_path_to_conf) +if 'XDG_CONFIG_HOME' in os.environ: + config_dir = os.path.join(os.environ['XDG_CONFIG_HOME'], 'scdl') +else: + config_dir = os.path.join(os.path.expanduser('~'), '.config', 'scdl') -if not os.path.exists(file_path_to_conf): - with open(file_path_to_conf, 'w') as f: - f.write(text) +config_file = os.path.join(config_dir, 'scdl.cfg') + +if not os.path.exists(config_file): + if not os.path.exists(config_dir): + os.makedirs(config_dir) + + with open(config_file, 'w') as f: + f.write(default_config) diff --git a/scdl/scdl.py b/scdl/scdl.py index b24d5e9..85acfa4 100755 --- a/scdl/scdl.py +++ b/scdl/scdl.py @@ -204,7 +204,16 @@ def get_config(): """ global token config = configparser.ConfigParser() - config.read(os.path.join(os.path.expanduser('~'), '.config/scdl/scdl.cfg'), "utf8") + + if 'XDG_CONFIG_HOME' in os.environ: + config_file = os.path.join( + os.environ['XDG_CONFIG_HOME'], 'scdl', 'scdl.cfg', + ) + else: + config_file = os.path.join( + os.path.expanduser('~'), '.config', 'scdl', 'scdl.cfg', + ) + config.read(config_file, 'utf8') try: token = config['scdl']['auth_token'] path = config['scdl']['path'] @@ -454,7 +463,7 @@ def download_original_file(track, title): if r.status_code == 401: logger.info('The original file has no download left.') return None - + if r.status_code == 404: logger.info('Could not get name from stream - using basic name') return None @@ -494,7 +503,7 @@ def download_original_file(track, title): newfilename = filename[:-4] + ".flac" new = shlex.quote(newfilename) old = shlex.quote(filename) - + commands = ['ffmpeg', '-i', old, new, '-loglevel', 'fatal'] logger.debug("Commands: {}".format(commands)) subprocess.call(commands)