mirror of
https://github.com/pyrogram/pyrogram
synced 2025-08-28 04:48:06 +00:00
Make get_user_profile_photos return the correct type
This commit is contained in:
parent
750caa7471
commit
01034c174a
@ -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 <pyrogram.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
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
|
@ -17,8 +17,10 @@
|
||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
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(
|
||||
"<iiqqqqi",
|
||||
2,
|
||||
loc.dc_id,
|
||||
photo.id,
|
||||
photo.access_hash,
|
||||
loc.volume_id,
|
||||
loc.secret,
|
||||
loc.local_id
|
||||
)
|
||||
),
|
||||
width=size.w,
|
||||
height=size.h,
|
||||
file_size=file_size,
|
||||
date=photo.date
|
||||
)
|
||||
|
||||
photo_sizes.append(photo_size)
|
||||
|
||||
user_profile_photos.append(photo_sizes)
|
||||
|
||||
return pyrogram_types.UserProfilePhotos(
|
||||
total_count=total_count,
|
||||
photos=user_profile_photos
|
||||
)
|
||||
|
||||
|
||||
def decode(s: str) -> bytes:
|
||||
s = b64decode(s + "=" * (-len(s) % 4), "-_")
|
||||
r = b""
|
||||
|
Loading…
x
Reference in New Issue
Block a user