From d28f7d417efc124e8c0069956613376e2b72c83a Mon Sep 17 00:00:00 2001 From: Nekmo Date: Mon, 4 Mar 2019 02:52:33 +0100 Subject: [PATCH] Fix mkv video metadata and thumbnail. --- telegram_upload/files.py | 8 ++++++-- telegram_upload/video.py | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/telegram_upload/files.py b/telegram_upload/files.py index 75171d1d..99a40c16 100644 --- a/telegram_upload/files.py +++ b/telegram_upload/files.py @@ -16,10 +16,14 @@ def get_file_attributes(file): mime = get_file_mime(file) if mime == 'video': metadata = video_metadata(file) + video_meta = metadata + meta_groups = metadata._MultipleMetadata__groups + if not metadata.has('width') and meta_groups: + video_meta = meta_groups[next(filter(lambda x: x.startswith('video'), meta_groups._key_list))] attrs.append(DocumentAttributeStreamVideo( (0, metadata.get('duration').seconds)[metadata.has('duration')], - (0, metadata.get('width'))[metadata.has('width')], - (0, metadata.get('height'))[metadata.has('height')] + (0, video_meta.get('width'))[video_meta.has('width')], + (0, video_meta.get('height'))[video_meta.has('height')] )) return attrs diff --git a/telegram_upload/video.py b/telegram_upload/video.py index 39c15af3..5fd964e8 100644 --- a/telegram_upload/video.py +++ b/telegram_upload/video.py @@ -33,5 +33,6 @@ def get_video_thumb(file, output=None, width=90): '-vframes', '1', output, ], stdout=subprocess.PIPE, stderr=subprocess.DEVNULL) + p.communicate() if not p.returncode and os.path.lexists(file): return output