Allow downloading of mobile links
parent
0f6991077b
commit
f5f41705f3
|
@ -2,4 +2,4 @@
|
||||||
|
|
||||||
"""Python Soundcloud Music Downloader."""
|
"""Python Soundcloud Music Downloader."""
|
||||||
|
|
||||||
__version__ = "v2.2.5"
|
__version__ = "v2.3.0"
|
28
scdl/scdl.py
28
scdl/scdl.py
|
@ -76,6 +76,7 @@ import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
import time
|
import time
|
||||||
import traceback
|
import traceback
|
||||||
|
import urllib.parse
|
||||||
import warnings
|
import warnings
|
||||||
from dataclasses import asdict
|
from dataclasses import asdict
|
||||||
|
|
||||||
|
@ -218,17 +219,42 @@ def main():
|
||||||
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(arguments["-l"])
|
||||||
|
|
||||||
# convert arguments dict to python_args (kwargs-friendly args)
|
# convert arguments dict to python_args (kwargs-friendly 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
|
||||||
|
|
||||||
download_url(client, **python_args)
|
download_url(client, **python_args)
|
||||||
|
|
||||||
if arguments["--remove"]:
|
if arguments["--remove"]:
|
||||||
remove_files()
|
remove_files()
|
||||||
|
|
||||||
|
def validate_url(url: str):
|
||||||
|
"""
|
||||||
|
If url is a valid soundcloud.com url, return it.
|
||||||
|
Otherwise, try to fix the url so that it is valid.
|
||||||
|
If it cannot be fixed, exit the program.
|
||||||
|
"""
|
||||||
|
if url.startswith("https://m.soundcloud.com") or url.startswith("http://m.soundcloud.com") or url.startswith("m.soundcloud.com"):
|
||||||
|
url = url.replace("m.", "", 1)
|
||||||
|
if url.startswith("https://www.soundcloud.com") or url.startswith("http://www.soundcloud.com") or url.startswith("www.soundcloud.com"):
|
||||||
|
url = url.replace("www.", "", 1)
|
||||||
|
if url.startswith("soundcloud.com"):
|
||||||
|
url = "https://" + url
|
||||||
|
if url.startswith("https://soundcloud.com") or url.startswith("http://soundcloud.com"):
|
||||||
|
return url
|
||||||
|
|
||||||
|
# see if link redirects to soundcloud.com
|
||||||
|
resp = requests.get(url)
|
||||||
|
url = urllib.parse.urljoin(resp.url, urllib.parse.urlparse(resp.url).path)
|
||||||
|
if url.startswith("https://soundcloud.com") or url.startswith("http://soundcloud.com"):
|
||||||
|
return url
|
||||||
|
|
||||||
|
logger.error("URL is not valid")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
def get_config(config_file: pathlib.Path) -> configparser.ConfigParser:
|
def get_config(config_file: pathlib.Path) -> configparser.ConfigParser:
|
||||||
"""
|
"""
|
||||||
Gets config from scdl.cfg
|
Gets config from scdl.cfg
|
||||||
|
|
Loading…
Reference in New Issue