mirror of
https://github.com/TeamPGM/pyrogram.git
synced 2024-11-23 23:34:28 +00:00
Add download support for non-CDN files
This commit is contained in:
parent
0fbc5e1a90
commit
0f2ef8e681
@ -806,8 +806,10 @@ class Client:
|
||||
else:
|
||||
return r
|
||||
|
||||
def get_file(self, id: int, access_hash: int, version: int):
|
||||
def get_file(self, id: int, access_hash: int, version: int = 0):
|
||||
# TODO: Refine
|
||||
# TODO: Use proper file name and extension
|
||||
|
||||
limit = 512 * 1024
|
||||
offset = 0
|
||||
|
||||
@ -827,6 +829,28 @@ class Client:
|
||||
)
|
||||
)
|
||||
|
||||
if isinstance(r, types.upload.File):
|
||||
with open("_".join([str(id), str(access_hash), str(version)]) + ".jpg", "wb") as f:
|
||||
while True:
|
||||
chunk = r.bytes
|
||||
|
||||
if not chunk:
|
||||
break
|
||||
|
||||
f.write(chunk)
|
||||
offset += limit
|
||||
|
||||
r = session.send(
|
||||
functions.upload.GetFile(
|
||||
location=types.InputDocumentFileLocation(
|
||||
id=id,
|
||||
access_hash=access_hash,
|
||||
version=version
|
||||
),
|
||||
offset=offset,
|
||||
limit=limit
|
||||
)
|
||||
)
|
||||
if isinstance(r, types.upload.FileCdnRedirect):
|
||||
ctr = CTR(r.encryption_key, r.encryption_iv)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user