commit aebd1ed4fb772cd856c83e99cc7472e0f920f19c parent a14fb8510532c1f291cc45cdaff8667c87fbfb26 Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st> Date: Sat, 14 Nov 2026 00:36:12 -0500 Public Present never names a raw window with hidden regions; recording boxes on every raw player; the zoom on its frame - Present's public payload (canUncensor false) carries no raw window for a clip with hidden regions: media is null, and `censored` names its built segment when that segment's cut record hides exactly its boxes (played whole from /api/report/segment), else null -- the slide says the clip is not shown. The operator's Present keeps the window with the overlay. - The claim bench, the candidates panel and the article's cited clip overlay the recording's boxes (recordingRegionsOf: render.censor matched on the video; a cited project clip's own too), outlined, Peek off. - The zoom ran one frame early: perspective's `in` counts from 1. Time is (in-1)/fps; the render test now checks every frame against its second, the first pushed frame and the last eased one. - knobs.md separates what is hidden in the file (builds, exports, stills) from what is only overlaid on the operator's screen, and says what the public payload carries. Co-Authored-By: Claude <noreply@anthropic.com> Diffstat:
17 files changed, 266 insertions(+), 51 deletions(-)
diff --git a/editor/CHANGELOG.md b/editor/CHANGELOG.md @@ -11,8 +11,11 @@ - Every path that draws or cuts a clip's picture either hides them or refuses by name. They are hidden in a cut, a short, a desktop clip, Make a short, a short of an already-rendered take (the project's boxes are added), `umtool shorts --again`, the YouTube thumbnail, stills, and `umtool export` as cut or with context. - - Play, the live preview and Present (its public payload too) draw them over the picture. The clip editor's player - and the clip bench draw them outlined, with a **Peek** toggle that is off by default. + - Players of a raw window overlay them on the operator's screen; they are not hidden in the file. These are Play, + the live preview, the operator's Present, the claim bench, the candidates panel and the article's cited clip. + The clip editor's player and the clip bench draw them outlined, with a **Peek** toggle that is off by default. + - A public Present payload never names the raw window of a clip with boxes. It plays the clip's built segment when + that segment hides exactly those boxes, and otherwise says the clip is not shown. - A montage, a basic cut, `--chrome-only` after the boxes changed and `--reframe` of a take rendered before them are refused. So is `umtool export --raw`, unless `--uncensored-raw` asks for the recording as it is (and the export says UNCENSORED). diff --git a/umtool/app/api/report/candidates/route.ts b/umtool/app/api/report/candidates/route.ts @@ -3,6 +3,7 @@ import { StaleToken, StructureRefused, manifestToken } from "@/lib/report/manife import { CandidatesError, candidatesView, dismissCandidate, insertCandidate } from "@/lib/report/candidates.mjs"; import { projectCache, resolveReport } from "@/lib/report/serve.mjs"; import { refuseCaller } from "@/lib/report/caller"; +import { recordingRegionsOf } from "umtool-report-to-video/clip-censor"; export const dynamic = "force-dynamic"; @@ -11,7 +12,7 @@ export const dynamic = "force-dynamic"; // panel. Proposals come in from a terminal only (`umtool candidates <p> // import|add`); this route is the operator's two presses. // -// GET ?project=<id> { …candidatesView, token, playable: { <id>: true } } +// GET ?project=<id> { …candidatesView, token, playable: { <id>: true }, hidden: { <id>: its recording's regions } } // (playable: a cached window holds the cited second, so Play plays it here) // POST { project, op: "insert", id, section | group, token } through `timeline insert`'s writer // → { ok, inserted, clip, window, token, editNotes, attributionError? } | 409 stale @@ -32,7 +33,13 @@ export async function GET(request: Request) { if (wins.some((w) => w.from <= c.t && w.to >= c.t + 2)) playable[c.id] = true; } } - return Response.json({ ...view, token: await manifestToken(r.project.dir), playable }, { headers }); + // Each candidate's recording's hidden regions (render.censor): overlaid where it plays, as on every raw window. + const hidden: Record<string, ReturnType<typeof recordingRegionsOf>> = {}; + for (const c of view.candidates as { id: string; video: string; channel?: string }[]) { + const g = recordingRegionsOf(c.video, c.channel ?? null, r.manifest.render ?? {}, r.manifest.provenance ?? {}); + if (g.length) hidden[c.id] = g; + } + return Response.json({ ...view, token: await manifestToken(r.project.dir), playable, hidden }, { headers }); } export async function POST(request: Request) { diff --git a/umtool/components/clips/CitedClip.tsx b/umtool/components/clips/CitedClip.tsx @@ -8,6 +8,7 @@ import { spanClock } from "@/lib/clips/words"; import { cn } from "@/lib/utils"; import { STORED_URL_UI_MODE } from "yt-dlp-transcript-common/lib/storedMediaUrl"; import StoredUrlOption from "./StoredUrlOption"; +import CensorOverlay from "@/components/projects/review/CensorOverlay"; // --------------------------------------------------------------------------- // THE CITED CLIP (release 32 R1): the seconds a citation names, played so a @@ -105,6 +106,7 @@ const CitedClip = forwardRef< const [fetching, setFetching] = useState<CitedFetchAnswer | { state: "asking" } | null>(null); const [fromStored, setFromStored] = useState(false); const [now, setNow] = useState(target.from); + const [picAspect, setPicAspect] = useState<number | null>(null); const [playing, setPlaying] = useState(false); const media = useRef<HTMLMediaElement | null>(null); const spanning = useRef(false); @@ -248,6 +250,8 @@ const CitedClip = forwardRef< tabIndex: -1, onLoadedMetadata: (e: React.SyntheticEvent<HTMLMediaElement>) => { e.currentTarget.currentTime = play ? (card ? play.offset : Math.max(0, play.offset - (play.kind === "prepared" ? play.offset : 3))) : 0; + const el = e.currentTarget; + if (el instanceof HTMLVideoElement && el.videoWidth > 0 && el.videoHeight > 0) setPicAspect(el.videoWidth / el.videoHeight); if (wantPlay.current) playSpanNow(); }, onTimeUpdate: (e: React.SyntheticEvent<HTMLMediaElement>) => { @@ -291,13 +295,17 @@ const CitedClip = forwardRef< <audio {...mediaProps} controls={!card} className={card ? "hidden" : "w-full"} /> </div> ) : ( - <video - {...mediaProps} - controls={!card} - playsInline - onClick={card ? () => api.playSpan() : undefined} - className={cn("aspect-video w-full rounded-[3px] bg-black", card && "cursor-pointer")} - /> + <div className="relative"> + <video + {...mediaProps} + controls={!card} + playsInline + onClick={card ? () => api.playSpan() : undefined} + className={cn("aspect-video w-full rounded-[3px] bg-black", card && "cursor-pointer")} + /> + {/* The project's hidden regions on this recording (clip-censor.mjs): overlaid on the screen, outlined. */} + {(play.hidden?.length ?? 0) > 0 && <CensorOverlay regions={play.hidden ?? []} at={now} aspect={picAspect} mode="edit" testId="cited-censor" />} + </div> )} <div className="flex flex-wrap items-center gap-2"> {card ? ( diff --git a/umtool/components/projects/ClaimBench.tsx b/umtool/components/projects/ClaimBench.tsx @@ -9,6 +9,7 @@ import { ReaderPane } from "@/components/ui/reader-pane"; import { citationText } from "@/lib/research/facets.mjs"; import { BenchBody, VerdictBar } from "./bench/BenchShell"; import CopyCitation from "./bench/CopyCitation"; +import CensorOverlay, { type CensorRegion } from "./review/CensorOverlay"; import { POPULATIONS, SCOPES, @@ -54,6 +55,8 @@ export type ClaimBenchData = { source: { title: string | null; uploadDate: string | null; duration: number | null; webpageUrl: string | null } | null; noCues: boolean; windows: Array<{ name: string; from: number; to: number }>; + /** Its recording's hidden regions (render.censor): overlaid on the window, Peek off by default. */ + hidden?: CensorRegion[]; gaps: string[]; fired: Array<{ rule: string; text: string }>; prev: string | null; @@ -183,6 +186,8 @@ export default function ClaimBench({ data }: { data: ClaimBenchData }) { // is playable with no download at all -- which is most of them once a build // has run, because the build already over-fetched around every clip. const cached = data.windows[0] ?? null; + const [hiddenAt, setHiddenAt] = useState<number | null>(null); + const [hiddenAspect, setHiddenAspect] = useState<number | null>(null); const roles = useMemo(() => parseRoles(roleText), [roleText]); const rosterPreview = roles.ok ? rosterLine(roles.list) : null; @@ -384,14 +389,23 @@ export default function ClaimBench({ data }: { data: ClaimBenchData }) { <div className="grid gap-3 lg:grid-cols-[minmax(0,1fr)_360px]"> <div className="space-y-3"> {cached ? ( - <video - ref={video} - data-testid="claim-video" - src={`/api/report/raw?project=${encodeURIComponent(data.project)}&claim=${encodeURIComponent(claim.id)}&file=${encodeURIComponent(cached.name)}`} - className="aspect-video w-full rounded border border-[var(--color-line)] bg-black" - preload="metadata" - controls - /> + <div className="relative"> + <video + ref={video} + data-testid="claim-video" + src={`/api/report/raw?project=${encodeURIComponent(data.project)}&claim=${encodeURIComponent(claim.id)}&file=${encodeURIComponent(cached.name)}`} + className="aspect-video w-full rounded border border-[var(--color-line)] bg-black" + preload="metadata" + controls + onLoadedMetadata={(e) => { + const el = e.currentTarget; + if (el.videoWidth > 0 && el.videoHeight > 0) setHiddenAspect(el.videoWidth / el.videoHeight); + }} + onTimeUpdate={(e) => setHiddenAt(cached.from + e.currentTarget.currentTime)} + onSeeked={(e) => setHiddenAt(cached.from + e.currentTarget.currentTime)} + /> + {(data.hidden?.length ?? 0) > 0 && <CensorOverlay regions={data.hidden ?? []} at={hiddenAt} aspect={hiddenAspect} mode="edit" testId="claim-censor" />} + </div> ) : ( <div className="flex aspect-video w-full flex-col items-center justify-center gap-2 rounded border border-dashed border-[var(--color-line)] text-[12px] text-[var(--color-dim)]"> <div>no cached window covers this moment</div> diff --git a/umtool/components/projects/ClaimBenchPage.tsx b/umtool/components/projects/ClaimBenchPage.tsx @@ -5,6 +5,7 @@ import ClaimBench, { type ClaimBenchData } from "./ClaimBench"; import { manifestToken } from "@/lib/report/manifest.mjs"; import { readClaimDetail, readManifest } from "@/lib/projects/report.mjs"; import { ledgerTotals } from "umtool-report-to-video/ledger-totals"; +import { recordingRegionsOf } from "umtool-report-to-video/clip-censor"; import { pieceHrefOfProject } from "@/lib/pieces/article"; import type { ProjectRef } from "@/lib/project-types"; @@ -74,6 +75,8 @@ export default async function ClaimBenchPage({ source: detail.source, noCues: detail.noCues, windows: detail.windows, + // Its recording's hidden regions (render.censor, clip-censor.mjs): overlaid on the window it plays. + hidden: recordingRegionsOf((detail.claim.video as string) ?? null, (detail.claim.channel as string) ?? null, manifest.render ?? {}, manifest.provenance ?? {}), gaps: detail.gaps, fired, prev: i > 0 ? String(ledger[i - 1].id) : null, diff --git a/umtool/components/projects/present/PresentView.tsx b/umtool/components/projects/present/PresentView.tsx @@ -52,8 +52,13 @@ type ClipSlide = SlideBase & { quote: string | null; qrUrl: string | null; blur: { strength: number; caption: string; from: number | null; to: number | null } | null; - /** Its hidden regions (clip-censor.mjs): drawn over the picture always -- no viewer toggle lifts them. */ + /** Its hidden regions (clip-censor.mjs): overlaid on the raw window on the operator's page -- no toggle lifts them. */ hidden?: CensorRegion[]; + /** + * A PUBLIC payload of a clip with hidden regions (no `media`: the raw window is never named): its built segment, + * which hides them in the file (`segment` its version), or null -- the slide says the clip is not shown. + */ + censored?: { segment: number; seconds: number | null } | null; }; type TextSlide = SlideBase & { kind: "section" | "day" | "teaser" | "card"; lines?: string[]; tail?: string | null; seconds?: number | null; heading?: string; within?: string | null }; type VideoSlide = SlideBase & { kind: "video"; src: string; from: number; to: number; seconds: number }; @@ -484,9 +489,14 @@ function ClipView({ slide, project, take, playing, sound, censor, onDone }: { sl const [done, setDone] = useState(false); const [aspect, setAspect] = useState<number | null>(null); const media = slide.media; + // A public page's clip with hidden regions plays its BUILT segment (the regions burned in), whole, or nothing. + const built = !media && slide.censored ? slide.censored : null; + const withheld = !media && slide.censored === null; const src = media ? `/api/report/raw?${new URLSearchParams({ project, clip: slide.entry ?? slide.id, ...(take ? { take } : {}), file: media.name, ...(media.v ? { v: media.v } : {}) }).toString()}` - : null; + : built + ? `/api/report/segment?${new URLSearchParams({ project, clip: slide.entry ?? slide.id, v: String(built.segment) }).toString()}` + : null; // Where it is in its source, followed every frame; past a span's end, on to the next, past the last, done. useEffect(() => { const v = video.current; @@ -517,12 +527,12 @@ function ClipView({ slide, project, take, playing, sound, censor, onDone }: { sl else if (!v.paused) v.pause(); }, [playing, done]); useEffect(() => { - if (!media && slide.spans.length) { + if (!media && !built && slide.spans.length) { // Not fetched: nothing plays, and the slide reads for its length. const t = setTimeout(() => setDone(true), slide.seconds * 1000); return () => clearTimeout(t); } - }, [media, slide.spans.length, slide.seconds]); + }, [media, built, slide.spans.length, slide.seconds]); const blurNow = censor && slide.blur && at !== null && (slide.blur.from === null || at >= slide.blur.from) && (slide.blur.to === null || at < slide.blur.to); return ( <div data-present-clip={slide.id} data-present-clip-at={at === null ? "" : at.toFixed(2)} data-present-clip-done={done ? "1" : "0"} className="absolute inset-0 flex flex-col bg-black" style={{ containerType: "size" }}> @@ -536,6 +546,8 @@ function ClipView({ slide, project, take, playing, sound, censor, onDone }: { sl muted={!sound} data-present-clip-video="" data-present-clip-blurred={blurNow ? "1" : "0"} + data-present-clip-built={built ? "1" : undefined} + onEnded={built ? () => setDone(true) : undefined} onLoadedMetadata={(e) => { const el = e.currentTarget; if (el.videoWidth > 0 && el.videoHeight > 0) setAspect(el.videoWidth / el.videoHeight); @@ -545,11 +557,11 @@ function ClipView({ slide, project, take, playing, sound, censor, onDone }: { sl style={{ filter: blurNow && slide.blur ? `blur(${slide.blur.strength}cqh)` : undefined }} /> ) : ( - <div data-present-clip-missing="" className="absolute inset-0 flex items-center justify-center text-[2.4cqh] text-white/50"> - not fetched yet — its words below + <div data-present-clip-missing={withheld ? "withheld" : ""} className="absolute inset-0 flex items-center justify-center px-[4cqh] text-center text-[2.4cqh] text-white/50"> + {withheld ? "this clip hides parts of its picture, and no build of it is here: it is not shown on this page — its words below" : "not fetched yet — its words below"} </div> )} - {src && (slide.hidden?.length ?? 0) > 0 && <CensorOverlay regions={slide.hidden ?? []} at={at} aspect={aspect} mode="cover" testId="present-clip-censor" />} + {media && src && (slide.hidden?.length ?? 0) > 0 && <CensorOverlay regions={slide.hidden ?? []} at={at} aspect={aspect} mode="cover" testId="present-clip-censor" />} {blurNow && slide.blur && ( <div className="pointer-events-none absolute inset-x-0 top-[5%] text-center text-[3.2cqh] font-semibold text-white drop-shadow">{slide.blur.caption}</div> )} diff --git a/umtool/components/projects/report/CandidatesPanel.tsx b/umtool/components/projects/report/CandidatesPanel.tsx @@ -6,6 +6,7 @@ import { badgeVariants } from "@/components/ui/badge"; import { buttonVariants } from "@/components/ui/button"; import { cn } from "@/lib/utils"; import { MANIFEST_CHANGED, announceManifestChanged } from "../timelineApi"; +import CensorOverlay, { type CensorRegion } from "../review/CensorOverlay"; // --------------------------------------------------------------------------- // THE CANDIDATES INBOX on the Cut tab (UI notes item 14). A sweep or an agent @@ -53,6 +54,8 @@ type View = { groups: { id: string; claim: string; section: number; ids: string[] }[]; token: string | null; playable: Record<string, boolean>; + /** Each candidate's recording's hidden regions (render.censor): overlaid on its player. */ + hidden?: Record<string, CensorRegion[]>; }; const clock = (t: number) => { @@ -63,9 +66,11 @@ const clock = (t: number) => { }; /** The cited moment, played here from a cached window (seeked to its second). */ -function InlinePlayer({ project, c }: { project: string; c: Candidate }) { +function InlinePlayer({ project, c, hidden = [] }: { project: string; c: Candidate; hidden?: CensorRegion[] }) { const ref = useRef<HTMLVideoElement | null>(null); const [from, setFrom] = useState<number | null>(null); + const [at, setAt] = useState<number | null>(null); + const [aspect, setAspect] = useState<number | null>(null); const [err, setErr] = useState<string | null>(null); const src = `/api/report/raw?project=${encodeURIComponent(project)}&candidate=${encodeURIComponent(c.id)}`; useEffect(() => { @@ -83,7 +88,7 @@ function InlinePlayer({ project, c }: { project: string; c: Candidate }) { }, [src]); if (err) return <span className="text-[11px] text-[var(--color-bad)]">could not play: {err}</span>; if (from === null) return <span className="text-[11px] text-[var(--color-dim)]">opening…</span>; - return ( + const video = ( <video ref={ref} data-candidate-player={c.id} @@ -91,12 +96,24 @@ function InlinePlayer({ project, c }: { project: string; c: Candidate }) { controls autoPlay preload="auto" - className="mt-1 w-full max-w-md rounded border border-[var(--color-line)]" + className={hidden.length ? "w-full rounded border border-[var(--color-line)]" : "mt-1 w-full max-w-md rounded border border-[var(--color-line)]"} onLoadedMetadata={(e) => { e.currentTarget.currentTime = Math.max(0, c.t - from); + const el = e.currentTarget; + if (el.videoWidth > 0 && el.videoHeight > 0) setAspect(el.videoWidth / el.videoHeight); }} + onTimeUpdate={hidden.length ? (e) => setAt(from + e.currentTarget.currentTime) : undefined} + onSeeked={hidden.length ? (e) => setAt(from + e.currentTarget.currentTime) : undefined} /> ); + if (!hidden.length) return video; + // Its recording's hidden regions, over the picture (outlined, Peek off by default). + return ( + <div className="relative mt-1 w-full max-w-md"> + {video} + <CensorOverlay regions={hidden} at={at} aspect={aspect} mode="edit" testId="candidate-censor" /> + </div> + ); } export default function CandidatesPanel({ project }: { project: string }) { @@ -310,7 +327,7 @@ export default function CandidatesPanel({ project }: { project: string }) { </button> </div> )} - {playing === c.id && <InlinePlayer project={project} c={c} />} + {playing === c.id && <InlinePlayer project={project} c={c} hidden={view.hidden?.[c.id] ?? []} />} </li> ); })} diff --git a/umtool/docs/knobs.md b/umtool/docs/knobs.md @@ -535,27 +535,34 @@ the SOURCE picture and may be limited to a span of the clip. the same part of the recording whatever frames it. - **Privacy, not TOS:** it stays on in the uncensored variant (`render.blur: "off"`), as a post's censor does. No caption is drawn. A hidden region is a privacy control, so every path that draws or cuts a clip's picture either - draws the boxes or REFUSES by name -- none skips them quietly: + hides the boxes or REFUSES by name -- none skips them quietly. Only the builds, the exports and the stills hide them + IN THE FILE; every player of a raw window overlays them on the operator's screen, which hides nothing from someone + who saves the window -- so a public payload never names a raw window of a clip that has them: | Path | The boxes | |---|---| +| **hidden in the file** | | | a cut, with or without the deck (`umtool take`, build-video) | drawn into each clip's segment; the cut record names them (`censor: [{box, style, strength?, from?, to?}]`) | | a short, a desktop clip, the take's own 16:9 look (`umtool vertical`, `umtool shorts`, Make a short) | drawn; a RENDERED take's frozen render gets the project's `render.censor` added (add-only: the take's boxes stay) | | `umtool shorts --again` | the clip's boxes now AND the batch record's snapshot, both (a box added since is kept, none taken off) | | the YouTube thumbnail (`thumbnail.clip`/`at`) | drawn on the grabbed frame, before its blur | | a still (`umtool still`, Play's Still, "Use this frame", promo `--portrait-from`) | drawn on the PNG, the boxes over that second | | `umtool export` as cut / `--context N` | drawn (the export says how many) | -| Play (the canvas), the live preview | drawn over the picture, the same boxes, spans and style | -| Present, its public payload too | drawn over the picture (`hidden` on each clip slide); no viewer toggle lifts them | -| the clip editor's player, the clip bench | drawn as an overlay, outlined, with **Peek** (off by default) to see under them there only | +| **overlaid on the operator's screen, not hidden in the file** | | +| Play (the canvas), the live deck preview | drawn over the raw window: the same boxes, spans and style | +| Present (the operator's) | drawn over the raw window (`hidden` on each clip slide); no toggle lifts them | +| the clip editor's player, the clip bench | outlined and filled, with **Peek** (off by default) to see under them there only | +| the claim bench, the candidates panel, a cited clip (the article player) | the RECORDING's boxes (`render.censor` matched on its video; a cited project clip's own too), outlined, Peek off | +| **public** | | +| Present's public payload (`public=1`, `umtool present --public`) | a clip with boxes carries NO raw window (`media: null`): it plays its BUILT segment (`/api/report/segment`, when that segment's record hides exactly its boxes: `censored.segment`), else the slide says the clip is not shown (`censored: null`). A page outside umtool cannot reach `/api/report/*` at all, so a public export must carry the segment itself | +| **refused** | | | a montage (`render.montage`) | REFUSED by name (a montage re-cuts its pictures and draws no boxes yet) | | a basic cut (`render.mode: "basic"`) | REFUSED by name, `render.blur: "off"` or not | | `umtool export --raw` | REFUSED by name; `--uncensored-raw` (the app: `uncensoredRaw`) exports as recorded and says UNCENSORED | | `--chrome-only` / `--chrome-preview` | REFUSED when a segment on disk hides other boxes than the cut asks for (a box added, changed or taken off since): build again | | `umtool vertical --reframe` | REFUSED when a clip's boxes changed since the take was rendered (it cuts the take's finished picture) | -Not drawn: the claim bench's and the candidates panel's windows (no clip yet -- a recording's boxes are not looked up -there), and the rendered segment previews (already cut with them). +The rendered segment previews (the bench's) play the built segment, which hides them in the file. | Knob | Values (default) | What it does | |---|---|---| diff --git a/umtool/lib/clips/cited.test.ts b/umtool/lib/clips/cited.test.ts @@ -6,14 +6,17 @@ // Run with: pnpm --filter umtool exec tsx --test lib/clips/cited.test.ts import { before, test } from "node:test"; import assert from "node:assert/strict"; -import { mkdtemp } from "node:fs/promises"; +import { mkdir, mkdtemp, writeFile } from "node:fs/promises"; import os from "node:os"; import path from "node:path"; let lib: typeof import("./cited"); +let ROOT = ""; before(async () => { - process.env.CHANNELS_DIR = path.join(await mkdtemp(path.join(os.tmpdir(), "umtool-cited-")), "channels"); + ROOT = await mkdtemp(path.join(os.tmpdir(), "umtool-cited-")); + process.env.CHANNELS_DIR = path.join(ROOT, "channels"); + process.env.REPORTS_DIR = path.join(ROOT, "reports"); lib = await import("./cited"); }); @@ -81,3 +84,19 @@ test("Cut from the stored media URL rides on the fetch as fetch_clip's storedUrl await lib.fetchCitedClip({ target, reason: "review" }, plain.deps); assert.equal("storedUrl" in (plain.calls[0].body ?? {}), false); }); + +test("a cited span of a project carries the regions it hides on that recording: its clip's, else the recording's", async () => { + const dir = path.join(ROOT, "reports", "hide"); + await mkdir(path.join(dir, "out", "clips-raw"), { recursive: true }); + await writeFile(path.join(dir, "out", "clips-raw", "vid1_0.00-10.00.mp4"), "a window"); + await writeFile(path.join(dir, "video.manifest.json"), JSON.stringify({ + schemaVersion: 1, slug: "hide", title: "Hide", + provenance: { channelSlug: "chan", channelsDir: path.join(ROOT, "channels") }, + render: { fps: 30, censor: [{ video: "vid1", boxes: [[0.75, 0, 0.25, 1]], style: "black" }] }, + timeline: [{ type: "clip", id: "c1", channel: "chan", video: "vid1", start: 2, end: 6, censor: { boxes: [[0, 0, 0.2, 0.2]] } }], + })); + const play = await lib.findCitedPlay({ channel: "chan", video: "vid1", from: 2, to: 6, project: "hide", clip: "c1" }); + assert.ok(play, "the project's window plays"); + assert.equal(play.kind, "window"); + assert.equal(play.hidden?.length, 2, "the recording's box and the clip's own"); +}); diff --git a/umtool/lib/clips/cited.ts b/umtool/lib/clips/cited.ts @@ -8,7 +8,7 @@ import { resolveEvidenceSource } from "yt-dlp-transcript-common/lib/evidenceClip import { CHANNELS_DIR } from "@/lib/paths"; import { answerOf } from "@/lib/research/fetch"; import { SourceError } from "@/lib/research/sources"; -import { projectCache, resolveClip, windowVersion, windowsFor } from "@/lib/report/serve.mjs"; +import { projectCache, resolveClip, resolveReport, windowVersion, windowsFor } from "@/lib/report/serve.mjs"; import { corpusMediaUrl } from "@/lib/articles/article"; import type { CitedFetchAnswer, CitedPlay, CitedTarget } from "./types"; import { fetchFailureSentence } from "./words"; @@ -80,9 +80,22 @@ async function projectPlay(t: CitedTarget): Promise<CitedPlay | null> { }; } -/** What plays the span now, or null (nothing on disk: offer Fetch clip). */ +/** What plays the span now, or null (nothing on disk: offer Fetch clip). A project's hidden regions ride along. */ export async function findCitedPlay(t: CitedTarget): Promise<CitedPlay | null> { - return (await projectPlay(t)) ?? (await corpusPlay(t)); + const play = (await projectPlay(t)) ?? (await corpusPlay(t)); + if (!play || play.audio || !t.project) return play; + const hidden = await citedHidden(t); + return hidden.length ? { ...play, hidden } : play; +} + +/** The regions a project hides on the cited recording: its clip's (render.censor's and its own), else the recording's. */ +async function citedHidden(t: CitedTarget) { + const { censorRegionsOf, recordingRegionsOf } = await import("umtool-report-to-video/clip-censor"); + const r = t.clip ? await resolveClip(t.project as string, t.clip).catch(() => null) : null; + if (r && !("error" in r)) return censorRegionsOf(r.clip, r.manifest.render ?? {}, r.manifest.provenance ?? {}); + const rep = await resolveReport(t.project as string).catch(() => null); + if (!rep || "error" in rep) return []; + return recordingRegionsOf(t.video, t.channel, rep.manifest.render ?? {}, rep.manifest.provenance ?? {}); } /** Parse a target from a query string or a JSON body; throws a 400 in words. */ diff --git a/umtool/lib/clips/types.ts b/umtool/lib/clips/types.ts @@ -9,6 +9,11 @@ export type CitedPlay = { offset: number; audio: boolean; label: string; + /** + * The regions the project hides on this recording (clip-censor.mjs: the clip's own and render.censor's, or the + * recording's alone where no clip is named), on the SOURCE clock: the player overlays them. Absent: none. + */ + hidden?: Array<{ box: number[]; style: "blur" | "black" | "pixelate"; strength: number; from: number | null; to: number | null }>; }; /** diff --git a/umtool/lib/report/present.mjs b/umtool/lib/report/present.mjs @@ -36,7 +36,7 @@ import { clockZoneOf } from "umtool-report-to-video/post-clock"; import { estimateSchedule } from "umtool-report-to-video/deck"; import { gapsOf, keptSpans } from "umtool-report-to-video/gaps"; import { clipBlurOf } from "umtool-report-to-video/clip-blur"; -import { censorRegionsOf } from "umtool-report-to-video/clip-censor"; +import { censorRecordOf, censorRegionsOf } from "umtool-report-to-video/clip-censor"; import { playViewWith } from "./playView.mjs"; import { projectRedaction } from "./postRedaction.mjs"; import { sectionModel } from "./sectionEdit.mjs"; @@ -316,9 +316,14 @@ function postSlideId(e) { * THE PAYLOAD, pure (the tests' door): Play's view of the cut, the cut itself, the project's redaction and the * deck's estimated schedule -> the presentation. * - * @param {{ view: Record<string, any>, manifest: Record<string, any>, red: any, canUncensor?: boolean }} o + * A clip that hides regions of its picture (clip-censor.mjs) carries NO raw window on a payload that cannot uncensor: + * its `media` is null, and `censored` names its BUILT segment when one hides exactly its regions (`censoredSegments`, + * read by presentPayload: `{v, seconds}` by entry id), else null -- the slide says the clip is not shown. The + * operator's payload keeps the window, the regions overlaid on the operator's screen. + * + * @param {{ view: Record<string, any>, manifest: Record<string, any>, red: any, canUncensor?: boolean, censoredSegments?: Map<string, { v: number, seconds: number | null }> }} o */ -export function presentFrom({ view, manifest, red, canUncensor = true }) { +export function presentFrom({ view, manifest, red, canUncensor = true, censoredSegments = new Map() }) { const render = manifest.render ?? {}; const timeline = (Array.isArray(manifest.timeline) ? manifest.timeline : []).filter((e) => e && typeof e.id === "string"); const zone = clockZoneOf(render); @@ -422,6 +427,10 @@ export function presentFrom({ view, manifest, red, canUncensor = true }) { const to = fin(e.cutEnd) ? e.cutEnd : e.end; const spans = keptSpans(from, to, gapsOf(e)); const day = dayOfKey(e.dateKey); + // Its hidden regions (clip-censor.mjs). A public payload never names the raw window of a clip that has them. + const hidden = censorRegionsOf(src, render, manifest.provenance ?? {}); + const withheld = !canUncensor && hidden.length > 0; + const seg = withheld ? (censoredSegments.get(e.id) ?? null) : null; slides.push({ id: unique(e.id), kind: "clip", @@ -432,7 +441,8 @@ export function presentFrom({ view, manifest, red, canUncensor = true }) { dateLabel: dayLabel(day), video: e.video, channel: e.channel ?? null, - media: e.media ?? null, + media: withheld ? null : (e.media ?? null), + ...(withheld ? { censored: seg ? { segment: seg.v, seconds: seg.seconds } : null } : {}), spans, seconds: Math.round(spans.reduce((n, s) => n + (s.to - s.from), 0) * 1000) / 1000, title: words?.title || text(e.heading), @@ -440,8 +450,8 @@ export function presentFrom({ view, manifest, red, canUncensor = true }) { quote: e.quote ?? null, qrUrl: words?.qrUrl ?? null, blur: clipBlurOf(src, render), - // Its hidden regions (clip-censor.mjs): drawn over the picture on every Present page, a public one too. - hidden: censorRegionsOf(src, render, manifest.provenance ?? {}), + // The operator's page overlays them on the raw window (on the screen, not in the file). + hidden, }); continue; } @@ -518,5 +528,31 @@ export async function presentPayload(project, { take = null, bare = false, canUn if ("error" in r) return r; const { anonymiseManifest } = await import("umtool-report-to-video/post-anon"); const manifest = anonymity ? anonymiseManifest(r.manifest, anonymity.doc, { set: anonymity.set }) : r.manifest; - return presentFrom({ view: r.view, manifest, red, canUncensor }); + return presentFrom({ view: r.view, manifest, red, canUncensor, censoredSegments: canUncensor ? new Map() : await censoredSegmentsOf(project, manifest) }); +} + +/** + * The BUILT segments (/api/report/segment: the project's out/, its cut record beside it) that hide exactly the + * regions a clip asks for now, by entry id -- what a public Present plays instead of the raw window. A segment cut + * with other boxes (or none) is not used. + * + * @param {{ id: string, dir: string }} project + * @param {Record<string, any>} manifest + */ +export async function censoredSegmentsOf(project, manifest) { + const { segmentFor } = await import("./serve.mjs"); + const { readFile } = await import("node:fs/promises"); + const out = new Map(); + for (const e of manifest.timeline ?? []) { + if (e?.type !== "clip") continue; + const want = censorRecordOf(censorRegionsOf(e, manifest.render ?? {}, manifest.provenance ?? {})); + if (!want.length) continue; + const seg = await segmentFor(project, e.id).catch(() => null); + if (!seg) continue; + const rec = await readFile(/* turbopackIgnore: true */ seg.abs.replace(/\.mp4$/, ".cut.json"), "utf8").then(JSON.parse, () => null); + if (JSON.stringify(rec?.censor ?? []) !== JSON.stringify(want)) continue; + const seconds = typeof rec?.start === "number" && typeof rec?.end === "number" ? Math.round((rec.end - rec.start) * 1000) / 1000 : null; + out.set(e.id, { v: seg.mtimeMs, seconds }); + } + return out; } diff --git a/umtool/lib/report/present.test.mjs b/umtool/lib/report/present.test.mjs @@ -14,6 +14,8 @@ const ROOT = await mkdtemp(path.join(tmpdir(), "umtool-present-")); after(() => rm(ROOT, { recursive: true, force: true })); // Never the real corpus: the play view looks for cached windows and markup under the channels dir. process.env.CHANNELS_DIR = path.join(ROOT, "channels"); +// The projects are under it: the built-segment lookup (serve.mjs segmentFor) reads only inside the read roots. +process.env.REPORTS_DIR = path.join(ROOT, "reports"); process.env.UMTOOL_PRINTS_CACHE = path.join(ROOT, "prints"); const { presentPayload, presentFrom, censorData, publicPostEntry, dayIn, dayLabel, isPostReel, PRESENT_DEFAULTS } = await import("./present.mjs"); @@ -260,3 +262,38 @@ test("hidden regions (clip-censor.mjs): a clip slide carries its own boxes and i const view = await playView(p); assert.equal(view.entries.find((e) => e.id === "c01").censor.length, 2, "Play draws the same boxes"); }); + +test("a PUBLIC payload never names the raw window of a clip that hides regions: its built segment when it hides exactly them, else none; the operator's keeps the window", async () => { + const own = { style: "black", boxes: [[0.1, 0.1, 0.2, 0.2]] }; + const timeline = [ + { type: "clip", id: "c01", video: "v1", start: 1, end: 3, lock: true, censor: own }, + { type: "clip", id: "c02", video: "v2", start: 1, end: 3, lock: true }, + ]; + const p = await project("withheld", timeline); + await mkdir(path.join(p.dir, "out", "clips-raw"), { recursive: true }); + await writeFile(path.join(p.dir, "out", "clips-raw", "v1_0.00-6.00.mp4"), "raw window one"); + await writeFile(path.join(p.dir, "out", "clips-raw", "v2_0.00-6.00.mp4"), "raw window two"); + const op = await presentPayload(p); + assert.equal(op.slides.find((s) => s.id === "c01").media?.name, "v1_0.00-6.00.mp4", "the operator's page plays the window, overlaid"); + const pub = await presentPayload(p, { canUncensor: false }); + const json = JSON.stringify(pub); + assert.ok(!json.includes("v1_0.00-6.00"), "no path to the raw window anywhere in the public payload"); + const c1 = pub.slides.find((s) => s.id === "c01"); + assert.equal(c1.media, null); + assert.equal(c1.censored, null, "no build here: the slide says it is not shown"); + // The same clip without regions: unchanged. + assert.deepEqual(pub.slides.find((s) => s.id === "c02"), (await presentPayload(p, { canUncensor: false })).slides.find((s) => s.id === "c02")); + assert.equal(pub.slides.find((s) => s.id === "c02").media?.name, "v2_0.00-6.00.mp4"); + assert.equal("censored" in pub.slides.find((s) => s.id === "c02"), false); + // A built segment that hides exactly its regions: played instead; one cut with other boxes is not. + const segs = path.join(p.dir, "out", "segments"); + await mkdir(segs, { recursive: true }); + await writeFile(path.join(segs, "c01.mp4"), "built"); + await writeFile(path.join(segs, "c01.cut.json"), JSON.stringify({ version: 1, id: "c01", start: 1, end: 3, censor: [] })); + assert.equal((await presentPayload(p, { canUncensor: false })).slides.find((s) => s.id === "c01").censored, null, "a segment cut without the boxes"); + await writeFile(path.join(segs, "c01.cut.json"), JSON.stringify({ version: 1, id: "c01", start: 1, end: 3, censor: [{ box: [0.1, 0.1, 0.2, 0.2], style: "black" }] })); + const built = (await presentPayload(p, { canUncensor: false })).slides.find((s) => s.id === "c01"); + assert.equal(typeof built.censored.segment, "number"); + assert.equal(built.censored.seconds, 2); + assert.equal(built.media, null); +}); diff --git a/umtool/report-to-video/clip-censor.mjs b/umtool/report-to-video/clip-censor.mjs @@ -130,6 +130,13 @@ export function censorRegionsOf(entry, render, provenance = {}) { return out; } +/** + * The regions `render.censor` hides on a RECORDING (its video, and channel when known), for a player of it where no + * clip exists yet (the claim bench, a candidate, a cited span): its recording's boxes, none of a clip's own. + */ +export const recordingRegionsOf = (video, channel, render, provenance = {}) => + typeof video === "string" && video ? censorRegionsOf({ type: "clip", id: "~recording", video, ...(typeof channel === "string" && channel ? { channel } : {}) }, render, provenance) : []; + const f3 = (n) => Number(n).toFixed(3); /** diff --git a/umtool/report-to-video/clip-censor.test.mjs b/umtool/report-to-video/clip-censor.test.mjs @@ -5,7 +5,7 @@ import assert from "node:assert/strict"; import { chmodSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs"; import { tmpdir } from "node:os"; import path from "node:path"; -import { censorParts, censorProblems, censorRecordOf, censorRegionsOf, clipCensorErrors, namesClip, renderCensorErrors, stillCensorArgs, validateCensor } from "./clip-censor.mjs"; +import { recordingRegionsOf, censorParts, censorProblems, censorRecordOf, censorRegionsOf, clipCensorErrors, namesClip, renderCensorErrors, stillCensorArgs, validateCensor } from "./clip-censor.mjs"; import { buildVideo, segmentFraming, setProgressMode } from "./build-video.mjs"; import { mergeCensor, withOverrides } from "./vertical-plan.mjs"; import { parseBox, withRecording } from "../lib/report/censorCli.mjs"; @@ -142,3 +142,11 @@ test("a batch's snapshot never takes a box off (mergeCensor, withOverrides): the assert.deepEqual(withOverrides(tl, { c1: { censor: null, vertical: null } })[0].censor, { boxes: [A] }, "a box added after the batch is kept"); assert.equal("censor" in withOverrides([{ ...tl[0], censor: undefined }], { c1: { censor: null } })[0], false); }); + +test("a recording's regions where no clip exists yet (recordingRegionsOf): render.censor matched on its video and channel", () => { + const render = { censor: [CHAT, TAB, { video: "other", boxes: [[0, 0, 0.5, 0.5]] }] }; + assert.equal(recordingRegionsOf("rec1", "chan", render, {}).length, 2); + assert.equal(recordingRegionsOf("rec1", "elsewhere", render, {}).length, 1, "TAB names its channel"); + assert.deepEqual(recordingRegionsOf("rec2", null, render, {}), []); + assert.deepEqual(recordingRegionsOf(null, null, render, {}), []); +}); diff --git a/umtool/report-to-video/clip-zoom.mjs b/umtool/report-to-video/clip-zoom.mjs @@ -183,7 +183,8 @@ function pushExpr(z, t) { */ export function zoomFilters(zooms, { srcW, srcH, fps }) { if (!zooms?.length) return []; - const t = `(in/${fps})`; + // perspective's `in` counts frames from 1 (enable's `n` from 0): frame n is at (in − 1) / fps. + const t = `((in-1)/${fps})`; const Z = `(1+${zooms.map((z) => pushExpr(z, t)).join("+")})`; // The focus of the push under way (a nested choice by span); outside every push the filter is off. const pick = (k) => zooms.reduceRight((acc, z) => `if(between(${t},${f(z.at)},${f(zoomEnd(z))}),${f(z.focus[k])},${acc})`, "0.5"); diff --git a/umtool/report-to-video/clip-zoom.test.mjs b/umtool/report-to-video/clip-zoom.test.mjs @@ -87,7 +87,7 @@ test("the filter: frames at the cut's rate, a sub-pixel perspective eased by smo assert.deepEqual(zoomFilters([], { srcW: 1920, srcH: 1080, fps: 30 }), []); const [fps, zp] = zoomFilters([{ at: 2, ramp: 0.4, hold: 1.5, scale: 1.5, focus: [0.75, 0.3] }], { srcW: 1920, srcH: 1080, fps: 30 }); assert.equal(fps, "fps=30"); - assert.match(zp, /^perspective=x0='if\(between\(\(in\/30\),2\.0000,4\.3000\),0\.7500,0\.5\)\*W\*\(1-1\/\(1\+if\(between\(\(in\/30\),2\.0000,4\.3000\),0\.5000\*if\(lt\(\(in\/30\),2\.4000\),/); + assert.match(zp, /^perspective=x0='if\(between\(\(\(in-1\)\/30\),2\.0000,4\.3000\),0\.7500,0\.5\)\*W\*\(1-1\/\(1\+if\(between\(\(\(in-1\)\/30\),2\.0000,4\.3000\),0\.5000\*if\(lt\(\(\(in-1\)\/30\),2\.4000\),/); assert.match(zp, /\*\(3-2\*/, "smoothstep"); assert.match(zp, /:interpolation=cubic:sense=source:eval=frame:enable='between\(n\/30,2\.0000,4\.3000\)'$/); assert.doesNotMatch(zp, /zoompan/, "zoompan rounds its crop to whole pixels: a slow ease wobbles"); @@ -119,6 +119,24 @@ test("a slow push (1 s eases, 2 s held: 4 s) moves the picture monotonically -- if (t(i) > z.at + z.ramp + z.hold && t(i) <= zoomEnd(z) && d > 0.02) steps.push(`out at ${t(i).toFixed(2)} s: +${d.toFixed(2)} px`); } assert.deepEqual(steps, [], "a back-step in the ease"); + // On time, frame by frame: the edge where the eased zoom puts it at that frame's second -- 160·(Z − 1) px past 480 + // (focus in the middle). One frame early or late is off by tenths of a pixel in the ramps. + const ease = (u) => u * u * (3 - 2 * u); + const want = (s) => { + if (s < z.at || s > zoomEnd(z)) return 480; + const u = s < z.at + z.ramp ? ease((s - z.at) / z.ramp) : s < z.at + z.ramp + z.hold ? 1 : ease((zoomEnd(z) - s) / z.ramp); + return 480 + 160 * (z.scale - 1) * u; + }; + const off = edge.map((e, i) => Math.abs(e - want(t(i)))); + assert.ok(Math.max(...off) < 0.06, `frame ${off.indexOf(Math.max(...off))} is ${Math.max(...off).toFixed(3)} px off its second`); + // The first pushed frame (at 0.5 s, the ease at 0) is still the source; the next has moved; the last eased frame + // (one before 4.5 s) is a hair out, the one at 4.5 s back home. + const first = Math.round(z.at * FPS); + const last = Math.round(zoomEnd(z) * FPS); + assert.ok(Math.abs(edge[first] - 480) < 0.01, `the first pushed frame ${edge[first]}`); + assert.ok(edge[first + 1] - 480 > 0.015, `the second pushed frame ${edge[first + 1]}`); + assert.ok(edge[last - 1] - 480 > 0.015, `the last eased frame ${edge[last - 1]}`); + assert.ok(Math.abs(edge[last] - 480) < 0.01, `the push over ${edge[last]}`); // Pushed in about the centre: the edge at 480 lands at (480 − 0.5·640·(1 − 1/1.06))·1.06 = 489.6 while held. const held = edge[Math.round((z.at + z.ramp + 1) * FPS)]; assert.ok(Math.abs(held - 489.6) < 0.3, `held at ${held}`);