mirror of
https://github.com/JimLiu/baoyu-skills.git
synced 2026-07-12 05:51:44 +08:00
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:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user