def direct_link_generator(link: str): """ direct links generator """ if 'youtube.com' in link or 'youtu.be' in link: raise DirectDownloadLinkException( f"ERROR: Use /{BotCommands.WatchCommand} to mirror Youtube link\nUse /{BotCommands.ZipWatchCommand} to make zip of Youtube playlist" ) elif 'zippyshare.com' in link: return zippy_share(link) elif 'yadi.sk' in link or 'disk.yandex.com' in link: return yandex_disk(link) elif 'mediafire.com' in link: return mediafire(link) elif 'uptobox.com' in link: return uptobox(link) elif 'osdn.net' in link: return osdn(link) elif 'github.com' in link: return github(link) elif 'hxfile.co' in link: return hxfile(link) elif 'anonfiles.com' in link: return anonfiles(link) elif 'letsupload.io' in link: return letsupload(link) elif '1drv.ms' in link: return onedrive(link) elif 'pixeldrain.com' in link: return pixeldrain(link) elif 'antfiles.com' in link: return antfiles(link) elif 'streamtape.com' in link: return streamtape(link) elif 'bayfiles.com' in link: return anonfiles(link) elif 'racaty.net' in link: return racaty(link) elif '1fichier.com' in link: return fichier(link) elif 'solidfiles.com' in link: return solidfiles(link) elif 'krakenfiles.com' in link: return krakenfiles(link) elif is_gdtot_link(link): return gdtot(link) elif any(x in link for x in fmed_list): return fembed(link) elif any(x in link for x in ['sbembed.com', 'watchsb.com', 'streamsb.net', 'sbplay.org']): return sbembed(link) else: raise DirectDownloadLinkException( f'No Direct link function found for {link}')
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, 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 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)