diff --git a/bot/helper/mirror_utils/download_utils/direct_link_generator.py b/bot/helper/mirror_utils/download_utils/direct_link_generator.py index b9895f0584e..3a2383e8640 100644 --- a/bot/helper/mirror_utils/download_utils/direct_link_generator.py +++ b/bot/helper/mirror_utils/download_utils/direct_link_generator.py @@ -344,61 +344,61 @@ def fichier(link: str) -> str: """ 1Fichier direct links generator Based on https://github.com/Maujar/updateref-16-7-21 https://github.com/breakdowns/slam-mirrorbot """ - regex = r"^([http:\/\/|https:\/\/]+)?.*1fichier\.com\/\?.+" - gan = re.match(regex, link) - if not gan: - raise DirectDownloadLinkException("ERROR: The link you entered is wrong!") - if "::" in link: - pswd = link.split("::")[-1] - url = link.split("::")[-2] - else: - pswd = None - url = link - try: - if pswd is None: - req = requests.post(url) + regex = r"^([http:\/\/|https:\/\/]+)?.*1fichier\.com\/\?.+" + gan = re.match(regex, link) + if not gan: + raise DirectDownloadLinkException("ERROR: The link you entered is wrong!") + if "::" in link: + pswd = link.split("::")[-1] + url = link.split("::")[-2] else: - pw = {"pass": pswd} - req = requests.post(url, data=pe) - except: - raise DirectDownloadLinkException("ERROR: Unable to reach 1fichier server!") - if req.status_code == 404: - raise DirectDownloadLinkException("ERROR: File not found / The link you entered is wrong!") - soup = BeautifulSoup(req.content, 'lxml') - if soup.find("a", {"class": "ok btn-general btn-orange"}) is not None: - dl_url = soup.find("a", {"class": "ok btn-general btn-orange"})["href"] - if dl_url is None: - raise DirectDownloadLinkException("ERROR: Unable to generate Direct Link 1fichier!") + pswd = None + url = link + try: + if pswd is None: + req = requests.post(url) + else: + pw = {"pass": pswd} + req = requests.post(url, data=pe) + except: + raise DirectDownloadLinkException("ERROR: Unable to reach 1fichier server!") + if req.status_code == 404: + raise DirectDownloadLinkException("ERROR: File not found / The link you entered is wrong!") + soup = BeautifulSoup(req.content, 'lxml') + if soup.find("a", {"class": "ok btn-general btn-orange"}) is not None: + dl_url = soup.find("a", {"class": "ok btn-general btn-orange"})["href"] + if dl_url is None: + raise DirectDownloadLinkException("ERROR: Unable to generate Direct Link 1fichier!") + else: + return dl_url else: - return dl_url - else: - if len(soup.find_all("div", {"class": "ct_warn"})) == 2: - str_2 = soup.find_all("div", {"class": "ct_warn"})[-1] - if "you must wait" in str(str_2).lower(): - numbers = [int(word) for word in str(str_2).split() if word.isdigit()] - if len(numbers) == 0: - raise DirectDownloadLinkException("ERROR: 1fichier is on a limit. Please wait a few minutes/hour.") + if len(soup.find_all("div", {"class": "ct_warn"})) == 2: + str_2 = soup.find_all("div", {"class": "ct_warn"})[-1] + if "you must wait" in str(str_2).lower(): + numbers = [int(word) for word in str(str_2).split() if word.isdigit()] + if len(numbers) == 0: + raise DirectDownloadLinkException("ERROR: 1fichier is on a limit. Please wait a few minutes/hour.") + else: + raise DirectDownloadLinkException(f"ERROR: 1fichier is on a limit. Please wait {numbers[0]} minute.") + elif "protect access" in str(str_2).lower(): + raise DirectDownloadLinkException("ERROR: This link requires a password!\n\nThis link requires a password!\n- Insert sign :: after the link and write the password after the sign.\n\nExample:\n/mirror https://1fichier.com/?smmtd8twfpm66awbqz04::love you\n\n* No spaces between the signs ::\n* For the password, you can use a space!") else: - raise DirectDownloadLinkException(f"ERROR: 1fichier is on a limit. Please wait {numbers[0]} minute.") - elif "protect access" in str(str_2).lower(): - raise DirectDownloadLinkException("ERROR: This link requires a password!\n\nThis link requires a password!\n- Insert sign :: after the link and write the password after the sign.\n\nExample:\n/mirror https://1fichier.com/?smmtd8twfpm66awbqz04::love you\n\n* No spaces between the signs ::\n* For the password, you can use a space!") - else: - raise DirectDownloadLinkException("ERROR: Error trying to generate Direct Link from 1fichier!") - elif len(soup.find_all("div", {"class": "ct_warn"})) == 3: - str_1 = soup.find_all("div", {"class": "ct_warn"})[-2] - str_3 = soup.find_all("div", {"class": "ct_warn"})[-1] - if "you must wait" in str(str_1).lower(): - numbers = [int(word) for word in str(str_1).split() if word.isdigit()] - if len(numbers) == 0: - raise DirectDownloadLinkException("ERROR: 1fichier is on a limit. Please wait a few minutes/hour.") + raise DirectDownloadLinkException("ERROR: Error trying to generate Direct Link from 1fichier!") + elif len(soup.find_all("div", {"class": "ct_warn"})) == 3: + str_1 = soup.find_all("div", {"class": "ct_warn"})[-2] + str_3 = soup.find_all("div", {"class": "ct_warn"})[-1] + if "you must wait" in str(str_1).lower(): + numbers = [int(word) for word in str(str_1).split() if word.isdigit()] + if len(numbers) == 0: + raise DirectDownloadLinkException("ERROR: 1fichier is on a limit. Please wait a few minutes/hour.") + else: + raise DirectDownloadLinkException(f"ERROR: 1fichier is on a limit. Please wait {numbers[0]} minute.") + elif "bad password" in str(str_3).lower(): + raise DirectDownloadLinkException("ERROR: The password you entered is wrong!") else: - raise DirectDownloadLinkException(f"ERROR: 1fichier is on a limit. Please wait {numbers[0]} minute.") - elif "bad password" in str(str_3).lower(): - raise DirectDownloadLinkException("ERROR: The password you entered is wrong!") + raise DirectDownloadLinkException("ERROR: Error trying to generate Direct Link from 1fichier!") else: raise DirectDownloadLinkException("ERROR: Error trying to generate Direct Link from 1fichier!") - else: - raise DirectDownloadLinkException("ERROR: Error trying to generate Direct Link from 1fichier!") def useragent():