import { NextResponse } from "next/server"; import { RECORD_LIVE_BODY_KEYS, recordLiveCheckCommand } from "yt-dlp-transcript-common/controller/recordLive"; import { recordLiveAction } from "../../../channels/[slug]/liveMediaActions"; import { ops, opsFail, reqSlug } from "../_lib"; export const dynamic = "force-dynamic"; // POST { slug, url? | id?, fromStart? (true), maxHeight? (720; null = tallest), // separate? (YouTube true, else false), transcribe?, doNotClean?, note?, // insurance? (true | "whole" | false; absent: on when marked keep), // dryRun? } -> { ok: true, jobId, kind: "record-live", check } // // `check` is the command that answers for the recording afterwards (`pnpm ops // get live-recordings /`): whether it records, grows, failed — from // its own record, never from "a job for this video id". `pnpm ops record-live // … --wait-started` polls it until media bytes are being written. // // A LIVE STREAM RECORDED UNTIL IT ENDS (controller/recordLive.ts; // plans/live-capture.md): yt-dlp `--live-from-start` (Rumble's DVR playlist // holds the stream from its start for its first 4 hours; YouTube's from the // start is separate DASH video + audio, merged); on Rumble, when // yt-dlp is refused, the page's own playlist found by a browser and recorded // by ffmpeg; on Kick, the ongoing VOD polled from its first segment beside the // channel's live stream. Then the longest part lands as the video's source, // as import-media lands a file. One job per stream on its own queue; Cancel // stops the recorders with SIGINT and lands what they have. export async function POST(request: Request) { return ops(request, RECORD_LIVE_BODY_KEYS, async (body) => { const slug = reqSlug(body, "slug"); const result = await recordLiveAction(body); if (!result.ok) return opsFail(result.error, 400, result.info ? { info: true } : undefined); void result.stream.cancel(); return NextResponse.json({ ok: true, jobId: result.jobId, kind: "record-live", check: recordLiveCheckCommand(slug, body) }); }); }