mirror of
https://github.com/pyrogram/pyrogram
synced 2025-08-28 21:07:59 +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:
|
else:
|
||||||
return r
|
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: Refine
|
||||||
|
# TODO: Use proper file name and extension
|
||||||
|
|
||||||
limit = 512 * 1024
|
limit = 512 * 1024
|
||||||
offset = 0
|
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):
|
if isinstance(r, types.upload.FileCdnRedirect):
|
||||||
ctr = CTR(r.encryption_key, r.encryption_iv)
|
ctr = CTR(r.encryption_key, r.encryption_iv)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user