def _mirror(bot, update, isTar=False): 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}/') 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) ydl = YoutubeDLHelper(listener) try: sup_link = ydl.extractMetaData(link) except Exception as e: sup_link = None if sup_link: ydl.add_download(link, f'{DOWNLOAD_DIR}{listener.uid}') else: aria = aria2_download.AriaDownloadHelper(listener) aria.add_download(link, f'{DOWNLOAD_DIR}/{listener.uid}/') sendStatusMessage(update, bot) if len(Interval) == 0: Interval.append( setInterval(DOWNLOAD_STATUS_UPDATE_INTERVAL, update_all_messages))
def _watch(bot, update, isZip=False, isLeech=False): mssg = update.message.text user_id = update.message.from_user.id msg_id = update.message.message_id try: link = mssg.split(' ')[1].strip() if link.startswith(("|", "pswd:", "args:")): link = '' except IndexError: link = '' try: name_arg = mssg.split('|', maxsplit=1) if 'args: ' in name_arg[0]: raise IndexError else: name = name_arg[1] name = resplit(r' pswd: | args: ', name)[0] name = name.strip() except IndexError: name = '' try: pswd = mssg.split(' pswd: ')[1] pswd = pswd.split(' args: ')[0] except IndexError: pswd = None try: args = mssg.split(' args: ')[1] except IndexError: args = None 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: if len(link) == 0: link = reply_to.text.strip() 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): help_msg = "<b>Send link along with command line:</b>" help_msg += "\n<code>/command</code> {link} |newname pswd: mypassword [π£ππ] args: x:y|x1:y1" help_msg += "\n\n<b>By replying to link:</b>" help_msg += "\n<code>/command</code> |newname pswd: mypassword [π£ππ] args: x:y|x1:y1" help_msg += "\n\n<b>Args Example:</b> args: playliststart:^10|match_filter:season_number=18|matchtitle:S1" help_msg += "\n\n<b>NOTE:</b> Add `^` before integer, some values must be integer and some string." help_msg += " Like playlist_items:10 works with string so no need to add `^` before the number" help_msg += " but playlistend works only with integer so you must add `^` before the number like example above." help_msg += "\n\nCheck all arguments from this <a href='https://github.com/yt-dlp/yt-dlp/blob/a3125791c7a5cdf2c8c025b99788bf686edd1a8a/yt_dlp/YoutubeDL.py#L194'>FILE</a>." return sendMessage(help_msg, bot, update) listener = MirrorListener(bot, update, isZip, isLeech=isLeech, pswd=pswd, tag=tag) buttons = button_build.ButtonMaker() best_video = "bv*+ba/b" best_audio = "ba/b" ydl = YoutubeDLHelper(listener) try: result = ydl.extractMetaData(link, name, True) except Exception as e: msg = str(e).replace('<', ' ').replace('>', ' ') return sendMessage(tag + " " + msg, bot, update) if 'entries' in result: for i in ['144', '240', '360', '480', '720', '1080', '1440', '2160']: video_format = f"bv*[height<={i}][ext=mp4]" buttons.sbutton(f"{i}-mp4", f"qu {msg_id} {video_format} t") video_format = f"bv*[height<={i}][ext=webm]" buttons.sbutton(f"{i}-webm", f"qu {msg_id} {video_format} t") buttons.sbutton("Audios", f"qu {msg_id} audio t") buttons.sbutton("Best Videos", f"qu {msg_id} {best_video} t") buttons.sbutton("Best Audios", f"qu {msg_id} {best_audio} t") buttons.sbutton("Cancel", f"qu {msg_id} cancel") YTBUTTONS = InlineKeyboardMarkup(buttons.build_menu(3)) listener_dict[msg_id] = [ listener, user_id, link, name, YTBUTTONS, args ] bmsg = sendMarkup('Choose Playlist Videos Quality:', bot, update, YTBUTTONS) else: formats = result.get('formats') formats_dict = {} if formats is not None: for frmt in formats: if not frmt.get('tbr') or not frmt.get('height'): continue if frmt.get('fps'): quality = f"{frmt['height']}p{frmt['fps']}-{frmt['ext']}" else: quality = f"{frmt['height']}p-{frmt['ext']}" if frmt.get('filesize'): size = frmt['filesize'] elif frmt.get('filesize_approx'): size = frmt['filesize_approx'] else: size = 0 if quality in formats_dict: formats_dict[quality][frmt['tbr']] = size else: subformat = {} subformat[frmt['tbr']] = size formats_dict[quality] = subformat for forDict in formats_dict: if len(formats_dict[forDict]) == 1: qual_fps_ext = resplit(r'p|-', forDict, maxsplit=2) height = qual_fps_ext[0] fps = qual_fps_ext[1] ext = qual_fps_ext[2] if fps != '': video_format = f"bv*[height={height}][fps={fps}][ext={ext}]" else: video_format = f"bv*[height={height}][ext={ext}]" size = list(formats_dict[forDict].values())[0] buttonName = f"{forDict} ({get_readable_file_size(size)})" buttons.sbutton(str(buttonName), f"qu {msg_id} {video_format}") else: buttons.sbutton(str(forDict), f"qu {msg_id} dict {forDict}") buttons.sbutton("Audios", f"qu {msg_id} audio") buttons.sbutton("Best Video", f"qu {msg_id} {best_video}") buttons.sbutton("Best Audio", f"qu {msg_id} {best_audio}") buttons.sbutton("Cancel", f"qu {msg_id} cancel") YTBUTTONS = InlineKeyboardMarkup(buttons.build_menu(2)) listener_dict[msg_id] = [ listener, user_id, link, name, YTBUTTONS, args, formats_dict ] bmsg = sendMarkup('Choose Video Quality:', bot, update, YTBUTTONS) Thread(target=_auto_cancel, args=(bmsg, msg_id)).start()
def _watch(bot, update, isZip=False, isLeech=False, pswd=None, tag=None): mssg = update.message.text message_args = mssg.split(' ') name_args = mssg.split('|', maxsplit=1) user_id = update.message.from_user.id msg_id = update.message.message_id try: link = message_args[1].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 = '' pswdMsg = mssg.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: link = reply_to.text.strip() 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): 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:</b>" help_msg += "\n<code>/command</code> |newname pswd: mypassword [π£ππ]" return sendMessage(help_msg, bot, update) LOGGER.info(link) listener = MirrorListener(bot, update, isZip, isLeech=isLeech, pswd=pswd, tag=tag) buttons = button_build.ButtonMaker() best_video = "bv*+ba/b" best_audio = "ba/b" ydl = YoutubeDLHelper(listener) try: result = ydl.extractMetaData(link, name, True) except Exception as e: return sendMessage(str(e), bot, update) if 'entries' in result: for i in ['144', '240', '360', '480', '720', '1080', '1440', '2160']: video_format = f"bv*[height<={i}][ext=mp4]+ba/b" buttons.sbutton(f"{i}-mp4", f"qu {msg_id} {video_format} t") video_format = f"bv*[height<={i}][ext=webm]+ba/b" buttons.sbutton(f"{i}-webm", f"qu {msg_id} {video_format} t") buttons.sbutton("Audios", f"qu {msg_id} audio t") buttons.sbutton("Best Videos", f"qu {msg_id} {best_video} t") buttons.sbutton("Best Audios", f"qu {msg_id} {best_audio} t") buttons.sbutton("Cancel", f"qu {msg_id} cancel") YTBUTTONS = InlineKeyboardMarkup(buttons.build_menu(3)) listener_dict[msg_id] = [listener, user_id, link, name, YTBUTTONS] bmsg = sendMarkup('Choose Playlist Videos Quality:', bot, update, YTBUTTONS) else: formats = result.get('formats') formats_dict = {} if formats is not None: for frmt in formats: if not frmt.get('tbr') or not frmt.get('height'): continue if frmt.get('fps'): quality = f"{frmt['height']}p{frmt['fps']}-{frmt['ext']}" else: quality = f"{frmt['height']}p-{frmt['ext']}" if frmt.get('filesize'): size = frmt['filesize'] elif frmt.get('filesize_approx'): size = frmt['filesize_approx'] else: size = 0 if quality in formats_dict: formats_dict[quality][frmt['tbr']] = size else: subformat = {} subformat[frmt['tbr']] = size formats_dict[quality] = subformat for forDict in formats_dict: if len(formats_dict[forDict]) == 1: qual_fps_ext = resplit(r'p|-', forDict, maxsplit=2) height = qual_fps_ext[0] fps = qual_fps_ext[1] ext = qual_fps_ext[2] if fps != '': video_format = f"bv*[height={height}][fps={fps}][ext={ext}]+ba/b" else: video_format = f"bv*[height={height}][ext={ext}]+ba/b" size = list(formats_dict[forDict].values())[0] buttonName = f"{forDict} ({get_readable_file_size(size)})" buttons.sbutton(str(buttonName), f"qu {msg_id} {video_format}") else: buttons.sbutton(str(forDict), f"qu {msg_id} dict {forDict}") buttons.sbutton("Audios", f"qu {msg_id} audio") buttons.sbutton("Best Video", f"qu {msg_id} {best_video}") buttons.sbutton("Best Audio", f"qu {msg_id} {best_audio}") buttons.sbutton("Cancel", f"qu {msg_id} cancel") YTBUTTONS = InlineKeyboardMarkup(buttons.build_menu(2)) listener_dict[msg_id] = [listener, user_id, link, name, YTBUTTONS, formats_dict] bmsg = sendMarkup('Choose Video Quality:', bot, update, YTBUTTONS) Thread(target=_auto_cancel, args=(bmsg, msg_id)).start()