mirror of
https://github.com/pyrogram/pyrogram
synced 2025-08-28 21:07:59 +00:00
Merge branch 'new-file-id-format' into develop
This commit is contained in:
commit
77e4128d54
@ -1064,6 +1064,7 @@ class Client(Methods, BaseClient):
|
|||||||
access_hash=data.access_hash,
|
access_hash=data.access_hash,
|
||||||
thumb_size=data.thumb_size,
|
thumb_size=data.thumb_size,
|
||||||
peer_id=data.peer_id,
|
peer_id=data.peer_id,
|
||||||
|
peer_access_hash=data.peer_access_hash,
|
||||||
volume_id=data.volume_id,
|
volume_id=data.volume_id,
|
||||||
local_id=data.local_id,
|
local_id=data.local_id,
|
||||||
file_size=data.file_size,
|
file_size=data.file_size,
|
||||||
@ -1708,6 +1709,7 @@ class Client(Methods, BaseClient):
|
|||||||
access_hash: int,
|
access_hash: int,
|
||||||
thumb_size: str,
|
thumb_size: str,
|
||||||
peer_id: int,
|
peer_id: int,
|
||||||
|
peer_access_hash: int,
|
||||||
volume_id: int,
|
volume_id: int,
|
||||||
local_id: int,
|
local_id: int,
|
||||||
file_size: int,
|
file_size: int,
|
||||||
@ -1752,7 +1754,10 @@ class Client(Methods, BaseClient):
|
|||||||
|
|
||||||
if media_type == 1:
|
if media_type == 1:
|
||||||
location = types.InputPeerPhotoFileLocation(
|
location = types.InputPeerPhotoFileLocation(
|
||||||
peer=self.resolve_peer(peer_id),
|
peer=types.InputPeerUser(
|
||||||
|
user_id=peer_id,
|
||||||
|
access_hash=peer_access_hash
|
||||||
|
),
|
||||||
volume_id=volume_id,
|
volume_id=volume_id,
|
||||||
local_id=local_id,
|
local_id=local_id,
|
||||||
big=is_big or None
|
big=is_big or None
|
||||||
|
@ -20,8 +20,9 @@
|
|||||||
class FileData:
|
class FileData:
|
||||||
def __init__(
|
def __init__(
|
||||||
self, *, media_type: int = None, dc_id: int = None, document_id: int = None, access_hash: int = None,
|
self, *, media_type: int = None, dc_id: int = None, document_id: int = None, access_hash: int = None,
|
||||||
thumb_size: str = None, peer_id: int = None, volume_id: int = None, local_id: int = None, is_big: bool = None,
|
thumb_size: str = None, peer_id: int = None, peer_access_hash: int = None, volume_id: int = None,
|
||||||
file_size: int = None, mime_type: str = None, file_name: str = None, date: int = None
|
local_id: int = None, is_big: bool = None, file_size: int = None, mime_type: str = None, file_name: str = None,
|
||||||
|
date: int = None
|
||||||
):
|
):
|
||||||
self.media_type = media_type
|
self.media_type = media_type
|
||||||
self.dc_id = dc_id
|
self.dc_id = dc_id
|
||||||
@ -29,6 +30,7 @@ class FileData:
|
|||||||
self.access_hash = access_hash
|
self.access_hash = access_hash
|
||||||
self.thumb_size = thumb_size
|
self.thumb_size = thumb_size
|
||||||
self.peer_id = peer_id
|
self.peer_id = peer_id
|
||||||
|
self.peer_access_hash = peer_access_hash
|
||||||
self.volume_id = volume_id
|
self.volume_id = volume_id
|
||||||
self.local_id = local_id
|
self.local_id = local_id
|
||||||
self.is_big = is_big
|
self.is_big = is_big
|
||||||
|
@ -104,8 +104,8 @@ def get_input_media_from_file_id(
|
|||||||
raise ValueError("This file_id can only be used for download: {}".format(file_id_str))
|
raise ValueError("This file_id can only be used for download: {}".format(file_id_str))
|
||||||
|
|
||||||
if media_type == 2:
|
if media_type == 2:
|
||||||
unpacked = struct.unpack("<iiqqc", decoded)
|
unpacked = struct.unpack("<iiqqqiiii", decoded)
|
||||||
dc_id, file_id, access_hash, thumb_size = unpacked[1:]
|
dc_id, file_id, access_hash, volume_id, _, _, type, local_id = unpacked[1:]
|
||||||
|
|
||||||
return types.InputMediaPhoto(
|
return types.InputMediaPhoto(
|
||||||
id=types.InputPhoto(
|
id=types.InputPhoto(
|
||||||
|
@ -138,21 +138,22 @@ class DownloadMedia(BaseClient):
|
|||||||
media_type = decoded[0]
|
media_type = decoded[0]
|
||||||
|
|
||||||
if media_type == 1:
|
if media_type == 1:
|
||||||
unpacked = struct.unpack("<iiqqib", decoded)
|
unpacked = struct.unpack("<iiqqqiiiqi", decoded)
|
||||||
dc_id, peer_id, volume_id, local_id, is_big = unpacked[1:]
|
dc_id, photo_id, _, volume_id, size_type, peer_id, _, peer_access_hash, local_id = unpacked[1:]
|
||||||
|
|
||||||
data = FileData(
|
data = FileData(
|
||||||
**get_existing_attributes(),
|
**get_existing_attributes(),
|
||||||
media_type=media_type,
|
media_type=media_type,
|
||||||
dc_id=dc_id,
|
dc_id=dc_id,
|
||||||
peer_id=peer_id,
|
peer_id=peer_id,
|
||||||
|
peer_access_hash=peer_access_hash,
|
||||||
volume_id=volume_id,
|
volume_id=volume_id,
|
||||||
local_id=local_id,
|
local_id=local_id,
|
||||||
is_big=bool(is_big)
|
is_big=size_type == 3
|
||||||
)
|
)
|
||||||
elif media_type in (0, 2, 14):
|
elif media_type in (0, 2, 14):
|
||||||
unpacked = struct.unpack("<iiqqc", decoded)
|
unpacked = struct.unpack("<iiqqqiiii", decoded)
|
||||||
dc_id, document_id, access_hash, thumb_size = unpacked[1:]
|
dc_id, document_id, access_hash, volume_id, _, _, thumb_size, local_id = unpacked[1:]
|
||||||
|
|
||||||
data = FileData(
|
data = FileData(
|
||||||
**get_existing_attributes(),
|
**get_existing_attributes(),
|
||||||
@ -160,7 +161,7 @@ class DownloadMedia(BaseClient):
|
|||||||
dc_id=dc_id,
|
dc_id=dc_id,
|
||||||
document_id=document_id,
|
document_id=document_id,
|
||||||
access_hash=access_hash,
|
access_hash=access_hash,
|
||||||
thumb_size=thumb_size.decode()
|
thumb_size=chr(thumb_size)
|
||||||
)
|
)
|
||||||
elif media_type in (3, 4, 5, 8, 9, 10, 13):
|
elif media_type in (3, 4, 5, 8, 9, 10, 13):
|
||||||
unpacked = struct.unpack("<iiqq", decoded)
|
unpacked = struct.unpack("<iiqq", decoded)
|
||||||
|
@ -77,10 +77,10 @@ class Photo(Object):
|
|||||||
return Photo(
|
return Photo(
|
||||||
file_id=encode(
|
file_id=encode(
|
||||||
pack(
|
pack(
|
||||||
"<iiqqc",
|
"<iiqqqiiii",
|
||||||
2, photo.dc_id,
|
2, photo.dc_id, photo.id, photo.access_hash,
|
||||||
photo.id, photo.access_hash,
|
big.location.volume_id, 1, 2, ord(big.type),
|
||||||
big.type.encode()
|
big.location.local_id
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
width=big.w,
|
width=big.w,
|
||||||
|
@ -66,7 +66,7 @@ class Thumbnail(Object):
|
|||||||
) -> Union[List[Union[StrippedThumbnail, "Thumbnail"]], None]:
|
) -> Union[List[Union[StrippedThumbnail, "Thumbnail"]], None]:
|
||||||
if isinstance(media, types.Photo):
|
if isinstance(media, types.Photo):
|
||||||
raw_thumbnails = media.sizes[:-1]
|
raw_thumbnails = media.sizes[:-1]
|
||||||
media_type = 0
|
media_type = 2
|
||||||
elif isinstance(media, types.Document):
|
elif isinstance(media, types.Document):
|
||||||
raw_thumbnails = media.thumbs
|
raw_thumbnails = media.thumbs
|
||||||
media_type = 14
|
media_type = 14
|
||||||
@ -87,10 +87,10 @@ class Thumbnail(Object):
|
|||||||
Thumbnail(
|
Thumbnail(
|
||||||
file_id=encode(
|
file_id=encode(
|
||||||
pack(
|
pack(
|
||||||
"<iiqqc",
|
"<iiqqqiiii",
|
||||||
media_type, media.dc_id,
|
media_type, media.dc_id, media.id, media.access_hash,
|
||||||
media.id, media.access_hash,
|
thumbnail.location.volume_id, 1, 2, ord(thumbnail.type),
|
||||||
thumbnail.type.encode()
|
thumbnail.location.local_id
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
width=thumbnail.w,
|
width=thumbnail.w,
|
||||||
|
@ -54,20 +54,40 @@ class ChatPhoto(Object):
|
|||||||
if not isinstance(chat_photo, (types.UserProfilePhoto, types.ChatPhoto)):
|
if not isinstance(chat_photo, (types.UserProfilePhoto, types.ChatPhoto)):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
photo_id = getattr(chat_photo, "photo_id", 0)
|
||||||
loc_small = chat_photo.photo_small
|
loc_small = chat_photo.photo_small
|
||||||
loc_big = chat_photo.photo_big
|
loc_big = chat_photo.photo_big
|
||||||
|
|
||||||
|
peer = client.resolve_peer(peer_id)
|
||||||
|
|
||||||
|
if isinstance(peer, types.InputPeerUser):
|
||||||
|
peer_id = peer.user_id
|
||||||
|
peer_access_hash = peer.access_hash
|
||||||
|
x = 0
|
||||||
|
elif isinstance(peer, types.InputPeerChat):
|
||||||
|
peer_id = -peer.chat_id
|
||||||
|
peer_access_hash = 0
|
||||||
|
x = -1
|
||||||
|
else:
|
||||||
|
peer_id += 1000727379968
|
||||||
|
peer_access_hash = peer.access_hash
|
||||||
|
x = -234
|
||||||
|
|
||||||
return ChatPhoto(
|
return ChatPhoto(
|
||||||
small_file_id=encode(
|
small_file_id=encode(
|
||||||
pack(
|
pack(
|
||||||
"<iiqqib",
|
"<iiqqqiiiqi",
|
||||||
1, chat_photo.dc_id, peer_id, loc_small.volume_id, loc_small.local_id, 0
|
1, chat_photo.dc_id, photo_id,
|
||||||
|
0, loc_small.volume_id,
|
||||||
|
2, peer_id, x, peer_access_hash, loc_small.local_id
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
big_file_id=encode(
|
big_file_id=encode(
|
||||||
pack(
|
pack(
|
||||||
"<iiqqib",
|
"<iiqqqiiiqi",
|
||||||
1, chat_photo.dc_id, peer_id, loc_big.volume_id, loc_big.local_id, 1
|
1, chat_photo.dc_id, photo_id,
|
||||||
|
0, loc_big.volume_id,
|
||||||
|
3, peer_id, x, peer_access_hash, loc_big.local_id
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
client=client
|
client=client
|
||||||
|
Loading…
x
Reference in New Issue
Block a user