From c7267df8176e71c5872522e2fccd788cf35769d8 Mon Sep 17 00:00:00 2001 From: Pikachu <71721661+aenulrofik@users.noreply.github.com> Date: Wed, 9 Oct 2024 23:15:28 +0800 Subject: [PATCH] fix ddl mediafire v2 --- .../download_utils/direct_link_generator.py | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/bot/helper/mirror_leech_utils/download_utils/direct_link_generator.py b/bot/helper/mirror_leech_utils/download_utils/direct_link_generator.py index 4d1daa57b5a..3ff52aee5c6 100644 --- a/bot/helper/mirror_leech_utils/download_utils/direct_link_generator.py +++ b/bot/helper/mirror_leech_utils/download_utils/direct_link_generator.py @@ -231,6 +231,13 @@ def mediafire(url, session=None): r"https?:\/\/download\d+\.mediafire\.com\/\S+\/\S+\/\S+", url ): return final_link[0] + def _repair_download(url, session): + try: + html = HTML(session.get(url).text) + if new_link := html.xpath('//a[@id="continue-btn"]/@href'): + return mediafire(f"https://mediafire.com/{new_link[0]}") + except Exception as e: + raise DirectDownloadLinkException(f"ERROR: {e.__class__.__name__}") from e if session is None: session = create_scraper() parsed_url = urlparse(url) @@ -258,7 +265,8 @@ def mediafire(url, session=None): session.close() raise DirectDownloadLinkException("ERROR: Wrong password.") if not (final_link := html.xpath('//a[@aria-label="Download file"]/@href')): - session.close() + if repair_link := html.xpath("//a[@class='retry']/@href"): + return _repair_download(repair_link[0], session) raise DirectDownloadLinkException( "ERROR: No links found in this page Try Again" ) @@ -1092,6 +1100,16 @@ def __get_info(folderkey): details["title"] = folder_infos[0]["name"] def __scraper(url): + session = create_scraper() + parsed_url = urlparse(url) + url = f"{parsed_url.scheme}://{parsed_url.netloc}{parsed_url.path}" + def __repair_download(url): + try: + html = HTML(session.get(url).text) + if new_link := html.xpath('//a[@id="continue-btn"]/@href'): + return __scraper(f"https://mediafire.com/{new_link[0]}") + except: + return try: html = HTML(session.get(url).text) except: @@ -1108,7 +1126,11 @@ def __scraper(url): if html.xpath("//div[@class='passwordPrompt']"): return if final_link := html.xpath('//a[@aria-label="Download file"]/@href'): + if final_link[0].startswith("//"): + return __scraper(f"https://{final_link[0][2:]}") return final_link[0] + if repair_link := html.xpath("//a[@class='retry']/@href"): + return __repair_download(repair_link[0]) def __get_content(folderKey, folderPath="", content_type="folders"): try: