commit 163c8ac76d64eb0a7f46dad30c6cd22689500851
parent 3d3d0f76a439eb3451de3e68533d4ce564dea4ed
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Thu, 5 Nov 2026 15:58:48 -0500
umtool: timeline add-video / set-video -- a video entry into the cut or a take only, its knobs set
`umtool timeline <p> [--take <t>] add-video <src> [--from S] [--to S] [--fit]
[--bass dB] [--gain dB] [--enter cut|<out>,<in>] [--hold S] [--title T] [--id ID]
[--after <id>|-] [--dry-run] [--json]` (the file probed: fileSeconds), and
`set-video <id> key=value...` through updateVideoEntry / updateTakeVideoEntry;
checked as the build checks it. Exit 0 / 1 refused / 2 usage. ls shows its span.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Diffstat:
4 files changed, 230 insertions(+), 4 deletions(-)
diff --git a/umtool/lib/report/manifest.mjs b/umtool/lib/report/manifest.mjs
@@ -40,7 +40,7 @@ import { verticalErrors } from "umtool-report-to-video/look";
import { LOOK_KEYS, applyLookPatch, lookOf } from "yt-dlp-transcript-common/lib/report/look.mjs";
import { sideErrors } from "yt-dlp-transcript-common/lib/report/vertical.mjs";
import { validateRoom } from "umtool-report-to-video/room";
-import { validateVideoEntries } from "umtool-report-to-video/video-entry";
+import { applyVideoPatch, validateVideoEntries, validateVideoEntry } from "umtool-report-to-video/video-entry";
import { applySectionEnter } from "./sections.mjs";
import { citeUrlAt, parseClipSpec } from "./clipEditorModel.mjs";
import { addSectionIn, followSplitMarkers, moveBoundaryIn, moveToSectionIn, placeIn, reanchorMarkers, removeBoundaryIn, sectionModel, sectionWords, setSectionIn } from "./sectionEdit.mjs";
@@ -3765,6 +3765,25 @@ const TEASER_PATCH_KEYS = ["lines", "beat", "dip", "tail", "tailWait"];
* @param {Record<string, unknown>} patch
* @param {{ token?: string | null, at?: number | null }} [opts]
*/
+/**
+ * SET a video entry's knobs (video-entry.mjs applyVideoPatch: from, to, fit,
+ * audio.bass, audio.gain, enter, holdLast, deck, title, note, src), checked as
+ * the build checks it; one undo point.
+ */
+export async function updateVideoEntry(dir, id, patch, { token = null, at = null } = {}) {
+ if (!patch || typeof patch !== "object" || !Object.keys(patch).length) throw new Error("nothing to change");
+ return structural(dir, "video", token, (m) => {
+ const i = entryIndex(m.timeline, id, at);
+ const e = m.timeline[i];
+ if (e.type !== "video") throw new Error(`${id} is a ${e.type ?? "non-video"} entry, not a video`);
+ const next = applyVideoPatch(e, patch);
+ const errors = validateVideoEntry(next, `timeline[${i}] (${id})`);
+ if (errors.length) throw new Error(errors.join("; "));
+ m.timeline[i] = next;
+ return { id, at: i, entry: next };
+ });
+}
+
export async function updateTeaser(dir, id, patch, { token = null, at = null } = {}) {
if (!patch || typeof patch !== "object" || Array.isArray(patch)) throw new Error("a teaser patch is an object");
const keys = Object.keys(patch);
diff --git a/umtool/lib/report/takeEdit.mjs b/umtool/lib/report/takeEdit.mjs
@@ -347,6 +347,33 @@ export async function insertTakeEntry(projectDir, id, afterId, spec, { token = n
);
}
+/**
+ * SET a video entry's knobs in a TAKE's timeline (video-entry.mjs
+ * applyVideoPatch), checked as the build checks it; an undo point of the take's.
+ */
+export async function updateTakeVideoEntry(projectDir, id, entryId, patch, { token = null, at = null, now = new Date() } = {}) {
+ const { applyVideoPatch, validateVideoEntry } = await import("umtool-report-to-video/video-entry");
+ if (!patch || typeof patch !== "object" || !Object.keys(patch).length) throw new Error("nothing to change");
+ return editTakeTimeline(
+ projectDir,
+ id,
+ "video",
+ token,
+ (m) =>
+ applyStructural(m, (x) => {
+ const i = entryIndex(x.timeline, entryId, at);
+ const e = x.timeline[i];
+ if (e.type !== "video") throw new Error(`${entryId} is a ${e.type ?? "non-video"} entry, not a video`);
+ const next = applyVideoPatch(e, patch);
+ const errors = validateVideoEntry(next, `timeline[${i}] (${entryId})`);
+ if (errors.length) throw new Error(errors.join("; "));
+ x.timeline[i] = next;
+ return { id: entryId, at: i, entry: next };
+ }),
+ { now },
+ );
+}
+
/** A take's label: one line, at most this long. */
export const TAKE_LABEL_MAX = 200;
diff --git a/umtool/lib/report/timelineCli.mjs b/umtool/lib/report/timelineCli.mjs
@@ -88,6 +88,7 @@ import {
undoStructural,
updateClip,
updateTeaser,
+ updateVideoEntry,
upsertPost,
} from "./manifest.mjs";
@@ -165,6 +166,12 @@ export const TIMELINE_USAGE = [
" umtool timeline <project> groups promote <gid> [--label L] the group opens a subsection: a level-2 marker at",
" its first clip titled with its claim (--label when it is over 24); the render sees only this",
" A clip moved out of its group's run leaves the group; moved alone into the middle of a run, it joins it",
+ " umtool timeline <project> [--take <t>] add-video <src> [--from S] [--to S] [--fit contain|cover] [--bass dB]",
+ " [--gain dB] [--enter cut|<out>[,<in>]] [--hold S] [--title T] [--id ID] [--after <id>|-] [--dry-run] [--json]",
+ " a VIDEO ENTRY: a file of the project (src, relative) played FULL FRAME with its sound, no chrome over it;",
+ " at the end unless --after (`-`: the start); --from/--to source seconds (no --to: the file's end)",
+ " umtool timeline <project> [--take <t>] set-video <id> <key>=<value>… from= to= fit= audio.bass= audio.gain=",
+ " enter=cut|<out>,<in> enter.out= enter.in= holdLast= deck=hidden|shown title= note= src= (`key=` clears)",
" umtool timeline <project> --take <id> [ls | move <id> --to <index> | remove <id> | undo | insert <spec> --after <id>|-]",
" a take's timeline (walk a take): written into the take's patch (takes/<id>/take.json),",
" each write with an undo point of the take's own; the project's manifest is untouched",
@@ -174,9 +181,9 @@ export const TIMELINE_USAGE = [
].join("\n");
const SECTION_VERBS = ["sections", "section-move", "section-add", "section-boundary", "section-remove", "section-set"];
-const VERBS = ["ls", "insert", "move", "place", "remove", "reject", "wrong-speaker", "duplicate", "post", "post-remove", "teaser", "undo", ...SECTION_VERBS, "split", "flash-forward", "order", "groups", "threads"];
+const VERBS = ["ls", "insert", "add-video", "set-video", "move", "place", "remove", "reject", "wrong-speaker", "duplicate", "post", "post-remove", "teaser", "undo", ...SECTION_VERBS, "split", "flash-forward", "order", "groups", "threads"];
const GROUP_VERBS = ["ls", "import", "set", "move", "label", "promote", "remove"];
-const VALUED = new Set(["--group", "--after", "--before", "--to", "--at", "--id", "--section", "--title", "--stream-title", "--date", "--quote", "--cite", "--cite-url", "--take", "--correction", "--note", "--to-section", "--label", "--color", "--level", "--claim", "--conversation"]);
+const VALUED = new Set(["--group", "--after", "--before", "--to", "--at", "--id", "--section", "--title", "--stream-title", "--date", "--quote", "--cite", "--cite-url", "--take", "--correction", "--note", "--to-section", "--label", "--color", "--level", "--claim", "--conversation", "--from", "--fit", "--bass", "--gain", "--enter", "--hold"]);
/** What `--take <id>` does on a take's timeline (takeEdit.mjs): the walk's structure and its undo. */
const TAKE_VERBS = ["ls", "move", "remove", "undo", "insert"];
@@ -281,6 +288,8 @@ export function timelineRows(manifest) {
media: Array.isArray(e.media) ? e.media.map((m) => m?.kind) : [],
}
: {}),
+ // A video entry (video-entry.mjs): its file and the source span it plays.
+ ...(e.type === "video" ? { src: String(e.src ?? ""), from: e.from ?? 0, to: e.to ?? e.fileSeconds ?? null } : {}),
date: typeof e.date === "string" ? (e.type === "post" ? e.date.slice(0, 10) : e.date) : null,
title: typeof title === "string" ? title : e.type === "post" ? `${String(e.text ?? "").replace(/^RT @[A-Za-z0-9_]+:\s*/, "").replace(/\s+/g, " ").trim().slice(0, 60)}` : null,
};
@@ -295,7 +304,9 @@ export function timelineLines(rows) {
r.type === "clip"
? `${String(r.video ?? "?").padEnd(14)} ${fmt(r.start)}–${fmt(r.end)}${r.cutStart != null ? ` (cut ${fmt(r.cutStart)}–${fmt(r.cutEnd)})` : ""}` +
(r.gaps?.length ? ` gaps ${r.gaps.map((g) => `−${fmt(g.from)}–${fmt(g.to)}`).join(" ")} (plays ${fmt(r.plays)}s)` : "")
- : r.type === "post"
+ : r.type === "video"
+ ? `${String(r.src ?? "").padEnd(14)} ${fmt(r.from)}–${r.to == null ? "end" : fmt(r.to)}`
+ : r.type === "post"
? `${String(r.post ?? "").padEnd(14)} ${fmt(r.seconds)}s ${r.media?.length ? r.media.join("+") : "text"}`
: "".padEnd(14);
const label = [r.date, r.title].filter(Boolean).join(" ");
@@ -501,6 +512,8 @@ export async function timelineCommand(args, { root = REPORTS_ROOT, out = (s) =>
}
if (!VERBS.includes(verb)) throw new CliError(`unknown: timeline ${verb} — ${VERBS.join(", ")}`);
const project = await projectOf(projectArg, root);
+ // A video entry (video-entry.mjs), into the cut or a take's timeline.
+ if (verb === "add-video" || verb === "set-video") return await videoVerb(project, verb, rest, flags, { out, json });
if (flags.has("--take")) return await takeTimeline(project, String(flags.get("--take")), verb, rest, flags, { out, json });
const manifest = await readManifest(project.dir);
if (!manifest) throw new CliError(`${project.id} has no manifest`);
@@ -910,6 +923,131 @@ async function takeTimeline(project, take, verb, rest, flags, { out, json }) {
return 0;
}
+/** A number flag, or null when absent; a usage error when it is not one. */
+function numFlag(flags, name) {
+ if (!flags.has(name)) return null;
+ const v = flags.get(name);
+ const n = Number(v);
+ if (v === true || v === "" || !Number.isFinite(n)) throw new CliError(`${name} needs a number (got ${v === true ? "nothing" : v})`);
+ return n;
+}
+
+/** A file's length in seconds (ffprobe), or null. */
+async function probeSeconds(file) {
+ const { execFile } = await import("node:child_process");
+ return new Promise((resolve) => {
+ execFile(process.env.FFPROBE ?? "ffprobe", ["-v", "error", "-show_entries", "format=duration:stream=codec_type", "-of", "json", file], (e, stdout) => {
+ if (e) return resolve(null);
+ try {
+ const doc = JSON.parse(stdout);
+ const d = Number(doc.format?.duration);
+ resolve({ seconds: Number.isFinite(d) && d > 0 ? Math.round(d * 1000) / 1000 : null, hasVideo: (doc.streams ?? []).some((x) => x.codec_type === "video") });
+ } catch {
+ resolve(null);
+ }
+ });
+ });
+}
+
+/**
+ * `umtool timeline <p> [--take <t>] add-video <src> …` and `set-video <id> k=v…`: a VIDEO ENTRY
+ * (video-entry.mjs) put into the cut -- or the take's timeline only -- through the timeline's writers,
+ * checked as the build checks it. `--dry-run`: the entry and where it goes, nothing written.
+ * Exit 0 · 1 refused (no such file, take or entry; the build would not take it) · 2 usage.
+ */
+async function videoVerb(project, verb, rest, flags, { out, json }) {
+ const V = await import("umtool-report-to-video/video-entry");
+ const take = flags.has("--take") ? String(flags.get("--take")) : null;
+ const dry = flags.has("--dry-run");
+ const edit = take ? await import("./takeEdit.mjs") : null;
+ let timeline;
+ if (take) {
+ const { resolveTakeManifest } = await import("./takeManifest.mjs");
+ timeline = (await resolveTakeManifest(project.dir, take)).manifest.timeline ?? [];
+ } else {
+ const manifest = await readManifest(project.dir);
+ if (!manifest) throw new CliError(`${project.id} has no manifest`);
+ timeline = manifest.timeline ?? [];
+ }
+ const where = take ? `take ${take} of ${project.id}` : project.id;
+ let result;
+ if (verb === "add-video") {
+ const src = rest[0];
+ if (!src) throw new CliError("add-video needs <src>: a video file of the project, relative to its directory");
+ const rel = src.replace(/^\.\//, "");
+ const file = path.resolve(project.dir, rel);
+ const r = path.relative(project.dir, file);
+ if (path.isAbsolute(src) || r.startsWith("..")) throw new CliError(`${src}: a video entry plays a file INSIDE the project (relative to ${project.dir})`);
+ const probe = await probeSeconds(file);
+ if (!probe) throw new Error(`no video at ${file} (src: ${rel})`);
+ if (!probe.hasVideo) throw new Error(`${rel} has no picture -- a video entry plays a video`);
+ const patch = {};
+ for (const [flag, key] of [["--from", "from"], ["--to", "to"], ["--hold", "holdLast"], ["--bass", "audio.bass"], ["--gain", "audio.gain"]]) {
+ const n = numFlag(flags, flag);
+ if (n !== null) patch[key] = n;
+ }
+ if (flags.has("--fit")) patch.fit = String(flags.get("--fit"));
+ if (flags.has("--enter")) patch.enter = String(flags.get("--enter"));
+ if (flags.has("--title")) patch.title = String(flags.get("--title"));
+ let entry;
+ try {
+ entry = V.applyVideoPatch({ type: "video", id: flags.has("--id") ? String(flags.get("--id")) : "video", src: rel }, patch);
+ } catch (e) {
+ throw new CliError(e instanceof Error ? e.message : String(e));
+ }
+ if (probe.seconds) entry.fileSeconds = probe.seconds;
+ const errors = V.validateVideoEntry(entry, "add-video");
+ if (errors.length) throw new Error(errors.join("; "));
+ const afterArg = flags.has("--after") ? String(flags.get("--after")) : null;
+ const after = afterArg === null ? (timeline.length ? timeline[timeline.length - 1].id : null) : afterArg === "-" || afterArg === "" ? null : afterArg;
+ if (after && !timeline.some((e) => e?.id === after)) throw new Error(`no entry ${after} in ${where}`);
+ const at = after ? timeline.findIndex((e) => e?.id === after) + 1 : 0;
+ if (dry) {
+ const span = V.videoSpan(entry, probe.seconds);
+ if (json) out(JSON.stringify({ ok: true, op: verb, dryRun: true, ...(take ? { take } : {}), at, after, entry, span, seconds: V.videoSeconds(entry, 0, probe.seconds) }, null, 2));
+ else out(`would add video ${entry.id} at ${at}${after ? ` (after ${after})` : " (the start)"} in ${where}: ${rel} ${span.from}–${span.to} s, ${V.videoFit(entry)}${entry.audio?.bass ? `, bass +${entry.audio.bass} dB` : ""}`);
+ return 0;
+ }
+ result = take
+ ? await edit.insertTakeEntry(project.dir, take, after, entry, { token: await edit.takeToken(project.dir, take) })
+ : await withEditNotes(project, async () => insertEntry(project.dir, after, entry, { token: await manifestToken(project.dir) }));
+ } else {
+ const id = rest[0];
+ if (!id) throw new CliError("set-video needs the video entry's id, then key=value…");
+ const patch = {};
+ for (const a of rest.slice(1)) {
+ const m = /^([a-zA-Z.]+)=(.*)$/s.exec(a);
+ if (!m) throw new CliError(`${a}: a setting is key=value (\`key=\` clears it)`);
+ if (!V.VIDEO_SET_KEYS.includes(m[1])) throw new CliError(`${m[1]} is not a video entry's setting (${V.VIDEO_SET_KEYS.join(", ")})`);
+ patch[m[1]] = m[2] === "" ? null : m[2];
+ }
+ if (!Object.keys(patch).length) throw new CliError("set-video needs at least one key=value");
+ const i = timeline.findIndex((e) => e?.id === id);
+ if (i < 0) throw new Error(`no entry ${id} in ${where}`);
+ if (timeline[i].type !== "video") throw new Error(`${id} is a ${timeline[i].type ?? "non-video"} entry, not a video`);
+ if (dry) {
+ const next = V.applyVideoPatch(timeline[i], patch);
+ const errors = V.validateVideoEntry(next, id);
+ if (errors.length) throw new Error(errors.join("; "));
+ if (json) out(JSON.stringify({ ok: true, op: verb, dryRun: true, ...(take ? { take } : {}), at: i, entry: next }, null, 2));
+ else out(`would set ${id} in ${where}: ${JSON.stringify(next)}`);
+ return 0;
+ }
+ result = take
+ ? await edit.updateTakeVideoEntry(project.dir, take, id, patch, { token: await edit.takeToken(project.dir, take) })
+ : await withEditNotes(project, async () => updateVideoEntry(project.dir, id, patch, { token: await manifestToken(project.dir) }));
+ }
+ const r = result?.result ?? result;
+ if (json) {
+ out(JSON.stringify({ ok: true, op: verb, ...(take ? { take } : {}), [verb === "add-video" ? "inserted" : "updated"]: { id: r.id, at: r.at, entry: r.entry },
+ ...(result?.revision ? { revision: result.revision.rel } : {}) }, null, 2));
+ return 0;
+ }
+ out(`${verb === "add-video" ? "added video" : "set video"} ${r.id} at ${r.at} in ${where}`);
+ if (take && result?.revision) out(` undo point: takes/${take}/${result.revision.rel} (umtool timeline ${project.id} --take ${take} undo)`);
+ return 0;
+}
+
/** `sections`, one line each: §, its marker, colour, label, its clips. */
/**
* `umtool timeline <p> threads [--write [--conversation <id>]]`: the cut's conversations
diff --git a/umtool/report-to-video/video-entry.mjs b/umtool/report-to-video/video-entry.mjs
@@ -262,3 +262,45 @@ export function blackoutEnable(blackouts, shift = 0) {
const n = (v) => String(Math.round(Number(v) * 1e6) / 1e6);
return `:enable='not(${blackouts.map(([a, b]) => `between(t,${n(a - shift)},${n(b - shift)})`).join("+")})'`;
}
+
+/**
+ * A video entry with `patch` applied (VIDEO_SET_KEYS; `audio.bass`, `enter.out`
+ * dotted; `enter: "cut"` or `"<out>,<in>"`; null or "" removes a key). A new
+ * object; the caller validates it (validateVideoEntry). Throws on a key it
+ * does not set.
+ */
+export function applyVideoPatch(entry, patch) {
+ const e = JSON.parse(JSON.stringify(entry));
+ const num = (k, v) => {
+ const n = Number(v);
+ if (!Number.isFinite(n)) throw new Error(`${k} must be a number (got ${v})`);
+ return Math.round(n * 1000) / 1000;
+ };
+ for (const [k, v] of Object.entries(patch ?? {})) {
+ if (!VIDEO_SET_KEYS.includes(k)) throw new Error(`${k} is not a video entry's setting (${VIDEO_SET_KEYS.join(", ")})`);
+ const clear = v === null || v === undefined || v === "";
+ const [head, sub] = k.split(".");
+ if (sub) {
+ if (head === "enter" && (e.enter === "cut" || !isObj(e.enter))) e.enter = {};
+ if (head === "audio" && !isObj(e.audio)) e.audio = {};
+ if (clear) delete e[head][sub];
+ else e[head][sub] = num(k, v);
+ if (!Object.keys(e[head]).length) delete e[head];
+ continue;
+ }
+ if (clear) {
+ delete e[k];
+ continue;
+ }
+ if (k === "from" || k === "to" || k === "holdLast") e[k] = num(k, v);
+ else if (k === "enter") {
+ if (v === "cut") e.enter = "cut";
+ else if (isObj(v)) e.enter = v;
+ else {
+ const [o, i] = String(v).split(",").map((x) => x.trim());
+ e.enter = { out: num("enter.out", o), ...(i !== undefined && i !== "" ? { in: num("enter.in", i) } : {}) };
+ }
+ } else e[k] = String(v);
+ }
+ return e;
+}