From d3938784acdd8e26724530679d8d18d43d94ce36 Mon Sep 17 00:00:00 2001 From: lzzy12 Date: Sat, 9 May 2020 00:09:38 +0530 Subject: [PATCH] Remove broken direct download link extracters Signed-off-by: lzzy12 --- .gitmodules | 3 - bot/__main__.py | 13 ++- .../download_utils/direct_link_generator.py | 103 ------------------ 3 files changed, 7 insertions(+), 112 deletions(-) diff --git a/.gitmodules b/.gitmodules index f53bcd466..ea40a2d28 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,3 @@ -[submodule "vendor/megadown"] - path = vendor/megadown - url = https://github.com/tonikelope/megadown.git [submodule "vendor/cmrudl.py"] path = vendor/cmrudl.py url = https://github.com/JrMasterModelBuilder/cmrudl.py.git diff --git a/bot/__main__.py b/bot/__main__.py index 712cee668..4140a3b33 100644 --- a/bot/__main__.py +++ b/bot/__main__.py @@ -6,7 +6,7 @@ from sys import executable from telegram.ext import CommandHandler, run_async -from bot import dispatcher, updater, botStartTime, DOWNLOAD_DIR +from bot import dispatcher, updater, botStartTime from bot.helper.ext_utils import fs_utils from bot.helper.telegram_helper.bot_commands import BotCommands from bot.helper.telegram_helper.message_utils import * @@ -16,7 +16,7 @@ @run_async -def stats(update,context): +def stats(update, context): currentTime = get_readable_time((time.time() - botStartTime)) total, used, free = shutil.disk_usage('.') total = get_readable_file_size(total) @@ -24,13 +24,13 @@ def stats(update,context): free = get_readable_file_size(free) stats = f'Bot Uptime: {currentTime}\n' \ f'Total disk space: {total}\n' \ - f'Used: {used}\n' \ - f'Free: {free}' + f'Used: {used}\n' \ + f'Free: {free}' sendMessage(stats, context.bot, update) @run_async -def start(update,context): +def start(update, context): sendMessage("This is a bot which can mirror all your links to Google drive!\n" "Type /help to get a list of available commands", context.bot, update) @@ -45,6 +45,7 @@ def restart(update, context): execl(executable, executable, "-m", "bot") +@run_async def ping(update, context): start_time = int(round(time.time() * 1000)) reply = sendMessage("Starting Ping", context.bot, update) @@ -100,7 +101,7 @@ def main(): ping_handler = CommandHandler(BotCommands.PingCommand, ping, filters=CustomFilters.authorized_chat | CustomFilters.authorized_user) restart_handler = CommandHandler(BotCommands.RestartCommand, restart, - filters=CustomFilters.owner_filter) + filters=CustomFilters.owner_filter) help_handler = CommandHandler(BotCommands.HelpCommand, bot_help, filters=CustomFilters.authorized_chat | CustomFilters.authorized_user) stats_handler = CommandHandler(BotCommands.StatsCommand, 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 71d361913..84ea43a5b 100644 --- a/bot/helper/mirror_utils/download_utils/direct_link_generator.py +++ b/bot/helper/mirror_utils/download_utils/direct_link_generator.py @@ -24,12 +24,8 @@ def direct_link_generator(link: str): """ direct links generator """ if not link: raise DirectDownloadLinkException("`No links found!`") - if 'drive.google.com' in link: - return gdrive(link) elif 'zippyshare.com' in link: return zippy_share(link) - elif 'mega.' in link: - return mega_dl(link) elif 'yadi.sk' in link: return yandex_disk(link) elif 'cloud.mail.ru' in link: @@ -40,49 +36,10 @@ def direct_link_generator(link: str): return osdn(link) elif 'github.com' in link: return github(link) - elif 'androidfilehost.com' in link: - return androidfilehost(link) else: raise DirectDownloadLinkException(f'No Direct link function found for {link}') -def gdrive(url: str) -> str: - """ GDrive direct links generator """ - drive = 'https://drive.google.com' - try: - link = re.findall(r'\bhttps?://drive\.google\.com\S+', url)[0] - except IndexError: - reply = "`No Google drive links found`\n" - return reply - file_id = '' - if link.find("view") != -1: - file_id = link.split('/')[-2] - elif link.find("open?id=") != -1: - file_id = link.split("open?id=")[1].strip() - elif link.find("uc?id=") != -1: - file_id = link.split("uc?id=")[1].strip() - url = f'{drive}/uc?export=download&id={file_id}' - download = requests.get(url, stream=True, allow_redirects=False) - cookies = download.cookies - try: - # In case of small file size, Google downloads directly - dl_url = download.headers["location"] - if 'accounts.google.com' in dl_url: # non-public file - raise DirectDownloadLinkException('`Link not public`') - except KeyError: - # In case of download warning page - page = BeautifulSoup(download.content, 'lxml') - export = drive + page.find('a', {'id': 'uc-download-link'}).get('href') - response = requests.get(export, - stream=True, - allow_redirects=False, - cookies=cookies) - dl_url = response.headers['location'] - if 'accounts.google.com' in dl_url: - raise DirectDownloadLinkException('`Link not public`') - return dl_url - - def zippy_share(url: str) -> str: """ ZippyShare direct links generator Based on https://github.com/LameLemon/ziggy""" @@ -125,23 +82,6 @@ def yandex_disk(url: str) -> str: raise DirectDownloadLinkException("`Error: File not found / Download limit reached`\n") -def mega_dl(url: str) -> str: - """ MEGA.nz direct links generator - Using https://github.com/tonikelope/megadown""" - try: - link = re.findall(r'\bhttps?://.*mega.*\.nz\S+', url)[0] - except IndexError: - raise DirectDownloadLinkException("`No MEGA.nz links found`\n") - command = f'vendor/megadown/megadown -q -m {link}' - result = popen(command).read() - try: - data = json.loads(result) - except json.JSONDecodeError: - raise DirectDownloadLinkException("`Error: Can't extract the link`\n") - dl_url = data['url'] - return dl_url - - def cm_ru(url: str) -> str: """ cloud.mail.ru direct links generator Using https://github.com/JrMasterModelBuilder/cmrudl.py""" @@ -206,49 +146,6 @@ def github(url: str) -> str: raise DirectDownloadLinkException("`Error: Can't extract the link`\n") -def androidfilehost(url: str) -> str: - """ AFH direct links generator """ - try: - link = re.findall(r'\bhttps?://.*androidfilehost.*fid.*\S+', url)[0] - except IndexError: - raise DirectDownloadLinkException("`No AFH links found`\n") - fid = re.findall(r'\?fid=(.*)', link)[0] - session = requests.Session() - user_agent = useragent() - headers = {'user-agent': user_agent} - res = session.get(link, headers=headers, allow_redirects=True) - headers = { - 'origin': 'https://androidfilehost.com', - 'accept-encoding': 'gzip, deflate, br', - 'accept-language': 'en-US,en;q=0.9', - 'user-agent': user_agent, - 'content-type': 'application/x-www-form-urlencoded; charset=UTF-8', - 'x-mod-sbb-ctype': 'xhr', - 'accept': '*/*', - 'referer': f'https://androidfilehost.com/?fid={fid}', - 'authority': 'androidfilehost.com', - 'x-requested-with': 'XMLHttpRequest', - } - data = { - 'submit': 'submit', - 'action': 'getdownloadmirrors', - 'fid': f'{fid}' - } - error = "`Error: Can't find Mirrors for the link`\n" - try: - req = session.post( - 'https://androidfilehost.com/libs/otf/mirrors.otf.php', - headers=headers, - data=data, - cookies=res.cookies) - mirrors = req.json()['MIRRORS'] - except (json.decoder.JSONDecodeError, TypeError): - raise DirectDownloadLinkException(error) - if not mirrors: - raise DirectDownloadLinkException(error) - return mirrors[0] - - def useragent(): """ useragent random setter