def _mirror(bot, update, isZip=False, extract=False, isQbit=False, isLeech=False, pswd=None): mesg = update.message.text.split('\n') message_args = mesg[0].split(' ', maxsplit=1) name_args = mesg[0].split('|', maxsplit=1) qbitsel = False is_gdtot = False try: link = message_args[1] if link.startswith("s ") or link == "s": qbitsel = True message_args = mesg[0].split(' ', maxsplit=2) link = message_args[2].strip() if link.startswith(("|", "pswd: ")): link = '' except IndexError: link = '' try: name = name_args[1] name = name.split(' pswd: ')[0] name = name.strip() except IndexError: name = '' link = resplit(r"pswd:| \|", link)[0] link = link.strip() pswdMsg = mesg[0].split(' pswd: ') if len(pswdMsg) > 1: pswd = pswdMsg[1] if update.message.from_user.username: tag = f"@{update.message.from_user.username}" else: tag = update.message.from_user.mention_html(update.message.from_user.first_name) reply_to = update.message.reply_to_message if reply_to is not None: file = None media_array = [reply_to.document, reply_to.video, reply_to.audio] for i in media_array: if i is not None: file = i break if not reply_to.from_user.is_bot: if reply_to.from_user.username: tag = f"@{reply_to.from_user.username}" else: tag = reply_to.from_user.mention_html(reply_to.from_user.first_name) if ( not is_url(link) and not is_magnet(link) or len(link) == 0 ): if file is None: reply_text = reply_to.text if is_url(reply_text) or is_magnet(reply_text): link = reply_text.strip() elif isQbit: file_name = str(time()).replace(".", "") + ".torrent" link = file.get_file().download(custom_path=file_name) elif file.mime_type != "application/x-bittorrent": listener = MirrorListener(bot, update, isZip, extract, isQbit, isLeech, pswd, tag) tg_downloader = TelegramDownloadHelper(listener) ms = update.message tg_downloader.add_download(ms, f'{DOWNLOAD_DIR}{listener.uid}/', name) return else: link = file.get_file().file_path if len(mesg) > 1: try: ussr = quote(mesg[1], safe='') pssw = quote(mesg[2], safe='') link = link.split("://", maxsplit=1) link = f'{link[0]}://{ussr}:{pssw}@{link[1]}' except IndexError: pass if not is_url(link) and not is_magnet(link) and not ospath.exists(link): help_msg = "<b>Send link along with command line:</b>" help_msg += "\n<code>/command</code> {link} |newname pswd: mypassword [𝚣𝚒𝚙/𝚞𝚗𝚣𝚒𝚙]" help_msg += "\n\n<b>By replying to link or file:</b>" help_msg += "\n<code>/command</code> |newname pswd: mypassword [𝚣𝚒𝚙/𝚞𝚗𝚣𝚒𝚙]" help_msg += "\n\n<b>Direct link authorization:</b>" help_msg += "\n<code>/command</code> {link} |newname pswd: mypassword\nusername\npassword" help_msg += "\n\n<b>Qbittorrent selection:</b>" help_msg += "\n<code>/qbcommand</code> <b>s</b> {link} or by replying to {file}" return sendMessage(help_msg, bot, update) LOGGER.info(link) if not is_mega_link(link) and not isQbit and not is_magnet(link) \ and not ospath.exists(link) and not is_gdrive_link(link) and not link.endswith('.torrent'): content_type = get_content_type(link) if content_type is None or match(r'text/html|text/plain', content_type): try: is_gdtot = is_gdtot_link(link) link = direct_link_generator(link) LOGGER.info(f"Generated link: {link}") except DirectDownloadLinkException as e: LOGGER.info(str(e)) if str(e).startswith('ERROR:'): return sendMessage(str(e), bot, update) elif isQbit and not is_magnet(link) and not ospath.exists(link): if link.endswith('.torrent'): content_type = None else: content_type = get_content_type(link) if content_type is None or match(r'application/x-bittorrent|application/octet-stream', content_type): try: resp = requests.get(link, timeout=10) if resp.status_code == 200: file_name = str(time()).replace(".", "") + ".torrent" with open(file_name, "wb") as t: t.write(resp.content) link = str(file_name) else: return sendMessage(f"ERROR: link got HTTP response: {resp.status_code}", bot, update) except Exception as e: error = str(e).replace('<', ' ').replace('>', ' ') if error.startswith('No connection adapters were found for'): link = error.split("'")[1] else: LOGGER.error(str(e)) return sendMessage(tag + " " + error, bot, update) else: msg = "Qb commands for torrents only. if you are trying to dowload torrent then report." return sendMessage(msg, bot, update) listener = MirrorListener(bot, update, isZip, extract, isQbit, isLeech, pswd, tag) if is_gdrive_link(link): if not isZip and not extract and not isLeech: gmsg = f"Use /{BotCommands.CloneCommand} to clone Google Drive file/folder\n\n" gmsg += f"Use /{BotCommands.ZipMirrorCommand} to make zip of Google Drive folder\n\n" gmsg += f"Use /{BotCommands.UnzipMirrorCommand} to extracts Google Drive archive file" return sendMessage(gmsg, bot, update) Thread(target=add_gd_download, args=(link, listener, is_gdtot)).start() elif is_mega_link(link): if BLOCK_MEGA_LINKS: sendMessage("Mega links are blocked!", bot, update) return link_type = get_mega_link_type(link) if link_type == "folder" and BLOCK_MEGA_FOLDER: sendMessage("Mega folder are blocked!", bot, update) else: Thread(target=add_mega_download, args=(link, f'{DOWNLOAD_DIR}{listener.uid}/', listener)).start() elif isQbit and (is_magnet(link) or ospath.exists(link)): Thread(target=add_qb_torrent, args=(link, f'{DOWNLOAD_DIR}{listener.uid}', listener, qbitsel)).start() else: Thread(target=add_aria2c_download, args=(link, f'{DOWNLOAD_DIR}{listener.uid}', listener, name)).start()
def _mirror(bot, update, isTar=False, extract=False): message_args = update.message.text.split(' ') name_args = update.message.text.split('|') try: link = message_args[1] if link.startswith("|") or link.startswith("pswd: "): link = '' except IndexError: link = '' try: name = name_args[1] name = name.strip() if name.startswith("pswd: "): name = '' except IndexError: name = '' pswd = re.search('(?<=pswd: )(.*)', update.message.text) if pswd is not None: pswd = pswd.groups() pswd = " ".join(pswd) LOGGER.info(link) link = link.strip() reply_to = update.message.reply_to_message if reply_to is not None: file = None tag = reply_to.from_user.username media_array = [reply_to.document, reply_to.video, reply_to.audio] for i in media_array: if i is not None: file = i break if not bot_utils.is_url(link) and not bot_utils.is_magnet(link) or len(link) == 0: if file is not None: if file.mime_type != "application/x-bittorrent": listener = MirrorListener(bot, update, pswd, isTar, tag, extract) tg_downloader = TelegramDownloadHelper(listener) tg_downloader.add_download(reply_to, f'{DOWNLOAD_DIR}{listener.uid}/', name) sendMessage(f"<b>☞ Your Telegram File Has Been Added To Download Queue.\n☞ Check Status By Clicking</b> /{BotCommands.StatusCommand}", bot, update) if len(Interval) == 0: Interval.append(setInterval(DOWNLOAD_STATUS_UPDATE_INTERVAL, update_all_messages)) return else: link = file.get_file().file_path else: tag = None if not bot_utils.is_url(link) and not bot_utils.is_magnet(link): sendMessage('No download source provided', bot, update) return try: link = direct_link_generator(link) except DirectDownloadLinkException as e: LOGGER.info(f'{link}: {e}') listener = MirrorListener(bot, update, pswd, isTar, tag, extract) if bot_utils.is_mega_link(link): link_type = get_mega_link_type(link) if link_type == "folder" and BLOCK_MEGA_FOLDER: sendMessage("☞ Mega Folders Are Blocked On This Bot!! ☞</b>", bot, update) elif BLOCK_MEGA_LINKS: sendMessage("<b>☞ Mega Links Are Blocked On This Bot!! ☞</b>", bot, update) else: mega_dl = MegaDownloadHelper() mega_dl.add_download(link, f'{DOWNLOAD_DIR}/{listener.uid}/', listener) sendMessage(f"<b>☞ Mega.nz Link Added To Ⓜ️ /{BotCommands.StatusCommand}\n Only 2 Download At A Time Otherwise Ban.\n☞ Do Not Forget To Read Mega Download Rules.</b>", bot, update) else: ariaDlManager.add_download(link, f'{DOWNLOAD_DIR}/{listener.uid}/', listener, name) sendMessage(f"<b>☞ Your URI Link Has Been Added To List /{BotCommands.StatusCommand}\n☞ Max Mirror Size Is <u>60GB</u> In This Group.\n☞ Do Not Forget To Read Group Rules On Pinned Messages.</b>", bot, update) if len(Interval) == 0: Interval.append(setInterval(DOWNLOAD_STATUS_UPDATE_INTERVAL, update_all_messages))
def _mirror(bot, update, isTar=False, extract=False): message_args = update.message.text.split(' ') name_args = update.message.text.split('|') try: link = message_args[1] if link.startswith("|") or link.startswith("pswd: "): link = '' except IndexError: link = '' try: name = name_args[1] name = name.strip() if name.startswith("pswd: "): name = '' except IndexError: name = '' pswd = re.search('(?<=pswd: )(.*)', update.message.text) if pswd is not None: pswd = pswd.groups() pswd = " ".join(pswd) LOGGER.info(link) link = link.strip() reply_to = update.message.reply_to_message if reply_to is not None: file = None tag = reply_to.from_user.username media_array = [reply_to.document, reply_to.video, reply_to.audio] for i in media_array: if i is not None: file = i break if not bot_utils.is_url(link) and not bot_utils.is_magnet(link) or len( link) == 0: if file is not None: if file.mime_type != "application/x-bittorrent": listener = MirrorListener(bot, update, pswd, isTar, tag, extract) tg_downloader = TelegramDownloadHelper(listener) tg_downloader.add_download( reply_to, f'{DOWNLOAD_DIR}{listener.uid}/', name) sendStatusMessage(update, bot) if len(Interval) == 0: Interval.append( setInterval(DOWNLOAD_STATUS_UPDATE_INTERVAL, update_all_messages)) return else: link = file.get_file().file_path else: tag = None if not bot_utils.is_url(link) and not bot_utils.is_magnet(link): sendMessage('No download source provided', bot, update) return try: link = direct_link_generator(link) except DirectDownloadLinkException as e: LOGGER.info(f'{link}: {e}') listener = MirrorListener(bot, update, pswd, isTar, tag, extract) if bot_utils.is_mega_link(link): link_type = get_mega_link_type(link) if link_type == "folder" and BLOCK_MEGA_FOLDER: sendMessage("Mega folder are blocked!", bot, update) elif BLOCK_MEGA_LINKS: sendMessage( "Mega links are blocked bcoz mega downloading is too much unstable and buggy. mega support will be added back after fix", bot, update) else: mega_dl = MegaDownloadHelper() mega_dl.add_download(link, f'{DOWNLOAD_DIR}/{listener.uid}/', listener) sendStatusMessage(update, bot) else: ariaDlManager.add_download(link, f'{DOWNLOAD_DIR}/{listener.uid}/', listener, name) sendStatusMessage(update, bot) if len(Interval) == 0: Interval.append( setInterval(DOWNLOAD_STATUS_UPDATE_INTERVAL, update_all_messages))
def _mirror(bot, update, isTar=False, extract=False): mesg = update.message.text.split('\n') message_args = mesg[0].split(' ') name_args = mesg[0].split('|') qbit = False qbitsel = False try: link = message_args[1] if link == "qb" or link == "qbs": qbit = True if link == "qbs": qbitsel = True link = message_args[2] print(link) if link.startswith("|") or link.startswith("pswd: "): link = '' except IndexError: link = '' try: name = name_args[1] name = name.strip() if name.startswith("pswd: "): name = '' except IndexError: name = '' try: ussr = urllib.parse.quote(mesg[1], safe='') pssw = urllib.parse.quote(mesg[2], safe='') except: ussr = '' pssw = '' if ussr != '' and pssw != '': link = link.split("://", maxsplit=1) link = f'{link[0]}://{ussr}:{pssw}@{link[1]}' pswd = re.search('(?<=pswd: )(.*)', update.message.text) if pswd is not None: pswd = pswd.groups() pswd = " ".join(pswd) LOGGER.info(link) link = link.strip() reply_to = update.message.reply_to_message if reply_to is not None: file = None media_array = [reply_to.document, reply_to.video, reply_to.audio] for i in media_array: if i is not None: file = i break if not bot_utils.is_url(link) and not bot_utils.is_magnet(link) or len(link) == 0: if file is not None: if file.mime_type != "application/x-bittorrent": listener = MirrorListener(bot, update, pswd, isTar, extract) tg_downloader = TelegramDownloadHelper(listener) ms = update.message tg_downloader.add_download(ms, f'{DOWNLOAD_DIR}{listener.uid}/', name) return else: if qbit: file.get_file().download(custom_path=f"/usr/src/app/{file.file_name}") link = f"/usr/src/app/{file.file_name}" else: link = file.get_file().file_path if not bot_utils.is_url(link) and not bot_utils.is_magnet(link): sendMessage('No download source provided', bot, update) return try: link = direct_link_generator(link) except DirectDownloadLinkException as e: LOGGER.info(e) if "ERROR:" in str(e): sendMessage(f"{e}", bot, update) return if "Youtube" in str(e): sendMessage(f"{e}", bot, update) return listener = MirrorListener(bot, update, pswd, isTar, extract, qbit) if bot_utils.is_gdrive_link(link): if not isTar and not extract: sendMessage(f"Use /{BotCommands.CloneCommand} to clone Google Drive file/folder\nUse /{BotCommands.TarMirrorCommand} to make tar of Google Drive folder\nUse /{BotCommands.UnzipMirrorCommand} to extracts archive Google Drive file", bot, update) return res, size, name, files = gdriveTools.GoogleDriveHelper().clonehelper(link) if res != "": sendMessage(res, bot, update) return if TAR_UNZIP_LIMIT is not None: LOGGER.info(f'Checking File/Folder Size') limit = TAR_UNZIP_LIMIT limit = limit.split(' ', maxsplit=1) limitint = int(limit[0]) msg = f'Failed, Tar/Unzip limit is {TAR_UNZIP_LIMIT}.\nYour File/Folder size is {get_readable_file_size(size)}.' if 'G' in limit[1] or 'g' in limit[1]: if size > limitint * 1024**3: sendMessage(msg, listener.bot, listener.update) return elif 'T' in limit[1] or 't' in limit[1]: if size > limitint * 1024**4: sendMessage(msg, listener.bot, listener.update) return LOGGER.info(f"Download Name : {name}") drive = gdriveTools.GoogleDriveHelper(name, listener) gid = ''.join(random.SystemRandom().choices(string.ascii_letters + string.digits, k=12)) download_status = DownloadStatus(drive, size, listener, gid) with download_dict_lock: download_dict[listener.uid] = download_status sendStatusMessage(update, bot) drive.download(link) elif bot_utils.is_mega_link(link): link_type = get_mega_link_type(link) if link_type == "folder" and BLOCK_MEGA_FOLDER: sendMessage("Mega folder are blocked!", bot, update) elif BLOCK_MEGA_LINKS: sendMessage("Mega links are blocked!", bot, update) else: mega_dl = MegaDownloadHelper() mega_dl.add_download(link, f'{DOWNLOAD_DIR}/{listener.uid}/', listener) elif qbit and (bot_utils.is_magnet(link) or os.path.exists(link)): qbit = qbittorrent() qbit.add_torrent(link, f'{DOWNLOAD_DIR}{listener.uid}/', listener, qbitsel) else: ariaDlManager.add_download(link, f'{DOWNLOAD_DIR}/{listener.uid}/', listener, name) sendStatusMessage(update, bot)
def add_download(mega_link: str, path: str, listener): if MEGA_API_KEY is None: raise MegaDownloaderException( 'Mega API KEY not provided! Cannot mirror Mega links') executor = AsyncExecutor() api = MegaApi(MEGA_API_KEY, None, None, 'telegram-mirror-bot') global listeners mega_listener = MegaAppListener(executor.continue_event, listener) listeners.append(mega_listener) api.addListener(mega_listener) if MEGA_EMAIL_ID is not None and MEGA_PASSWORD is not None: executor.do(api.login, (MEGA_EMAIL_ID, MEGA_PASSWORD)) link_type = get_mega_link_type(mega_link) if link_type == "file": LOGGER.info( "File. If your download didn't start, then check your link if it's available to download" ) executor.do(api.getPublicNode, (mega_link, )) node = mega_listener.public_node else: LOGGER.info( "Folder. If your download didn't start, then check your link if it's available to download" ) folder_api = MegaApi(MEGA_API_KEY, None, None, 'TgBot') folder_api.addListener(mega_listener) executor.do(folder_api.loginToFolder, (mega_link, )) node = folder_api.authorizeNode(mega_listener.node) if mega_listener.error is not None: return listener.onDownloadError(str(mega_listener.error)) if STOP_DUPLICATE: LOGGER.info(f'Checking File/Folder if already in Drive') mname = node.getName() if listener.isTar: mname = mname + ".tar" if listener.extract: smsg = None else: gd = GoogleDriveHelper() smsg, button = gd.drive_list(mname) if smsg: msg1 = "File/Folder is already available in Drive.\nHere are the search results:" sendMarkup(msg1, listener.bot, listener.update, button) executor.continue_event.set() return if MEGA_LIMIT is not None or TAR_UNZIP_LIMIT is not None: limit = None LOGGER.info(f'Checking File/Folder Size') if TAR_UNZIP_LIMIT is not None and (listener.isTar or listener.extract): limit = TAR_UNZIP_LIMIT msg3 = f'Failed, Tar/Unzip limit is {TAR_UNZIP_LIMIT}.\nYour File/Folder size is {get_readable_file_size(api.getSize(node))}.' elif MEGA_LIMIT is not None and limit is None: limit = MEGA_LIMIT msg3 = f'Failed, Mega limit is {MEGA_LIMIT}.\nYour File/Folder size is {get_readable_file_size(api.getSize(node))}.' if limit is not None: limit = limit.split(' ', maxsplit=1) limitint = int(limit[0]) if 'G' in limit[1] or 'g' in limit[1]: if api.getSize(node) > limitint * 1024**3: sendMessage(msg3, listener.bot, listener.update) executor.continue_event.set() return elif 'T' in limit[1] or 't' in limit[1]: if api.getSize(node) > limitint * 1024**4: sendMessage(msg3, listener.bot, listener.update) executor.continue_event.set() return with download_dict_lock: download_dict[listener.uid] = MegaDownloadStatus( mega_listener, listener) os.makedirs(path) gid = ''.join(random.SystemRandom().choices(string.ascii_letters + string.digits, k=8)) mega_listener.setValues(node.getName(), api.getSize(node), gid) sendStatusMessage(listener.update, listener.bot) executor.do(api.startDownload, (node, path))
def _mirror(bot, update, isTar=False, extract=False): mesg = update.message.text.split('\n') message_args = mesg[0].split(' ') name_args = mesg[0].split('|') try: link = message_args[1] print(link) if link.startswith("|") or link.startswith("pswd: "): link = '' except IndexError: link = '' try: name = name_args[1] name = name.strip() if name.startswith("pswd: "): name = '' except IndexError: name = '' try: ussr = urllib.parse.quote(mesg[1], safe='') pssw = urllib.parse.quote(mesg[2], safe='') except: ussr = '' pssw = '' if ussr != '' and pssw != '': link = link.split("://", maxsplit=1) link = f'{link[0]}://{ussr}:{pssw}@{link[1]}' pswd = re.search('(?<=pswd: )(.*)', update.message.text) if pswd is not None: pswd = pswd.groups() pswd = " ".join(pswd) LOGGER.info(link) link = link.strip() reply_to = update.message.reply_to_message if reply_to is not None: file = None tag = reply_to.from_user.username media_array = [reply_to.document, reply_to.video, reply_to.audio] for i in media_array: if i is not None: file = i break if not bot_utils.is_url(link) and not bot_utils.is_magnet(link) or len(link) == 0: if file is not None: if file.mime_type != "application/x-bittorrent": listener = MirrorListener(bot, update, pswd, isTar, tag, extract) tg_downloader = TelegramDownloadHelper(listener) tg_downloader.add_download(reply_to, f'{DOWNLOAD_DIR}{listener.uid}/', name) sendMessage(f"<b>📥 Your Telegram File Has Been Added To Download Queue.\n\n‼️ Do Not Forget To Read Group Rules.\n\n ✅ Check Progress : /{BotCommands.StatusCommand}</b>", bot, update) if len(Interval) == 0: Interval.append(setInterval(DOWNLOAD_STATUS_UPDATE_INTERVAL, update_all_messages)) return else: link = file.get_file().file_path else: tag = None if not bot_utils.is_url(link) and not bot_utils.is_magnet(link): sendMessage('No download source provided', bot, update) return try: link = direct_link_generator(link) except DirectDownloadLinkException as e: LOGGER.info(f'{link}: {e}') if "ERROR:" in str(e): sendMessage(f"{e}", bot, update) return if "Youtube" in str(e): sendMessage(f"{e}", bot, update) return listener = MirrorListener(bot, update, pswd, isTar, tag, extract) if bot_utils.is_gdrive_link(link): if not isTar and not extract: sendMessage(f"Use /{BotCommands.CloneCommand} to clone Google Drive file/folder\nUse /{BotCommands.TarMirrorCommand} to make tar of Google Drive folder\nUse /{BotCommands.UnzipMirrorCommand} to extracts archive Google Drive file", bot, update) return res, size, name = gdriveTools.GoogleDriveHelper().clonehelper(link) if res != "": sendMessage(res, bot, update) return if TAR_UNZIP_LIMIT is not None: LOGGER.info(f'Checking File/Folder Size') limit = TAR_UNZIP_LIMIT limit = limit.split(' ', maxsplit=1) limitint = int(limit[0]) msg = f'Failed, Tar/Unzip limit is {TAR_UNZIP_LIMIT}.\nYour File/Folder size is {get_readable_file_size(size)}.' if 'G' in limit[1] or 'g' in limit[1]: if size > limitint * 1024**3: sendMessage(msg, listener.bot, listener.update) return elif 'T' in limit[1] or 't' in limit[1]: if size > limitint * 1024**4: sendMessage(msg, listener.bot, listener.update) return LOGGER.info(f"Download Name : {name}") drive = gdriveTools.GoogleDriveHelper(name, listener) gid = ''.join(random.SystemRandom().choices(string.ascii_letters + string.digits, k=12)) download_status = DownloadStatus(drive, size, listener, gid) with download_dict_lock: download_dict[listener.uid] = download_status if len(Interval) == 0: Interval.append(setInterval(DOWNLOAD_STATUS_UPDATE_INTERVAL, update_all_messages)) sendStatusMessage(update, bot) drive.download(link) elif bot_utils.is_mega_link(link): link_type = get_mega_link_type(link) if link_type == "folder" and BLOCK_MEGA_FOLDER: sendMessage("Mega folder are blocked!", bot, update) elif BLOCK_MEGA_LINKS: sendMessage("Mega links are blocked!", bot, update) else: mega_dl = MegaDownloadHelper() mega_dl.add_download(link, f'{DOWNLOAD_DIR}/{listener.uid}/', listener) sendMessage(f"<b>📥 Mega.nz Link Has Been Added To Download Queue\n\n⛔ Only 1 Download At A Time Otherwise Ban.\n\n‼️ Do Not Forget To Read Mega Download Rules.\n\n✅ Check Progress : /{BotCommands.StatusCommand}</b>", bot, update) else: ariaDlManager.add_download(link, f'{DOWNLOAD_DIR}/{listener.uid}/', listener, name) sendMessage(f"<b>📥 Your URL Link Has Been Added To Download Queue.\n\nⓂ️ Max Mirror Size Is <u>60GB</u> In This Group.\n\n‼️ Do Not Forget To Read Group Rules.\n\n✅ Check Progress : /{BotCommands.StatusCommand}</b>", bot, update) if len(Interval) == 0: Interval.append(setInterval(DOWNLOAD_STATUS_UPDATE_INTERVAL, update_all_messages))
def add_download(mega_link: str, path: str, listener): if MEGA_API_KEY is None: raise MegaDownloaderException( 'Mega API KEY not provided! Cannot mirror mega links') executor = AsyncExecutor() api = MegaApi(MEGA_API_KEY, None, None, 'telegram-mirror-bot') global listeners mega_listener = MegaAppListener(executor.continue_event, listener) listeners.append(mega_listener) api.addListener(mega_listener) if MEGA_EMAIL_ID is not None and MEGA_PASSWORD is not None: executor.do(api.login, (MEGA_EMAIL_ID, MEGA_PASSWORD)) link_type = get_mega_link_type(mega_link) if link_type == "file": executor.do(api.getPublicNode, (mega_link, )) node = mega_listener.public_node else: LOGGER.info("Logging into mega folder") folder_api = MegaApi(MEGA_API_KEY, None, None, 'TgBot') folder_api.addListener(mega_listener) executor.do(folder_api.loginToFolder, (mega_link, )) node = folder_api.authorizeNode(mega_listener.node) if STOP_DUPLICATE_MEGA: msg = sendMessage('Check the File/Folder if already in drive...', listener.bot, listener.update) LOGGER.info(f'Check the File/Folder if already in drive') mname = node.getName() if listener.isTar == True: mname = mname + ".tar" if listener.extract == True: smsg = None else: gd = GoogleDriveHelper() smsg, button = gd.drive_list(mname) if smsg: deleteMessage(listener.bot, msg) msg1 = "File/Folder is already available in Drive.\nHere are the search results:" sendMarkup(msg1, listener.bot, listener.update, button) return else: deleteMessage(listener.bot, msg) if MEGA_LIMIT is not None: msg2 = sendMessage('Check the File/Folder size...', listener.bot, listener.update) LOGGER.info(f'Check the File/Folder size') limit = MEGA_LIMIT limit = limit.split(' ', maxsplit=1) limitint = int(limit[0]) msg3 = f'Failed, Mega limit is {MEGA_LIMIT}.\nYour File/Folder size is {get_readable_file_size(api.getSize(node))}.' if 'GB' in limit or 'gb' in limit: if api.getSize(node) > limitint * 1024**3: deleteMessage(listener.bot, msg2) sendMessage(msg3, listener.bot, listener.update) return else: deleteMessage(listener.bot, msg2) elif 'TB' in limit or 'tb' in limit: if api.getSize(node) > limitint * 1024**4: deleteMessage(listener.bot, msg2) sendMessage(msg3, listener.bot, listener.update) return else: deleteMessage(listener.bot, msg2) sendStatusMessage(listener.update, listener.bot) with download_dict_lock: download_dict[listener.uid] = MegaDownloadStatus( mega_listener, listener) os.makedirs(path) gid = ''.join(random.SystemRandom().choices(string.ascii_letters + string.digits, k=8)) mega_listener.setValues(node.getName(), api.getSize(node), gid) executor.do(api.startDownload, (node, path))
def add_mega_download(mega_link: str, path: str, listener): executor = AsyncExecutor() api = MegaApi(MEGA_API_KEY, None, None, 'mirror-leech-telegram-bot') mega_listener = MegaAppListener(executor.continue_event, listener) global listeners api.addListener(mega_listener) listeners.append(mega_listener) if MEGA_EMAIL_ID is not None and MEGA_PASSWORD is not None: executor.do(api.login, (MEGA_EMAIL_ID, MEGA_PASSWORD)) link_type = get_mega_link_type(mega_link) if link_type == "file": LOGGER.info( "File. If your download didn't start, then check your link if it's available to download" ) executor.do(api.getPublicNode, (mega_link, )) node = mega_listener.public_node else: LOGGER.info( "Folder. If your download didn't start, then check your link if it's available to download" ) folder_api = MegaApi(MEGA_API_KEY, None, None, 'mltb') folder_api.addListener(mega_listener) executor.do(folder_api.loginToFolder, (mega_link, )) node = folder_api.authorizeNode(mega_listener.node) if mega_listener.error is not None: return sendMessage(str(mega_listener.error), listener.bot, listener.update) if STOP_DUPLICATE and not listener.isLeech: LOGGER.info('Checking File/Folder if already in Drive') mname = node.getName() if listener.isZip: mname = mname + ".zip" elif listener.extract: try: mname = get_base_name(mname) except: mname = None if mname is not None: smsg, button = GoogleDriveHelper().drive_list(mname, True) if smsg: msg1 = "File/Folder is already available in Drive.\nHere are the search results:" return sendMarkup(msg1, listener.bot, listener.update, button) if any([STORAGE_THRESHOLD, ZIP_UNZIP_LIMIT, MEGA_LIMIT]): size = api.getSize(node) arch = any([listener.isZip, listener.extract]) if STORAGE_THRESHOLD is not None: acpt = check_storage_threshold(size, arch) if not acpt: msg = f'You must leave {STORAGE_THRESHOLD}GB free storage.' msg += f'\nYour File/Folder size is {get_readable_file_size(size)}' return sendMessage(msg, listener.bot, listener.update) limit = None if ZIP_UNZIP_LIMIT is not None and arch: msg3 = f'Failed, Zip/Unzip limit is {ZIP_UNZIP_LIMIT}GB.\nYour File/Folder size is {get_readable_file_size(api.getSize(node))}.' limit = ZIP_UNZIP_LIMIT elif MEGA_LIMIT is not None: msg3 = f'Failed, Mega limit is {MEGA_LIMIT}GB.\nYour File/Folder size is {get_readable_file_size(api.getSize(node))}.' limit = MEGA_LIMIT if limit is not None: LOGGER.info('Checking File/Folder Size...') if size > limit * 1024**3: return sendMessage(msg3, listener.bot, listener.update) with download_dict_lock: download_dict[listener.uid] = MegaDownloadStatus( mega_listener, listener) makedirs(path) gid = ''.join(random.SystemRandom().choices(string.ascii_letters + string.digits, k=8)) mega_listener.setValues(node.getName(), api.getSize(node), gid) sendStatusMessage(listener.update, listener.bot) executor.do(api.startDownload, (node, path))
def _mirror(bot, update, isTar=False, extract=False): mesg = update.message.text.split('\n') message_args = mesg[0].split(' ') name_args = mesg[0].split('|') try: link = message_args[1] print(link) if link.startswith("|") or link.startswith("pswd: "): link = '' except IndexError: link = '' try: name = name_args[1] name = name.strip() if name.startswith("pswd: "): name = '' except IndexError: name = '' try: ussr = urllib.parse.quote(mesg[1], safe='') pssw = urllib.parse.quote(mesg[2], safe='') except: ussr = '' pssw = '' if ussr != '' and pssw != '': link = link.split("://", maxsplit=1) link = f'{link[0]}://{ussr}:{pssw}@{link[1]}' pswd = re.search('(?<=pswd: )(.*)', update.message.text) if pswd is not None: pswd = pswd.groups() pswd = " ".join(pswd) LOGGER.info(link) link = link.strip() reply_to = update.message.reply_to_message if reply_to is not None: file = None tag = reply_to.from_user.username media_array = [reply_to.document, reply_to.video, reply_to.audio] for i in media_array: if i is not None: file = i break if not bot_utils.is_url(link) and not bot_utils.is_magnet(link) or len( link) == 0: if file is not None: if file.mime_type != "application/x-bittorrent": listener = MirrorListener(bot, update, pswd, isTar, tag, extract) tg_downloader = TelegramDownloadHelper(listener) tg_downloader.add_download( reply_to, f'{DOWNLOAD_DIR}{listener.uid}/', name) sendStatusMessage(update, bot) if len(Interval) == 0: Interval.append( setInterval(DOWNLOAD_STATUS_UPDATE_INTERVAL, update_all_messages)) return else: link = file.get_file().file_path else: tag = None if not bot_utils.is_url(link) and not bot_utils.is_magnet(link): sendMessage('No download source provided', bot, update) return try: link = direct_link_generator(link) except DirectDownloadLinkException as e: LOGGER.info(f'{link}: {e}') if "ERROR:" in str(e): sendMessage(f"{e}", bot, update) return if "Youtube" in str(e): sendMessage(f"ERROR: {e}", bot, update) return listener = MirrorListener(bot, update, pswd, isTar, tag, extract) if bot_utils.is_gdrive_link(link): if not isTar and not extract: sendMessage( f"Use /{BotCommands.CloneCommand} To Copy Google Drive File/Folder", bot, update) return res, size, name = gdriveTools.GoogleDriveHelper().clonehelper(link) if res != "": sendMessage(res, bot, update) return LOGGER.info(f"Download Name : {name}") drive = gdriveTools.GoogleDriveHelper(name, listener) gid = ''.join(random.SystemRandom().choices(string.ascii_letters + string.digits, k=12)) download_status = DownloadStatus(drive, size, listener, gid) with download_dict_lock: download_dict[listener.uid] = download_status if len(Interval) == 0: Interval.append( setInterval(DOWNLOAD_STATUS_UPDATE_INTERVAL, update_all_messages)) sendStatusMessage(update, bot) drive.download(link) elif bot_utils.is_mega_link(link): link_type = get_mega_link_type(link) if link_type == "folder" and BLOCK_MEGA_FOLDER: sendMessage("Mega folder are blocked!", bot, update) elif BLOCK_MEGA_LINKS: sendMessage("Mega links are blocked!", bot, update) else: mega_dl = MegaDownloadHelper() mega_dl.add_download(link, f'{DOWNLOAD_DIR}/{listener.uid}/', listener) else: ariaDlManager.add_download(link, f'{DOWNLOAD_DIR}/{listener.uid}/', listener, name) sendStatusMessage(update, bot) if len(Interval) == 0: Interval.append( setInterval(DOWNLOAD_STATUS_UPDATE_INTERVAL, update_all_messages))
def _mirror(bot, update, isTar=False, extract=False): message_args = update.message.text.split(' ') name_args = update.message.text.split('|') try: link = message_args[1] if link.startswith("|") or link.startswith("pswd: "): link = '' except IndexError: link = '' try: name = name_args[1] name = name.strip() if name.startswith("pswd: "): name = '' except IndexError: name = '' pswd = re.search('(?<=pswd: )(.*)', update.message.text) if pswd is not None: pswd = pswd.groups() pswd = " ".join(pswd) LOGGER.info(link) link = link.strip() reply_to = update.message.reply_to_message if reply_to is not None: file = None tag = reply_to.from_user.username media_array = [reply_to.document, reply_to.video, reply_to.audio] for i in media_array: if i is not None: file = i break if not bot_utils.is_url(link) and not bot_utils.is_magnet(link) or len(link) == 0: if file is not None: if file.mime_type != "application/x-bittorrent": listener = MirrorListener(bot, update, pswd, isTar, tag, extract) tg_downloader = TelegramDownloadHelper(listener) tg_downloader.add_download(reply_to, f'{DOWNLOAD_DIR}{listener.uid}/', name) sendMessage(f"<b> Your Telegram media has been ADDED for Mirror check /{BotCommands.StatusCommand}</b>", bot, update) if len(Interval) == 0: Interval.append(setInterval(DOWNLOAD_STATUS_UPDATE_INTERVAL, update_all_messages)) return else: link = file.get_file().file_path else: tag = None if not bot_utils.is_url(link) and not bot_utils.is_magnet(link): sendMessage('Opps 🤦\n\n📋 <b>Example</b>: \n\n➩ <b>For Torrent , Direct URL</b>:\n👉 <code>/filesmirror</code> {your Torrent link }\n\n➩ <b>For Telegram Media</b>:\n👉 Send Telegram media and Reply with <code>/filesmirror</code>', bot, update) return try: link = direct_link_generator(link) except DirectDownloadLinkException as e: LOGGER.info(f'{link}: {e}') listener = MirrorListener(bot, update, pswd, isTar, tag, extract) if bot_utils.is_mega_link(link): link_type = get_mega_link_type(link) if link_type == "folder" and BLOCK_MEGA_FOLDER: sendMessage("🚫 Mega Link Support has been Disabled", bot, update) elif BLOCK_MEGA_LINKS: sendMessage("🚫 Mega Links Support has been Disabled", bot, update) else: mega_dl = MegaDownloadHelper() mega_dl.add_download(link, f'{DOWNLOAD_DIR}/{listener.uid}/', listener) sendMessage(f"<b>★ Mega.nz Link Added To 📊 /{BotCommands.StatusCommand}\n★ Only 1 Download At A Time Otherwise Ban.\n★ Do Not Forget To Read Mega Download Rules.</b>", bot, update) else: ariaDlManager.add_download(link, f'{DOWNLOAD_DIR}/{listener.uid}/', listener, name) sendMessage(f"<b> Your Link has been ADDED for Mirror😋.\n Check /{BotCommands.StatusCommand}</b>", bot, update) if len(Interval) == 0: Interval.append(setInterval(DOWNLOAD_STATUS_UPDATE_INTERVAL, update_all_messages))
def _mirror(bot, update, isTar=False, extract=False): if update.message.from_user.last_name: last_name = f" {update.message.from_user.last_name}" else: last_name = "" if update.message.from_user.username: username = f"- @{update.message.from_user.username}" else: username = "******" name = f'<a href="tg://user?id={update.message.from_user.id}">{update.message.from_user.first_name}{last_name}</a>' msg = f"User: {name} {username} (<code>{update.message.from_user.id}</code>)\n" message_args = update.message.text.split(' ') try: link = message_args[1] except IndexError: link = '' LOGGER.info(link) link = link.strip() reply_to = update.message.reply_to_message if reply_to is not None: file = None tag = reply_to.from_user.username media_array = [reply_to.document, reply_to.video, reply_to.audio] for i in media_array: if i is not None: file = i break if len(link) == 0: if file is not None: if file.mime_type != "application/x-bittorrent": listener = MirrorListener(bot, update, isTar, tag) tg_downloader = TelegramDownloadHelper(listener) tg_downloader.add_download(reply_to, f'{DOWNLOAD_DIR}{listener.uid}/') msg += f"Message: <code>{file.mime_type}</code> | <code>{download_dict[listener.uid].name()}</code> | {download_dict[listener.uid].size()}" sendMessage(msg, bot, update) sendStatusMessage(update, bot) if len(Interval) == 0: Interval.append(setInterval(DOWNLOAD_STATUS_UPDATE_INTERVAL, update_all_messages)) return else: link = file.get_file().file_path else: tag = None if not bot_utils.is_url(link) and not bot_utils.is_magnet(link): sendMessage('No download source provided', bot, update) return try: link = direct_link_generator(link) except DirectDownloadLinkException as e: LOGGER.info(f'{link}: {e}') listener = MirrorListener(bot, update, isTar, tag, extract) if bot_utils.is_mega_link(link): link_type = get_mega_link_type(link) if link_type == "folder" and BLOCK_MEGA_FOLDER: sendMessage("🚫 <b>Mega Folder Blocked!</b> 🚫", bot, update) elif BLOCK_MEGA_LINKS: sendMessage("🚫 <b>Mega Links Blocked!</b> 🚫\n\n<b>Because Unstable & Buggy</b>", bot, update) else: mega_dl = MegaDownloadHelper() mega_dl.add_download(link, f'{DOWNLOAD_DIR}/{listener.uid}/', listener) msg += f"Message: {update.message.text}" sendMessage(msg, bot, update) sendStatusMessage(update, bot) else: ariaDlManager.add_download(link, f'{DOWNLOAD_DIR}/{listener.uid}/', listener) if reply_to is not None: msg += f"Message: <code>{file.mime_type}</code> | <code>{file.file_name}</code> | {get_readable_file_size(file.file_size)}" else: msg += f"Message: {update.message.text}" sendMessage(msg, bot, update) sendStatusMessage(update, bot) if len(Interval) == 0: Interval.append(setInterval(DOWNLOAD_STATUS_UPDATE_INTERVAL, update_all_messages))
def _mirror(bot, update, isTar=False, extract=False): mesg = update.message.text.split('\n') message_args = mesg[0].split(' ') name_args = mesg[0].split('|') try: link = message_args[1] print(link) if link.startswith("|") or link.startswith("pswd: "): link = '' except IndexError: link = '' try: name = name_args[1] name = name.strip() if name.startswith("pswd: "): name = '' except IndexError: name = '' try: ussr = urllib.parse.quote(mesg[1], safe='') pssw = urllib.parse.quote(mesg[2], safe='') except: ussr = '' pssw = '' if ussr != '' and pssw != '': link = link.split("://", maxsplit=1) link = f'{link[0]}://{ussr}:{pssw}@{link[1]}' pswd = re.search('(?<=pswd: )(.*)', update.message.text) if pswd is not None: pswd = pswd.groups() pswd = " ".join(pswd) LOGGER.info(link) link = link.strip() reply_to = update.message.reply_to_message if reply_to is not None: file = None tag = reply_to.from_user.username media_array = [reply_to.document, reply_to.video, reply_to.audio] for i in media_array: if i is not None: file = i break if not bot_utils.is_url(link) and not bot_utils.is_magnet(link) or len( link) == 0: if file is not None: if file.mime_type != "application/x-bittorrent": listener = MirrorListener(bot, update, pswd, isTar, tag, extract) tg_downloader = TelegramDownloadHelper(listener) tg_downloader.add_download( reply_to, f'{DOWNLOAD_DIR}{listener.uid}/', name) sendMessage( f"<b>📝 Your Telegram File Has Been Added To Bot Queue...\n💡 Check Progress By 💢</b> /{BotCommands.StatusCommand} 💢", bot, update) if len(Interval) == 0: Interval.append( setInterval(DOWNLOAD_STATUS_UPDATE_INTERVAL, update_all_messages)) return else: link = file.get_file().file_path else: tag = None if not bot_utils.is_url(link) and not bot_utils.is_magnet(link): sendMessage( f'<b>𝐎𝐩𝐩𝐬 🤦 \n\n📢 𝐈𝐟 𝐲𝐨𝐮 𝐃𝐨𝐧❜𝐭 𝐤𝐧𝐨𝐰 𝐡𝐨𝐰 𝐭𝐨 𝐮𝐬𝐞 𝐂𝐡𝐞𝐜𝐤 𝐎𝐭𝐡𝐞𝐫𝐬 𝐌𝐞𝐬𝐬𝐚𝐠𝐞 𝐨𝐫 𝐌𝐞𝐧𝐭𝐢𝐨𝐧 𝐀𝐃𝐌𝐈𝐍😐</b>\n\n<b>🏷️𝗘𝘅𝗮𝗺𝗽𝗹𝗲:</b>\n /{BotCommands.MirrorCommand} <b>Your Torrent Magnet or Direct URL Link</b>', bot, update) return try: link = direct_link_generator(link) except DirectDownloadLinkException as e: LOGGER.info(f'{link}: {e}') listener = MirrorListener(bot, update, pswd, isTar, tag, extract) if bot_utils.is_mega_link(link): link_type = get_mega_link_type(link) if link_type == "folder" and BLOCK_MEGA_FOLDER: sendMessage("🚫 Mega folder are blocked!🚫", bot, update) elif BLOCK_MEGA_LINKS: sendMessage( "🚫 Mega links are blocked bcoz mega downloading is too much unstable and buggy. mega support will be added back after fix🚫", bot, update) else: mega_dl = MegaDownloadHelper() mega_dl.add_download(link, f'{DOWNLOAD_DIR}/{listener.uid}/', listener) sendMessage( f"<b>📝 Mega.nz Link Added To Bot Queue ...\n🆙 Check Progress By 💢 /{BotCommands.StatusCommand} 💢\n\n★ Only 1 Download At A Time Otherwise Ban.\n★ Do Not Forget To Read Mega Download Rules.</b>", bot, update) else: ariaDlManager.add_download(link, f'{DOWNLOAD_DIR}/{listener.uid}/', listener, name) sendMessage( f"<b>📝 Your URI Link Added To Bot Queue....\n🆙 Check Progress By 💢 /{BotCommands.StatusCommand} 💢\n\n☆ Max Mirror Size Is <u>60GB</u> In This Group.\n★ Do Not Forget To Read Group Rules On Pinned Messages.</b>", bot, update) if len(Interval) == 0: Interval.append( setInterval(DOWNLOAD_STATUS_UPDATE_INTERVAL, update_all_messages))
def _mirror(bot, update, isTar=False, extract=False): mesg = update.message.text.split('\n') message_args = mesg[0].split(' ') name_args = mesg[0].split('|') try: link = message_args[1] print(link) if link.startswith("|") or link.startswith("pswd: "): link = '' except IndexError: link = '' try: name = name_args[1] name = name.strip() if name.startswith("pswd: "): name = '' except IndexError: name = '' try: ussr = urllib.parse.quote(mesg[1], safe='') pssw = urllib.parse.quote(mesg[2], safe='') except: ussr = '' pssw = '' if ussr != '' and pssw != '': link = link.split("://", maxsplit=1) link = f'{link[0]}://{ussr}:{pssw}@{link[1]}' pswd = re.search('(?<=pswd: )(.*)', update.message.text) if pswd is not None: pswd = pswd.groups() pswd = " ".join(pswd) LOGGER.info(link) link = link.strip() reply_to = update.message.reply_to_message if reply_to is not None: file = None tag = reply_to.from_user.username media_array = [reply_to.document, reply_to.video, reply_to.audio] for i in media_array: if i is not None: file = i break if not bot_utils.is_url(link) and not bot_utils.is_magnet(link) or len( link) == 0: if file is not None: if file.mime_type != "application/x-bittorrent": listener = MirrorListener(bot, update, pswd, isTar, tag, extract) tg_downloader = TelegramDownloadHelper(listener) tg_downloader.add_download( reply_to, f'{DOWNLOAD_DIR}{listener.uid}/', name) sendStatusMessage(update, bot) if len(Interval) == 0: Interval.append( setInterval(DOWNLOAD_STATUS_UPDATE_INTERVAL, update_all_messages)) return else: link = file.get_file().file_path else: tag = None if not bot_utils.is_url(link) and not bot_utils.is_magnet(link): sendMessage( 'ржХржорж╛ржирзНржбрзЗрж░ рж╕рж╛ржерзЗ ржпрзЗржХрзЛржи Download Source ржжрж┐рждрзЗ рж╣ржмрзЗред ржХржорж╛ржирзНржб ржнрзЗржжрзЗ Download Source ржнрж┐ржирзНржи рж╣рждрзЗ ржкрж╛рж░рзЗред \n<code>/mirror Download-Source</code>\nржПржЗ ржлрж░ржорзНржпрж╛ржЯрзЗ ржХржорж╛ржирзНржб ржжрж┐рждрзЗ рж╣ржмрзЗред <code>/mirror</code> ржПрж░ ржпрж╛рзЯржЧрж╛рзЯ ржЕржирзНржп ржХржорж╛ржирзНржб рж╣рждрзЗ ржкрж╛рж░рзЗред Download Source рж╣рждрзЗ ржкрж╛рж░рзЗ- Direct Download Link, Magnet Link, Mega Lile Url, Mediafire File Url, Index Link, Youtube Link ржЗрждрзНржпрж╛ржжрж┐ред ржЖрж░ ржпржжрж┐ Torrent File ржмрж╛ Telegram File ржорж┐рж░рж░ ржХрж░рждрзЗ ржЪрж╛ржи рждрж╛рж╣рж▓рзЗ ржлрж╛ржЗрж▓ржЯрж╛ржХрзЗ ржкрзНрж░ржержорзЗ ржЧрзНрж░рзБржкрзЗ рж╕рзЗржирзНржб ржЕржержмрж╛ Forward ржХрж░рзЗ рж╕рзЗржЗ ржлрж╛ржЗрж▓рзЗрж░ Relply рждрзЗ \n<code>/mirror</code> ржХржорж╛ржирзНржб ржжрж┐рждрзЗ рж╣ржмрзЗред\n\nржирж╛ ржмрзБржЭрж▓рзЗ <a href="https://telegra.ph/Bot-Commands-02-06">Bot Commands</a> ржнрж╛рж▓ ржХрж░рзЗ ржкрзЬрзБржиред\n<a href="https://t.me/gdrivemcloud/6">Direct Download Link Tutorial</a>', bot, update) return try: link = direct_link_generator(link) except DirectDownloadLinkException as e: LOGGER.info(f'{link}: {e}') listener = MirrorListener(bot, update, pswd, isTar, tag, extract) if bot_utils.is_mega_link(link): link_type = get_mega_link_type(link) if link_type == "folder" and BLOCK_MEGA_FOLDER: sendMessage("Mega folder are blocked!", bot, update) elif BLOCK_MEGA_LINKS: sendMessage("Mega links are blocked!", bot, update) else: mega_dl = MegaDownloadHelper() mega_dl.add_download(link, f'{DOWNLOAD_DIR}/{listener.uid}/', listener) sendStatusMessage(update, bot) else: ariaDlManager.add_download(link, f'{DOWNLOAD_DIR}/{listener.uid}/', listener, name) sendStatusMessage(update, bot) if len(Interval) == 0: Interval.append( setInterval(DOWNLOAD_STATUS_UPDATE_INTERVAL, update_all_messages))
def _mirror(bot, update, isTar=False, extract=False): if update.message.from_user.last_name: last_name = f" {update.message.from_user.last_name}" else: last_name = "" if update.message.from_user.username: username = f"- @{update.message.from_user.username}" else: username = "******" name = f'<a href="tg://user?id={update.message.from_user.id}">{update.message.from_user.first_name}{last_name}</a>' msg = f"User: {name} {username} (<code>{update.message.from_user.id}</code>)\n" mesg = update.message.text.split('\n') message_args = mesg[0].split(' ') name_args = mesg[0].split('|') try: link = message_args[1] print(link) if link.startswith("|") or link.startswith("pswd: "): link = '' except IndexError: link = '' try: name = name_args[1] name = name.strip() if name.startswith("pswd: "): name = '' except IndexError: name = '' try: ussr = urllib.parse.quote(mesg[1], safe='') pssw = urllib.parse.quote(mesg[2], safe='') except: ussr = '' pssw = '' if ussr != '' and pssw != '': link = link.split("://", maxsplit=1) link = f'{link[0]}://{ussr}:{pssw}@{link[1]}' pswd = re.search('(?<=pswd: )(.*)', update.message.text) if pswd is not None: pswd = pswd.groups() pswd = " ".join(pswd) LOGGER.info(link) link = link.strip() reply_to = update.message.reply_to_message if reply_to is not None: file = None tag = reply_to.from_user.username media_array = [reply_to.document, reply_to.video, reply_to.audio] for i in media_array: if i is not None: file = i break if not bot_utils.is_url(link) and not bot_utils.is_magnet(link) or len( link) == 0: if file is not None: if file.mime_type != "application/x-bittorrent": listener = MirrorListener(bot, update, pswd, isTar, tag, extract) tg_downloader = TelegramDownloadHelper(listener) tg_downloader.add_download( reply_to, f'{DOWNLOAD_DIR}{listener.uid}/', name) msg += f"Message: <code>{file.mime_type}</code> | <code>{download_dict[listener.uid].name()}</code> | {download_dict[listener.uid].size()}" sendMessage(msg, bot, update) sendStatusMessage(update, bot) if len(Interval) == 0: Interval.append( setInterval(DOWNLOAD_STATUS_UPDATE_INTERVAL, update_all_messages)) return else: link = file.get_file().file_path else: tag = None if not bot_utils.is_url(link) and not bot_utils.is_magnet(link): sendMessage('No download source provided', bot, update) return try: link = direct_link_generator(link) except DirectDownloadLinkException as e: LOGGER.info(f'{link}: {e}') listener = MirrorListener(bot, update, pswd, isTar, tag, extract) if bot_utils.is_mega_link(link): link_type = get_mega_link_type(link) if link_type == "folder" and BLOCK_MEGA_FOLDER: sendMessage("Mega folder are blocked!", bot, update) elif BLOCK_MEGA_LINKS: sendMessage( "Mega links are blocked bcoz mega downloading is too much unstable and buggy. mega support will be added back after fix", bot, update) else: mega_dl = MegaDownloadHelper() mega_dl.add_download(link, f'{DOWNLOAD_DIR}/{listener.uid}/', listener) msg += f"Message: {update.message.text}" sendMessage(msg, bot, update) sendStatusMessage(update, bot) else: ariaDlManager.add_download(link, f'{DOWNLOAD_DIR}/{listener.uid}/', listener, name) if reply_to is not None: msg += f"Message: <code>{file.mime_type}</code> | <code>{file.file_name}</code> | {get_readable_file_size(file.file_size)}" else: msg += f"Message: {update.message.text}" sendMessage(msg, bot, update) sendStatusMessage(update, bot) if len(Interval) == 0: Interval.append( setInterval(DOWNLOAD_STATUS_UPDATE_INTERVAL, update_all_messages))