2
0
mirror of https://github.com/pyrogram/pyrogram synced 2025-08-28 12:57:52 +00:00

Make get_user_profile_photos return the correct type

This commit is contained in:
Dan 2018-04-28 09:04:45 +02:00
parent 750caa7471
commit 01034c174a
2 changed files with 65 additions and 6 deletions

View File

@ -2432,15 +2432,20 @@ class Client:
Limits the number of photos to be retrieved. Limits the number of photos to be retrieved.
Values between 1100 are accepted. Defaults to 100. Values between 1100 are accepted. Defaults to 100.
Returns:
On success, :obj:`UserProfilePhotos` is returned.
Raises: Raises:
:class:`Error <pyrogram.Error>` :class:`Error <pyrogram.Error>`
""" """
return self.send( return utils.parse_photos(
functions.photos.GetUserPhotos( self.send(
user_id=self.resolve_peer(user_id), functions.photos.GetUserPhotos(
offset=offset, user_id=self.resolve_peer(user_id),
max_id=0, offset=offset,
limit=limit max_id=0,
limit=limit
)
) )
) )

View File

@ -17,8 +17,10 @@
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>. # along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from base64 import b64decode, b64encode from base64 import b64decode, b64encode
from struct import pack
from pyrogram.api import types from pyrogram.api import types
from pyrogram.client import types as pyrogram_types
def get_peer_id(input_peer) -> int: def get_peer_id(input_peer) -> int:
@ -48,6 +50,58 @@ def get_offset_date(dialogs):
return 0 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: def decode(s: str) -> bytes:
s = b64decode(s + "=" * (-len(s) % 4), "-_") s = b64decode(s + "=" * (-len(s) % 4), "-_")
r = b"" r = b""