web-dev-qa-db-fra.com

Comment télécharger tous les fichiers multimédias partagés à partir d'un groupe de télégrammes?

Il existe un groupe de télégrammes contenant plus de 40 000 fichiers partagés.
Existe-t-il un bot pour les télécharger tous en même temps? Sinon, existe-t-il une méthode de script api télégramme utilisant python pour télécharger des fichiers multimédias partagés?

5
Mohsen Haddadi

vous pouvez utiliser telethon , un client de télégramme pour télécharger tous les fichiers dans un groupe public

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('hamidzr')
messages = client.get_messages('intothestates', limit=2000)
print(len(messages))
for msg in tqdm(messages):
client.download_media(msg)
4
victorvs

L'API du télégramme bot ne permet malheureusement pas d'afficher les anciens messages (ou fichiers).

La seule façon de le faire est d'utiliser une API telle que Téléthon , qui agit en tant qu'utilisateur en ce qui concerne les télégrammes.

1
jsmnbom

Il semble que Téléthon a changé depuis la réponse de victorvs. ( Documents )

cela devrait fonctionner:

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>'))
0
mh sattarian