From 01034c174a73a0df8c175943b004ac7415fa31d2 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 28 Apr 2018 09:04:45 +0200 Subject: [PATCH] Make get_user_profile_photos return the correct type --- pyrogram/client/client.py | 17 +++++++----- pyrogram/client/utils.py | 54 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 6 deletions(-) diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index eed83798..4a5b1d42 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -2432,15 +2432,20 @@ class Client: Limits the number of photos to be retrieved. Values between 1—100 are accepted. Defaults to 100. + Returns: + On success, :obj:`UserProfilePhotos` is returned. + Raises: :class:`Error ` """ - return self.send( - functions.photos.GetUserPhotos( - user_id=self.resolve_peer(user_id), - offset=offset, - max_id=0, - limit=limit + return utils.parse_photos( + self.send( + functions.photos.GetUserPhotos( + user_id=self.resolve_peer(user_id), + offset=offset, + max_id=0, + limit=limit + ) ) ) diff --git a/pyrogram/client/utils.py b/pyrogram/client/utils.py index d4b1c38e..221cdab5 100644 --- a/pyrogram/client/utils.py +++ b/pyrogram/client/utils.py @@ -17,8 +17,10 @@ # along with Pyrogram. If not, see . from base64 import b64decode, b64encode +from struct import pack from pyrogram.api import types +from pyrogram.client import types as pyrogram_types def get_peer_id(input_peer) -> int: @@ -48,6 +50,58 @@ def get_offset_date(dialogs): return 0 +def parse_photos(photos): + if isinstance(photos, types.photos.Photos): + total_count = len(photos.photos) + else: + total_count = photos.count + + user_profile_photos = [] + + for photo in photos.photos: + if isinstance(photo, types.Photo): + sizes = photo.sizes + photo_sizes = [] + + for size in sizes: + if isinstance(size, (types.PhotoSize, types.PhotoCachedSize)): + loc = size.location + + if isinstance(size, types.PhotoSize): + file_size = size.size + else: + file_size = len(size.bytes) + + if isinstance(loc, types.FileLocation): + photo_size = pyrogram_types.PhotoSize( + file_id=encode( + pack( + " bytes: s = b64decode(s + "=" * (-len(s) % 4), "-_") r = b""