Commit cbf318f

benny-dou <60535774+benny-dou@users.noreply.github.com>
2025-01-22 18:13:03
feat: add support to disable ytdlp comments
1 parent 1f72e3a
Changed files (1)
src
preview
src/preview/ytdlp.py
@@ -39,6 +39,8 @@ async def preview_ytdlp(
     ytdlp_audio_only: bool = False,
     ytdlp_send_video: bool = True,
     ytdlp_send_audio: bool = False,
+    bilibili_comments: bool = True,
+    youtube_comments: bool = True,
     proxy: str | None = None,
     **kwargs,
 ):
@@ -52,6 +54,8 @@ async def preview_ytdlp(
         ytdlp_audio_only (bool, optional): Download audio only. Defaults to True.
         ytdlp_send_video (bool, optional): Send video. Defaults to True.
         ytdlp_send_audio (bool, optional): Send audio. Defaults to False.
+        bilibili_comments (bool, optional): Get bilibili comments. Defaults to True.
+        youtube_comments (bool, optional): Get youtube comments. Defaults to True.
         proxy (str, optional): Proxy to use. Defaults to None.
     """
     logger.trace(f"url: {url} kwargs: {kwargs}")
@@ -175,7 +179,13 @@ async def preview_ytdlp(
         warnings.simplefilter("ignore", MarkupResemblesLocatorWarning)
         soup = BeautifulSoup(desc, "html.parser")
         texts += f"\n{soup_to_text(soup)}"
-    comments = await get_bilibili_comments(kwargs.get("bvid")) if platform == "bilibili" else await get_youtube_comments(kwargs.get("vid"))
+    # comments
+    comments = []
+    if bilibili_comments and platform == "bilibili":
+        comments = await get_bilibili_comments(kwargs.get("bvid"))
+    if youtube_comments and platform == "youtube":
+        await get_youtube_comments(kwargs.get("vid"))
+
     for comment in comments:
         if len(f"{texts}{comment}") < CAPTION_LENGTH:
             texts += comment