Improve Mediafire parsing even further

This commit is contained in:
Joshua Boniface 2023-04-29 11:11:25 -04:00
parent 0a0fb144c0
commit 7a2154db69
1 changed files with 9 additions and 14 deletions

View File

@ -294,27 +294,24 @@ def parseC3Universe(dl_link):
download_url = download_element.get("href")
return download_url
except Exception as e:
click.echo(f"Failed parsing or retrieving file URL from link {dl_link}: {e}")
return None
def parseMediafirePage(dl_link):
def parseMediafire(dl_link):
try:
p = requests.get(dl_link)
parsed_html = BeautifulSoup(p.text, "html.parser")
download_element = parsed_html.find(
"a", attrs={"aria-label": "Download file"}
)
if download_element is not None:
download_url = download_element.get("href")
else:
download_url = re.search(r"'(http[s]*://download[0-9]+.mediafire.com/.*)';", p.text).group(1)
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
except Exception as e:
click.echo(f"Failed parsing or retrieving file URL from link {dl_link}: {e}")
return None
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']:
download_url = parseC3Universe(dl_link["link"])
elif 'www.mediafire.com' in dl_link["link"]:
download_url = parseMediafirePage(dl_link["link"])
if download_url is None:
download_url = parseMediafireJS(dl_link["link"])
download_url = parseMediafire(dl_link["link"])
else:
click.echo("Download URL is not valid for CLI download; skipping...")
click.echo(f"URL: {dl_link['link']}")
continue
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
download_filename = filename.format(