Commit c33e31f
Changed files (1)
src
ytdlp
src/ytdlp/utils.py
@@ -11,8 +11,9 @@ from pyrogram.types import Message
from yt_dlp.utils import YoutubeDLError
from asr.voice_recognition import asr_file
-from config import COOKIE, DOWNLOAD_DIR, PROXY
+from config import CAPTION_LENGTH, COOKIE, DOWNLOAD_DIR, PROXY
from cookies import ytdlp_bilibili_cookie
+from messages.utils import smart_split
from multimedia import convert_img_to_telegram_format, generate_cover
from networking import match_social_media_link
from subtitles.base import fetch_subtitle
@@ -207,7 +208,7 @@ async def append_subtitle(name: str, sent_messages: dict) -> dict:
}
"""
- def new_caption(m: Message) -> str:
+ async def new_caption(m: Message) -> str:
# insert name after description
html = glom(m, "content.html", default="")
lines = html.split("\n")
@@ -217,15 +218,16 @@ async def append_subtitle(name: str, sent_messages: dict) -> dict:
pos = i + 1
break
lines.insert(pos, name)
- return "\n".join(lines)
+ captions = await smart_split("\n".join(lines), CAPTION_LENGTH)
+ return captions[0]
video_msgs = []
audio_msg = None
for k, message in sent_messages.items():
if k == "video":
- video_msgs = [await msg.edit_caption(new_caption(msg)) for msg in message]
+ video_msgs = [await msg.edit_caption(await new_caption(msg)) for msg in message]
else:
- audio_msg = await message.edit_caption(new_caption(message))
+ audio_msg = await message.edit_caption(await new_caption(message))
modified = {}
if all(isinstance(x, Message) for x in video_msgs):
modified["video"] = video_msgs