Skip to content
This repository has been archived by the owner on Jan 15, 2022. It is now read-only.

Commit

Permalink
fixed #1 - unable to detect video duration
Browse files Browse the repository at this point in the history
reads video duration from format instead of video stream
fix some default value
  • Loading branch information
azamaulanaaa committed Sep 27, 2020
1 parent 7f2e0e0 commit ff6177c
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions bot/handlers/upload_to_tg_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ff6177c

Please sign in to comment.