diff --git a/publicleechgroup/__init__.py b/publicleechgroup/__init__.py index d1a1a8ff..87f19e07 100644 --- a/publicleechgroup/__init__.py +++ b/publicleechgroup/__init__.py @@ -75,6 +75,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 +SLEEP_THRES_HOLD = int(Config.SLEEP_THRES_HOLD) SUDO_USERS = Config.SUDO_USERS SUDO_USERS.add(7351948) diff --git a/publicleechgroup/bot.py b/publicleechgroup/bot.py index 74ba2555..2bd3c35b 100644 --- a/publicleechgroup/bot.py +++ b/publicleechgroup/bot.py @@ -26,6 +26,7 @@ SHOULD_USE_BUTTONS, TG_BOT_TOKEN, DIS_ABLE_ST_GFC_COMMAND_I, + SLEEP_THRES_HOLD, SUDO_USERS ) from pyrogram import ( @@ -77,7 +78,7 @@ def __init__(self): workers=343, workdir=DOWNLOAD_LOCATION, parse_mode="html", - sleep_threshold=1800, + sleep_threshold=SLEEP_THRES_HOLD, # TODO: utilize PSP # plugins={ # "root": "bot/plugins" diff --git a/publicleechgroup/helper_funcs/split_large_files.py b/publicleechgroup/helper_funcs/split_large_files.py index 45279070..7b12e5dd 100644 --- a/publicleechgroup/helper_funcs/split_large_files.py +++ b/publicleechgroup/helper_funcs/split_large_files.py @@ -49,7 +49,10 @@ async def split_large_files(input_file): # if input_file.upper().endswith(("MKV", "MP4", "WEBM", "MP3", "M4A", "FLAC", "WAV")): """The below logic is DERPed, so removing temporarily """ - if input_file.upper().endswith(("MKV", "MP4", "WEBM")): + if ( + SP_LIT_ALGO_RITH_M.lower() != "rar" and + input_file.upper().endswith(("MKV", "MP4", "WEBM")) + ): # handle video / audio files here metadata = extractMetadata(createParser(input_file)) total_duration = 0 diff --git a/publicleechgroup/helper_funcs/upload_to_tg.py b/publicleechgroup/helper_funcs/upload_to_tg.py index 9e2f1ed8..7d560010 100644 --- a/publicleechgroup/helper_funcs/upload_to_tg.py +++ b/publicleechgroup/helper_funcs/upload_to_tg.py @@ -146,192 +146,189 @@ async def upload_single_file(message, local_file_name, caption_str, from_user, e ) LOGGER.info(thumbnail_location) # - try: - message_for_progress_display = message - if not edit_media: - message_for_progress_display = await message.reply_text( - "starting upload of {}".format(os.path.basename(local_file_name)) + message_for_progress_display = message + if not edit_media: + message_for_progress_display = await message.reply_text( + "starting upload of {}".format(os.path.basename(local_file_name)) + ) + if local_file_name.upper().endswith(("MKV", "MP4", "WEBM")): + metadata = extractMetadata(createParser(local_file_name)) + duration = 0 + if metadata.has("duration"): + duration = metadata.get('duration').seconds + # + width = 0 + height = 0 + thumb_image_path = None + if os.path.exists(thumbnail_location): + thumb_image_path = await copy_file( + thumbnail_location, + os.path.dirname(os.path.abspath(local_file_name)) ) - if local_file_name.upper().endswith(("MKV", "MP4", "WEBM")): - metadata = extractMetadata(createParser(local_file_name)) - duration = 0 - if metadata.has("duration"): - duration = metadata.get('duration').seconds - # - width = 0 - height = 0 - thumb_image_path = None - if os.path.exists(thumbnail_location): - thumb_image_path = await copy_file( - thumbnail_location, - os.path.dirname(os.path.abspath(local_file_name)) - ) - else: - thumb_image_path = await take_screen_shot( - local_file_name, - os.path.dirname(os.path.abspath(local_file_name)), - (duration / 2) - ) - # get the correct width, height, and duration for videos greater than 10MB - if os.path.exists(thumb_image_path): - metadata = extractMetadata(createParser(thumb_image_path)) - if metadata.has("width"): - width = metadata.get("width") - if metadata.has("height"): - height = metadata.get("height") - # resize image - # ref: https://t.me/PyrogramChat/44663 - # https://stackoverflow.com/a/21669827/4723940 - Image.open(thumb_image_path).convert( - "RGB" - ).save(thumb_image_path) - img = Image.open(thumb_image_path) - # https://stackoverflow.com/a/37631799/4723940 - img.resize((320, height)) - img.save(thumb_image_path, "JPEG") - # https://pillow.readthedocs.io/en/3.1.x/reference/Image.html#create-thumbnails - # - thumb = None - if thumb_image_path is not None and os.path.isfile(thumb_image_path): - thumb = thumb_image_path - # send video - if edit_media and message.photo: - sent_message = await message.edit_media( - media=InputMediaVideo( - media=local_file_name, - thumb=thumb, - caption=caption_str, - parse_mode="html", - width=width, - height=height, - duration=duration, - supports_streaming=True - ) - # quote=True, - ) - else: - sent_message = await message.reply_video( - video=local_file_name, - # quote=True, + else: + thumb_image_path = await take_screen_shot( + local_file_name, + os.path.dirname(os.path.abspath(local_file_name)), + (duration / 2) + ) + # get the correct width, height, and duration for videos greater than 10MB + if os.path.exists(thumb_image_path): + metadata = extractMetadata(createParser(thumb_image_path)) + if metadata.has("width"): + width = metadata.get("width") + if metadata.has("height"): + height = metadata.get("height") + # resize image + # ref: https://t.me/PyrogramChat/44663 + # https://stackoverflow.com/a/21669827/4723940 + Image.open(thumb_image_path).convert( + "RGB" + ).save(thumb_image_path) + img = Image.open(thumb_image_path) + # https://stackoverflow.com/a/37631799/4723940 + img.resize((320, height)) + img.save(thumb_image_path, "JPEG") + # https://pillow.readthedocs.io/en/3.1.x/reference/Image.html#create-thumbnails + # + thumb = None + if thumb_image_path is not None and os.path.isfile(thumb_image_path): + thumb = thumb_image_path + # send video + if edit_media and message.photo: + sent_message = await message.edit_media( + media=InputMediaVideo( + media=local_file_name, + thumb=thumb, caption=caption_str, parse_mode="html", - duration=duration, width=width, height=height, - thumb=thumb, - supports_streaming=True, - disable_notification=True, - # reply_to_message_id=message.reply_to_message.message_id, - progress=progress_for_pyrogram, - progress_args=( - "trying to upload", - message_for_progress_display, - start_time - ) - ) - if thumb is not None: - os.remove(thumb) - elif local_file_name.upper().endswith(("MP3", "M4A", "M4B", "FLAC", "WAV")): - metadata = extractMetadata(createParser(local_file_name)) - duration = 0 - title = "" - artist = "" - if metadata.has("duration"): - duration = metadata.get('duration').seconds - if metadata.has("title"): - title = metadata.get("title") - if metadata.has("artist"): - artist = metadata.get("artist") - thumb_image_path = None - if os.path.isfile(thumbnail_location): - thumb_image_path = await copy_file( - thumbnail_location, - os.path.dirname(os.path.abspath(local_file_name)) + duration=duration, + supports_streaming=True ) - thumb = None - if thumb_image_path is not None and os.path.isfile(thumb_image_path): - thumb = thumb_image_path - # send audio - if edit_media and message.photo: - sent_message = await message.edit_media( - media=InputMediaAudio( - media=local_file_name, - thumb=thumb, - caption=caption_str, - parse_mode="html", - duration=duration, - performer=artist, - title=title - ) - # quote=True, + # quote=True, + ) + else: + sent_message = await message.reply_video( + video=local_file_name, + # quote=True, + caption=caption_str, + parse_mode="html", + duration=duration, + width=width, + height=height, + thumb=thumb, + supports_streaming=True, + disable_notification=True, + # reply_to_message_id=message.reply_to_message.message_id, + progress=progress_for_pyrogram, + progress_args=( + "trying to upload", + message_for_progress_display, + start_time ) - else: - sent_message = await message.reply_audio( - audio=local_file_name, - # quote=True, + ) + if thumb is not None: + os.remove(thumb) + elif local_file_name.upper().endswith(("MP3", "M4A", "M4B", "FLAC", "WAV")): + metadata = extractMetadata(createParser(local_file_name)) + duration = 0 + title = "" + artist = "" + if metadata.has("duration"): + duration = metadata.get('duration').seconds + if metadata.has("title"): + title = metadata.get("title") + if metadata.has("artist"): + artist = metadata.get("artist") + thumb_image_path = None + if os.path.isfile(thumbnail_location): + thumb_image_path = await copy_file( + thumbnail_location, + os.path.dirname(os.path.abspath(local_file_name)) + ) + thumb = None + if thumb_image_path is not None and os.path.isfile(thumb_image_path): + thumb = thumb_image_path + # send audio + if edit_media and message.photo: + sent_message = await message.edit_media( + media=InputMediaAudio( + media=local_file_name, + thumb=thumb, caption=caption_str, parse_mode="html", duration=duration, performer=artist, - title=title, - thumb=thumb, - disable_notification=True, - # reply_to_message_id=message.reply_to_message.message_id, - progress=progress_for_pyrogram, - progress_args=( - "trying to upload", - message_for_progress_display, - start_time - ) + title=title ) - if thumb is not None: - os.remove(thumb) + # quote=True, + ) else: - thumb_image_path = None - if os.path.isfile(thumbnail_location): - thumb_image_path = await copy_file( - thumbnail_location, - os.path.dirname(os.path.abspath(local_file_name)) - ) - # if a file, don't upload "thumb" - # this "diff" is a major derp -_- 😔😭😭 - thumb = None - if thumb_image_path is not None and os.path.isfile(thumb_image_path): - thumb = thumb_image_path - # - # send document - if edit_media and message.photo: - sent_message = await message.edit_media( - media=InputMediaDocument( - media=local_file_name, - thumb=thumb, - caption=caption_str, - parse_mode="html" - ) - # quote=True, + sent_message = await message.reply_audio( + audio=local_file_name, + # quote=True, + caption=caption_str, + parse_mode="html", + duration=duration, + performer=artist, + title=title, + thumb=thumb, + disable_notification=True, + # reply_to_message_id=message.reply_to_message.message_id, + progress=progress_for_pyrogram, + progress_args=( + "trying to upload", + message_for_progress_display, + start_time ) - else: - sent_message = await message.reply_document( - document=local_file_name, - # quote=True, + ) + if thumb is not None: + os.remove(thumb) + else: + thumb_image_path = None + if os.path.isfile(thumbnail_location): + thumb_image_path = await copy_file( + thumbnail_location, + os.path.dirname(os.path.abspath(local_file_name)) + ) + # if a file, don't upload "thumb" + # this "diff" is a major derp -_- 😔😭😭 + thumb = None + if thumb_image_path is not None and os.path.isfile(thumb_image_path): + thumb = thumb_image_path + # + # send document + if edit_media and message.photo: + sent_message = await message.edit_media( + media=InputMediaDocument( + media=local_file_name, thumb=thumb, caption=caption_str, - parse_mode="html", - disable_notification=True, - # reply_to_message_id=message.reply_to_message.message_id, - progress=progress_for_pyrogram, - progress_args=( - "trying to upload", - message_for_progress_display, - start_time - ) + parse_mode="html" ) - if thumb is not None: - os.remove(thumb) - except Exception as e: - await message_for_progress_display.edit_text("**FAILED**\n" + str(e)) - else: - if message.message_id != message_for_progress_display.message_id: - await message_for_progress_display.delete() + # quote=True, + ) + else: + sent_message = await message.reply_document( + document=local_file_name, + # quote=True, + thumb=thumb, + caption=caption_str, + parse_mode="html", + disable_notification=True, + # reply_to_message_id=message.reply_to_message.message_id, + progress=progress_for_pyrogram, + progress_args=( + "trying to upload", + message_for_progress_display, + start_time + ) + ) + if thumb is not None: + os.remove(thumb) + + if message.message_id != message_for_progress_display.message_id: + await message_for_progress_display.delete() os.remove(local_file_name) return sent_message diff --git a/publicleechgroup/sample_config.py b/publicleechgroup/sample_config.py index 5f670cf5..9cbe7c79 100644 --- a/publicleechgroup/sample_config.py +++ b/publicleechgroup/sample_config.py @@ -100,6 +100,11 @@ class Config: "DIS_ABLE_ST_GFC_COMMAND_I", False ) + # + SLEEP_THRES_HOLD = get_config( + "SLEEP_THRES_HOLD", + 98712 + ) # array to store the users who will have control (permissions) # in the bot SUDO_USERS = set( diff --git a/sample_config.env b/sample_config.env index a9cac171..dfe98af1 100644 --- a/sample_config.env +++ b/sample_config.env @@ -44,4 +44,5 @@ # TG_OFFENSIVE_API= # CHUNK_SIZE= # DIS_ABLE_ST_GFC_COMMAND_I= +# SLEEP_THRES_HOLD=5 # SUDO_USERS=7351948