From 1b51d930a4b47b755c048e0b2bb022e14e118baf Mon Sep 17 00:00:00 2001 From: 7x11x13 Date: Sat, 25 Dec 2021 12:08:38 -0500 Subject: [PATCH] Dynamically generate client_id if specified client_id is not valid --- scdl/__init__.py | 2 +- scdl/scdl.py | 55 ++++++++++++++++++++++++------------------------ setup.py | 8 +++---- 3 files changed, 33 insertions(+), 32 deletions(-) diff --git a/scdl/__init__.py b/scdl/__init__.py index 6433cbe..1a7b381 100644 --- a/scdl/__init__.py +++ b/scdl/__init__.py @@ -2,4 +2,4 @@ """Python Soundcloud Music Downloader.""" -__version__ = "v2.3.5" \ No newline at end of file +__version__ = "v2.4.0" diff --git a/scdl/scdl.py b/scdl/scdl.py index fcc1014..90ed194 100755 --- a/scdl/scdl.py +++ b/scdl/scdl.py @@ -142,33 +142,29 @@ def main(): # import conf file config = get_config(config_file) - # change download path - path = config["scdl"]["path"] - if os.path.exists(path): - os.chdir(path) - else: - logger.error(f"Invalid download path '{path}' in {config_file}") - sys.exit(1) - logger.info("Soundcloud Downloader") logger.debug(arguments) - - if not arguments["--client-id"]: - arguments["--client-id"] = config["scdl"]["client_id"] - - if not arguments["--auth-token"]: - arguments["--auth-token"] = config["scdl"]["auth_token"] - - client_id, token = arguments["--client-id"], arguments["--auth-token"] + + client_id = arguments["--client-id"] or config["scdl"]["client_id"] + token = arguments["--auth-token"] or config["scdl"]["auth_token"] client = SoundCloud(client_id, token if token else None) if not client.is_client_id_valid(): - logger.error(f"Invalid client_id in {config_file}") - sys.exit(1) + if arguments["--client-id"]: + logger.error(f"Invalid client_id specified by --client-id argument. Using a dynamically generated client_id...") + elif config["scdl"]["client_id"]: + logger.error(f"Invalid client_id in {config_file}. Using a dynamically generated client_id...") + client = SoundCloud(None, token if token else None) + if not client.is_client_id_valid(): + logger.error("Dynamically generated client_id is not valid") + sys.exit(1) if (token or arguments["me"]) and not client.is_auth_token_valid(): - logger.error(f"Invalid auth_token in {config_file}") + if arguments["--auth-token"]: + logger.error(f"Invalid auth_token specified by --auth-token argument") + else: + logger.error(f"Invalid auth_token in {config_file}") sys.exit(1) if arguments["-o"] is not None: @@ -201,14 +197,6 @@ def main(): if arguments["--hidewarnings"]: warnings.filterwarnings("ignore") - - if arguments["--path"] is not None: - if os.path.exists(arguments["--path"]): - os.chdir(arguments["--path"]) - else: - logger.error("Invalid path in arguments...") - sys.exit(1) - logger.debug("Downloading to " + os.getcwd() + "...") if not arguments["--name-format"]: arguments["--name-format"] = config["scdl"]["name_format"] @@ -226,6 +214,19 @@ def main(): for key, value in arguments.items(): key = key.strip("-").replace("-", "_") python_args[key] = value + + # change download path + path = arguments["--path"] or config["scdl"]["path"] + if os.path.exists(path): + os.chdir(path) + else: + if arguments["--path"]: + logger.error(f"Invalid download path '{path}' specified by --path argument") + else: + logger.error(f"Invalid download path '{path}' in {config_file}") + sys.exit(1) + logger.debug("Downloading to " + os.getcwd() + "...") + download_url(client, **python_args) if arguments["--remove"]: diff --git a/setup.py b/setup.py index f81f6df..8a5fbab 100755 --- a/setup.py +++ b/setup.py @@ -1,12 +1,12 @@ #!/usr/bin/env python3 # -*- encoding: utf-8 -*- -from setuptools import setup, find_packages +from os import path + +from setuptools import find_packages, setup import scdl -from os import path - this_directory = path.abspath(path.dirname(__file__)) with open(path.join(this_directory, "README.md"), encoding="utf-8") as f: long_description = f.read() @@ -28,7 +28,7 @@ setup( "requests", "clint", "pathvalidate", - "soundcloud-v2>=1.1.6" + "soundcloud-v2>=1.2.0" ], url="https://github.com/flyingrub/scdl", classifiers=[