English 中文(简体)
How to download all shared media files from a telegram group?
原标题:

There is a telegram group with more than 40,000 shared files in it.
Is there any bot to download all of them all at once? If not is there any telegram api script method using python to download shared media files?

问题回答

You can use Telethon, a Telegram client to download all the files in a public group:

from telethon import TelegramClient
from tqdm import tqdm
# These example values won t work. You must get your own api_id and
# api_hash from `my.telegram.org` , under API Development.
api_id = APIID
api_hash =  APIHASH 
client = TelegramClient( session_name , api_id, api_hash)
client.start()
print(client.get_me().stringify())
# client.send_message( username ,  Hello! Talking to you from Telethon )
# client.send_file( username ,  /home/myself/Pictures/holidays.jpg )
# client.download_profile_photo( vic )
messages = client.get_messages( intothestates , limit=2000)
print(len(messages))
for msg in tqdm(messages):
    client.download_media(msg)

It seems Telethon has changed since victorvs answer. (Docs)

this should work:

from telethon.sync import TelegramClient, events
from tqdm import  tqdm
import os

# 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 = <api_id>
api_hash =  <api_hash> 


with TelegramClient( name , api_id, api_hash) as client:
    messages = client.get_messages( <channel/chat> , limit=50) # limit defaults to 1
    for msg in tqdm(messages):
        msg.download_media(file=os.path.join( media ,  <file_name> ))

The telegram bot api unfortunately doesn t allow viewed old messages (or files).

The only way to do this is using an API such as Telethon, which acts as a user as far as telegram is concerned.





相关问题
Telegram API, how to add newlines?

Tried many way with parse_mode: Markdown or HTML: curl -s "https://api.telegram.org/bot$botToken/sendMessage" -H Content-Type: application/json -d { "parse_mode": "HTML&...

How to download all shared media files from a telegram group?

There is a telegram group with more than 40,000 shared files in it. Is there any bot to download all of them all at once? If not is there any telegram api script method using python to download shared ...

show specific user page in Telegram

I m creating an app by phonegap and I want to open Telegram groups or channels from my app. In other mean when I click on a group , Telegram open and that group shows to user. I used the following ...

I have a bot in telegram can I delete user s messages?

I am writing a bot on JS using grammy bibliothek I made a function createStickerPack everything works but I need to make it so that when the user sends sticker pack names after creating a sticker the ...

热门标签