// IS THIS VIDEO A STREAM THAT HAS NOT FINISHED? — and the sentence a // download-for-transcription says when it is. // // A one-video download of a video that is live reads the HLS at 1x: yt-dlp // follows the stream until it ends, and the platform's queue is held for the // stream's whole length (4 Nov: a transcribe-one on a live YouTube video sat // on platform:youtube for hours). Such a video is recorded by record-live, or // transcribed once its VOD exists — never downloaded as a finished video. // // What a download already knows is the video's metadata.info.json (yt-dlp's // `is_live` / `live_status`, the same fields skip-live and record-live read). // It is a snapshot: a stream that has ended since still says `is_live` until // the record is re-read, which is why the sentence names refresh-metadata. // // The three states are record-live's LIVE_STATES: `is_live`, `is_upcoming` // (scheduled, not started) and `post_live` (ended; its VOD is still being // processed and a download of it now is the stream's fragments, or an // incomplete file). `was_live` is a finished VOD and downloads normally. export type LiveNowState = "is_live" | "is_upcoming" | "post_live"; export type LiveFields = { is_live?: unknown; live_status?: unknown; }; export function liveNowState(meta: LiveFields | null | undefined): LiveNowState | null { if (!meta || typeof meta !== "object") return null; const status = typeof meta.live_status === "string" ? meta.live_status : ""; if (status === "is_live" || status === "is_upcoming" || status === "post_live") return status; // An extractor that sets only the boolean (older records, some platforms). // A `live_status` that says otherwise wins: it is the newer field. if (meta.is_live === true && (status === "" || status === "is_live")) return "is_live"; return null; } // The refusal. `slug` and `videoId` make the two commands it names runnable // as they stand. export function liveDownloadRefusal( state: LiveNowState, { slug, videoId }: { slug: string; videoId: string }, ): string { const body = JSON.stringify({ slug, id: videoId }); const record = `pnpm ops record-live --json '${body}'`; const refresh = `pnpm ops refresh-metadata --json '${body}'`; if (state === "is_upcoming") { return ( `${videoId} is a scheduled stream that has not started (live_status is_upcoming): there is nothing to ` + `transcribe yet. Record it from its start with record-live (${record}), or wait for the VOD; once it has ` + `aired, ${refresh} re-reads its record.` ); } if (state === "post_live") { return ( `${videoId}'s stream has ended but its VOD is still being processed (live_status post_live): a download now ` + `reads the stream's fragments, not the finished video. Wait for the VOD; ${refresh} re-reads its record ` + `once it is ready.` ); } return ( `${videoId} is live now (live_status is_live): a download would read the stream at 1x and hold the ` + `platform's queue for as long as it runs. Record it with record-live (${record}), or wait for the VOD; ` + `once it has ended, ${refresh} re-reads its record.` ); }