"use client"; // LIVE PRE-CLIP (plans/live-preclip.md): a recording in progress transcribed // and mined while it records — the same job as `pnpm ops live-preclip` // (controller/livePreclip.ts). Drawn when the video has a live recording or a // live transcript: the job's state (ticks, what was skipped and why, the last // lines), the umtool project it grows, the PROVISIONAL transcript so far, and // a share of a few seconds of it while it is still live (`pnpm ops live-clip`). // // TYPE-ONLY from the controller (it reaches node:fs): the state arrives as // props, read by the page. import { useState } from "react"; import { StreamActionLog } from "yt-dlp-transcript-common/components/StreamActionLog"; import type { LivePreclipStatusView } from "yt-dlp-transcript-common/controller/livePreclip"; import type { Cue } from "yt-dlp-transcript-common/lib/vtt"; import { cancelJobAction } from "../../../../../jobs/actions"; import { shareLiveClipAction, startLivePreclipAction, stopLivePreclipAction } from "../livePreclipActions"; const input = "rounded border border-border bg-card px-2 py-1 text-sm"; function clock(seconds: number): string { const s = Math.max(0, Math.round(seconds)); const h = Math.floor(s / 3600); const m = Math.floor((s % 3600) / 60); const sec = s % 60; return h > 0 ? `${h}:${String(m).padStart(2, "0")}:${String(sec).padStart(2, "0")}` : `${m}:${String(sec).padStart(2, "0")}`; } // "1:02:03", "62:03" or "3723" → seconds. function parseClock(v: string): number | null { const t = v.trim(); if (!t) return null; if (/^\d+(\.\d+)?$/.test(t)) return Number(t); const parts = t.split(":").map(Number); if (parts.some((p) => !Number.isFinite(p))) return null; return parts.reduce((a, p) => a * 60 + p, 0); } export function LivePreclipPanel({ slug, videoId, umtoolUrl, view, cues, }: { slug: string; videoId: string; umtoolUrl: string | null; view: LivePreclipStatusView; // The live transcript's cues (all of them, while it is not superseded). cues: Cue[]; }) { const [every, setEvery] = useState(""); const [from, setFrom] = useState(""); const [to, setTo] = useState(""); const [stopNote, setStopNote] = useState(null); const state = view.state; const t = view.transcript; const recording = view.recording?.status === "recording"; const running = view.job !== null; const start = parseClock(from); const end = parseClock(to); const shareOk = start !== null && end !== null && end > start && end - start <= 140; const status = running ? `running — ${state?.ticks ?? 0} tick(s), ${clock(t?.transcribedTo ?? 0)} transcribed${state?.recordedSeconds ? ` of ${clock(state.recordedSeconds)}` : ""}` : state ? `${state.status}${t ? ` — ${clock(t.transcribedTo)} transcribed` : ""}` : recording ? "not running" : "—"; return (

Live pre-clip

{status}
{!umtoolUrl && (

UMTOOL_URL is not set on the editor: the live transcript is kept, no clip windows are mined.

)} {recording && !running && (
)} {recording && !running && ( startLivePreclipAction(slug, videoId, Number(every) > 0 ? Number(every) : undefined)} cancelAction={cancelJobAction} buttonLabel="Start pre-clip" runningLabel="Pre-clipping…" label={`Live pre-clip of ${videoId}`} /> )} {running && (
its job {stopNote && {stopNote}}
)} {state && (
{state.mined && (

Clips:{" "} {umtoolUrl ? ( {state.mined.project} ) : ( {state.mined.project} )}{" "} — {state.mined.proposals} proposal(s), {state.mined.clips} clip(s) {state.mined.error ? `; last mining failed: ${state.mined.error}` : ""}

)} {state.check && (

Landing check: {state.check.verdict} — {state.check.why}

)} {Object.keys(state.skipped).length > 0 && (

Skipped ticks: {Object.entries(state.skipped).map(([k, n]) => `${k} ${n}`).join(", ")}

)} {state.log.length > 0 && (
              {state.log.join("\n")}
            
)}
)} {t && (
Live transcript ({t.status === "superseded" ? "superseded by the final transcript" : "provisional"}): {t.cues} cue(s) to {clock(t.transcribedTo)} {t.restarts ? `, restarted ${t.restarts}×` : ""} {t.status !== "superseded" && (
    {cues.map((c, i) => (
  1. {" "} {c.text}
  2. ))}
)}
)} {(recording || (t && t.status !== "superseded")) && (
shareLiveClipAction(slug, videoId, start ?? 0, end ?? 0)} cancelAction={cancelJobAction} buttonLabel="Share this clip" runningLabel="Making the short…" label={`Live share of ${videoId}`} disabled={!umtoolUrl || !shareOk} />
)}
); }