Remove default client_id

This commit is contained in:
7x11x13
2024-06-14 12:30:40 -04:00
parent e8a4161032
commit 42fbc5c23e
3 changed files with 24 additions and 17 deletions

View File

@@ -1,3 +1,3 @@
# -*- encoding: utf-8 -*- # -*- encoding: utf-8 -*-
"""Python Soundcloud Music Downloader.""" """Python Soundcloud Music Downloader."""
__version__ = "v2.7.11" __version__ = "v2.7.12"

View File

@@ -1,5 +1,5 @@
[scdl] [scdl]
client_id = a3e059563d7fd3372b49b37f00a00bcf client_id =
auth_token = auth_token =
path = . path = .
name_format = {title} name_format = {title}

View File

@@ -138,7 +138,7 @@ def main():
logger.level = logging.DEBUG logger.level = logging.DEBUG
elif arguments["--error"]: elif arguments["--error"]:
logger.level = logging.ERROR logger.level = logging.ERROR
if "XDG_CONFIG_HOME" in os.environ: if "XDG_CONFIG_HOME" in os.environ:
config_file = pathlib.Path(os.environ["XDG_CONFIG_HOME"], "scdl", "scdl.cfg") config_file = pathlib.Path(os.environ["XDG_CONFIG_HOME"], "scdl", "scdl.cfg")
else: else:
@@ -146,25 +146,32 @@ def main():
# import conf file # import conf file
config = get_config(config_file) config = get_config(config_file)
logger.info("Soundcloud Downloader") logger.info("Soundcloud Downloader")
logger.debug(arguments) logger.debug(arguments)
client_id = arguments["--client-id"] or config["scdl"]["client_id"] client_id = arguments["--client-id"] or config["scdl"]["client_id"]
token = arguments["--auth-token"] or config["scdl"]["auth_token"] token = arguments["--auth-token"] or config["scdl"]["auth_token"]
client = SoundCloud(client_id, token if token else None) client = SoundCloud(client_id, token if token else None)
if not client.is_client_id_valid(): if not client.is_client_id_valid():
if arguments["--client-id"]: if arguments["--client-id"]:
logger.error(f"Invalid client_id specified by --client-id argument. Using a dynamically generated client_id...") logger.warning(f"Invalid client_id specified by --client-id argument. Using a dynamically generated client_id...")
elif config["scdl"]["client_id"]: elif config["scdl"]["client_id"]:
logger.error(f"Invalid client_id in {config_file}. Using a dynamically generated client_id...") logger.warning(f"Invalid client_id in {config_file}. Using a dynamically generated client_id...")
else:
logger.info(f"Generating dynamic client_id")
client = SoundCloud(None, token if token else None) client = SoundCloud(None, token if token else None)
if not client.is_client_id_valid(): if not client.is_client_id_valid():
logger.error("Dynamically generated client_id is not valid") logger.error("Dynamically generated client_id is not valid")
sys.exit(1) sys.exit(1)
config["scdl"]["client_id"] = client.client_id
# save client_id
config_file.parent.mkdir(parents=True, exist_ok=True)
with open(config_file, "w", encoding="UTF-8") as f:
config.write(f)
if (token or arguments["me"]) and not client.is_auth_token_valid(): if (token or arguments["me"]) and not client.is_auth_token_valid():
if arguments["--auth-token"]: if arguments["--auth-token"]:
logger.error(f"Invalid auth_token specified by --auth-token argument") logger.error(f"Invalid auth_token specified by --auth-token argument")
@@ -202,28 +209,28 @@ def main():
if arguments["--hidewarnings"]: if arguments["--hidewarnings"]:
warnings.filterwarnings("ignore") warnings.filterwarnings("ignore")
if not arguments["--name-format"]: if not arguments["--name-format"]:
arguments["--name-format"] = config["scdl"]["name_format"] arguments["--name-format"] = config["scdl"]["name_format"]
if not arguments["--playlist-name-format"]: if not arguments["--playlist-name-format"]:
arguments["--playlist-name-format"] = config["scdl"]["playlist_name_format"] arguments["--playlist-name-format"] = config["scdl"]["playlist_name_format"]
if arguments["me"]: if arguments["me"]:
# set url to profile associated with auth token # set url to profile associated with auth token
arguments["-l"] = client.get_me().permalink_url arguments["-l"] = client.get_me().permalink_url
arguments["-l"] = validate_url(client, arguments["-l"]) arguments["-l"] = validate_url(client, arguments["-l"])
if arguments["--sync"]: if arguments["--sync"]:
arguments["--download-archive"] = arguments["--sync"] arguments["--download-archive"] = arguments["--sync"]
# convert arguments dict to python_args (kwargs-friendly args) # convert arguments dict to python_args (kwargs-friendly args)
python_args = {} python_args = {}
for key, value in arguments.items(): for key, value in arguments.items():
key = key.strip("-").replace("-", "_") key = key.strip("-").replace("-", "_")
python_args[key] = value python_args[key] = value
# change download path # change download path
path = arguments["--path"] or config["scdl"]["path"] path = arguments["--path"] or config["scdl"]["path"]
if os.path.exists(path): if os.path.exists(path):
@@ -235,7 +242,7 @@ def main():
logger.error(f"Invalid download path '{path}' in {config_file}") logger.error(f"Invalid download path '{path}' in {config_file}")
sys.exit(1) sys.exit(1)
logger.debug("Downloading to " + os.getcwd() + "...") logger.debug("Downloading to " + os.getcwd() + "...")
download_url(client, **python_args) download_url(client, **python_args)
if arguments["--remove"]: if arguments["--remove"]: