Last active
July 11, 2020 12:12
-
-
Save HirbodBehnam/d95d210d9b763e3a5752e2aa8829f486 to your computer and use it in GitHub Desktop.
A python script to download a file from Telegram
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Usage: At first send the file to your saved messages. Make sure it's the last message and run this script with python | |
| # At first install Telethon and humanize with pip3 install telethon humanize cryptg | |
| # Note that cryptg is optional and only is used for speeding up the downloads | |
| import asyncio | |
| import humanize | |
| from telethon import TelegramClient | |
| # These example values won't work. You must get your own api_id and | |
| # api_hash from https://my.telegram.org, under API Development. | |
| api_id = 12345 | |
| api_hash = '0123456789abcdef0123456789abcdef' | |
| def upload_progress_callback(downloaded_bytes, total_bytes): | |
| print("Downloaded: " + humanize.naturalsize(downloaded_bytes) + " of " + humanize.naturalsize(total_bytes), | |
| end='\r') | |
| async def load(): | |
| async with TelegramClient('session_name', api_id, api_hash) as client: | |
| messages = await client.get_messages('me', limit=1) | |
| await messages[0].download_media(progress_callback=upload_progress_callback) | |
| loop = asyncio.get_event_loop() | |
| loop.run_until_complete(load()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment