import { getPaths } from "yt-dlp-transcript-common/lib/paths"; import { compactedLine, savedAlternatesLine } from "yt-dlp-transcript-common/lib/savedVideo"; import { isValidChannelSlug } from "yt-dlp-transcript-common/controller/channels"; import { listSavedAlternates } from "yt-dlp-transcript-common/controller/savedVideoInventory"; import { readRoute } from "../_read"; import { opsFail } from "../_lib"; export const dynamic = "force-dynamic"; // GET [?slug=] // -> { ok, count, videos: [{ slug, id, line, dir, active: { file, bytes, // height?, seconds?, origin?, storedAt }, alternates: [...] }], // notAnswering: [slug] } // // Every saved video that holds two copies (ytdlp/savedAlternates.ts): a // download over a container already in the store keeps both, one active and // the other flagged here for a check — or, with `keptAs: "proxy"`, kept on // purpose: the lower-quality copy persist-videos' "below-height" replaced. // The /saved-videos page lists the same. // Pointers only — no container is opened. Nothing is written. export async function GET(request: Request) { return readRoute(request, ["slug"], async (q) => { const slug = q.get("slug")?.trim() || undefined; if (slug && !isValidChannelSlug(slug)) return opsFail(`"${slug}" is not a valid channel slug`); const notAnswering: string[] = []; const entries = await listSavedAlternates({ paths: getPaths(), channelSlug: slug, notAnswering }); return { count: entries.length, videos: entries.map((e) => ({ slug: e.slug, id: e.videoId, line: savedAlternatesLine(e.pointer), dir: e.pointer.dir, active: { file: e.pointer.file, bytes: e.pointer.bytes, ...((e.pointer.format?.height ?? e.pointer.probed?.height) ? { height: e.pointer.format?.height ?? e.pointer.probed?.height } : {}), ...(e.pointer.probed?.seconds ? { seconds: e.pointer.probed.seconds } : {}), ...(e.pointer.keepReason ? { keepReason: e.pointer.keepReason } : {}), ...(e.pointer.origin ? { origin: e.pointer.origin } : {}), storedAt: e.pointer.storedAt, // A re-encode says so (compact-saved-videos): of what, how. ...(e.pointer.compacted ? { reencode: compactedLine(e.pointer) } : {}), }, alternates: e.pointer.alternates ?? [], })), notAnswering: notAnswering.sort(), }; }); }