Код: Выделить всё
from telethon import TelegramClient
client = TelegramClient('anon', api_id, api_hash)
async def main():
async for dialog in client.iter_messages(entity=peer_channel):
await dialog.download_media("file....")
def bot():
with client:
client.loop.run_until_complete(main())
client.start()
client.run_until_disconnected()
if __name__ == "__main__":
bot()
Код: Выделить всё
INFO:root:Download total: 99% 1048.50 mb/1057.82 mb tmp/Evil/2x12 Evil.rar
INFO:telethon.network.mtprotosender:Disconnecting from xxx.xxx.xxx.xxx:443/TcpFull...
INFO:telethon.network.mtprotosender:Disconnection from xxx.xxx.xxx.xxx:443/TcpFull complete!
INFO:telethon.network.mtprotosender:Connecting to xxx.xxx.xxx.xxx:443/TcpFull...
INFO:telethon.network.mtprotosender:Connection to xxx.xxx.xxx.xxx:443/TcpFull complete!
INFO:root:[DEBUG] DOWNLOADING /export/nasty/tmp/Evil/2x12 Evil.rar
INFO:telethon.client.downloads:Starting direct file download in chunks of 524288 at 0, stride 524288
Это отвратительно... файл был на 99 %, но соединение не удалось и необходимо перезапустить загрузку с нуля.
Читая документацию, я нашел этот client.iter_download
Я попробовал:
Код: Выделить всё
async def main():
async for dialog in client.iter_messages(entity=peer_channel):
# Filename should be generated by dialog.media, is a example
with open('file.rar', 'wb') as fd:
async for chunk in client.iter_download(dialog.media):
fd.write(chunk)
Подробнее здесь: https://stackoverflow.com/questions/706 ... load-media
Мобильная версия