tangyoha / telegram_media_downloader

基于Dineshkarthik的项目, 电报视频下载,电报资源下载,跨平台,支持web查看下载进度 ,支持bot下发指令下载,支持下载已经加入的私有群但是限制下载的资源, telegram media download,Download media files from a telegram conversation/chat/channel up to 2GiB per file
MIT License
2.39k stars 277 forks source link

[Bug]: media caption 过长会导致转发失败 #157

Closed zj1123581321 closed 2 months ago

zj1123581321 commented 6 months ago

telegram_media_downloader version or commit

v2.2.3

What OS are you seeing the problem on?

Windows

Python Version

3.11.6

What happened?

telegram 频道里的 photo/video 的 caption 字符长度如果超过 1024,则无法通过 api 转发,会报错 caption 过长。

这里原因在于:Media captions on Telegram can have up to 1024 characters, but Premium users can have up to 2048 characters.

Increase character limit for media captions – Bugs and Suggestions

Expected Behavior

可以将 caption 拆分成 3 段文本,然后结合媒体再进行发送

Current Behavior

发送失败,且 bot 无提示。

Possible Solution

可以将 caption 拆分成 3 段文本,然后结合媒体再进行发送

Steps to Reproduce

转发任意 photo/video 的 caption 超过 1024 长度即可复现。

Relevant log output

2024-03-19 23:10:31.069 | ERROR    | module.pyrogram_extension:upload_telegram_chat_message:305 - Upload file D:\Tg_media_downloader\2023_11\25032..mp4 error: Telegram says: [400 MEDIA_CAPTION_TOO_LONG] - The media caption is too long (caused by "messages.SendMultiMedia")
Traceback (most recent call last):

  File "media_downloader.py", line 662, in <module>

  File "media_downloader.py", line 636, in main

  File "media_downloader.py", line 590, in _exec_loop

  File "asyncio\base_events.py", line 640, in run_until_complete

  File "asyncio\windows_events.py", line 321, in run_forever

  File "asyncio\base_events.py", line 607, in run_forever

  File "asyncio\base_events.py", line 1922, in _run_once

  File "asyncio\events.py", line 80, in _run

  File "media_downloader.py", line 498, in worker

  File "media_downloader.py", line 284, in download_task

  File "module\pyrogram_extension.py", line 256, in upload_telegram_chat

> File "module\pyrogram_extension.py", line 295, in upload_telegram_chat_message

  File "module\pyrogram_extension.py", line 450, in _upload_telegram_chat_message

  File "module\pyrogram_extension.py", line 532, in forward_multi_media

  File "module\pyrogram_extension.py", line 568, in proc_cache_forward

  File "module\send_media_group_v2.py", line 389, in send_media_group_v2

  File "pyrogram\methods\advanced\invoke.py", line 79, in invoke

  File "pyrogram\session\session.py", line 358, in invoke

  File "pyrogram\session\session.py", line 328, in send

  File "pyrogram\errors\rpc_error.py", line 91, in raise_it

pyrogram.errors.exceptions.bad_request_400.MediaCaptionTooLong: Telegram says: [400 MEDIA_CAPTION_TOO_LONG] - The media caption is too long (caused by "messages.SendMultiMedia")
tangyoha commented 2 months ago

797898eacc60e2397a669b5b32040b41c0607013