import { getPaths } from "yt-dlp-transcript-common/lib/paths"; import { getSettings } from "yt-dlp-transcript-common/lib/settings"; import { getRegistry } from "yt-dlp-transcript-common/jobs/registry"; import { LIVE_BOOT_DELAY_MS, restartInterruptedLiveRecordings, } from "yt-dlp-transcript-common/controller/liveRecordingBoot"; import { recordLiveAction } from "../../channels/[slug]/liveMediaActions"; // THE LIVE RECORDINGS AN EDITOR RESTART INTERRUPTED, RESTARTED (operator // ruling, 21 Nov 2026): instrumentation.ts arms this below the idle gate and // never on the e2e test server. LIVE_BOOT_DELAY_MS after boot (an orphan // recorder of the last process has written by then, and is refused), one pass // of common/controller/liveRecordingBoot.ts: each interrupted run asks for a // record-live job through the same door the ops route and Record again use, // with `resumeOf`, and that job reads the stream's state before it records. // The pass itself makes no request. export function armLiveRecordingBootPass(bootedAt: number): void { const t = setTimeout(() => { void runPass(bootedAt).catch((e: Error) => console.log(`[boot] live recordings: the restart pass failed (${e.message})`)); }, LIVE_BOOT_DELAY_MS); t.unref?.(); } async function runPass(bootedAt: number): Promise { const settings = getSettings(); await restartInterruptedLiveRecordings({ paths: getPaths(), bootedAt, enabled: settings.liveRecording.autoRestartOnBoot, isRunning: (jobId, slug, id) => { const jobs = getRegistry().list(); return jobs.some( (j) => (j.status === "running" || j.status === "queued") && (jobId ? j.id === jobId : j.kind === "record-live" && j.channelSlug === slug && j.videoId === id), ); }, start: async (_slug, body, resumeOf) => { const r = await recordLiveAction(body, { resumeOf }); if (!r.ok) return { ok: false, error: r.error }; void r.stream.cancel(); return { ok: true, jobId: r.jobId }; }, log: (line) => console.log(line), }); }