Improve Mediafire parsing even further
This commit is contained in:
parent
0a0fb144c0
commit
7a2154db69
|
@ -294,27 +294,24 @@ def parseC3Universe(dl_link):
|
||||||
download_url = download_element.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 file URL from link {dl_link}: {e}")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def parseMediafirePage(dl_link):
|
def parseMediafire(dl_link):
|
||||||
try:
|
try:
|
||||||
p = requests.get(dl_link)
|
p = requests.get(dl_link)
|
||||||
parsed_html = BeautifulSoup(p.text, "html.parser")
|
parsed_html = BeautifulSoup(p.text, "html.parser")
|
||||||
download_element = parsed_html.find(
|
download_element = parsed_html.find(
|
||||||
"a", attrs={"aria-label": "Download file"}
|
"a", attrs={"aria-label": "Download file"}
|
||||||
)
|
)
|
||||||
download_url = download_element.get("href")
|
if download_element is not None:
|
||||||
return download_url
|
download_url = download_element.get("href")
|
||||||
except Exception as e:
|
else:
|
||||||
return None
|
download_url = re.search(r"'(http[s]*://download[0-9]+.mediafire.com/.*)';", p.text).group(1)
|
||||||
|
|
||||||
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 file URL from link {dl_link}: {e}")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def downloadSong(destination, filename, entry, dlid, dldesc):
|
def downloadSong(destination, filename, entry, dlid, dldesc):
|
||||||
|
@ -346,16 +343,14 @@ 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 = parseMediafirePage(dl_link["link"])
|
download_url = parseMediafire(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...")
|
click.echo(f"No valid download URL found, skipping...")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
download_filename = filename.format(
|
download_filename = filename.format(
|
||||||
|
|
Loading…
Reference in New Issue