Commit a83730f

benny-dou <60535774+benny-dou@users.noreply.github.com>
2025-09-14 18:18:52
fix(bilibili): support link without `/video/` segment
1 parent d2d3f82
Changed files (1)
src/networking.py
@@ -346,7 +346,8 @@ async def match_social_media_link(text: str, *, flatten_first: bool = True) -> d
         }
 
     # https://www.bilibili.com/video/BV1TC411J7PK
-    if matched := re.search(r"(https?://)?(:?m\.|www\.)?bilibili\.com/video/(\w+)", text):
+    # https://www.bilibili.com/BV1TC411J7PK
+    if matched := re.search(r"(https?://)?(:?m\.|www\.)?bilibili\.com/(video/)?(BV1[a-zA-Z0-9]{9})", text):
         base_url = matched.group(0).split("?")[0]
         bvid = Path(base_url).stem
         queries = parse_qs(urlparse(matched.group(0)).query)
@@ -521,10 +522,12 @@ if __name__ == "__main__":
     # asyncio.run(flatten_rediercts("https://v.douyin.com/CeiJfJMQG/"))
     # asyncio.run(flatten_rediercts("https://www.tiktok.com/t/ZT2mcMA7f/"))
     # asyncio.run(flatten_rediercts("https://t.co/Wwo3x69CQz"))
-    print(asyncio.run(match_social_media_link("https://www.instagram.com/miyoshi.aa/p/DN5hFcUE8rS/")))
-    print(asyncio.run(match_social_media_link("https://www.youtube.com/watch?v=D6aE2E0RHTc")))
-    print(asyncio.run(match_social_media_link("https://youtube.com/shorts/lFKHbluAlJw")))
-    print(asyncio.run(match_social_media_link("https://youtu.be/vOiP3kfFlrE?si=zPd-Bt1GO03jxpI_")))
+    print(asyncio.run(match_social_media_link("https://www.bilibili.com/video/BV1TC411J7PK")))
+    print(asyncio.run(match_social_media_link("https://www.bilibili.com/BV1TC411J7PK")))
+    # print(asyncio.run(match_social_media_link("https://www.instagram.com/miyoshi.aa/p/DN5hFcUE8rS/")))
+    # print(asyncio.run(match_social_media_link("https://www.youtube.com/watch?v=D6aE2E0RHTc")))
+    # print(asyncio.run(match_social_media_link("https://youtube.com/shorts/lFKHbluAlJw")))
+    # print(asyncio.run(match_social_media_link("https://youtu.be/vOiP3kfFlrE?si=zPd-Bt1GO03jxpI_")))
     # res = asyncio.run(hx_req("https://httpbin.org/delay/10"))
     # asyncio.run(hx_req("https://httpbin.org/get", check_kv={"url": "https://httpbin.org/get", "headers.Pragma": "no-cache1"}, max_retry=1))
     # resp = asyncio.run(hx_req("https://httpbin.org/get", check_kv={"headers": {"Accept-Language": "en-US,en;q=0.8"}}))