Skip to content

Commit 3ff19f2

Browse files
committed
Fix file reference
1 parent 26bf84e commit 3ff19f2

5 files changed

Lines changed: 26 additions & 7 deletions

File tree

pyrogram/client/client.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,7 +1212,7 @@ def download_worker(self):
12121212
final_file_path = ""
12131213

12141214
try:
1215-
data, directory, file_name, done, progress, progress_args, path = packet
1215+
data, directory, file_name, done, progress, progress_args, path, file_reference = packet
12161216

12171217
temp_file_path = self.get_file(
12181218
media_type=data.media_type,
@@ -1225,6 +1225,7 @@ def download_worker(self):
12251225
volume_id=data.volume_id,
12261226
local_id=data.local_id,
12271227
file_size=data.file_size,
1228+
file_reference=file_reference,
12281229
is_big=data.is_big,
12291230
progress=progress,
12301231
progress_args=progress_args
@@ -1871,7 +1872,8 @@ def get_file(
18711872
file_size: int,
18721873
is_big: bool,
18731874
progress: callable,
1874-
progress_args: tuple = ()
1875+
progress_args: tuple = (),
1876+
file_reference: bytes = b""
18751877
) -> str:
18761878
with self.media_sessions_lock:
18771879
session = self.media_sessions.get(dc_id, None)
@@ -1922,21 +1924,21 @@ def get_file(
19221924
location = types.InputPhotoFileLocation(
19231925
id=document_id,
19241926
access_hash=access_hash,
1925-
file_reference=b"",
1927+
file_reference=file_reference,
19261928
thumb_size=thumb_size
19271929
)
19281930
elif media_type == 14:
19291931
location = types.InputDocumentFileLocation(
19301932
id=document_id,
19311933
access_hash=access_hash,
1932-
file_reference=b"",
1934+
file_reference=file_reference,
19331935
thumb_size=thumb_size
19341936
)
19351937
else:
19361938
location = types.InputDocumentFileLocation(
19371939
id=document_id,
19381940
access_hash=access_hash,
1939-
file_reference=b"",
1941+
file_reference=file_reference,
19401942
thumb_size=""
19411943
)
19421944

pyrogram/client/methods/messages/download_media.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ def download_media(
102102
file_size = None
103103
mime_type = None
104104
date = None
105+
file_reference = b""
105106

106107
if isinstance(message, pyrogram.Message):
107108
for kind in available_media:
@@ -120,6 +121,7 @@ def download_media(
120121
file_id_str = media.file_id
121122
media_file_name = getattr(media, "file_name", "")
122123
file_size = getattr(media, "file_size", None)
124+
file_reference = getattr(media, "file_reference", b"")
123125
mime_type = getattr(media, "mime_type", None)
124126
date = getattr(media, "date", None)
125127

@@ -216,7 +218,7 @@ def get_existing_attributes() -> dict:
216218
)
217219

218220
# Cast to string because Path objects aren't supported by Python 3.5
219-
self.download_queue.put((data, str(directory), str(file_name), done, progress, progress_args, path))
221+
self.download_queue.put((data, str(directory), str(file_name), done, progress, progress_args, path, file_reference))
220222

221223
if block:
222224
done.wait()

pyrogram/client/types/messages_and_media/animation.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ class Animation(Object):
5858
Animation thumbnails.
5959
"""
6060

61+
__slots__ = ["file_id", "file_name", "mime_type", "file_size", "file_reference", "date", "width", "height", "duration", "thumbs"]
62+
6163
def __init__(
6264
self,
6365
*,
@@ -67,6 +69,7 @@ def __init__(
6769
height: int,
6870
duration: int,
6971
file_name: str = None,
72+
file_reference: bytes = b"",
7073
mime_type: str = None,
7174
file_size: int = None,
7275
date: int = None,
@@ -83,6 +86,7 @@ def __init__(
8386
self.height = height
8487
self.duration = duration
8588
self.thumbs = thumbs
89+
self.file_reference = file_reference
8690

8791
@staticmethod
8892
def _parse(
@@ -106,6 +110,7 @@ def _parse(
106110
duration=getattr(video_attributes, "duration", 0),
107111
mime_type=animation.mime_type,
108112
file_size=animation.size,
113+
file_reference=animation.file_reference,
109114
file_name=file_name,
110115
date=animation.date,
111116
thumbs=Thumbnail._parse(client, animation),

pyrogram/client/types/messages_and_media/document.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ class Document(Object):
4949
Document thumbnails as defined by sender.
5050
"""
5151

52+
__slots__ = ["file_id", "file_name", "mime_type", "file_size", "file_reference", "date", "thumbs"]
53+
5254
def __init__(
5355
self,
5456
*,
@@ -57,6 +59,7 @@ def __init__(
5759
file_name: str = None,
5860
mime_type: str = None,
5961
file_size: int = None,
62+
file_reference: bytes = b"",
6063
date: int = None,
6164
thumbs: List[Thumbnail] = None
6265
):
@@ -68,6 +71,7 @@ def __init__(
6871
self.file_size = file_size
6972
self.date = date
7073
self.thumbs = thumbs
74+
self.file_reference = file_reference
7175

7276
@staticmethod
7377
def _parse(client, document: types.Document, file_name: str) -> "Document":
@@ -84,6 +88,7 @@ def _parse(client, document: types.Document, file_name: str) -> "Document":
8488
file_name=file_name,
8589
mime_type=document.mime_type,
8690
file_size=document.size,
91+
file_reference=document.file_reference,
8792
date=document.date,
8893
thumbs=Thumbnail._parse(client, document),
8994
client=client

pyrogram/client/types/messages_and_media/photo.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ class Photo(Object):
4949
Available thumbnails of this photo.
5050
"""
5151

52+
__slots__ = ["file_id", "width", "height", "file_size", "file_reference", "date", "thumbs"]
53+
5254
def __init__(
5355
self,
5456
*,
@@ -58,7 +60,8 @@ def __init__(
5860
height: int,
5961
file_size: int,
6062
date: int,
61-
thumbs: List[Thumbnail]
63+
thumbs: List[Thumbnail],
64+
file_reference: bytes
6265
):
6366
super().__init__(client)
6467

@@ -68,6 +71,7 @@ def __init__(
6871
self.file_size = file_size
6972
self.date = date
7073
self.thumbs = thumbs
74+
self.file_reference = file_reference
7175

7276
@staticmethod
7377
def _parse(client, photo: types.Photo) -> "Photo":
@@ -86,6 +90,7 @@ def _parse(client, photo: types.Photo) -> "Photo":
8690
width=big.w,
8791
height=big.h,
8892
file_size=big.size,
93+
file_reference=photo.file_reference,
8994
date=photo.date,
9095
thumbs=Thumbnail._parse(client, photo),
9196
client=client

0 commit comments

Comments
 (0)