diff --git a/pyrogram/client/types/messages_and_media/photo.py b/pyrogram/client/types/messages_and_media/photo.py
index 4037025b..b1021d93 100644
--- a/pyrogram/client/types/messages_and_media/photo.py
+++ b/pyrogram/client/types/messages_and_media/photo.py
@@ -16,7 +16,13 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see .
+from base64 import b64encode
+from struct import pack
+
+from pyrogram.api import types
from pyrogram.api.core import Object
+from .photo_size import PhotoSize
+from ...ext.utils import encode
class Photo(Object):
@@ -35,7 +41,60 @@ class Photo(Object):
ID = 0xb0700027
- def __init__(self, id: str, date: int, sizes: list):
+ def __init__(self, id: str, date: int, sizes: list, *,
+ client=None, raw=None):
self.id = id
self.date = date
self.sizes = sizes
+
+ self._client = client
+ self._raw = raw
+
+ @staticmethod
+ def parse(client, photo: types.Photo):
+ if isinstance(photo, types.Photo):
+ raw_sizes = photo.sizes
+ sizes = []
+
+ 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):
+ file_size = len(raw_size.bytes)
+ else:
+ file_size = 0
+
+ loc = raw_size.location
+
+ if isinstance(loc, types.FileLocation):
+ size = PhotoSize(
+ file_id=encode(
+ pack(
+ ".
+from struct import pack
+
+from pyrogram.api import types
from pyrogram.api.core import Object
+from pyrogram.client.ext.utils import encode
class PhotoSize(Object):
@@ -38,8 +42,39 @@ class PhotoSize(Object):
ID = 0xb0700005
- def __init__(self, file_id: str, width: int, height: int, file_size: int):
+ def __init__(self, file_id: str, width: int, height: int, file_size: int, *,
+ client=None, raw=None):
self.file_id = file_id
self.width = width
self.height = height
self.file_size = file_size
+
+ self._client = client
+ self._raw = raw
+
+ @staticmethod
+ def parse(client, photo_size: types.PhotoSize or types.PhotoCachedSize):
+ if isinstance(photo_size, (types.PhotoSize, types.PhotoCachedSize)):
+
+ 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
+
+ loc = photo_size.location
+
+ if isinstance(loc, types.FileLocation):
+ return PhotoSize(
+ file_id=encode(
+ pack(
+ "