From ff3c21c805ae30009e51619e6e0cc84b2518da2a Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Sat, 13 Feb 2021 22:52:27 +0100 Subject: [PATCH] Update file.size to reflect the size of the largest thumbnail This way we avoid relying on the order of the thumbnails, and just pick the largest. --- telethon/tl/custom/file.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/telethon/tl/custom/file.py b/telethon/tl/custom/file.py index d1e5d834..07f2e1a5 100644 --- a/telethon/tl/custom/file.py +++ b/telethon/tl/custom/file.py @@ -120,9 +120,11 @@ class File: def size(self): """ The size in bytes of this file. + + For photos, this is the heaviest thumbnail, as it often repressents the largest dimensions. """ if isinstance(self.media, types.Photo): - return utils._photo_size_byte_count(self.media.sizes[-1]) + return max(filter(None, map(utils._photo_size_byte_count, self.media.sizes)), default=None) elif isinstance(self.media, types.Document): return self.media.size