import { isValidChannelSlug } from "yt-dlp-transcript-common/controller/channels"; import { listLiveRecordings } from "yt-dlp-transcript-common/controller/liveRecordings"; import { getPaths } from "yt-dlp-transcript-common/lib/paths"; import { readRoute } from "../_read"; import { opsFail } from "../_lib"; export const dynamic = "force-dynamic"; // GET [?slug=[&id=]][&all=1] // -> { ok, needsAttention, stalled, stallMinutes, files: [{ slug, file, // state (set-aside | unreadable), reason, needsAttention, message }], // rows: [{ slug, id, url, status (recording | interrupted | landed | // failed | cancelled), job, bytes, lastGrowthAt, stalled, // streamElapsedSeconds, capturedSeconds, coverage?, attempts, // failureClass?, fallback?, lost?, missingStream?, keptParts?, // stoppedBy?, error?, mustKeep, needsAttention, reason, check, // parts (each its bytes and lastGrowthAt while recording), … }] } // // IS THIS STREAM BEING RECORDED, AND IS IT GROWING (controller/ // liveRecordings.ts): each run from its own record, never from "a job for this // video id". Default: what is recording, what needs a person, and the last 7 // days; `all=1` every run kept. Nothing is written. export async function GET(request: Request) { return readRoute(request, ["slug", "id", "all"], async (q) => { const slug = q.get("slug")?.trim() || undefined; const id = q.get("id")?.trim() || undefined; if (slug && !isValidChannelSlug(slug)) return opsFail(`"${slug}" is not a valid channel slug`); if (id && !slug) return opsFail('"id" goes with "slug"'); if (id && !/^[\w.-]+$/.test(id)) return opsFail(`"${id}" is not a record id`); const listing = await listLiveRecordings(getPaths(), { ...(slug ? { slug } : {}), ...(id ? { id } : {}), all: q.get("all") === "1" }); return { ...listing }; }); }