@@ -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" ]:
0 commit comments