Commit b39b44f

benny-dou <60535774+benny-dou@users.noreply.github.com>
2026-02-10 02:47:02
chore(ytdlp): enable separate toggles for Bilibili and YouTube
1 parent bffe227
Changed files (3)
src/messages/main.py
@@ -170,6 +170,8 @@ async def preview_social_media(
     music163: bool = True,  # Parse Music163
     spotify: bool = True,  # Parse Spotify
     ytdlp: bool = True,  # Parse YT-DLP link
+    ytdlp_bilibili: bool = True,  # Parse YT-DLP Bilibili link
+    ytdlp_youtube: bool = True,  # Parse YT-DLP YouTube link
     arxiv: bool = True,  # Parse arXiv
     **kwargs,
 ):
@@ -279,7 +281,11 @@ async def preview_social_media(
 
         sent_messages = []
         try:
-            if ytdlp and matched["platform"] in ["bilibili", "youtube", "ytdlp"]:
+            if ytdlp_bilibili and matched["platform"] == "bilibili":
+                sent_messages = await preview_ytdlp(client, message, **kwargs)
+            if ytdlp_youtube and matched["platform"] == "youtube":
+                sent_messages = await preview_ytdlp(client, message, **kwargs)
+            if ytdlp and matched["platform"] == "ytdlp":
                 sent_messages = await preview_ytdlp(client, message, **kwargs)
         except ProxyError:
             logger.error(f"🚫{matched['platform']}代理错误")
src/config.py
@@ -62,6 +62,8 @@ class ENABLE:  # see fine-grained permission in `src/permission.py`
     SPOTIFY = os.getenv("ENABLE_SPOTIFY", "1").lower() in ["1", "y", "yes", "t", "true", "on"]
     XHS = os.getenv("ENABLE_XHS", "1").lower() in ["1", "y", "yes", "t", "true", "on"]
     YTDLP = os.getenv("ENABLE_YTDLP", "1").lower() in ["1", "y", "yes", "t", "true", "on"]
+    YTDLP_BILIBILI = os.getenv("ENABLE_YTDLP_BILIBILI", "1").lower() in ["1", "y", "yes", "t", "true", "on"]
+    YTDLP_YOUTUBE = os.getenv("ENABLE_YTDLP_YOUTUBE", "1").lower() in ["1", "y", "yes", "t", "true", "on"]
     RAW_IMG_CONVERT = os.getenv("ENABLE_RAW_IMG_CONVERT", "1").lower() in ["1", "y", "yes", "t", "true", "on"]
     GROUPS = os.getenv("ENABLE_GROUPS", "1").lower() in ["1", "y", "yes", "t", "true", "on"]
     CHANNELS = os.getenv("ENABLE_CHANNELS", "1").lower() in ["1", "y", "yes", "t", "true", "on"]
src/permission.py
@@ -144,6 +144,8 @@ def check_service(cid: int | str, ctype: str) -> dict:
         "wechat": True,
         "reddit": True,
         "ytdlp": True,
+        "ytdlp_bilibili": True,
+        "ytdlp_youtube": True,
         "history": True,
         "favorite": True,
         "convert_chinese": True,
@@ -183,6 +185,10 @@ def check_service(cid: int | str, ctype: str) -> dict:
         permission["reddit"] = False
     if not ENABLE.YTDLP:
         permission["ytdlp"] = False
+    if not ENABLE.YTDLP_BILIBILI:
+        permission["ytdlp_bilibili"] = False
+    if not ENABLE.YTDLP_YOUTUBE:
+        permission["ytdlp_youtube"] = False
     if not ENABLE.ARXIV:
         permission["arxiv"] = False
     if not ENABLE.AI: