Archilyzer · Source

archilyzer

Archilyzer
git clone https://archilyzer.pages.dev/source/archilyzer.git
Log | Files | Refs | README | LICENSE

commit f97a5e526e5ce3c8921019700cf383574ab1d930
parent 19fc36d4e0ebcc426e480e3ffcbf0565ce1dbd89
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Tue, 27 Oct 2026 12:32:36 -0400

live pre-clip: the video page's panel — state, the provisional transcript, start, stop, share

Drawn for a video with a live recording or a live transcript: the job's ticks,
skips and last lines, the umtool project it grows, the landing check, the live
transcript (provisional until superseded) and a share of a span of it while
it is still live. The buttons run the same jobs as pnpm ops live-preclip and
live-clip.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

Diffstat:
Aeditor/app/channels/[slug]/videos/[id]/components/LivePreclipPanel.tsx | 208+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aeditor/app/channels/[slug]/videos/[id]/livePreclipActions.ts | 35+++++++++++++++++++++++++++++++++++
Meditor/app/channels/[slug]/videos/[id]/page.tsx | 25+++++++++++++++++++++++++
3 files changed, 268 insertions(+), 0 deletions(-)

diff --git a/editor/app/channels/[slug]/videos/[id]/components/LivePreclipPanel.tsx b/editor/app/channels/[slug]/videos/[id]/components/LivePreclipPanel.tsx @@ -0,0 +1,208 @@ +"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<string | null>(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 ( + <section aria-label="live pre-clip panel" className="flex flex-col gap-3 rounded border border-border p-3"> + <div className="flex flex-wrap items-baseline justify-between gap-2"> + <h2 className="text-lg font-semibold">Live pre-clip</h2> + <span aria-label="live pre-clip status" className="text-xs text-muted-foreground"> + {status} + </span> + </div> + {!umtoolUrl && ( + <p role="status" className="text-sm text-muted-foreground"> + UMTOOL_URL is not set on the editor: the live transcript is kept, no clip windows are mined. + </p> + )} + {recording && !running && ( + <div className="flex flex-wrap items-end gap-3 text-sm"> + <label className="flex flex-col gap-0.5"> + <span className="text-xs text-muted-foreground">Every (minutes; empty = {state?.options.everyMinutes ?? 10})</span> + <input type="number" min={1} max={120} value={every} onChange={(e) => setEvery(e.target.value)} aria-label="pre-clip every (minutes)" className={`${input} w-24`} /> + </label> + </div> + )} + {recording && !running && ( + <StreamActionLog + trigger={() => 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 && ( + <div className="flex flex-wrap items-center gap-3 text-sm"> + <button + type="button" + className="rounded border border-border px-2 py-1" + aria-label="stop pre-clip" + onClick={async () => { + const r = await stopLivePreclipAction(slug, videoId); + setStopNote(r.ok ? "Stopped (the recording goes on)." : (r.error ?? "not stopped")); + }} + > + Stop pre-clip + </button> + <a href={`/jobs/${view.job!.id}`} className="underline"> + its job + </a> + {stopNote && <span className="text-muted-foreground">{stopNote}</span>} + </div> + )} + {state && ( + <div className="flex flex-col gap-1 text-sm"> + {state.mined && ( + <p> + Clips:{" "} + {umtoolUrl ? ( + <a href={`${umtoolUrl}/projects/${encodeURIComponent(state.mined.project)}/clips`} className="font-mono underline" data-live-project> + {state.mined.project} + </a> + ) : ( + <span className="font-mono">{state.mined.project}</span> + )}{" "} + <span className="text-muted-foreground"> + — {state.mined.proposals} proposal(s), {state.mined.clips} clip(s) + {state.mined.error ? `; last mining failed: ${state.mined.error}` : ""} + </span> + </p> + )} + {state.check && ( + <p aria-label="live pre-clip check" className={state.check.verdict === "same" || state.check.verdict === "same-recording" ? "text-muted-foreground" : "text-amber-600"}> + Landing check: {state.check.verdict} — {state.check.why} + </p> + )} + {Object.keys(state.skipped).length > 0 && ( + <p className="text-xs text-muted-foreground"> + Skipped ticks: {Object.entries(state.skipped).map(([k, n]) => `${k} ${n}`).join(", ")} + </p> + )} + {state.log.length > 0 && ( + <pre aria-label="live pre-clip log" className="max-h-40 overflow-auto whitespace-pre-wrap rounded bg-muted p-2 text-xs"> + {state.log.join("\n")} + </pre> + )} + </div> + )} + {t && ( + <details className="text-sm" open={recording}> + <summary> + Live transcript ({t.status === "superseded" ? "superseded by the final transcript" : "provisional"}): {t.cues} cue(s) to {clock(t.transcribedTo)} + {t.restarts ? `, restarted ${t.restarts}×` : ""} + </summary> + {t.status !== "superseded" && ( + <ol aria-label="live transcript" className="mt-2 flex max-h-96 flex-col gap-0.5 overflow-auto font-mono text-xs"> + {cues.map((c, i) => ( + <li key={`${c.start}-${i}`}> + <button + type="button" + className="text-muted-foreground underline-offset-2 hover:underline" + title="share from here" + onClick={() => { + setFrom(clock(c.start)); + if (!to) setTo(clock(c.start + 30)); + }} + > + {clock(c.start)} + </button>{" "} + {c.text} + </li> + ))} + </ol> + )} + </details> + )} + {(recording || (t && t.status !== "superseded")) && ( + <div className="flex flex-col gap-2 text-sm"> + <div className="flex flex-wrap items-end gap-3"> + <label className="flex flex-col gap-0.5"> + <span className="text-xs text-muted-foreground">Share from</span> + <input value={from} onChange={(e) => setFrom(e.target.value)} placeholder="1:02:03" aria-label="share from" className={`${input} w-28`} /> + </label> + <label className="flex flex-col gap-0.5"> + <span className="text-xs text-muted-foreground">to (at most 2:20 later)</span> + <input value={to} onChange={(e) => setTo(e.target.value)} placeholder="1:03:00" aria-label="share to" className={`${input} w-28`} /> + </label> + </div> + <StreamActionLog + trigger={() => 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} + /> + </div> + )} + </section> + ); +} diff --git a/editor/app/channels/[slug]/videos/[id]/livePreclipActions.ts b/editor/app/channels/[slug]/videos/[id]/livePreclipActions.ts @@ -0,0 +1,35 @@ +"use server"; + +// The video page's Live pre-clip panel: the same jobs as `pnpm ops +// live-preclip` and `pnpm ops live-clip` (controller/livePreclip.ts, +// controller/liveClip.ts). NOTHING BUT FUNCTIONS IS DECLARED HERE (a "use +// server" file). + +import { getPaths } from "yt-dlp-transcript-common/lib/paths"; +import { readChannelConfig } from "yt-dlp-transcript-common/controller/channels"; +import { preclipDefaults, startLivePreclipJob, stopLivePreclip } from "yt-dlp-transcript-common/controller/livePreclip"; +import { parseLiveClipBody, runLiveClipJob } from "yt-dlp-transcript-common/controller/liveClip"; +import type { StreamActionResult } from "yt-dlp-transcript-common/jobs/streamCommand"; +import { safeRevalidate } from "../../../../lib/safeRevalidate"; + +export async function startLivePreclipAction(slug: string, videoId: string, everyMinutes?: number): Promise<StreamActionResult> { + const paths = getPaths(); + const config = await readChannelConfig(paths, slug); + if (!config) return { ok: false, error: `Channel "${slug}" not found` }; + const options = { ...preclipDefaults(), ...(everyMinutes && everyMinutes >= 1 && everyMinutes <= 120 ? { everyMinutes: Math.round(everyMinutes) } : {}) }; + const r = await startLivePreclipJob({ paths, slug, id: videoId, channelConfig: config, options }); + safeRevalidate([`/channels/${slug}/videos/${videoId}`]); + return r; +} + +export async function stopLivePreclipAction(slug: string, videoId: string): Promise<{ ok: boolean; error?: string }> { + const r = stopLivePreclip(slug, videoId); + safeRevalidate([`/channels/${slug}/videos/${videoId}`]); + return r.ok ? { ok: true } : { ok: false, error: r.error }; +} + +export async function shareLiveClipAction(slug: string, videoId: string, start: number, end: number): Promise<StreamActionResult> { + const parsed = parseLiveClipBody({ slug, id: videoId, start, end }); + if (!parsed.ok) return parsed; + return runLiveClipJob({ paths: getPaths(), request: parsed.value }); +} diff --git a/editor/app/channels/[slug]/videos/[id]/page.tsx b/editor/app/channels/[slug]/videos/[id]/page.tsx @@ -49,6 +49,9 @@ import { TagsPanel } from "./components/TagsPanel"; import { FrameScanPanel } from "./components/FrameScanPanel"; import { FindClipsPanel } from "./components/FindClipsPanel"; import { loadFindClipsRecord } from "yt-dlp-transcript-common/lib/findClipsRecord-server"; +import { LivePreclipPanel } from "./components/LivePreclipPanel"; +import { livePreclipStatus } from "yt-dlp-transcript-common/controller/livePreclip"; +import { liveTranscriptSidecar } from "yt-dlp-transcript-common/lib/livePreclip-server"; import { umtoolUrl as resolveUmtoolUrl } from "yt-dlp-transcript-common/lib/umtoolUrl"; import { frameScanView } from "./lib/frameScanView"; import { loadFrameScans } from "yt-dlp-transcript-common/lib/frameScan-server"; @@ -228,6 +231,21 @@ export default async function VideoDetailPage({ // What the last Find clips found (release 36 lane A): one small sidecar. const findClips = await loadFindClipsRecord(videoDir); + // Live pre-clip (plans/live-preclip.md): only for a video with a live + // recording or a live transcript — two small sidecars, then the + // transcript's cues while it is not superseded. + const livePreclipView = await livePreclipStatus(getPaths(), slug, id); + const livePreclip = + livePreclipView.recording || livePreclipView.transcript + ? { + view: livePreclipView, + cues: + livePreclipView.transcript && livePreclipView.transcript.status !== "superseded" + ? ((await liveTranscriptSidecar.load(videoDir))?.cues ?? []) + : [], + } + : null; + // The curated tags on this video, with each one's provenance. Reads tags.json // plus (for rule hits) ONE key out of the transcript index — not a scan. const tagsView = await loadVideoTags(slug, id); @@ -254,6 +272,7 @@ export default async function VideoDetailPage({ tagsView, frameScans, findClips, + livePreclip, }; }; const drive = config.dataDir?.trim(); @@ -289,6 +308,7 @@ export default async function VideoDetailPage({ tagsView, frameScans, findClips, + livePreclip, } = loaded; const registry = getRegistry(); @@ -451,6 +471,11 @@ export default async function VideoDetailPage({ readingT={readingT} /> + {/* A recording in progress, transcribed and mined while it records. */} + {livePreclip && ( + <LivePreclipPanel slug={slug} videoId={id} umtoolUrl={resolveUmtoolUrl()} view={livePreclip.view} cues={livePreclip.cues} /> + )} + {/* The clip finder's chain for this video (release 36 lane A). */} <FindClipsPanel slug={slug}