'How to partially download a telegram file in with pyrogram
Actually I need to download first few chunks of a file(video/audio/etc) for the sake of mediainfo.
pyrogram:
https://docs.pyrogram.org/api/methods/stop_transmission
https://docs.pyrogram.org/api/bound-methods/Message.download
progress fn (stops transmission when 1% of file has been downloaded)
def prog(curr, total, client):
print(curr * 100 / total, '%', flush=True)
if curr * 100 / total >= 1:
client.stop_transmission()
implementation
tmp = msg.download(progress=prog, in_memory=True, progress_args=(client,))
print(type(tmp), flush=True)
with open(f'{msg.id}', 'wb') as f:
f.write(tmp.getvalue())
What output I am getting is:
1.8244671728371091 %
<class 'NoneType'>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|