diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index e3bdb1a003..9d9f45d045 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -1212,7 +1212,7 @@ def download_worker(self): final_file_path = "" try: - data, directory, file_name, done, progress, progress_args, path = packet + data, directory, file_name, done, progress, progress_args, path, file_reference = packet temp_file_path = self.get_file( media_type=data.media_type, @@ -1225,6 +1225,7 @@ def download_worker(self): volume_id=data.volume_id, local_id=data.local_id, file_size=data.file_size, + file_reference=file_reference, is_big=data.is_big, progress=progress, progress_args=progress_args @@ -1871,7 +1872,8 @@ def get_file( file_size: int, is_big: bool, progress: callable, - progress_args: tuple = () + progress_args: tuple = (), + file_reference: bytes = b"" ) -> str: with self.media_sessions_lock: session = self.media_sessions.get(dc_id, None) @@ -1922,21 +1924,21 @@ def get_file( location = types.InputPhotoFileLocation( id=document_id, access_hash=access_hash, - file_reference=b"", + file_reference=file_reference, thumb_size=thumb_size ) elif media_type == 14: location = types.InputDocumentFileLocation( id=document_id, access_hash=access_hash, - file_reference=b"", + file_reference=file_reference, thumb_size=thumb_size ) else: location = types.InputDocumentFileLocation( id=document_id, access_hash=access_hash, - file_reference=b"", + file_reference=file_reference, thumb_size="" ) diff --git a/pyrogram/client/methods/messages/download_media.py b/pyrogram/client/methods/messages/download_media.py index 9cf60387c1..dfe2929f74 100644 --- a/pyrogram/client/methods/messages/download_media.py +++ b/pyrogram/client/methods/messages/download_media.py @@ -102,6 +102,7 @@ def download_media( file_size = None mime_type = None date = None + file_reference = b"" if isinstance(message, pyrogram.Message): for kind in available_media: @@ -120,6 +121,7 @@ def download_media( file_id_str = media.file_id media_file_name = getattr(media, "file_name", "") file_size = getattr(media, "file_size", None) + file_reference = getattr(media, "file_reference", b"") mime_type = getattr(media, "mime_type", None) date = getattr(media, "date", None) @@ -216,7 +218,7 @@ def get_existing_attributes() -> dict: ) # Cast to string because Path objects aren't supported by Python 3.5 - self.download_queue.put((data, str(directory), str(file_name), done, progress, progress_args, path)) + self.download_queue.put((data, str(directory), str(file_name), done, progress, progress_args, path, file_reference)) if block: done.wait() diff --git a/pyrogram/client/types/messages_and_media/animation.py b/pyrogram/client/types/messages_and_media/animation.py index ba6744ceb5..2ac2df81b9 100644 --- a/pyrogram/client/types/messages_and_media/animation.py +++ b/pyrogram/client/types/messages_and_media/animation.py @@ -58,6 +58,8 @@ class Animation(Object): Animation thumbnails. """ + __slots__ = ["file_id", "file_name", "mime_type", "file_size", "file_reference", "date", "width", "height", "duration", "thumbs"] + def __init__( self, *, @@ -67,6 +69,7 @@ def __init__( height: int, duration: int, file_name: str = None, + file_reference: bytes = b"", mime_type: str = None, file_size: int = None, date: int = None, @@ -83,6 +86,7 @@ def __init__( self.height = height self.duration = duration self.thumbs = thumbs + self.file_reference = file_reference @staticmethod def _parse( @@ -106,6 +110,7 @@ def _parse( duration=getattr(video_attributes, "duration", 0), mime_type=animation.mime_type, file_size=animation.size, + file_reference=animation.file_reference, file_name=file_name, date=animation.date, thumbs=Thumbnail._parse(client, animation), diff --git a/pyrogram/client/types/messages_and_media/document.py b/pyrogram/client/types/messages_and_media/document.py index 4bb40980ed..fb532d94d3 100644 --- a/pyrogram/client/types/messages_and_media/document.py +++ b/pyrogram/client/types/messages_and_media/document.py @@ -49,6 +49,8 @@ class Document(Object): Document thumbnails as defined by sender. """ + __slots__ = ["file_id", "file_name", "mime_type", "file_size", "file_reference", "date", "thumbs"] + def __init__( self, *, @@ -57,6 +59,7 @@ def __init__( file_name: str = None, mime_type: str = None, file_size: int = None, + file_reference: bytes = b"", date: int = None, thumbs: List[Thumbnail] = None ): @@ -68,6 +71,7 @@ def __init__( self.file_size = file_size self.date = date self.thumbs = thumbs + self.file_reference = file_reference @staticmethod def _parse(client, document: types.Document, file_name: str) -> "Document": @@ -84,6 +88,7 @@ def _parse(client, document: types.Document, file_name: str) -> "Document": file_name=file_name, mime_type=document.mime_type, file_size=document.size, + file_reference=document.file_reference, date=document.date, thumbs=Thumbnail._parse(client, document), client=client diff --git a/pyrogram/client/types/messages_and_media/photo.py b/pyrogram/client/types/messages_and_media/photo.py index ce117a25e7..b152d7ec78 100644 --- a/pyrogram/client/types/messages_and_media/photo.py +++ b/pyrogram/client/types/messages_and_media/photo.py @@ -49,6 +49,8 @@ class Photo(Object): Available thumbnails of this photo. """ + __slots__ = ["file_id", "width", "height", "file_size", "file_reference", "date", "thumbs"] + def __init__( self, *, @@ -58,7 +60,8 @@ def __init__( height: int, file_size: int, date: int, - thumbs: List[Thumbnail] + thumbs: List[Thumbnail], + file_reference: bytes ): super().__init__(client) @@ -68,6 +71,7 @@ def __init__( self.file_size = file_size self.date = date self.thumbs = thumbs + self.file_reference = file_reference @staticmethod def _parse(client, photo: types.Photo) -> "Photo": @@ -86,6 +90,7 @@ def _parse(client, photo: types.Photo) -> "Photo": width=big.w, height=big.h, file_size=big.size, + file_reference=photo.file_reference, date=photo.date, thumbs=Thumbnail._parse(client, photo), client=client diff --git a/pyrogram/client/types/messages_and_media/video.py b/pyrogram/client/types/messages_and_media/video.py index d9c2c37f11..2dca0fe623 100644 --- a/pyrogram/client/types/messages_and_media/video.py +++ b/pyrogram/client/types/messages_and_media/video.py @@ -74,7 +74,8 @@ def __init__( supports_streaming: bool = None, file_size: int = None, date: int = None, - thumbs: List[Thumbnail] = None + thumbs: List[Thumbnail] = None, + file_reference: bytes = b"" ): super().__init__(client) @@ -88,6 +89,7 @@ def __init__( self.file_size = file_size self.date = date self.thumbs = thumbs + self.file_reference = file_reference @staticmethod def _parse( @@ -110,6 +112,7 @@ def _parse( height=video_attributes.h, duration=video_attributes.duration, file_name=file_name, + file_reference=video.file_reference, mime_type=video.mime_type, supports_streaming=video_attributes.supports_streaming, file_size=video.size,