From ec00c332c23120f0e8dc5b57ccf21f7cc5e17397 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 2 Aug 2019 02:26:42 +0200 Subject: [PATCH 1/4] Update Photo file_id format --- pyrogram/client/types/messages_and_media/photo.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pyrogram/client/types/messages_and_media/photo.py b/pyrogram/client/types/messages_and_media/photo.py index 8ccaaf19..ce117a25 100644 --- a/pyrogram/client/types/messages_and_media/photo.py +++ b/pyrogram/client/types/messages_and_media/photo.py @@ -77,10 +77,10 @@ class Photo(Object): return Photo( file_id=encode( pack( - " Date: Fri, 2 Aug 2019 02:27:29 +0200 Subject: [PATCH 2/4] Update Thumbnail (ex PhotoSize) file_id format --- pyrogram/client/types/messages_and_media/thumbnail.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pyrogram/client/types/messages_and_media/thumbnail.py b/pyrogram/client/types/messages_and_media/thumbnail.py index 936241c6..57f369c3 100644 --- a/pyrogram/client/types/messages_and_media/thumbnail.py +++ b/pyrogram/client/types/messages_and_media/thumbnail.py @@ -66,7 +66,7 @@ class Thumbnail(Object): ) -> Union[List[Union[StrippedThumbnail, "Thumbnail"]], None]: if isinstance(media, types.Photo): raw_thumbnails = media.sizes[:-1] - media_type = 0 + media_type = 2 elif isinstance(media, types.Document): raw_thumbnails = media.thumbs media_type = 14 @@ -87,10 +87,10 @@ class Thumbnail(Object): Thumbnail( file_id=encode( pack( - " Date: Fri, 2 Aug 2019 02:30:19 +0200 Subject: [PATCH 3/4] Update ChatPhoto file_id format --- .../client/types/user_and_chats/chat_photo.py | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/pyrogram/client/types/user_and_chats/chat_photo.py b/pyrogram/client/types/user_and_chats/chat_photo.py index 70e114af..7378e3ce 100644 --- a/pyrogram/client/types/user_and_chats/chat_photo.py +++ b/pyrogram/client/types/user_and_chats/chat_photo.py @@ -52,20 +52,40 @@ class ChatPhoto(Object): if not isinstance(chat_photo, (types.UserProfilePhoto, types.ChatPhoto)): return None + photo_id = getattr(chat_photo, "photo_id", 0) loc_small = chat_photo.photo_small 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( small_file_id=encode( pack( - " Date: Fri, 2 Aug 2019 02:33:52 +0200 Subject: [PATCH 4/4] Update download_media and util methods to work with new file_id formats --- pyrogram/client/client.py | 7 ++++++- pyrogram/client/ext/file_data.py | 6 ++++-- pyrogram/client/ext/utils.py | 4 ++-- pyrogram/client/methods/messages/download_media.py | 13 +++++++------ 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index 511dbf2a..6643e247 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -1063,6 +1063,7 @@ class Client(Methods, BaseClient): access_hash=data.access_hash, thumb_size=data.thumb_size, peer_id=data.peer_id, + peer_access_hash=data.peer_access_hash, volume_id=data.volume_id, local_id=data.local_id, file_size=data.file_size, @@ -1702,6 +1703,7 @@ class Client(Methods, BaseClient): access_hash: int, thumb_size: str, peer_id: int, + peer_access_hash: int, volume_id: int, local_id: int, file_size: int, @@ -1741,7 +1743,10 @@ class Client(Methods, BaseClient): if media_type == 1: 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, local_id=local_id, big=is_big or None diff --git a/pyrogram/client/ext/file_data.py b/pyrogram/client/ext/file_data.py index 9a19cd5d..ad1da9b6 100644 --- a/pyrogram/client/ext/file_data.py +++ b/pyrogram/client/ext/file_data.py @@ -20,8 +20,9 @@ class FileData: def __init__( 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, - file_size: int = None, mime_type: str = None, file_name: str = None, date: int = None + thumb_size: str = None, peer_id: int = None, peer_access_hash: int = None, volume_id: 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.dc_id = dc_id @@ -29,6 +30,7 @@ class FileData: self.access_hash = access_hash self.thumb_size = thumb_size self.peer_id = peer_id + self.peer_access_hash = peer_access_hash self.volume_id = volume_id self.local_id = local_id self.is_big = is_big diff --git a/pyrogram/client/ext/utils.py b/pyrogram/client/ext/utils.py index cdc0684c..39031adf 100644 --- a/pyrogram/client/ext/utils.py +++ b/pyrogram/client/ext/utils.py @@ -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)) if media_type == 2: - unpacked = struct.unpack("