gpt4 book ai didi

How to download all shared media files from a telegram group?(如何从电报组下载所有共享媒体文件?)

转载 作者:bug小助手 更新时间:2023-10-28 10:41:56 29 4
gpt4 key购买 nike



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?

有一个电报群,里面有4万多个共享文件。有没有机器人可以一次下载所有这些内容?如果没有,有没有什么电报API脚本方法,用python下载共享媒体文件?


更多回答
优秀答案推荐

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

您可以使用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)


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

自从维克托夫斯的回答后,Telethon似乎发生了变化。(文档)



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).

不幸的是,telegram bot api不允许查看旧消息(或文件)。



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

要做到这一点,唯一的方法是使用像Telethon这样的API,就电报而言,它充当用户。


更多回答

Here is the video tutorial for how to do it with Telethon - youtu.be/J5H_gRdPJSU

以下是有关如何使用Telethon-youtu.be/J5H_gRdPJSU执行此操作的视频教程

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com