Accept YouTube /live/ and /shorts/ URLs in extractVideoId
The video-id regex only matched /watch?v=, youtu.be, /embed/, and /v/ forms, so youtube.com/live/<id> and youtube.com/shorts/<id> links were rejected with "Invalid YouTube URL". Add both forms to the server and frontend extractors (kept in sync) and cover them with tests. Ship as 0.2.159.
This commit is contained in:
+3
-3
@@ -14,12 +14,12 @@ export function sendEvent(res, event, data) {
|
||||
}
|
||||
|
||||
// ── YouTube video-id extraction ─────────────────────────────────────────────
|
||||
// Accepts watch URLs, youtu.be, /embed/, /v/, or a bare 11-char id.
|
||||
// Returns null when no id can be extracted.
|
||||
// Accepts watch URLs, youtu.be, /embed/, /v/, /live/, /shorts/, or a bare
|
||||
// 11-char id. Returns null when no id can be extracted.
|
||||
export function extractVideoId(url) {
|
||||
if (!url) return null;
|
||||
const patterns = [
|
||||
/(?:youtube\.com\/watch\?v=|youtu\.be\/|youtube\.com\/embed\/|youtube\.com\/v\/)([a-zA-Z0-9_-]{11})/,
|
||||
/(?:youtube\.com\/watch\?v=|youtu\.be\/|youtube\.com\/embed\/|youtube\.com\/v\/|youtube\.com\/live\/|youtube\.com\/shorts\/)([a-zA-Z0-9_-]{11})/,
|
||||
/^([a-zA-Z0-9_-]{11})$/,
|
||||
];
|
||||
for (const p of patterns) {
|
||||
|
||||
Reference in New Issue
Block a user