def deletefile(update, context): args = update.message.text.split(" ", maxsplit=1) reply_to = update.message.reply_to_message if len(args) > 1: link = args[1] elif reply_to is not None: link = reply_to.text else: link = '' if is_gdrive_link(link): LOGGER.info(link) drive = gdriveTools.GoogleDriveHelper() msg = drive.deletefile(link) else: msg = 'Send Gdrive link along with command or by replying to the link by command' reply_message = sendMessage(msg, context.bot, update) Thread(target=auto_delete_message, args=(context.bot, update.message, reply_message)).start()
def countNode(update, context): args = update.message.text.split(" ", maxsplit=1) reply_to = update.message.reply_to_message link = '' if len(args) > 1: link = args[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) if reply_to is not None: if len(link) == 0: link = reply_to.text 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) gdtot_link = is_gdtot_link(link) if gdtot_link: try: link = gdtot(link) except DirectDownloadLinkException as e: return sendMessage(str(e), context.bot, update) if is_gdrive_link(link): msg = sendMessage(f"Counting: <code>{link}</code>", context.bot, update) gd = GoogleDriveHelper() result = gd.count(link) deleteMessage(context.bot, msg) cc = f'\n\n<b>cc: </b>{tag}' sendMessage(result + cc, context.bot, update) if gdtot_link: gd.deletefile(link) else: sendMessage( 'Send Gdrive link along with command or by replying to the link by command', context.bot, update)
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}') 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 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) and MEGA_KEY is not None: if BLOCK_MEGA_LINKS: sendMessage("Mega Links Are Blocked.", bot, update) else: mega_dl = MegaDownloader(listener) mega_dl.add_download(link, f'{DOWNLOAD_DIR}{listener.uid}/') 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('|') 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) 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) 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, 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 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("|") or 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 is_url(link) and not is_magnet(link) or len(link) == 0 ): 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 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) gdtot_link = is_gdtot_link(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: 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): content_type = get_content_type(link) if content_type is None or link.endswith('.torrent') \ 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" open(file_name, "wb").write(resp.content) link = f"{file_name}" else: return sendMessage(f"ERROR: link got HTTP response: {resp.status_code}", bot, update) except Exception as e: LOGGER.error(str(e)) error = str(e).replace('<', ' ').replace('>', ' ') return sendMessage(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, gdtot_link)).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, isZip=False, isQbit=False): mesg = update.message.text.split('\n') message_args = mesg[0].split(' ') name_args = mesg[0].split('|') qbitsel = False try: link = message_args[1] if link in ["qb", "qbs"]: isQbit = True if link == "qbs": qbitsel = True link = message_args[2] if bot_utils.is_url(link) and not bot_utils.is_magnet(link): resp = requests.get(link) if resp.status_code == 200: file_name = str(time.time()).replace(".", "") + ".torrent" with open(file_name, "wb") as f: f.write(resp.content) link = f"{file_name}" else: sendMessage( "ERROR: link got HTTP response:" + resp.status_code, bot, update) return 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) if link != '': 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) and file is not None: if isQbit: file_name = str(time.time()).replace(".", "") + ".torrent" file.get_file().download(custom_path=f"{file_name}") link = f"{file_name}" elif file.mime_type != "application/x-bittorrent": listener = MirrorListener(bot, update, pswd, isTar, extract, isZip) 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 not bot_utils.is_url(link) and not bot_utils.is_magnet(link): sendMessage('No download source provided', bot, update) return if not os.path.exists(link) and not bot_utils.is_mega_link( link) and not bot_utils.is_gdrive_link( link) and not bot_utils.is_magnet(link): 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, isZip, isQbit) 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: result = bot_utils.check_limit(size, TAR_UNZIP_LIMIT) if result: msg = f'Failed, Tar/Unzip limit is {TAR_UNZIP_LIMIT}.\nYour File/Folder size is {get_readable_file_size(size)}.' 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): if BLOCK_MEGA_LINKS: sendMessage("Mega links are blocked!", bot, update) return link_type = bot_utils.get_mega_link_type(link) if link_type == "folder" and BLOCK_MEGA_FOLDER: sendMessage("Mega folder are blocked!", bot, update) else: mega_dl = MegaDownloadHelper() mega_dl.add_download(link, f'{DOWNLOAD_DIR}{listener.uid}/', listener) elif isQbit 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 cloneNode(update, context): args = update.message.text.split(" ", maxsplit=1) reply_to = update.message.reply_to_message if len(args) > 1: link = args[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) elif reply_to is not None: link = reply_to.text 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) else: link = '' gdtot_link = is_gdtot_link(link) if gdtot_link: try: msg = sendMessage(f"Processing: <code>{link}</code>", context.bot, update) link = gdtot(link) deleteMessage(context.bot, msg) except DirectDownloadLinkException as e: deleteMessage(context.bot, msg) return sendMessage(str(e), context.bot, update) if is_gdrive_link(link): gd = GoogleDriveHelper() res, size, name, files = gd.helper(link) if res != "": return sendMessage(res, context.bot, update) if STOP_DUPLICATE: LOGGER.info('Checking File/Folder if already in Drive...') smsg, button = gd.drive_list(name, True, True) if smsg: msg3 = "File/Folder is already available in Drive.\nHere are the search results:" sendMarkup(msg3, context.bot, update, button) if gdtot_link: gd.deletefile(link) return if CLONE_LIMIT is not None: LOGGER.info('Checking File/Folder Size...') if size > CLONE_LIMIT * 1024**3: msg2 = f'Failed, Clone limit is {CLONE_LIMIT}GB.\nYour File/Folder size is {get_readable_file_size(size)}.' return sendMessage(msg2, context.bot, update) if files <= 10: msg = sendMessage(f"Cloning: <code>{link}</code>", context.bot, update) result, button = gd.clone(link) deleteMessage(context.bot, msg) else: drive = GoogleDriveHelper(name) gid = ''.join(random.SystemRandom().choices(string.ascii_letters + string.digits, k=12)) clone_status = CloneStatus(drive, size, update, gid) with download_dict_lock: download_dict[update.message.message_id] = clone_status sendStatusMessage(update, context.bot) result, button = drive.clone(link) with download_dict_lock: del download_dict[update.message.message_id] count = len(download_dict) try: if count == 0: Interval[0].cancel() del Interval[0] delete_all_messages() else: update_all_messages() except IndexError: pass cc = f'\n\n<b>cc: </b>{tag}' if button in ["cancelled", ""]: sendMessage(f"{tag} {result}", context.bot, update) else: sendMarkup(result + cc, context.bot, update, button) if gdtot_link: gd.deletefile(link) else: sendMessage( 'Send Gdrive or gdtot link along with command or by replying to the link by command', context.bot, update)