fix(bilibili): read the page query from the pasted video link

This commit is contained in:
TIANYAO ZHANG committed 2026-11-18 16:40:27 +08:00
1 parent b7779ab108
commit 79e9cd797c
2 files changed
+5 -3

No files matched your search

+2
View File
@@ -110,6 +110,8 @@ describe("parseSongRef (#90 exact-song selection)", () => {
"https://www.bilibili.com/video/BV1yxHQeYEuE/?p=%32",
"[URL]https://www.bilibili.com/video/BV1yxHQeYEuE/?p=2[/URL]",
"[url]https://www.bilibili.com/video/BV1yxHQeYEuE/?p=2#reply[/url]",
"[URL=https://www.bilibili.com/video/BV1yxHQeYEuE/?p=2]点击播放[/URL]",
"参考 https://example.com/?p=9 视频 https://www.bilibili.com/video/BV1yxHQeYEuE/?p=2 请播放",
])("preserves the Bilibili page query in %s", (input) => {
expect(parseSongRef(input)).toEqual({ id: "BV1yxHQeYEuE?p=2", platform: "bilibili" });
});
+3 -3
View File
@@ -69,9 +69,9 @@ export function parseSongRef(raw: string): SongRef | null {
// a "BV..." token never collides with them).
const bv = /BV[0-9A-Za-z]{8,12}/.exec(q);
if (bv && (/^BV[0-9A-Za-z]{8,12}$/.test(q) || /bilibili\.com|b23\.tv/i.test(q))) {
// TeamSpeak wraps pasted links in [URL] tags. Keep the page query while
// ignoring fragments, which can contain unrelated player state.
const query = /\?(.*)$/.exec(stripUrlBBCode(q).trim().split("#", 1)[0])?.[1];
// Extract the query attached to this BV id, including in [URL=...] tags.
const suffix = q.slice(bv.index + bv[0].length);
const query = /^\/?\?([^#\s[\]]*)/.exec(suffix)?.[1];
const page = new URLSearchParams(query).get("p");
return { id: page && /^\d+$/.test(page) ? `${bv[0]}?p=${page}` : bv[0], platform: "bilibili" };
}