Skip to content

Commit 8b347a2

Browse files
authored
Merge pull request #1876 from sys6101/master
fix download mediafire.com
2 parents 379efa5 + 1668153 commit 8b347a2

1 file changed

Lines changed: 20 additions & 28 deletions

File tree

bot/helper/mirror_leech_utils/download_utils/direct_link_generator.py

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,6 @@ def mediafile(url):
433433
except Exception as e:
434434
raise DirectDownloadLinkException(f"ERROR: {str(e)}") from e
435435

436-
437436
def mediafire(url, session=None):
438437
if "/folder/" in url:
439438
return mediafireFolder(url)
@@ -447,26 +446,13 @@ def mediafire(url, session=None):
447446
):
448447
return final_link[0]
449448

450-
def _decode_url(html, session):
451-
enc_url = html.xpath('//a[@id="downloadButton"]')
452-
if enc_url:
453-
final_link = enc_url[0].attrib.get('href')
454-
scrambled = enc_url[0].attrib.get('data-scrambled-url')
455-
456-
if final_link and scrambled:
457-
try:
458-
final_link = b64decode(scrambled).decode("utf-8")
459-
return final_link
460-
except Exception as e:
461-
raise ValueError(f"Failed to decode final link. {e.__class__.__name__}") from e
462-
elif final_link.startswith("http"):
463-
return final_link
464-
elif final_link.startswith("//"):
465-
return mediafire(f"https:{final_link}", session=session)
466-
else:
467-
raise ValueError("No download link found")
468-
else:
469-
raise ValueError("Download button not found in the HTML content. It may have been blocked by Cloudflare's anti-bot protection.")
449+
def _repair_download(url, session):
450+
try:
451+
html = HTML(session.get(url).text)
452+
if new_link := html.xpath('//a[@id="continue-btn"]/@href'):
453+
return mediafire(f"https://mediafire.com/{new_link[0]}")
454+
except Exception as e:
455+
raise DirectDownloadLinkException(f"ERROR: {e.__class__.__name__}") from e
470456

471457
if session is None:
472458
session = create_scraper()
@@ -494,14 +480,20 @@ def _decode_url(html, session):
494480
if html.xpath("//div[@class='passwordPrompt']"):
495481
session.close()
496482
raise DirectDownloadLinkException("ERROR: Wrong password.")
497-
try:
498-
final_link = _decode_url(html, session)
499-
except Exception as e:
500-
raise DirectDownloadLinkException(f"ERROR: {str(e)}")
483+
if not (final_link := html.xpath('//a[@aria-label="Download file"]/@href')):
484+
if repair_link := html.xpath("//a[@class='retry']/@href"):
485+
return _repair_download(repair_link[0], session)
486+
raise DirectDownloadLinkException(
487+
"ERROR: No links found in this page Try Again"
488+
)
489+
if final_link[0].startswith("//"):
490+
final_url = f"https://{final_link[0][2:]}"
491+
if _password:
492+
final_url += f"::{_password}"
493+
return mediafire(final_url, session)
501494
session.close()
502-
return final_link
503-
504-
495+
return final_link[0]
496+
505497
def osdn(url):
506498
with create_scraper() as session:
507499
try:

0 commit comments

Comments
 (0)