// A LIST OF VIDEOS, typed or pasted (release 32 R6: the Saved videos page's // "Save these videos", `pnpm ops persist-videos` from the UI). One video per // line, any of: // // / demo-channel/dQw4w9WgXcQ // , (space, tab or comma between) // an editor video link http://localhost:3001/channels/demo-channel/videos/dQw4w9WgXcQ // // Blank lines and lines starting with # are skipped; a repeat is listed once. // Pure: the action checks the channels and the records. export type ListedVideo = { slug: string; id: string }; export type VideoListParse = { items: ListedVideo[]; bad: { line: number; text: string }[] }; const NAME = /^[\w.-]+$/; const ok = (v: string) => NAME.test(v) && v !== "." && v !== ".."; function one(raw: string): ListedVideo | null { const link = /\/channels\/([^/\s?#]+)\/videos\/([^/\s?#]+)/.exec(raw); if (link) { const slug = decodeURIComponent(link[1]!); const id = decodeURIComponent(link[2]!); return ok(slug) && ok(id) ? { slug, id } : null; } const parts = raw.split(/[\s,/]+/).filter(Boolean); if (parts.length !== 2) return null; const [slug, id] = parts as [string, string]; return ok(slug) && ok(id) ? { slug, id } : null; } export function parseVideoList(text: string): VideoListParse { const items: ListedVideo[] = []; const bad: { line: number; text: string }[] = []; const seen = new Set(); text.split(/\r?\n/).forEach((l, i) => { const raw = l.trim(); if (!raw || raw.startsWith("#")) return; const v = one(raw); if (!v) { bad.push({ line: i + 1, text: raw }); return; } const key = `${v.slug}/${v.id}`; if (seen.has(key)) return; seen.add(key); items.push(v); }); return { items, bad }; }