diff --git a/bot/helper/ext_utils/media_utils.py b/bot/helper/ext_utils/media_utils.py index 7b3b24ad09a..1776c3e7c10 100644 --- a/bot/helper/ext_utils/media_utils.py +++ b/bot/helper/ext_utils/media_utils.py @@ -2,7 +2,7 @@ from aiofiles.os import remove, path as aiopath, makedirs from time import time from re import search as re_search -from asyncio import create_subprocess_exec, gather +from asyncio import create_subprocess_exec, gather, wait_for from asyncio.subprocess import PIPE from PIL import Image from aioshutil import move @@ -153,21 +153,40 @@ async def take_ss(video_file, ss_nb) -> list: name, _ = ospath.splitext(name) dirpath = f"{dirpath}/screenshots/" await makedirs(dirpath, exist_ok=True) - interval = duration // ss_nb + 1 + interval = duration // (ss_nb + 1) cap_time = interval outputs = [] - cmd = "" + cmds = [] for i in range(ss_nb): output = f"{dirpath}SS.{name}_{i:02}.png" outputs.append(output) - cmd += f'ffmpeg -hide_banner -loglevel error -ss {cap_time} -i "{video_file}" -q:v 1 -frames:v 1 "{output}"' + cmd = [ + "ffmpeg", + "-hide_banner", + "-loglevel", + "error", + "-ss", + f"{cap_time}", + "-i", + video_file, + "-q:v", + "1", + "-frames:v", + "1", + output, + ] cap_time += interval - if i + 1 != ss_nb: - cmd += " && " - _, err, code = await cmd_exec(cmd, True) - if code != 0: + cmds.append(cmd_exec(cmd)) + try: + resutls = await wait_for(gather(*cmds), timeout=15) + if resutls[0][2] != 0: + LOGGER.error( + f"Error while creating sreenshots from video. Path: {video_file}. stderr: {resutls[0][1]}" + ) + return [] + except: LOGGER.error( - f"Error while creating sreenshots from video. Path: {video_file} stderr: {err}" + f"Error while creating sreenshots from video. Path: {video_file}. Error: Timeout some issues with ffmpeg with specific arch!" ) return [] return outputs @@ -216,7 +235,7 @@ async def create_thumbnail(video_file, duration): "-loglevel", "error", "-ss", - str(duration), + f"{duration}", "-i", video_file, "-vf", @@ -225,10 +244,16 @@ async def create_thumbnail(video_file, duration): "1", des_dir, ] - _, err, code = await cmd_exec(cmd) - if code != 0 or not await aiopath.exists(des_dir): + try: + _, err, code = await wait_for(cmd_exec(cmd), timeout=15) + if code != 0 or not await aiopath.exists(des_dir): + LOGGER.error( + f"Error while extracting thumbnail from video. Name: {video_file} stderr: {err}" + ) + return None + except: LOGGER.error( - f"Error while extracting thumbnail from video. Name: {video_file} stderr: {err}" + f"Error while extracting thumbnail from video. Name: {video_file}. Error: Timeout some issues with ffmpeg with specific arch!" ) return None return des_dir diff --git a/bot/helper/mirror_utils/download_utils/jd_download.py b/bot/helper/mirror_utils/download_utils/jd_download.py index 01fe77e0df3..adc38f6bded 100644 --- a/bot/helper/mirror_utils/download_utils/jd_download.py +++ b/bot/helper/mirror_utils/download_utils/jd_download.py @@ -171,7 +171,9 @@ async def add_jd_download(listener, path): for link in links if link["availability"].lower() != "online" ]: - await retry_function(jdownloader.device.linkgrabber.remove_links, to_remove) + await retry_function( + jdownloader.device.linkgrabber.remove_links, to_remove + ) break listener.name = listener.name or name diff --git a/bot/helper/mirror_utils/rclone_utils/list.py b/bot/helper/mirror_utils/rclone_utils/list.py index 77f67bebb6d..b1499493055 100644 --- a/bot/helper/mirror_utils/rclone_utils/list.py +++ b/bot/helper/mirror_utils/rclone_utils/list.py @@ -217,7 +217,17 @@ async def get_path(self, itype=""): self.item_type == itype elif self.list_status == "rcu": self.item_type == "--dirs-only" - cmd = ["rclone", "lsjson", self.item_type, "--fast-list", "--no-mimetype", "--no-modtime", "--config", self.config_path, f"{self.remote}{self.path}"] + cmd = [ + "rclone", + "lsjson", + self.item_type, + "--fast-list", + "--no-mimetype", + "--no-modtime", + "--config", + self.config_path, + f"{self.remote}{self.path}", + ] if self.is_cancelled: return res, err, code = await cmd_exec(cmd) diff --git a/bot/helper/mirror_utils/telegram_uploader.py b/bot/helper/mirror_utils/telegram_uploader.py index bb4f0312d00..28994359f4f 100644 --- a/bot/helper/mirror_utils/telegram_uploader.py +++ b/bot/helper/mirror_utils/telegram_uploader.py @@ -111,11 +111,11 @@ async def _msg_to_reply(self): ) if self._sent_msg is None: self._sent_msg = await user.send_message( - chat_id=self._listener.message.chat.id, - text="Deleted Cmd Message! Don't delete the cmd message again!", - disable_web_page_preview=True, - disable_notification=True, - ) + chat_id=self._listener.message.chat.id, + text="Deleted Cmd Message! Don't delete the cmd message again!", + disable_web_page_preview=True, + disable_notification=True, + ) else: self._sent_msg = self._listener.message return True @@ -139,7 +139,7 @@ async def _prepare_file(self, file_, dirpath): self._up_path = new_path else: cap_mono = f"{file_}" - if len(file_) > 54: + if len(file_) > 60: if is_archive(file_): name = get_base_name(file_) ext = file_.split(name, 1)[1] @@ -153,7 +153,7 @@ async def _prepare_file(self, file_, dirpath): name = file_ ext = "" extn = len(ext) - remain = 54 - extn + remain = 60 - extn name = name[:remain] if ( self._listener.seed @@ -198,16 +198,16 @@ async def _send_screenshots(self): inputs.append(InputMediaPhoto(m, cap)) else: outputs.remove(m) - if outputs: - self._sent_msg = ( - await self._sent_msg.reply_media_group( - media=inputs, - quote=True, - disable_notification=True, - ) - )[-1] - for m in outputs: - await remove(m) + if outputs: + self._sent_msg = ( + await self._sent_msg.reply_media_group( + media=inputs, + quote=True, + disable_notification=True, + ) + )[-1] + for m in outputs: + await remove(m) async def _send_media_group(self, subkey, key, msgs): msgs_list = await msgs[0].reply_to_message.reply_media_group( diff --git a/bot/modules/bot_settings.py b/bot/modules/bot_settings.py index 46ffed29d40..79193fd3053 100644 --- a/bot/modules/bot_settings.py +++ b/bot/modules/bot_settings.py @@ -124,9 +124,7 @@ async def get_buttons(key=None, edit_type=None): buttons.ibutton("Back", "botset back") buttons.ibutton("Close", "botset close") for x in range(0, len(config_dict), 10): - buttons.ibutton( - f"{int(x/10)}", f"botset start var {x}", position="footer" - ) + buttons.ibutton(f"{int(x/10)}", f"botset start var {x}", position="footer") msg = f"Config Variables | Page: {int(START/10)} | State: {STATE}" elif key == "private": buttons.ibutton("Back", "botset back") @@ -146,9 +144,7 @@ async def get_buttons(key=None, edit_type=None): buttons.ibutton("Back", "botset back") buttons.ibutton("Close", "botset close") for x in range(0, len(aria2_options), 10): - buttons.ibutton( - f"{int(x/10)}", f"botset start aria {x}", position="footer" - ) + buttons.ibutton(f"{int(x/10)}", f"botset start aria {x}", position="footer") msg = f"Aria2c Options | Page: {int(START/10)} | State: {STATE}" elif key == "qbit": for k in list(qbit_options.keys())[START : 10 + START]: @@ -160,9 +156,7 @@ async def get_buttons(key=None, edit_type=None): buttons.ibutton("Back", "botset back") buttons.ibutton("Close", "botset close") for x in range(0, len(qbit_options), 10): - buttons.ibutton( - f"{int(x/10)}", f"botset start qbit {x}", position="footer" - ) + buttons.ibutton(f"{int(x/10)}", f"botset start qbit {x}", position="footer") msg = f"Qbittorrent Options | Page: {int(START/10)} | State: {STATE}" button = buttons.build_menu(1) if key is None else buttons.build_menu(2) return msg, button diff --git a/bot/modules/exec.py b/bot/modules/exec.py index c0c3795d6a8..5cb85f6b6b8 100644 --- a/bot/modules/exec.py +++ b/bot/modules/exec.py @@ -85,7 +85,9 @@ async def do(func, message): try: with redirect_stdout(stdout): - func_return = await sync_to_async(rfunc) if func == "exec" else await rfunc() + func_return = ( + await sync_to_async(rfunc) if func == "exec" else await rfunc() + ) except Exception as e: value = stdout.getvalue() return f"{value}{format_exc()}" diff --git a/bot/modules/status.py b/bot/modules/status.py index 40971fb68fb..a630f471367 100644 --- a/bot/modules/status.py +++ b/bot/modules/status.py @@ -138,7 +138,7 @@ async def status_pages(_, query): OULS: {get_readable_file_size(up_speed)}/s OSDS: {get_readable_file_size(seed_speed)}/s """ - await query.answer(msg, show_alert=True, cache_time=30) + await query.answer(msg, show_alert=True) bot.add_handler(