【问题标题】:python-telegram-bot indexing a file library (videos and photos)python-telegram-bot 索引文件库(视频和照片)
【发布时间】:2021-10-28 19:21:42
【问题描述】:

我正在使用 python-telegram-bot 8

我正在尝试创建一个数据库 (mysql) 索引电报超级组中的用户发送的所有文件(视频和照片),以便在有人发送已经发送的文件时发出警告。

视频和照片具有“file_id”属性,但如果两个人发送相同的文件,则此 file_id 不同。

对于发送到组的文件是否有唯一标识符?

视频:

update.message.video.file_id

update.message.video.file_size

update.message.video.duration

照片:

update.message.photo[2].file_id

update.message.photo[2].file_size

谢谢

【问题讨论】:

    标签: python-telegram-bot


    【解决方案1】:

    您无法获得文件的唯一标识符,您需要下载它,并计算它的哈希值。 :(

    顺便说一句,您可以向@BotSupport提出建议,开发团队将来可能会添加此属性。

    【讨论】:

      【解决方案2】:
      file_info = bot.get_file(message.video.file_id)
      downloaded_file = bot.download_file(file_info.file_path)
      src=os.path.join(str(user_id),'input.mp4')
      with open(src, "wb") as new_file:
          new_file.write(downloaded_file)
      

      此代码会将视频文件保存在 src 路径中

      【讨论】:

        猜你喜欢
        • 2021-10-03
        • 1970-01-01
        • 1970-01-01
        • 2021-06-28
        • 1970-01-01
        • 1970-01-01
        • 2017-06-06
        • 2021-04-24
        • 2018-11-12
        相关资源
        最近更新 更多