mirror of
https://github.com/TeamPGM/pyrogram.git
synced 2024-11-16 20:59:29 +00:00
Fix FILE_REFERENCE_* errors for downloads
This commit is contained in:
parent
7df4b58a51
commit
1cd94520bf
@ -1224,6 +1224,7 @@ class Client(Methods, BaseClient):
|
||||
peer_access_hash=data.peer_access_hash,
|
||||
volume_id=data.volume_id,
|
||||
local_id=data.local_id,
|
||||
file_ref=data.file_ref,
|
||||
file_size=data.file_size,
|
||||
is_big=data.is_big,
|
||||
progress=progress,
|
||||
@ -1868,6 +1869,7 @@ class Client(Methods, BaseClient):
|
||||
peer_access_hash: int,
|
||||
volume_id: int,
|
||||
local_id: int,
|
||||
file_ref: bytes,
|
||||
file_size: int,
|
||||
is_big: bool,
|
||||
progress: callable,
|
||||
@ -1922,21 +1924,21 @@ class Client(Methods, BaseClient):
|
||||
location = types.InputPhotoFileLocation(
|
||||
id=document_id,
|
||||
access_hash=access_hash,
|
||||
file_reference=b"",
|
||||
file_reference=file_ref,
|
||||
thumb_size=thumb_size
|
||||
)
|
||||
elif media_type == 14:
|
||||
location = types.InputDocumentFileLocation(
|
||||
id=document_id,
|
||||
access_hash=access_hash,
|
||||
file_reference=b"",
|
||||
file_reference=file_ref,
|
||||
thumb_size=thumb_size
|
||||
)
|
||||
else:
|
||||
location = types.InputDocumentFileLocation(
|
||||
id=document_id,
|
||||
access_hash=access_hash,
|
||||
file_reference=b"",
|
||||
file_reference=file_ref,
|
||||
thumb_size=""
|
||||
)
|
||||
|
||||
|
@ -22,7 +22,7 @@ class FileData:
|
||||
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, 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
|
||||
date: int = None, file_ref: bytes = None
|
||||
):
|
||||
self.media_type = media_type
|
||||
self.dc_id = dc_id
|
||||
@ -38,3 +38,4 @@ class FileData:
|
||||
self.mime_type = mime_type
|
||||
self.file_name = file_name
|
||||
self.date = date
|
||||
self.file_ref = file_ref
|
||||
|
@ -35,6 +35,7 @@ class DownloadMedia(BaseClient):
|
||||
def download_media(
|
||||
self,
|
||||
message: Union["pyrogram.Message", str],
|
||||
file_ref: bytes = None,
|
||||
file_name: str = DEFAULT_DOWNLOAD_DIR,
|
||||
block: bool = True,
|
||||
progress: callable = None,
|
||||
@ -47,6 +48,9 @@ class DownloadMedia(BaseClient):
|
||||
Pass a Message containing the media, the media itself (message.audio, message.video, ...) or
|
||||
the file id as string.
|
||||
|
||||
file_ref (``bytes``, *optional*):
|
||||
A valid file reference obtained by a recently fetched media message.
|
||||
|
||||
file_name (``str``, *optional*):
|
||||
A custom *file_name* to be used instead of the one provided by Telegram.
|
||||
By default, all files are downloaded in the *downloads* folder in your working directory.
|
||||
@ -122,12 +126,14 @@ class DownloadMedia(BaseClient):
|
||||
file_size = getattr(media, "file_size", None)
|
||||
mime_type = getattr(media, "mime_type", None)
|
||||
date = getattr(media, "date", None)
|
||||
file_ref = getattr(media, "file_ref", None)
|
||||
|
||||
data = FileData(
|
||||
file_name=media_file_name,
|
||||
file_size=file_size,
|
||||
mime_type=mime_type,
|
||||
date=date
|
||||
date=date,
|
||||
file_ref=file_ref or b""
|
||||
)
|
||||
|
||||
def get_existing_attributes() -> dict:
|
||||
|
@ -33,6 +33,9 @@ class Animation(Object):
|
||||
file_id (``str``):
|
||||
Unique identifier for this file.
|
||||
|
||||
file_ref (``bytes``):
|
||||
Up to date file reference.
|
||||
|
||||
width (``int``):
|
||||
Animation width as defined by sender.
|
||||
|
||||
@ -63,6 +66,7 @@ class Animation(Object):
|
||||
*,
|
||||
client: "pyrogram.BaseClient" = None,
|
||||
file_id: str,
|
||||
file_ref: bytes,
|
||||
width: int,
|
||||
height: int,
|
||||
duration: int,
|
||||
@ -75,6 +79,7 @@ class Animation(Object):
|
||||
super().__init__(client)
|
||||
|
||||
self.file_id = file_id
|
||||
self.file_ref = file_ref
|
||||
self.file_name = file_name
|
||||
self.mime_type = mime_type
|
||||
self.file_size = file_size
|
||||
@ -101,6 +106,7 @@ class Animation(Object):
|
||||
animation.access_hash
|
||||
)
|
||||
),
|
||||
file_ref=animation.file_reference,
|
||||
width=getattr(video_attributes, "w", 0),
|
||||
height=getattr(video_attributes, "h", 0),
|
||||
duration=getattr(video_attributes, "duration", 0),
|
||||
|
@ -33,6 +33,9 @@ class Audio(Object):
|
||||
file_id (``str``):
|
||||
Unique identifier for this file.
|
||||
|
||||
file_ref (``bytes``):
|
||||
Up to date file reference.
|
||||
|
||||
duration (``int``):
|
||||
Duration of the audio in seconds as defined by sender.
|
||||
|
||||
@ -63,6 +66,7 @@ class Audio(Object):
|
||||
*,
|
||||
client: "pyrogram.BaseClient" = None,
|
||||
file_id: str,
|
||||
file_ref: bytes,
|
||||
duration: int,
|
||||
file_name: str = None,
|
||||
mime_type: str = None,
|
||||
@ -75,6 +79,7 @@ class Audio(Object):
|
||||
super().__init__(client)
|
||||
|
||||
self.file_id = file_id
|
||||
self.file_ref = file_ref
|
||||
self.file_name = file_name
|
||||
self.mime_type = mime_type
|
||||
self.file_size = file_size
|
||||
@ -101,6 +106,7 @@ class Audio(Object):
|
||||
audio.access_hash
|
||||
)
|
||||
),
|
||||
file_ref=audio.file_reference,
|
||||
duration=audio_attributes.duration,
|
||||
performer=audio_attributes.performer,
|
||||
title=audio_attributes.title,
|
||||
|
@ -33,6 +33,9 @@ class Document(Object):
|
||||
file_id (``str``):
|
||||
Unique file identifier.
|
||||
|
||||
file_ref (``bytes``):
|
||||
Up to date file reference.
|
||||
|
||||
file_name (``str``, *optional*):
|
||||
Original filename as defined by sender.
|
||||
|
||||
@ -54,6 +57,7 @@ class Document(Object):
|
||||
*,
|
||||
client: "pyrogram.BaseClient" = None,
|
||||
file_id: str,
|
||||
file_ref: bytes,
|
||||
file_name: str = None,
|
||||
mime_type: str = None,
|
||||
file_size: int = None,
|
||||
@ -63,6 +67,7 @@ class Document(Object):
|
||||
super().__init__(client)
|
||||
|
||||
self.file_id = file_id
|
||||
self.file_ref = file_ref
|
||||
self.file_name = file_name
|
||||
self.mime_type = mime_type
|
||||
self.file_size = file_size
|
||||
@ -81,6 +86,7 @@ class Document(Object):
|
||||
document.access_hash
|
||||
)
|
||||
),
|
||||
file_ref=document.file_reference,
|
||||
file_name=file_name,
|
||||
mime_type=document.mime_type,
|
||||
file_size=document.size,
|
||||
|
@ -33,6 +33,9 @@ class Photo(Object):
|
||||
file_id (``str``):
|
||||
Unique identifier for this photo.
|
||||
|
||||
file_ref (``bytes``):
|
||||
Up to date file reference.
|
||||
|
||||
width (``int``):
|
||||
Photo width.
|
||||
|
||||
@ -54,6 +57,7 @@ class Photo(Object):
|
||||
*,
|
||||
client: "pyrogram.BaseClient" = None,
|
||||
file_id: str,
|
||||
file_ref: bytes,
|
||||
width: int,
|
||||
height: int,
|
||||
file_size: int,
|
||||
@ -63,6 +67,7 @@ class Photo(Object):
|
||||
super().__init__(client)
|
||||
|
||||
self.file_id = file_id
|
||||
self.file_ref = file_ref
|
||||
self.width = width
|
||||
self.height = height
|
||||
self.file_size = file_size
|
||||
@ -83,6 +88,7 @@ class Photo(Object):
|
||||
big.location.local_id
|
||||
)
|
||||
),
|
||||
file_ref=photo.file_reference,
|
||||
width=big.w,
|
||||
height=big.h,
|
||||
file_size=big.size,
|
||||
|
@ -35,6 +35,9 @@ class Sticker(Object):
|
||||
file_id (``str``):
|
||||
Unique identifier for this file.
|
||||
|
||||
file_ref (``bytes``):
|
||||
Up to date file reference.
|
||||
|
||||
width (``int``):
|
||||
Sticker width.
|
||||
|
||||
@ -73,6 +76,7 @@ class Sticker(Object):
|
||||
*,
|
||||
client: "pyrogram.BaseClient" = None,
|
||||
file_id: str,
|
||||
file_ref: bytes,
|
||||
width: int,
|
||||
height: int,
|
||||
is_animated: bool,
|
||||
@ -87,6 +91,7 @@ class Sticker(Object):
|
||||
super().__init__(client)
|
||||
|
||||
self.file_id = file_id
|
||||
self.file_ref = file_ref
|
||||
self.file_name = file_name
|
||||
self.mime_type = mime_type
|
||||
self.file_size = file_size
|
||||
@ -135,6 +140,7 @@ class Sticker(Object):
|
||||
sticker.access_hash
|
||||
)
|
||||
),
|
||||
file_ref=sticker.file_reference,
|
||||
width=image_size_attributes.w if image_size_attributes else 512,
|
||||
height=image_size_attributes.h if image_size_attributes else 512,
|
||||
is_animated=sticker.mime_type == "application/x-tgsticker",
|
||||
|
@ -33,6 +33,9 @@ class Video(Object):
|
||||
file_id (``str``):
|
||||
Unique identifier for this file.
|
||||
|
||||
file_ref (``bytes``):
|
||||
Up to date file reference.
|
||||
|
||||
width (``int``):
|
||||
Video width as defined by sender.
|
||||
|
||||
@ -66,6 +69,7 @@ class Video(Object):
|
||||
*,
|
||||
client: "pyrogram.BaseClient" = None,
|
||||
file_id: str,
|
||||
file_ref: bytes,
|
||||
width: int,
|
||||
height: int,
|
||||
duration: int,
|
||||
@ -79,6 +83,7 @@ class Video(Object):
|
||||
super().__init__(client)
|
||||
|
||||
self.file_id = file_id
|
||||
self.file_ref = file_ref
|
||||
self.width = width
|
||||
self.height = height
|
||||
self.duration = duration
|
||||
@ -106,6 +111,7 @@ class Video(Object):
|
||||
video.access_hash
|
||||
)
|
||||
),
|
||||
file_ref=video.file_reference,
|
||||
width=video_attributes.w,
|
||||
height=video_attributes.h,
|
||||
duration=video_attributes.duration,
|
||||
|
@ -33,6 +33,9 @@ class VideoNote(Object):
|
||||
file_id (``str``):
|
||||
Unique identifier for this file.
|
||||
|
||||
file_ref (``bytes``):
|
||||
Up to date file reference.
|
||||
|
||||
length (``int``):
|
||||
Video width and height as defined by sender.
|
||||
|
||||
@ -57,6 +60,7 @@ class VideoNote(Object):
|
||||
*,
|
||||
client: "pyrogram.BaseClient" = None,
|
||||
file_id: str,
|
||||
file_ref: bytes,
|
||||
length: int,
|
||||
duration: int,
|
||||
thumbs: List[Thumbnail] = None,
|
||||
@ -67,6 +71,7 @@ class VideoNote(Object):
|
||||
super().__init__(client)
|
||||
|
||||
self.file_id = file_id
|
||||
self.file_ref = file_ref
|
||||
self.mime_type = mime_type
|
||||
self.file_size = file_size
|
||||
self.date = date
|
||||
@ -86,6 +91,7 @@ class VideoNote(Object):
|
||||
video_note.access_hash
|
||||
)
|
||||
),
|
||||
file_ref=video_note.file_reference,
|
||||
length=video_attributes.w,
|
||||
duration=video_attributes.duration,
|
||||
file_size=video_note.size,
|
||||
|
@ -31,6 +31,9 @@ class Voice(Object):
|
||||
file_id (``str``):
|
||||
Unique identifier for this file.
|
||||
|
||||
file_ref (``bytes``):
|
||||
Up to date file reference.
|
||||
|
||||
duration (``int``):
|
||||
Duration of the audio in seconds as defined by sender.
|
||||
|
||||
@ -52,6 +55,7 @@ class Voice(Object):
|
||||
*,
|
||||
client: "pyrogram.BaseClient" = None,
|
||||
file_id: str,
|
||||
file_ref: bytes,
|
||||
duration: int,
|
||||
waveform: bytes = None,
|
||||
mime_type: str = None,
|
||||
@ -61,6 +65,7 @@ class Voice(Object):
|
||||
super().__init__(client)
|
||||
|
||||
self.file_id = file_id
|
||||
self.file_ref = file_ref
|
||||
self.duration = duration
|
||||
self.waveform = waveform
|
||||
self.mime_type = mime_type
|
||||
@ -79,6 +84,7 @@ class Voice(Object):
|
||||
voice.access_hash
|
||||
)
|
||||
),
|
||||
file_ref=voice.file_reference,
|
||||
duration=attributes.duration,
|
||||
mime_type=voice.mime_type,
|
||||
file_size=voice.size,
|
||||
|
Loading…
Reference in New Issue
Block a user