Skip to content

Commit

Permalink
Update file.size to reflect the size of the largest thumbnail
Browse files Browse the repository at this point in the history
This way we avoid relying on the order of the thumbnails, and just
pick the largest.
  • Loading branch information
Lonami committed Feb 13, 2021
1 parent b102f1f commit ff3c21c
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion telethon/tl/custom/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,11 @@ def sticker_set(self):
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

Expand Down

0 comments on commit ff3c21c

Please sign in to comment.