From 0cefc7344849bc20629029c7a3d4aae4896b4be5 Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Tue, 11 Aug 2020 22:31:12 +0200 Subject: [PATCH] Support both str and VideoSize as thumb on download_media --- telethon/client/downloads.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/telethon/client/downloads.py b/telethon/client/downloads.py index 2a27f412..0a382ede 100644 --- a/telethon/client/downloads.py +++ b/telethon/client/downloads.py @@ -634,8 +634,10 @@ class DownloadMethods: return thumbs[-1] elif isinstance(thumb, int): return thumbs[thumb] + elif isinstance(thumb, str): + return next((t for t in thumbs if t.type == thumb), None) elif isinstance(thumb, (types.PhotoSize, types.PhotoCachedSize, - types.PhotoStrippedSize)): + types.PhotoStrippedSize, types.VideoSize)): return thumb else: return None @@ -670,11 +672,16 @@ class DownloadMethods: if not isinstance(photo, types.Photo): return - size = self._get_thumb(photo.sizes, thumb) + # Include video sizes here (but they may be None so provide an empty list) + size = self._get_thumb(photo.sizes + (photo.video_sizes or []), thumb) if not size or isinstance(size, types.PhotoSizeEmpty): return - file = self._get_proper_filename(file, 'photo', '.jpg', date=date) + if isinstance(size, types.VideoSize): + file = self._get_proper_filename(file, 'video', '.mp4', date=date) + else: + file = self._get_proper_filename(file, 'photo', '.jpg', date=date) + if isinstance(size, (types.PhotoCachedSize, types.PhotoStrippedSize)): return self._download_cached_photo_size(size, file)