【问题标题】:Telegram Telethon: Sharing media downloads across multiple different clientsTelegram Telethon:在多个不同的客户端之间共享媒体下载
【发布时间】:2023-02-18 07:15:14
【问题描述】:

我们尝试使用 1 个电报客户端从频道列表中连续流式传输消息,然后将消息生成到 kafka。然后我们有第二个电报客户端来使用消息并使用 client.download_media() 下载相关媒体(照片/视频)。我们的问题是,这仅在客户端 1 和 2 相同时有效,但在它们是不同帐户时无效。我们不确定这是否与会话文件或访问哈希有关,还是其他原因?

是否可以支持我们的用例?我们试图解决的主要问题是异步媒体下载可能会导致大量积压,如果我们的服务器死机,积压可能会消失。这就是为什么我们首先要将消息放入 kafka 进行短期存储。如果您有更好的建议,也将不胜感激。

这是制作方

    async with client:
        messages = client.iter_messages(channel_id, limit=10)
        async for message in messages:
            print(message)
            if message.media is not None:
                # orig_media = message.media
                # converted_media = BinaryReader(bytes(orig_media)).tgread_object()
                # print('orig, media', orig_media)
                # print('converted media', converted_media)
                message_bytes = bytes(message) #convert to bytes
                producer.produce(topic, message_bytes)

这是不同客户端的消费者端

            with self._client:
                #telethon.errors.rpcerrorlist.FileReferenceExpiredError: The file reference has expired and is no longer valid or it belongs to self-destructing media and cannot be resent (caused by GetFileRequest)
                try:
                    self._client.loop.run_until_complete(self._client.download_media(orig_media, in_memory))
                except Exception as e:
                    print(e)

【问题讨论】:

  • 来自官方文档,The file download operation may return a FILE_REFERENCE_EXPIRED error (or another error starting with FILE_REFERENCE_): in this case, the file_reference field of the input location must be refreshed。请查看this link

标签: python telegram telethon


【解决方案1】:

媒体文件(以及 Telegram 中的许多其他内容)包含 access_hash。虽然账户 A 和账户 B 都将看到 ID 为 1234 的媒体,但账户 A 的哈希值可能为 5678,而账户 B 的哈希值可能为 8765。

这是一种迂回的说法,即每个帐户都会看到一个仅有效的access_hash在该帐户内.如果同一哈希试图被不同的帐户使用,它将失败,因为另一个帐户需要它自己的哈希。

没有办法绕过这个,除了提供对正确媒体文件(或任何文件)的实际访问权限,以便它可以获得自己的哈希值。

【讨论】:

    猜你喜欢
    • 2013-06-20
    • 1970-01-01
    • 2022-01-25
    • 2010-11-05
    • 1970-01-01
    • 1970-01-01
    • 2020-07-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多