Skip to content

Commit

Permalink
Dynamically generate client_id if specified client_id is not valid
Browse files Browse the repository at this point in the history
  • Loading branch information
7x11x13 committed Dec 25, 2021
1 parent b6da470 commit 1b51d93
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 32 deletions.
2 changes: 1 addition & 1 deletion scdl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

"""Python Soundcloud Music Downloader."""

__version__ = "v2.3.5"
__version__ = "v2.4.0"
55 changes: 28 additions & 27 deletions scdl/scdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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"]
Expand All @@ -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"]:
Expand Down
8 changes: 4 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/usr/bin/env python3
# -*- encoding: utf-8 -*-

from setuptools import setup, find_packages
from os import path

import scdl
from setuptools import find_packages, setup

from os import path
import scdl

this_directory = path.abspath(path.dirname(__file__))
with open(path.join(this_directory, "README.md"), encoding="utf-8") as f:
Expand All @@ -28,7 +28,7 @@
"requests",
"clint",
"pathvalidate",
"soundcloud-v2>=1.1.6"
"soundcloud-v2>=1.2.0"
],
url="https://github.com/flyingrub/scdl",
classifiers=[
Expand Down

0 comments on commit 1b51d93

Please sign in to comment.