Commit 900ff8e

benny-dou <60535774+benny-dou@users.noreply.github.com>
2025-05-10 07:16:44
fix: always flatten social media link before matching
1 parent 9bc12e3
Changed files (3)
src/subtitles/base.py
@@ -20,9 +20,9 @@ async def match_url(client: Client, message: Message) -> str:
     if not startswith_prefix(info["text"], prefix=[PREFIX.SUBTITLE]):
         return ""
     # /subtitle "link"
-    matched = await match_social_media_link(info["text"], flatten_first=True)
+    matched = await match_social_media_link(info["text"])
     for entity_url in info["entity_urls"]:
-        matched = await match_social_media_link(entity_url, flatten_first=True)
+        matched = await match_social_media_link(entity_url)
         if matched["platform"] in ["youtube", "bilibili"]:
             return matched["url"]
     if matched["platform"] in ["youtube", "bilibili"]:
@@ -36,9 +36,9 @@ async def match_url(client: Client, message: Message) -> str:
     reply_messages = await client.get_media_group(message.chat.id, message.id) if message.media_group_id else [reply_message]
     for msg in reply_messages:
         info = parse_msg(msg, silent=True)
-        matched = await match_social_media_link(info["text"], flatten_first=True)
+        matched = await match_social_media_link(info["text"])
         for entity_url in info["entity_urls"]:
-            matched = await match_social_media_link(entity_url, flatten_first=True)
+            matched = await match_social_media_link(entity_url)
             if matched["platform"] in ["youtube", "bilibili"]:
                 return matched["url"]
         if matched["platform"] in ["youtube", "bilibili"]:
@@ -52,7 +52,7 @@ async def fetch_subtitle(url: str, provider: str) -> dict:
     succ = False
     error = "❌下载内嵌字幕失败\n🔄尝试使用语音转文字获取字幕"
     subtitles = []
-    matched = await match_social_media_link(url, flatten_first=True)
+    matched = await match_social_media_link(url)
     if matched["platform"] == "bilibili":
         return await get_bilibili_subtitle(url)
     video_id = matched["vid"]
src/handler.py
@@ -210,7 +210,7 @@ async def handle_social_media(
         # Caution: this format should be consistent with `save_messages` function in `message.database.py`
         kwargs["send_from_user"] = f"👤[@{info['full_name']}](tg://user?id={info['uid']})//"
     try:
-        matched = await match_social_media_link(info["text"], flatten_first=True)  # match "platform" and "url" (and other info)
+        matched = await match_social_media_link(info["text"])  # match "platform" and "url" (and other info)
         if matched["platform"]:
             logger.success(f"Matched: {matched}")
         kwargs |= matched
src/networking.py
@@ -254,7 +254,7 @@ async def download_media(media: list[dict], **kwargs) -> list[dict]:
 
 
 @cache.memoize(ttl=60)
-async def match_social_media_link(text: str, *, flatten_first: bool = False) -> dict:
+async def match_social_media_link(text: str, *, flatten_first: bool = True) -> dict:
     """Matches social media links in the given text and returns a dictionary with the matched information.
 
     Args: