From ff6177ce8f87b63c77aa81092a649a533e2bad71 Mon Sep 17 00:00:00 2001 From: Aza Maulana Date: Sun, 27 Sep 2020 23:56:20 +0700 Subject: [PATCH] fixed #1 - unable to detect video duration reads video duration from format instead of video stream fix some default value --- bot/handlers/upload_to_tg_handler.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/bot/handlers/upload_to_tg_handler.py b/bot/handlers/upload_to_tg_handler.py index 68513195..d36c0ee8 100644 --- a/bot/handlers/upload_to_tg_handler.py +++ b/bot/handlers/upload_to_tg_handler.py @@ -49,11 +49,14 @@ async def func(filepath: str, client: Client, message: Message, delete=False): elif file_ext in video: async def upload_fn(chat_id, file, **kwargs): probe = await ffprobe.func(file.path) + + duration = int(float(probe["format"]["duration"])) + video_stream = next((stream for stream in probe['streams'] if stream['codec_type'] == 'video'), None) + width = int(video_stream['width'] if 'width' in video_stream else 0) + height = int(video_stream['height'] if 'height' in video_stream else 0) + - duration = int(float(video_stream["duration"])) or 0 - width = int(video_stream['width']) or 0 - height = int(video_stream['height']) or 0 await message.edit( LOCAL.GENERATE_THUMBNAIL.format( name = file.name