From e99f86b69fc0d13f723703f08a53d4d4640ae273 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Mon, 21 Jan 2019 18:45:52 +0100
Subject: [PATCH] Update media thumbs parsing for L93
---
.../types/messages_and_media/animation.py | 2 +-
.../client/types/messages_and_media/audio.py | 2 +-
.../types/messages_and_media/document.py | 2 +-
.../client/types/messages_and_media/photo.py | 1 -
.../types/messages_and_media/photo_size.py | 44 ++++++++++---------
.../types/messages_and_media/sticker.py | 2 +-
.../client/types/messages_and_media/video.py | 2 +-
.../types/messages_and_media/video_note.py | 2 +-
8 files changed, 30 insertions(+), 27 deletions(-)
diff --git a/pyrogram/client/types/messages_and_media/animation.py b/pyrogram/client/types/messages_and_media/animation.py
index d5661ea8..9f3ba886 100644
--- a/pyrogram/client/types/messages_and_media/animation.py
+++ b/pyrogram/client/types/messages_and_media/animation.py
@@ -97,7 +97,7 @@ class Animation(PyrogramType):
width=getattr(video_attributes, "w", 0),
height=getattr(video_attributes, "h", 0),
duration=getattr(video_attributes, "duration", 0),
- thumb=PhotoSize._parse(client, animation.thumb),
+ thumb=PhotoSize._parse(client, animation.thumbs),
mime_type=animation.mime_type,
file_size=animation.size,
file_name=file_name,
diff --git a/pyrogram/client/types/messages_and_media/audio.py b/pyrogram/client/types/messages_and_media/audio.py
index cfecceae..9c5698f1 100644
--- a/pyrogram/client/types/messages_and_media/audio.py
+++ b/pyrogram/client/types/messages_and_media/audio.py
@@ -99,7 +99,7 @@ class Audio(PyrogramType):
title=audio_attributes.title,
mime_type=audio.mime_type,
file_size=audio.size,
- thumb=PhotoSize._parse(client, audio.thumb),
+ thumb=PhotoSize._parse(client, audio.thumbs),
file_name=file_name,
date=audio.date,
client=client
diff --git a/pyrogram/client/types/messages_and_media/document.py b/pyrogram/client/types/messages_and_media/document.py
index e84b5149..5cd01a92 100644
--- a/pyrogram/client/types/messages_and_media/document.py
+++ b/pyrogram/client/types/messages_and_media/document.py
@@ -78,7 +78,7 @@ class Document(PyrogramType):
document.access_hash
)
),
- thumb=PhotoSize._parse(client, document.thumb),
+ thumb=PhotoSize._parse(client, document.thumbs),
file_name=file_name,
mime_type=document.mime_type,
file_size=document.size,
diff --git a/pyrogram/client/types/messages_and_media/photo.py b/pyrogram/client/types/messages_and_media/photo.py
index 72187761..aa2b3a26 100644
--- a/pyrogram/client/types/messages_and_media/photo.py
+++ b/pyrogram/client/types/messages_and_media/photo.py
@@ -61,7 +61,6 @@ class Photo(PyrogramType):
for raw_size in raw_sizes:
if isinstance(raw_size, (types.PhotoSize, types.PhotoCachedSize)):
-
if isinstance(raw_size, types.PhotoSize):
file_size = raw_size.size
elif isinstance(raw_size, types.PhotoCachedSize):
diff --git a/pyrogram/client/types/messages_and_media/photo_size.py b/pyrogram/client/types/messages_and_media/photo_size.py
index 05f00455..e1be74df 100644
--- a/pyrogram/client/types/messages_and_media/photo_size.py
+++ b/pyrogram/client/types/messages_and_media/photo_size.py
@@ -17,6 +17,7 @@
# along with Pyrogram. If not, see .
from struct import pack
+from typing import List, Union
import pyrogram
from pyrogram.api import types
@@ -56,27 +57,30 @@ class PhotoSize(PyrogramType):
self.file_size = file_size
@staticmethod
- def _parse(client, photo_size: types.PhotoSize or types.PhotoCachedSize):
- if isinstance(photo_size, (types.PhotoSize, types.PhotoCachedSize)):
+ def _parse(client, thumbs: List) -> Union["PhotoSize", None]:
+ if not thumbs:
+ return None
- if isinstance(photo_size, types.PhotoSize):
- file_size = photo_size.size
- elif isinstance(photo_size, types.PhotoCachedSize):
- file_size = len(photo_size.bytes)
- else:
- file_size = 0
+ photo_size = thumbs[-1]
- loc = photo_size.location
+ if not isinstance(photo_size, (types.PhotoSize, types.PhotoCachedSize, types.PhotoStrippedSize)):
+ return None
- if isinstance(loc, types.FileLocation):
- return PhotoSize(
- file_id=encode(
- pack(
- "