From 3ddb0a3903cd47fcbeee8ebf3ecd7275db87ef5e Mon Sep 17 00:00:00 2001 From: Shrimadhav U K Date: Sun, 17 Jan 2021 22:01:26 +0530 Subject: [PATCH] Fix thumbnail for TDesktop and Telegram X users (#1673) --- telethon/client/uploads.py | 3 ++- telethon/utils.py | 14 +++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/telethon/client/uploads.py b/telethon/client/uploads.py index 8736d31b..939718a3 100644 --- a/telethon/client/uploads.py +++ b/telethon/client/uploads.py @@ -699,7 +699,8 @@ class UploadMethods: force_document=force_document and not is_image, voice_note=voice_note, video_note=video_note, - supports_streaming=supports_streaming + supports_streaming=supports_streaming, + thumb=thumb ) if not thumb: diff --git a/telethon/utils.py b/telethon/utils.py index 21932487..ffa7a192 100644 --- a/telethon/utils.py +++ b/telethon/utils.py @@ -664,7 +664,7 @@ def _get_metadata(file): def get_attributes(file, *, attributes=None, mime_type=None, force_document=False, voice_note=False, video_note=False, - supports_streaming=False): + supports_streaming=False, thumb=None): """ Get a list of attributes for the given file and the mime type as a tuple ([attribute], mime_type). @@ -700,6 +700,18 @@ def get_attributes(file, *, attributes=None, mime_type=None, if m.has('duration') else 0), supports_streaming=supports_streaming ) + elif thumb: + t_m = _get_metadata(thumb) + width = 1 + height = 1 + if t_m and t_m.has("width"): + width = t_m.get("width") + if t_m and t_m.has("height"): + height = t_m.get("height") + + doc = types.DocumentAttributeVideo( + 0, width, height, round_message=video_note, + supports_streaming=supports_streaming) else: doc = types.DocumentAttributeVideo( 0, 1, 1, round_message=video_note,