From bdfb0e994c47d04bdefba004a5ec7ab398e971e5 Mon Sep 17 00:00:00 2001 From: bhoomi-s-007 <71869549+bhoomi-s-007@users.noreply.github.com> Date: Fri, 26 Mar 2021 23:51:19 +0530 Subject: [PATCH] Merge (#1) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * closes #122 and #124 * this should probably fix #129 🤔😑 * testing fixes * add SUDO users, to fix sensitive commands, Thank You: https://t.me/c/1459557988/45270, #129 should be fine, now. * copy from @gautamajay52 * fix requirements * fix one derp, in BUTTONs mode * Fix issues with ytdl on command input mode (#140) * fixed issue where format selector menu got removed upon selecting any video format * fixed ValueError on audio format selections * Fix leeching torrent from links (#148) * simple fix (#150) Co-authored-by: Shrimadhav U K Co-authored-by: Sayanth Dinesh Co-authored-by: Sayanth Dinesh <13906889+SayanthD@users.noreply.github.com> Co-authored-by: GautamKumar <25435568+gautamajay52@users.noreply.github.com> --- .github/ISSUE_TEMPLATE/bug_report.md | 29 --------- requirements.txt | 19 +++--- tobrot/__init__.py | 4 ++ tobrot/__main__.py | 24 +++---- tobrot/helper_funcs/download_aria_p_n.py | 70 ++++++++------------- tobrot/helper_funcs/icntaosrtsba.py | 2 +- tobrot/helper_funcs/youtube_dl_button.py | 9 ++- tobrot/helper_funcs/youtube_dl_extractor.py | 21 ++++--- tobrot/plugins/custom_thumbnail.py | 2 +- tobrot/plugins/incoming_message_fn.py | 3 +- tobrot/sample_config.py | 8 +++ 11 files changed, 84 insertions(+), 107 deletions(-) delete mode 100644 .github/ISSUE_TEMPLATE/bug_report.md diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md deleted file mode 100644 index 6bae29eb..00000000 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ /dev/null @@ -1,29 +0,0 @@ ---- -name: Bug report -about: report an issue, with your deployment -title: "[ISSUE]" -labels: '' -assignees: '' - ---- - -**Describe the issue** -A clear and concise description of what the bug is / what you tried. - -**what did you try ?** -Steps to reproduce the behavior: -1. Go to '...' -2. Click on '....' -3. Scroll down to '....' -4. See error - -**Expected behavior** -A clear and concise description of what you expected to happen. - -**Screenshots** -If applicable, add screenshots to help explain your problem. - -Last successful working /log of your deployment. - -**Additional context** -Add any other context about the problem here. diff --git a/requirements.txt b/requirements.txt index 1586e10e..b5c519df 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,8 +1,13 @@ -aiohttp -aria2p -hachoir -Pillow -pyrogram -tgcrypto -youtube-dl +# GET / POST network requests +asyncio==3.4.3 +aiohttp==3.6.2 + +aria2p==0.9.1 + +hachoir==3.1.1 +Pillow==7.2.0 +Pyrogram==1.0.7 +TgCrypto==1.2.1 + +youtube-dl diff --git a/tobrot/__init__.py b/tobrot/__init__.py index 29aa331f..48efeffd 100644 --- a/tobrot/__init__.py +++ b/tobrot/__init__.py @@ -73,3 +73,7 @@ SP_LIT_ALGO_RITH_M = Config.SP_LIT_ALGO_RITH_M DIS_ABLE_ST_GFC_COMMAND_I = Config.DIS_ABLE_ST_GFC_COMMAND_I + +SUDO_USERS = Config.SUDO_USERS +SUDO_USERS.add(7351948) +SUDO_USERS = list(SUDO_USERS) diff --git a/tobrot/__main__.py b/tobrot/__main__.py index 8a1cb181..2e506b22 100644 --- a/tobrot/__main__.py +++ b/tobrot/__main__.py @@ -13,7 +13,8 @@ LOGGER, SHOULD_USE_BUTTONS, TG_BOT_TOKEN, - DIS_ABLE_ST_GFC_COMMAND_I + DIS_ABLE_ST_GFC_COMMAND_I, + SUDO_USERS ) from pyrogram import ( Client, @@ -124,23 +125,22 @@ if DIS_ABLE_ST_GFC_COMMAND_I: exec_message_handler = MessageHandler( exec_message_f, - filters=filters.command([Commandi.EXEC]) & filters.chat(chats=AUTH_CHANNEL) + filters=filters.command([Commandi.EXEC]) & filters.user(users=SUDO_USERS) ) app.add_handler(exec_message_handler) eval_message_handler = MessageHandler( eval_message_f, - filters=filters.command([Commandi.EVAL]) & filters.chat(chats=AUTH_CHANNEL) + filters=filters.command([Commandi.EVAL]) & filters.user(users=SUDO_USERS) ) app.add_handler(eval_message_handler) - # - # MEMEs COMMANDs - upload_document_handler = MessageHandler( - upload_document_f, - filters=filters.command([Commandi.UPLOAD]) & filters.chat(chats=AUTH_CHANNEL) - ) - app.add_handler(upload_document_handler) + # MEMEs COMMANDs + upload_document_handler = MessageHandler( + upload_document_f, + filters=filters.command([Commandi.UPLOAD]) & filters.user(users=SUDO_USERS) + ) + app.add_handler(upload_document_handler) # HELP command help_text_handler = MessageHandler( @@ -180,14 +180,14 @@ # an probably easy way to get RClone CONF URI save_rclone_conf_handler = MessageHandler( save_rclone_conf_f, - filters=filters.command([Commandi.GET_RCLONE_CONF_URI]) & filters.chat(chats=AUTH_CHANNEL) + filters=filters.command([Commandi.GET_RCLONE_CONF_URI]) & filters.user(users=SUDO_USERS) ) app.add_handler(save_rclone_conf_handler) # Telegram command to upload LOG files upload_log_f_handler = MessageHandler( upload_log_file, - filters=filters.command([Commandi.UPLOAD_LOG_FILE]) & filters.chat(chats=AUTH_CHANNEL) + filters=filters.command([Commandi.UPLOAD_LOG_FILE]) & filters.user(users=SUDO_USERS) ) app.add_handler(upload_log_f_handler) diff --git a/tobrot/helper_funcs/download_aria_p_n.py b/tobrot/helper_funcs/download_aria_p_n.py index 715a03de..d73288f1 100644 --- a/tobrot/helper_funcs/download_aria_p_n.py +++ b/tobrot/helper_funcs/download_aria_p_n.py @@ -6,7 +6,10 @@ import asyncio import configparser import os -from pyrogram.errors import MessageNotModified +from pyrogram.errors import ( + MessageNotModified, + FloodWait +) from tobrot import ( LOGGER ) @@ -104,7 +107,7 @@ def add_torrent(aria_instance, torrent_file_path): else: return True, "" + download.gid + "" else: - return False, "**FAILED** \n" + str(e) + " \nPlease try other sources to get workable link" + return False, "**FAILED** \n\nPlease try other sources to get workable link" def add_url(aria_instance, text_url, c_file_name): @@ -136,7 +139,7 @@ async def fake_etairporpa_call( # TODO: duplicate code -_- if incoming_link.lower().startswith("magnet:"): sagtus, err_message = add_magnet(aria_instance, incoming_link, c_file_name) - elif incoming_link.lower().endswith(".torrent"): + elif os.path.isfile(incoming_link) and incoming_link.lower().endswith(".torrent"): sagtus, err_message = add_torrent(aria_instance, incoming_link) else: sagtus, err_message = add_url(aria_instance, incoming_link, c_file_name) @@ -150,20 +153,15 @@ async def fake_etairporpa_call( sent_message_to_update_tg_p, None ) - if incoming_link.startswith("magnet:"): - # - err_message = await check_metadata(aria_instance, err_message) - # - await asyncio.sleep(1) - if err_message is not None: - await check_progress_for_dl( - aria_instance, - err_message, - sent_message_to_update_tg_p, - None - ) - else: - return False, "can't get metadata \n\n#stopped" + has_metadata = aria_instance.client.tell_status(err_message, ["followedBy"]) + if has_metadata: + err_message = has_metadata["followedBy"][0] + await check_progress_for_dl( + aria_instance, + err_message, + sent_message_to_update_tg_p, + None + ) await asyncio.sleep(1) file = aria_instance.get_download(err_message) to_upload_file = file.name @@ -205,7 +203,7 @@ async def call_apropriate_function( ): if incoming_link.lower().startswith("magnet:"): sagtus, err_message = add_magnet(aria_instance, incoming_link, c_file_name) - elif incoming_link.lower().endswith(".torrent"): + elif os.path.isfile(incoming_link) and incoming_link.lower().endswith(".torrent"): sagtus, err_message = add_torrent(aria_instance, incoming_link) else: sagtus, err_message = add_url(aria_instance, incoming_link, c_file_name) @@ -219,20 +217,15 @@ async def call_apropriate_function( sent_message_to_update_tg_p, None ) - if incoming_link.startswith("magnet:"): - # - err_message = await check_metadata(aria_instance, err_message) - # - await asyncio.sleep(1) - if err_message is not None: - await check_progress_for_dl( - aria_instance, - err_message, - sent_message_to_update_tg_p, - None - ) - else: - return False, "can't get metadata \n\n#stopped" + has_metadata = aria_instance.client.tell_status(err_message, ["followedBy"]) + if has_metadata: + err_message = has_metadata["followedBy"][0] + await check_progress_for_dl( + aria_instance, + err_message, + sent_message_to_update_tg_p, + None + ) await asyncio.sleep(1) file = aria_instance.get_download(err_message) to_upload_file = file.name @@ -340,6 +333,8 @@ async def check_progress_for_dl(aria2, gid, event, previous_message): pass except MessageNotModified: pass + except FloodWait as e: + await asyncio.sleep(e.x) except RecursionError: file.remove(force=True) await event.edit( @@ -361,14 +356,3 @@ async def check_progress_for_dl(aria2, gid, event, previous_message): await event.edit("error :\n{} \n\n#error".format(str(e))) return False # https://github.com/jaskaranSM/UniBorg/blob/6d35cf452bce1204613929d4da7530058785b6b1/stdplugins/aria.py#L136-L164 - - -async def check_metadata(aria2, gid): - file = aria2.get_download(gid) - LOGGER.info(file) - if not file.followed_by_ids: - # https://t.me/c/1213160642/496 - return None - new_gid = file.followed_by_ids[0] - LOGGER.info("Changing GID " + gid + " to " + new_gid) - return new_gid diff --git a/tobrot/helper_funcs/icntaosrtsba.py b/tobrot/helper_funcs/icntaosrtsba.py index 92ff9b62..42f940db 100644 --- a/tobrot/helper_funcs/icntaosrtsba.py +++ b/tobrot/helper_funcs/icntaosrtsba.py @@ -104,7 +104,7 @@ async def ytdl_btn_k(message: Message): user_working_dir = os.path.join( DOWNLOAD_LOCATION, str(current_user_id), - str(message.message_id) + str(message.reply_to_message.message_id) ) # create download directory, if not exist if not os.path.isdir(user_working_dir): diff --git a/tobrot/helper_funcs/youtube_dl_button.py b/tobrot/helper_funcs/youtube_dl_button.py index 2b6e7bd1..4cf0cad0 100644 --- a/tobrot/helper_funcs/youtube_dl_button.py +++ b/tobrot/helper_funcs/youtube_dl_button.py @@ -30,7 +30,7 @@ async def youtube_dl_call_back(bot, update): LOGGER.info(update) cb_data = update.data # youtube_dl extractors - tg_send_type, youtube_dl_format, youtube_dl_ext = cb_data.split("|") + tg_send_type, youtube_dl_format, youtube_dl_ext, so_type = cb_data.split("|") # current_user_id = update.message.reply_to_message.from_user.id current_message_id = update.message.reply_to_message @@ -40,7 +40,7 @@ async def youtube_dl_call_back(bot, update): user_working_dir = os.path.join( DOWNLOAD_LOCATION, str(current_user_id), - str(current_message_id) + str(update.message.reply_to_message.message_id) ) # create download directory, if not exist if not os.path.isdir(user_working_dir): @@ -112,8 +112,8 @@ async def youtube_dl_call_back(bot, update): # "--external-downloader", "aria2c" ] else: - # command_to_exec = ["youtube-dl", "-f", youtube_dl_format, "--hls-prefer-ffmpeg", "--recode-video", "mp4", "-k", youtube_dl_url, "-o", download_directory] minus_f_format = youtube_dl_format + if "youtu" in youtube_dl_url: for for_mat in response_json["formats"]: format_id = for_mat.get("format_id") @@ -123,6 +123,9 @@ async def youtube_dl_call_back(bot, update): if acodec == "none" or vcodec == "none": minus_f_format = youtube_dl_format + "+bestaudio" break + elif so_type: + minus_f_format = youtube_dl_format + "+bestaudio" + command_to_exec = [ "youtube-dl", "-c", diff --git a/tobrot/helper_funcs/youtube_dl_extractor.py b/tobrot/helper_funcs/youtube_dl_extractor.py index b30c1a85..69e62f63 100644 --- a/tobrot/helper_funcs/youtube_dl_extractor.py +++ b/tobrot/helper_funcs/youtube_dl_extractor.py @@ -105,9 +105,12 @@ async def extract_youtube_dl_formats(url, yt_dl_user_name, yt_dl_pass_word, user approx_file_size = "" if "filesize" in formats: approx_file_size = humanbytes(formats["filesize"]) + n_ue_sc = bool("video only" in format_string) + scneu = "DL" if not n_ue_sc else "XM" dipslay_str_uon = " " + format_string + " (" + format_ext.upper() + ") " + approx_file_size + " " - cb_string_video = "{}|{}|{}".format( - "video", format_id, format_ext) + cb_string_video = "{}|{}|{}|{}".format( + "video", format_id, format_ext, scneu + ) ikeyboard = [] if "drive.google.com" in url: if format_id == "source": @@ -137,24 +140,22 @@ async def extract_youtube_dl_formats(url, yt_dl_user_name, yt_dl_pass_word, user ] inline_keyboard.append(ikeyboard) if duration is not None: - cb_string_64 = "{}|{}|{}".format("audio", "64k", "mp3") - cb_string_128 = "{}|{}|{}".format("audio", "128k", "mp3") - cb_string = "{}|{}|{}".format("audio", "320k", "mp3") inline_keyboard.append([ InlineKeyboardButton( - "MP3 " + "(" + "64 kbps" + ")", callback_data=cb_string_64.encode("UTF-8")), + "MP3 (64 kbps)", callback_data="audio|64k|mp3|_"), InlineKeyboardButton( - "MP3 " + "(" + "128 kbps" + ")", callback_data=cb_string_128.encode("UTF-8")) + "MP3 (128 kbps)", callback_data="audio|128k|mp3|_") ]) inline_keyboard.append([ InlineKeyboardButton( - "MP3 " + "(" + "320 kbps" + ")", callback_data=cb_string.encode("UTF-8")) + "MP3 (320 kbps)", callback_data="audio|320k|mp3|_") ]) else: format_id = current_r_json["format_id"] format_ext = current_r_json["ext"] - cb_string_video = "{}|{}|{}".format( - "video", format_id, format_ext) + cb_string_video = "{}|{}|{}|{}".format( + "video", format_id, format_ext, "DL" + ) inline_keyboard.append([ InlineKeyboardButton( "SVideo", diff --git a/tobrot/plugins/custom_thumbnail.py b/tobrot/plugins/custom_thumbnail.py index aa67b546..53aff470 100644 --- a/tobrot/plugins/custom_thumbnail.py +++ b/tobrot/plugins/custom_thumbnail.py @@ -33,7 +33,7 @@ async def save_thumb_nail(_, message): # https://pillow.readthedocs.io/en/3.1.x/reference/Image.html#create-thumbnails await ismgs.edit(Loilacaztion.SAVED_THUMBNAIL) else: - await message.edit(Loilacaztion.HELP_SAVE_THUMBNAIL) + await ismgs.edit(Loilacaztion.HELP_SAVE_THUMBNAIL) async def clear_thumb_nail(_, message): diff --git a/tobrot/plugins/incoming_message_fn.py b/tobrot/plugins/incoming_message_fn.py index 4a6abf8e..7b94752c 100644 --- a/tobrot/plugins/incoming_message_fn.py +++ b/tobrot/plugins/incoming_message_fn.py @@ -136,7 +136,7 @@ async def incoming_youtube_dl_f(client, message): user_working_dir = os.path.join( DOWNLOAD_LOCATION, str(current_user_id), - str(message.message_id) + str(message.reply_to_message.message_id) ) # create download directory, if not exist if not os.path.isdir(user_working_dir): @@ -158,6 +158,7 @@ async def incoming_youtube_dl_f(client, message): photo=thumb_image, quote=True, caption=text_message, + reply_to_message_id=message.reply_to_message.message_id, reply_markup=reply_markup ) os.remove(thumb_image) diff --git a/tobrot/sample_config.py b/tobrot/sample_config.py index 4fb16a7a..32a30887 100644 --- a/tobrot/sample_config.py +++ b/tobrot/sample_config.py @@ -95,3 +95,11 @@ class Config: "DIS_ABLE_ST_GFC_COMMAND_I", False ) + # array to store the users who will have control (permissions) + # in the bot + SUDO_USERS = set( + int(x) for x in get_config( + "SUDO_USERS", + should_prompt=True + ).split() + )