Skip to content

Commit 01034c1

Browse files
committed
Make get_user_profile_photos return the correct type
1 parent 750caa7 commit 01034c1

2 files changed

Lines changed: 65 additions & 6 deletions

File tree

pyrogram/client/client.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2432,15 +2432,20 @@ def get_user_profile_photos(self,
24322432
Limits the number of photos to be retrieved.
24332433
Values between 1—100 are accepted. Defaults to 100.
24342434
2435+
Returns:
2436+
On success, :obj:`UserProfilePhotos` is returned.
2437+
24352438
Raises:
24362439
:class:`Error <pyrogram.Error>`
24372440
"""
2438-
return self.send(
2439-
functions.photos.GetUserPhotos(
2440-
user_id=self.resolve_peer(user_id),
2441-
offset=offset,
2442-
max_id=0,
2443-
limit=limit
2441+
return utils.parse_photos(
2442+
self.send(
2443+
functions.photos.GetUserPhotos(
2444+
user_id=self.resolve_peer(user_id),
2445+
offset=offset,
2446+
max_id=0,
2447+
limit=limit
2448+
)
24442449
)
24452450
)
24462451

pyrogram/client/utils.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
1818

1919
from base64 import b64decode, b64encode
20+
from struct import pack
2021

2122
from pyrogram.api import types
23+
from pyrogram.client import types as pyrogram_types
2224

2325

2426
def get_peer_id(input_peer) -> int:
@@ -48,6 +50,58 @@ def get_offset_date(dialogs):
4850
return 0
4951

5052

53+
def parse_photos(photos):
54+
if isinstance(photos, types.photos.Photos):
55+
total_count = len(photos.photos)
56+
else:
57+
total_count = photos.count
58+
59+
user_profile_photos = []
60+
61+
for photo in photos.photos:
62+
if isinstance(photo, types.Photo):
63+
sizes = photo.sizes
64+
photo_sizes = []
65+
66+
for size in sizes:
67+
if isinstance(size, (types.PhotoSize, types.PhotoCachedSize)):
68+
loc = size.location
69+
70+
if isinstance(size, types.PhotoSize):
71+
file_size = size.size
72+
else:
73+
file_size = len(size.bytes)
74+
75+
if isinstance(loc, types.FileLocation):
76+
photo_size = pyrogram_types.PhotoSize(
77+
file_id=encode(
78+
pack(
79+
"<iiqqqqi",
80+
2,
81+
loc.dc_id,
82+
photo.id,
83+
photo.access_hash,
84+
loc.volume_id,
85+
loc.secret,
86+
loc.local_id
87+
)
88+
),
89+
width=size.w,
90+
height=size.h,
91+
file_size=file_size,
92+
date=photo.date
93+
)
94+
95+
photo_sizes.append(photo_size)
96+
97+
user_profile_photos.append(photo_sizes)
98+
99+
return pyrogram_types.UserProfilePhotos(
100+
total_count=total_count,
101+
photos=user_profile_photos
102+
)
103+
104+
51105
def decode(s: str) -> bytes:
52106
s = b64decode(s + "=" * (-len(s) % 4), "-_")
53107
r = b""

0 commit comments

Comments
 (0)