Skip to content

Commit 1b51d93

Browse files
committed
Dynamically generate client_id if specified client_id is not valid
1 parent b6da470 commit 1b51d93

File tree

3 files changed

+33
-32
lines changed

3 files changed

+33
-32
lines changed

scdl/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
"""Python Soundcloud Music Downloader."""
44

5-
__version__ = "v2.3.5"
5+
__version__ = "v2.4.0"

scdl/scdl.py

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -142,33 +142,29 @@ def main():
142142
# import conf file
143143
config = get_config(config_file)
144144

145-
# change download path
146-
path = config["scdl"]["path"]
147-
if os.path.exists(path):
148-
os.chdir(path)
149-
else:
150-
logger.error(f"Invalid download path '{path}' in {config_file}")
151-
sys.exit(1)
152-
153145
logger.info("Soundcloud Downloader")
154146
logger.debug(arguments)
155-
156-
if not arguments["--client-id"]:
157-
arguments["--client-id"] = config["scdl"]["client_id"]
158-
159-
if not arguments["--auth-token"]:
160-
arguments["--auth-token"] = config["scdl"]["auth_token"]
161-
162-
client_id, token = arguments["--client-id"], arguments["--auth-token"]
147+
148+
client_id = arguments["--client-id"] or config["scdl"]["client_id"]
149+
token = arguments["--auth-token"] or config["scdl"]["auth_token"]
163150

164151
client = SoundCloud(client_id, token if token else None)
165152

166153
if not client.is_client_id_valid():
167-
logger.error(f"Invalid client_id in {config_file}")
168-
sys.exit(1)
154+
if arguments["--client-id"]:
155+
logger.error(f"Invalid client_id specified by --client-id argument. Using a dynamically generated client_id...")
156+
elif config["scdl"]["client_id"]:
157+
logger.error(f"Invalid client_id in {config_file}. Using a dynamically generated client_id...")
158+
client = SoundCloud(None, token if token else None)
159+
if not client.is_client_id_valid():
160+
logger.error("Dynamically generated client_id is not valid")
161+
sys.exit(1)
169162

170163
if (token or arguments["me"]) and not client.is_auth_token_valid():
171-
logger.error(f"Invalid auth_token in {config_file}")
164+
if arguments["--auth-token"]:
165+
logger.error(f"Invalid auth_token specified by --auth-token argument")
166+
else:
167+
logger.error(f"Invalid auth_token in {config_file}")
172168
sys.exit(1)
173169

174170
if arguments["-o"] is not None:
@@ -201,14 +197,6 @@ def main():
201197

202198
if arguments["--hidewarnings"]:
203199
warnings.filterwarnings("ignore")
204-
205-
if arguments["--path"] is not None:
206-
if os.path.exists(arguments["--path"]):
207-
os.chdir(arguments["--path"])
208-
else:
209-
logger.error("Invalid path in arguments...")
210-
sys.exit(1)
211-
logger.debug("Downloading to " + os.getcwd() + "...")
212200

213201
if not arguments["--name-format"]:
214202
arguments["--name-format"] = config["scdl"]["name_format"]
@@ -226,6 +214,19 @@ def main():
226214
for key, value in arguments.items():
227215
key = key.strip("-").replace("-", "_")
228216
python_args[key] = value
217+
218+
# change download path
219+
path = arguments["--path"] or config["scdl"]["path"]
220+
if os.path.exists(path):
221+
os.chdir(path)
222+
else:
223+
if arguments["--path"]:
224+
logger.error(f"Invalid download path '{path}' specified by --path argument")
225+
else:
226+
logger.error(f"Invalid download path '{path}' in {config_file}")
227+
sys.exit(1)
228+
logger.debug("Downloading to " + os.getcwd() + "...")
229+
229230
download_url(client, **python_args)
230231

231232
if arguments["--remove"]:

setup.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#!/usr/bin/env python3
22
# -*- encoding: utf-8 -*-
33

4-
from setuptools import setup, find_packages
4+
from os import path
55

6-
import scdl
6+
from setuptools import find_packages, setup
77

8-
from os import path
8+
import scdl
99

1010
this_directory = path.abspath(path.dirname(__file__))
1111
with open(path.join(this_directory, "README.md"), encoding="utf-8") as f:
@@ -28,7 +28,7 @@
2828
"requests",
2929
"clint",
3030
"pathvalidate",
31-
"soundcloud-v2>=1.1.6"
31+
"soundcloud-v2>=1.2.0"
3232
],
3333
url="https://github.com/flyingrub/scdl",
3434
classifiers=[

0 commit comments

Comments
 (0)