Handle Mediafire link when in Javascript

This commit is contained in:
Joshua Boniface 2023-04-29 11:06:54 -04:00
parent 6ecb62431e
commit 0a0fb144c0
1 changed files with 19 additions and 15 deletions

View File

@ -286,34 +286,35 @@ def downloadFile(download_url, download_path, download_filename):
def parseC3Universe(dl_link): def parseC3Universe(dl_link):
try: try:
p = requests.get(dl_link) p = requests.get(dl_link)
if p.status_code != 200:
raise HTTPError(dl_link, p.status_code, "", None, None)
parsed_html = BeautifulSoup(p.text, "html.parser") parsed_html = BeautifulSoup(p.text, "html.parser")
download_url = ( download_element = (
parsed_html.body.find("div", attrs={"class": "lock-head"}) parsed_html.body.find("div", attrs={"class": "lock-head"})
.find("a") .find("a")
.get("href")
) )
download_url = download_element.get("href")
return download_url return download_url
except Exception as e: except Exception as e:
click.echo(f"Failed parsing or retrieving HTML link: {e}")
return None return None
def parseMediafire(dl_link): def parseMediafirePage(dl_link):
try: try:
p = requests.get(dl_link) p = requests.get(dl_link)
if p.status_code != 200:
raise HTTPError(dl_link, p.status_code, "", None, None)
parsed_html = BeautifulSoup(p.text, "html.parser") parsed_html = BeautifulSoup(p.text, "html.parser")
download_url = parsed_html.find( download_element = parsed_html.find(
"a", attrs={"id": "downloadButton", "rel": "nofollow", "aria-label": "Download file"} "a", attrs={"aria-label": "Download file"}
).get("href") )
download_url = download_element.get("href")
return download_url
except Exception as e:
return None
def parseMediafireJS(dl_link):
try:
p = requests.get(dl_link)
download_url = re.find(r"'(http://download[0-9]+.mediafire.com/.*)';", p.text).group(1)
return download_url return download_url
except Exception as e: except Exception as e:
click.echo(f"Failed parsing or retrieving HTML link: {e}")
return None return None
def downloadSong(destination, filename, entry, dlid, dldesc): def downloadSong(destination, filename, entry, dlid, dldesc):
@ -345,13 +346,16 @@ def downloadSong(destination, filename, entry, dlid, dldesc):
if 'dl.c3universe.com' in dl_link['link']: if 'dl.c3universe.com' in dl_link['link']:
download_url = parseC3Universe(dl_link["link"]) download_url = parseC3Universe(dl_link["link"])
elif 'www.mediafire.com' in dl_link["link"]: elif 'www.mediafire.com' in dl_link["link"]:
download_url = parseMediafire(dl_link["link"]) download_url = parseMediafirePage(dl_link["link"])
if download_url is None:
download_url = parseMediafireJS(dl_link["link"])
else: else:
click.echo("Download URL is not valid for CLI download; skipping...") click.echo("Download URL is not valid for CLI download; skipping...")
click.echo(f"URL: {dl_link['link']}") click.echo(f"URL: {dl_link['link']}")
continue continue
if download_url is None: if download_url is None:
click.echo(f"Failed parsing or retrieving file URL from link {dl_link}, skipping...")
continue continue
download_filename = filename.format( download_filename = filename.format(