Skip to content

Instantly share code, notes, and snippets.

@lgg
Last active June 29, 2024 19:50
Show Gist options
  • Save lgg/3f0dc041b931222eedfae28e5cdff0fd to your computer and use it in GitHub Desktop.
Save lgg/3f0dc041b931222eedfae28e5cdff0fd to your computer and use it in GitHub Desktop.
Telegram save all media from chat/user/channel

Quick tip. It is possible to download media with small python script.

Goto https://my.telegram.org and generate api id and api hash Install Telethon library with pip3 install telethon Run saveAllMedia.py (replace api_id, api_hash and username with your values).

If you need proxy install https://github.com/Anorov/PySocks pip install PySocks

This code downloads all media from the dialog with username user/chat/channel in current directory.

LICENSE: Based on: telegramdesktop/tdesktop#1382 (comment) and https://github.com/LonamiWebs/Telethon

#uncomment line below if you need proxy
#import socks
from telethon import TelegramClient, sync
#import logging
api_id=400000
api_hash='supersecreethash'
#logging.basicConfig(level=logging.DEBUG)
client = TelegramClient('test_session123123123',
api_id, api_hash,
# You may want to use proxy to connect to Telegram
#proxy=(socks.SOCKS5, 'PROXYHOST', PORT, 'PROXYUSERNAME', 'PROXYPASSWORD')
)
client.start()
for message in client.iter_messages('CHATNAME/CHANNELNAME/USERNAME'):
client.download_media(message)
@smrdotgg
Copy link

Where do I find the messages after they have been downloaded? thanks in advance.

@lgg
Copy link
Author

lgg commented Feb 19, 2021

@semere01 sorry, I don't remember it was too long ago. For now Telegram has built-in function for export chats history in Telegram Desktop interface. I suggest you to use built-in functions, not external scripts.

@IntenseSoftwares
Copy link

how do I download a specific message from copied post link.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment