From 69fab9ff436499d095f7672bbbce52d61108b79d Mon Sep 17 00:00:00 2001 From: Sourcery AI <> Date: Tue, 14 Dec 2021 12:19:05 +0000 Subject: [PATCH] 'Refactored by Sourcery' --- database/database.py | 3 +-- helper_funcs/help_Nekmo_ffmpeg.py | 7 +++---- helper_funcs/help_uploadbot.py | 33 ++++++++++++++++--------------- plugins/video_converter.py | 20 ++++--------------- sample_config.py | 6 ++++-- 5 files changed, 29 insertions(+), 40 deletions(-) diff --git a/database/database.py b/database/database.py index 42d89a30..c0aede74 100644 --- a/database/database.py +++ b/database/database.py @@ -57,7 +57,6 @@ async def del_thumb(id): async def thumb(id): try: - t = SESSION.query(Thumbnail).get(id) - return t + return SESSION.query(Thumbnail).get(id) finally: SESSION.close() diff --git a/helper_funcs/help_Nekmo_ffmpeg.py b/helper_funcs/help_Nekmo_ffmpeg.py index 533c7a40..c23adb2f 100644 --- a/helper_funcs/help_Nekmo_ffmpeg.py +++ b/helper_funcs/help_Nekmo_ffmpeg.py @@ -142,14 +142,13 @@ async def generate_screen_shots( ): metadata = extractMetadata(createParser(video_file)) duration = 0 - if metadata is not None: - if metadata.has("duration"): - duration = metadata.get('duration').seconds + if metadata is not None and metadata.has("duration"): + duration = metadata.get('duration').seconds if duration > min_duration: images = [] ttl_step = duration // no_of_photos current_ttl = ttl_step - for looper in range(0, no_of_photos): + for _ in range(no_of_photos): ss_img = await take_screen_shot(video_file, output_directory, current_ttl) current_ttl = current_ttl + ttl_step if is_watermarkable: diff --git a/helper_funcs/help_uploadbot.py b/helper_funcs/help_uploadbot.py index 5c33f8c2..d85c32e0 100644 --- a/helper_funcs/help_uploadbot.py +++ b/helper_funcs/help_uploadbot.py @@ -13,8 +13,7 @@ def DetectFileSize(url): r = requests.get(url, allow_redirects=True, stream=True) - total_size = int(r.headers.get("content-length", 0)) - return total_size + return int(r.headers.get("content-length", 0)) def DownLoadFile(url, file_name, chunk_size, client, ud_type, message_id, chat_id): @@ -31,19 +30,21 @@ def DownLoadFile(url, file_name, chunk_size, client, ud_type, message_id, chat_i if chunk: fd.write(chunk) downloaded_size += chunk_size - if client is not None: - if ((total_size // downloaded_size) % 5) == 0: - time.sleep(0.3) - try: - client.edit_message_text( - chat_id, - message_id, - text="{}: {} of {}".format( - ud_type, - humanbytes(downloaded_size), - humanbytes(total_size) - ) + if ( + client is not None + and ((total_size // downloaded_size) % 5) == 0 + ): + time.sleep(0.3) + try: + client.edit_message_text( + chat_id, + message_id, + text="{}: {} of {}".format( + ud_type, + humanbytes(downloaded_size), + humanbytes(total_size) ) - except: - pass + ) + except: + pass return file_name diff --git a/plugins/video_converter.py b/plugins/video_converter.py index 2f7ee753..91cdc5e8 100644 --- a/plugins/video_converter.py +++ b/plugins/video_converter.py @@ -53,7 +53,7 @@ async def convert_to_video(bot, update): [ InlineKeyboardButton(text="đź””Join My Updates Channelđź””", url=f"https://t.me/{update_channel}")] ]) ) - return + return #TRChatBase(update.from_user.id, update.text, "c2v") if update.reply_to_message is not None: @@ -81,21 +81,11 @@ async def convert_to_video(bot, update): chat_id=update.chat.id, message_id=a.message_id ) - # don't care about the extension - # await bot.edit_message_text( - # text=Translation.UPLOAD_START, - # chat_id=update.chat.id, # message_id=a.message_id # ) logger.info(the_real_download_location) - # get the correct width, height, and duration for videos greater than 10MB - # ref: message from @Mo_Tech_Group - width = 0 - height = 0 - duration = 0 metadata = extractMetadata(createParser(the_real_download_location)) - if metadata.has("duration"): - duration = metadata.get('duration').seconds + duration = metadata.get('duration').seconds if metadata.has("duration") else 0 thumb_image_path = Config.DOWNLOAD_LOCATION + "/" + str(update.from_user.id) + ".jpg" if not os.path.exists(thumb_image_path): thumb_image_path = await take_screen_shot( @@ -109,10 +99,8 @@ async def convert_to_video(bot, update): logger.info(thumb_image_path) # 'thumb_image_path' will be available now metadata = extractMetadata(createParser(thumb_image_path)) - if metadata.has("width"): - width = metadata.get("width") - if metadata.has("height"): - height = metadata.get("height") + width = metadata.get("width") if metadata.has("width") else 0 + height = metadata.get("height") if metadata.has("height") else 0 # get the correct width, height, and duration for videos greater than 10MB # resize image # ref: https://t.me/PyrogramChat/44663 diff --git a/sample_config.py b/sample_config.py index 1d9b895f..01e3d3b9 100644 --- a/sample_config.py +++ b/sample_config.py @@ -1,6 +1,8 @@ import os -class Config(object): + + +class Config((object)): # get a token from @BotFather TG_BOT_TOKEN = os.environ.get("TG_BOT_TOKEN", "") # The Telegram API things @@ -13,7 +15,7 @@ class Config(object): # Get these values from my.telegram.org CHAT_ID = os.environ.get("CHAT_ID", "") # Array to store users who are authorized to use the bot - AUTH_USERS = set(int(x) for x in os.environ.get("AUTH_USERS", "").split()) + AUTH_USERS = {int(x) for x in os.environ.get("AUTH_USERS", "").split()} # Banned Unwanted Members.. BANNED_USERS = [] # the download location, where the HTTP Server runs