From 70a86274d9ec187c593b0a34b5c6c202e3e17025 Mon Sep 17 00:00:00 2001 From: Juned KH Date: Sat, 20 Jul 2024 11:53:22 +0530 Subject: [PATCH] Mediafire password support --- .../download_utils/direct_link_generator.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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 6adc5b6e995..eb391400e14 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 @@ -218,6 +218,11 @@ def get_captcha_token(session, params): def mediafire(url, session=None): if "/folder/" in url: return mediafireFolder(url) + if "::" in url: + _password = url.split("::")[-1] + url = url.split("::")[-2] + else: + _password = "" if final_link := findall( r"https?:\/\/download\d+\.mediafire\.com\/\S+\/\S+\/\S+", url ): @@ -234,6 +239,18 @@ def mediafire(url, session=None): if error := html.xpath('//p[@class="notranslate"]/text()'): session.close() raise DirectDownloadLinkException(f"ERROR: {error[0]}") + if html.xpath("//div[@class='passwordPrompt']"): + if not _password: + session.close() + raise DirectDownloadLinkException(f"ERROR: {PASSWORD_ERROR_MESSAGE}".format(url)) + try: + html = HTML(session.post(url, data={"downloadp": _password}).text) + except Exception as e: + session.close() + raise DirectDownloadLinkException(f"ERROR: {e.__class__.__name__}") from e + if html.xpath("//div[@class='passwordPrompt']"): + session.close() + raise DirectDownloadLinkException("ERROR: Wrong password.") if not (final_link := html.xpath("//a[@id='downloadButton']/@href")): session.close() raise DirectDownloadLinkException(