Moh*_*adi 5 telegram python-telegram-bot telegram-bot
有一个电报群,里面有40000多个共享文件。
是否有任何机器人可以一次下载所有这些?如果没有,是否有任何使用python下载共享媒体文件的电报api脚本方法?
您可以使用Telethon(一个 Telegram 客户端)下载公共群组中的所有文件:
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)
Run Code Online (Sandbox Code Playgroud)
这应该有效:
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>'))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
26202 次 |
| 最近记录: |