fix(baoyu-fetch): parse YouTube /embed/ URLs in parseYouTubeVideoId

parseYouTubeVideoId handled watch, youtu.be, /shorts/ and /live/ URLs but
not the common /embed/<id> player form, so embed links returned null and the
YouTube adapter treated them as "no document". Add an /embed/ branch
mirroring the existing /shorts/ and /live/ handling, with a regression test.
This commit is contained in:
Syed Osama Ali Shah
2026-06-09 23:55:40 +03:00
parent 894008c7f6
commit a1c4b732c5
2 changed files with 9 additions and 0 deletions
@@ -19,6 +19,10 @@ describe("parseYouTubeVideoId", () => {
test("parses shorts URLs", () => {
expect(parseYouTubeVideoId(new URL("https://www.youtube.com/shorts/abc123"))).toBe("abc123");
});
test("parses embed URLs", () => {
expect(parseYouTubeVideoId(new URL("https://www.youtube.com/embed/abc123"))).toBe("abc123");
});
});
describe("parseYouTubeDescriptionChapters", () => {
@@ -52,6 +52,11 @@ export function parseYouTubeVideoId(url: URL): string | null {
return liveMatch[1];
}
const embedMatch = url.pathname.match(/^\/embed\/([^/?#]+)/);
if (embedMatch) {
return embedMatch[1];
}
return null;
}