"use client"; import { useState } from "react"; import { StreamActionLog } from "yt-dlp-transcript-common/components/StreamActionLog"; import { cancelJobAction } from "../../../jobs/actions"; import { importMediaAction, recordLiveAction } from "../liveMediaActions"; // "Import a file" and "Record live" (plans/live-capture.md) — the forms over // `pnpm ops import-media` and `pnpm ops record-live`, on the channel page // (a new record: the source page's URL, or a title by hand) and on a video's // page (this record). Import previews first (its dry run) and is armed by a // preview of the same settings; a recording starts at once and runs until the // stream ends — its job's Cancel stops it and lands what it has. const input = "rounded border border-border bg-card px-2 py-1 text-sm"; export function ImportFileForm({ slug, videoId }: { slug: string; videoId?: string }) { const [file, setFile] = useState(""); const [url, setUrl] = useState(""); const [title, setTitle] = useState(""); const [date, setDate] = useState(""); const [newId, setNewId] = useState(""); const [move, setMove] = useState(false); const [replace, setReplace] = useState(false); const [transcribe, setTranscribe] = useState(false); const [keep, setKeep] = useState(false); const [note, setNote] = useState(""); const body = (dryRun: boolean): Record => ({ slug, path: file.trim(), ...(videoId ? { id: videoId } : url.trim() ? { url: url.trim() } : {}), ...(!videoId && !url.trim() && title.trim() ? { meta: { title: title.trim(), ...(date ? { date } : {}) }, ...(newId.trim() ? { id: newId.trim() } : {}) } : {}), ...(move ? { move: true } : {}), ...(replace ? { replace: true } : {}), ...(transcribe ? { transcribe: true } : {}), ...(keep ? { doNotClean: true } : {}), ...(note.trim() ? { note: note.trim() } : {}), ...(dryRun ? { dryRun: true } : {}), }); const key = JSON.stringify(body(false)); const [previewed, setPreviewed] = useState(null); const ready = file.trim().startsWith("/") && (Boolean(videoId) || Boolean(url.trim()) || Boolean(title.trim())); return (

Import a file

{!videoId && ( )}
{!videoId && !url.trim() && (
)}
setNote(e.target.value)} aria-label="import note" placeholder="note (optional)" className={`${input} w-56 max-w-full`} />
importMediaAction(body(true))} cancelAction={cancelJobAction} buttonLabel="Preview import" runningLabel="Reading the file…" label={`Preview import into ${slug}${videoId ? `/${videoId}` : ""}`} disabled={!ready} onSettled={(started) => setPreviewed(started ? key : null)} /> importMediaAction(body(false))} cancelAction={cancelJobAction} buttonLabel="Import" runningLabel="Importing…" label={`Import into ${slug}${videoId ? `/${videoId}` : ""}`} disabled={!ready || previewed !== key} /> {ready && previewed !== key &&

Preview these settings first.

}
); } export function RecordLiveForm({ slug, videoId }: { slug: string; videoId?: string }) { const [url, setUrl] = useState(""); const [fromStart, setFromStart] = useState(true); const [best, setBest] = useState(false); // "auto": the platform's default (YouTube separate video + audio; Rumble, Kick one muxed stream). const [streams, setStreams] = useState<"auto" | "separate" | "muxed">("auto"); const [transcribe, setTranscribe] = useState(false); const [keep, setKeep] = useState(false); const [note, setNote] = useState(""); const body: Record = { slug, ...(videoId ? { id: videoId } : { url: url.trim() }), ...(fromStart ? {} : { fromStart: false }), ...(best ? { maxHeight: null } : {}), ...(streams === "auto" ? {} : { separate: streams === "separate" }), ...(transcribe ? { transcribe: true } : {}), ...(keep ? { doNotClean: true } : {}), ...(note.trim() ? { note: note.trim() } : {}), }; return (

Record live

{!videoId && ( )}
setNote(e.target.value)} aria-label="record note" placeholder="note (optional)" className={`${input} w-56 max-w-full`} />
recordLiveAction(body)} cancelAction={cancelJobAction} buttonLabel="Record live" runningLabel="Recording…" label={`Record live into ${slug}${videoId ? `/${videoId}` : ""}`} disabled={!videoId && !/^https?:\/\//.test(url.trim())} />
); }