commit 06685a3286347badc10efe5eb87554ddb90a0e46 parent b08a6ca150b3d78710efa3bbef483b83bf9e1c66 Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st> Date: Sat, 21 Nov 2026 01:50:05 -0500 umtool: a cut's own name for a channel (render.channelNames), and channelTitle as a clip knob A cut made from two recordings of one channel printed two names for it: each clip is named by its own record, and an older record carries the channel's old uploader name. The only override was a per-clip channelTitle that no verb wrote. - render.channelNames {"<slug>": "<name>"}: a look key (common lib/report/channelNames.mjs holds the rules: at most 60 characters, one line, no control character; a slug no clip uses is a warning, not a refusal). Merged like gapCue: a slug null drops one, null drops all. - The resolver (attribution.mjs channelName / attributionParts / attributionLine) takes the names as a 4th argument: clip channelTitle > the cut's name > the record's uploader name > provenance.channel > slug. Absent or empty: exactly the old answer. - Every place a clip's channel is printed passes them: the burned-in header and the brand's head, the audio-only poster, the vertical source tag, the chapter list, the deck subtitle (schedule, the On-screen preview and route), the stacked deck's source line, a short's end card, the analysis item's citation, the bench's and the walk's sourceChannel. - umtool look <p> channelNames.<slug>=… (= clears one, channelNames= all), WARN for an unused slug; umtool set <p> <clip> channelTitle=… (= clears), checked in patchClipEntry; umtool show lists the names. Co-Authored-By: Claude <noreply@anthropic.com> Diffstat:
23 files changed, 549 insertions(+), 47 deletions(-)
diff --git a/common/lib/report/channelNames.d.mts b/common/lib/report/channelNames.d.mts @@ -0,0 +1,11 @@ +// Types for ./channelNames.mjs (lane channel-title): a cut's per-channel display name. + +type Render = Record<string, unknown> | null | undefined; + +export const CHANNEL_NAME_MAX: number; +export const CHANNEL_SLUG_RE: RegExp; +export function channelNameProblem(value: unknown): string | null; +export function channelNamesOf(render: Render): Record<string, unknown>; +export function validateChannelNames(manifest: unknown): string[]; +export function patchChannelNames(was: unknown, patch: unknown): Record<string, unknown> | null; +export function channelNamesWarnings(manifest: unknown): string[]; diff --git a/common/lib/report/channelNames.mjs b/common/lib/report/channelNames.mjs @@ -0,0 +1,109 @@ +// A CUT'S OWN NAME FOR A CHANNEL (lane channel-title): `render.channelNames`, +// `{ "<slug>": "<name>" }` -- what every clip of that channel is called on +// screen in this cut, whatever the record of each recording says. One +// channel's two recordings can carry two uploader names (an old one and the +// current one); this says once which to show, without touching a clip. +// +// The resolver is umtool's report-to-video/attribution.mjs `channelName`: +// a clip's own `channelTitle` > this > the record's uploader name > the +// sweep's display name > the slug. This module holds the rules every writer +// and reader checks (look.mjs applyLookPatch / validateLook, umtool's clip +// writer for a clip's `channelTitle`), so the editor's video assistant, the +// CLI, the Look panel and the build refuse the same names. +// +// PURE: no fs. Plain ESM with a .d.mts beside it. + +const isObj = (v) => !!v && typeof v === "object" && !Array.isArray(v); + +/** The longest name a channel is given on screen, in characters. */ +export const CHANNEL_NAME_MAX = 60; + +/** A channel slug as a clip's `channel` names it: no space, no slash, not empty. */ +export const CHANNEL_SLUG_RE = /^[^\s/]+$/; + +// C0 controls (newline and tab among them), DEL and the C1 controls. +// eslint-disable-next-line no-control-regex +const CONTROL_RE = /[\u0000-\u001f\u007f-\u009f]/; + +/** + * Why `value` cannot be a channel's name on screen, or null when it can: words + * (a string), not empty once trimmed, at most CHANNEL_NAME_MAX characters, no + * control character (a newline would break the one line the header is). + * @param {unknown} value + * @returns {string | null} + */ +export function channelNameProblem(value) { + if (typeof value !== "string") return `a channel's name is words, not ${JSON.stringify(value)}`; + const v = value.trim(); + if (!v) return "a channel's name is empty (clear it instead)"; + if (CONTROL_RE.test(value)) return "a channel's name has a control character (a newline, a tab …): one line of plain words"; + const n = [...v].length; + if (n > CHANNEL_NAME_MAX) return `a channel's name is ${n} characters (at most ${CHANNEL_NAME_MAX})`; + return null; +} + +/** `render.channelNames` as a plain map (an empty one when absent or malformed). */ +export function channelNamesOf(render) { + return isObj(render?.channelNames) ? render.channelNames : {}; +} + +/** + * `render.channelNames`: absent, or an object of slug → name, each name by + * channelNameProblem's rules. + * @returns {string[]} + */ +export function validateChannelNames(manifest) { + const v = manifest?.render?.channelNames; + if (v === undefined || v === null) return []; + if (!isObj(v)) return ['render.channelNames must be an object {"<channel slug>": "<name>"}']; + const errors = []; + for (const [slug, name] of Object.entries(v)) { + if (!CHANNEL_SLUG_RE.test(slug)) { + errors.push(`render.channelNames: ${JSON.stringify(slug)} is not a channel slug (no spaces, no slash)`); + continue; + } + const p = channelNameProblem(name); + if (p) errors.push(`render.channelNames.${slug}: ${p}`); + } + return errors; +} + +/** + * A patch of `render.channelNames` over what it holds: each key set (a string + * trimmed), a key null dropping one; `null` drops them all. Returns the new + * map, or null when none is left (written as no key). A value that is not a + * string is kept as given, for validateChannelNames to name. + * @param {unknown} was + * @param {unknown} patch + * @returns {Record<string, unknown> | null} + */ +export function patchChannelNames(was, patch) { + if (patch === null || patch === undefined) return null; + if (!isObj(patch)) return /** @type {any} */ (patch); + const next = { ...(isObj(was) ? was : {}) }; + for (const [k, v] of Object.entries(patch)) { + if (v === null || v === undefined) delete next[k]; + else next[k] = typeof v === "string" ? v.trim() : v; + } + return Object.keys(next).length ? next : null; +} + +/** + * The names given to a channel no clip of the cut is from -- a typo in the + * slug, or a clip since removed. Warned about, never refused: a name kept for + * a clip about to come back is harmless. + * @returns {string[]} + */ +export function channelNamesWarnings(manifest) { + const names = channelNamesOf(manifest?.render); + const keys = Object.keys(names); + if (!keys.length) return []; + const own = manifest?.provenance?.channelSlug ?? null; + const used = new Set( + (Array.isArray(manifest?.timeline) ? manifest.timeline : []) + .filter((e) => isObj(e) && e.type === "clip") + .map((e) => e.channel ?? own) + .filter(Boolean), + ); + return keys.filter((k) => !used.has(k)).map((k) => `render.channelNames.${k}: no clip of this cut is from "${k}" -- kept, but it names nothing (${[...used].join(", ") || "no clips"})`); +} diff --git a/common/lib/report/channelNames.test.ts b/common/lib/report/channelNames.test.ts @@ -0,0 +1,70 @@ +// channelNames.mjs (lane channel-title): a cut's per-channel display name +// (`render.channelNames`), its rules, its merge patch and its warnings. + +import { test } from "node:test"; +import assert from "node:assert/strict"; +import { + CHANNEL_NAME_MAX, + channelNameProblem, + channelNamesWarnings, + patchChannelNames, + validateChannelNames, +} from "./channelNames.mjs"; +import { LOOK_KEYS, applyLookPatch, lookOf } from "./look.mjs"; + +test("a name: a string, at most 60 characters, no control character, no newline", () => { + assert.equal(CHANNEL_NAME_MAX, 60); + assert.equal(channelNameProblem("Synth Channel"), null); + assert.equal(channelNameProblem("x".repeat(60)), null); + assert.match(String(channelNameProblem("x".repeat(61))), /at most 60/); + assert.match(String(channelNameProblem("Synth\nChannel")), /control character/); + assert.match(String(channelNameProblem("Synth\tChannel")), /control character/); + assert.match(String(channelNameProblem("Synth\u0007Channel")), /control character/); + assert.match(String(channelNameProblem(" ")), /empty/); + assert.match(String(channelNameProblem(42)), /words/); +}); + +test("validateChannelNames: absent is fine; a slug per key, a name per value", () => { + assert.deepEqual(validateChannelNames({ render: {} }), []); + assert.deepEqual(validateChannelNames({ render: { channelNames: { "synth-chan": "Synth Channel" } } }), []); + assert.match(validateChannelNames({ render: { channelNames: ["Synth Channel"] } }).join(), /an object/); + assert.match(validateChannelNames({ render: { channelNames: { "a b": "Synth" } } }).join(), /not a channel slug/); + assert.match(validateChannelNames({ render: { channelNames: { "synth-chan": "a\nb" } } }).join(), /render\.channelNames\.synth-chan.*control character/); +}); + +test("patchChannelNames: merged over what it holds, a key null drops one, null drops all, trimmed", () => { + assert.deepEqual(patchChannelNames(undefined, { a: " Synth A " }), { a: "Synth A" }); + assert.deepEqual(patchChannelNames({ a: "Synth A" }, { b: "Synth B" }), { a: "Synth A", b: "Synth B" }); + assert.equal(patchChannelNames({ a: "Synth A" }, { a: null }), null, "empty is no key"); + assert.equal(patchChannelNames({ a: "Synth A" }, null), null); + // A value that is not words is kept as given, for the validator to name. + assert.deepEqual(patchChannelNames({}, { a: 7 }), { a: 7 }); +}); + +test("the look writes it: a LOOK key, merged, checked", () => { + assert.ok(LOOK_KEYS.includes("channelNames")); + const m = { render: { fps: 30 }, timeline: [{ type: "clip", id: "c1", channel: "synth-chan", video: "v", start: 0, end: 1 }] }; + const a = applyLookPatch(m, { channelNames: { "synth-chan": "Synth Channel" } }); + assert.deepEqual(a.errors, []); + assert.deepEqual(lookOf(a.render).channelNames, { "synth-chan": "Synth Channel" }); + const b = applyLookPatch({ ...m, render: a.render }, { channelNames: { "synth-chan": null } }); + assert.deepEqual(b.errors, []); + assert.equal("channelNames" in b.render, false); + const bad = applyLookPatch(m, { channelNames: { "synth-chan": "Synth\u0000" } }); + assert.match(bad.errors.join(), /control character/); +}); + +test("channelNamesWarnings: a slug no clip of the cut uses is named, not refused", () => { + const m = { + provenance: { channelSlug: "own-chan" }, + render: { channelNames: { "synth-chan": "Synth Channel", "own-chan": "Own", "gone-chan": "Gone" } }, + timeline: [ + { type: "clip", id: "c1", channel: "synth-chan", video: "v", start: 0, end: 1 }, + { type: "clip", id: "c2", video: "w", start: 0, end: 1 }, + ], + }; + const w = channelNamesWarnings(m); + assert.equal(w.length, 1); + assert.match(w[0], /gone-chan/); + assert.deepEqual(channelNamesWarnings({ render: {} }), []); +}); diff --git a/common/lib/report/look.d.mts b/common/lib/report/look.d.mts @@ -4,7 +4,7 @@ type Manifest = { render?: Record<string, unknown> | null; timeline?: unknown[] } & Record<string, unknown>; type Render = Record<string, unknown> | null | undefined; -export type LookKey = "headerHeight" | "footerHeight" | "qr" | "transition" | "transitionStyle" | "loudness" | "captions" | "room" | "slide" | "blur" | "intro" | "format" | "vertical" | "mode" | "basic" | "tallWindows" | "desktop" | "promo" | "zooms" | "censor" | "gapCue"; +export type LookKey = "headerHeight" | "footerHeight" | "qr" | "transition" | "transitionStyle" | "loudness" | "captions" | "room" | "slide" | "blur" | "intro" | "format" | "vertical" | "mode" | "basic" | "tallWindows" | "desktop" | "promo" | "zooms" | "censor" | "gapCue" | "channelNames"; export const LOOK_KEYS: readonly LookKey[]; export const QR_CORNERS: readonly ["br", "bl", "tr", "tl"]; export const QR_LINK_VALUES: readonly ["cite", "moment", "channel"]; diff --git a/common/lib/report/look.mjs b/common/lib/report/look.mjs @@ -21,6 +21,8 @@ import { introPatchValue, validateIntro } from "./intro.mjs"; import { CLIP_OWN_LAYOUTS, validateVerticalFormat } from "./vertical.mjs"; // `gapCue` (lane gap-cue): the mark at a clip gap's join (./gapCue.mjs). import { patchGapCue, validateGapCue } from "./gapCue.mjs"; +// `channelNames` (lane channel-title): the cut's own name for a channel, by slug (./channelNames.mjs). +import { patchChannelNames, validateChannelNames } from "./channelNames.mjs"; const isObj = (v) => !!v && typeof v === "object" && !Array.isArray(v); const num = (v) => typeof v === "number" && Number.isFinite(v); @@ -31,7 +33,7 @@ const round2 = (n) => Number(Number(n).toFixed(2)); /** The corner code's corners and links (lane clip-kit; umtool report-to-video clip-kit.mjs draws them). */ export const QR_CORNERS = Object.freeze(["br", "bl", "tr", "tl"]); export const QR_LINK_VALUES = Object.freeze(["cite", "moment", "channel"]); -export const LOOK_KEYS = Object.freeze(["headerHeight", "footerHeight", "qr", "transition", "transitionStyle", "loudness", "captions", "room", "slide", "blur", "intro", "format", "vertical", "mode", "basic", "tallWindows", "desktop", "promo", "zooms", "censor", "gapCue"]); +export const LOOK_KEYS = Object.freeze(["headerHeight", "footerHeight", "qr", "transition", "transitionStyle", "loudness", "captions", "room", "slide", "blur", "intro", "format", "vertical", "mode", "basic", "tallWindows", "desktop", "promo", "zooms", "censor", "gapCue", "channelNames"]); /** `headerHeight` / `footerHeight`: whole pixels, 0 (off) to this. */ export const BAND_MAX = 240; @@ -386,7 +388,7 @@ export function validateLook(manifest) { // render.blur (the uncensored variant's switch) is part of the look too. return [ ...validateCaptions(manifest), ...validateLoudness(manifest), ...validateVertical(manifest), ...validateRoom(manifest), ...validateRenderBlur(manifest), ...validateIntro(manifest), - ...validateVerticalFormat(manifest), ...validateRenderMode(manifest), ...validateGapCue(manifest), + ...validateVerticalFormat(manifest), ...validateRenderMode(manifest), ...validateGapCue(manifest), ...validateChannelNames(manifest), ]; } @@ -495,6 +497,13 @@ export function applyLookPatch(manifest, patch) { else render.gapCue = next; break; } + case "channelNames": { + // Merged over what it holds (a slug null drops it, null drops all); validateChannelNames (lookErrors) says what is wrong. + const next = patchChannelNames(render.channelNames, v); + if (next === null) delete render.channelNames; + else render.channelNames = next; + break; + } case "format": // "landscape" is the default: written as no key at all. if (v === "landscape") delete render.format; diff --git a/common/lib/report/videoAssistOps.test.ts b/common/lib/report/videoAssistOps.test.ts @@ -26,7 +26,7 @@ test("the look's rules: one patch function — keys refused, null removes, qr on assert.deepEqual(bad.errors, validateTransitionStyle({ render: { slide: { blur: 9 } } })); assert.deepEqual(applyLookPatch(m, { loudness: { target: -40 } }).errors, validateLook({ render: { loudness: { target: -40 } } })); assert.deepEqual(lookErrors(m), []); - assert.equal(LOOK_KEYS.length, 21); + assert.equal(LOOK_KEYS.length, 22); }); test("render.mode and render.basic: deck is the default (no key), basic the footage alone; the fades checked", () => { diff --git a/common/package.json b/common/package.json @@ -63,6 +63,7 @@ "./lib/report/drafted.mjs": "./lib/report/drafted.mjs", "./lib/report/look.mjs": "./lib/report/look.mjs", "./lib/report/gapCue.mjs": "./lib/report/gapCue.mjs", + "./lib/report/channelNames.mjs": "./lib/report/channelNames.mjs", "./lib/report/vertical.mjs": "./lib/report/vertical.mjs", "./lib/report/intro.mjs": "./lib/report/intro.mjs", "./lib/report/fxParams.mjs": "./lib/report/fxParams.mjs", diff --git a/umtool/app/api/report/onscreen/route.ts b/umtool/app/api/report/onscreen/route.ts @@ -82,7 +82,7 @@ export async function GET(request: Request) { // An entry with marks (`claims`) shows its first here; the clip editor's Marks box edits them all. claim: e.claim ?? (Array.isArray(e.claims) ? (e.claims[0] ?? null) : null), ...(Array.isArray(e.claims) ? { marks: e.claims.length } : {}), - auto: deckText(bare, metas[i] ?? null, provenance, deck, multi), + auto: deckText(bare, metas[i] ?? null, provenance, deck, multi, "", (render as { channelNames?: Record<string, unknown> }).channelNames ?? null), }; }); return Response.json( diff --git a/umtool/lib/projects/report.mjs b/umtool/lib/projects/report.mjs @@ -154,6 +154,44 @@ export async function deadOriginQrsOf(dir, m, { channelsDir = null } = {}) { } /** + * The channels this cut's clips are from, for the Look panel's Channel names (render.channelNames, lane + * channel-title): each slug once, in the cut's order, with how many clips are from it, the names the + * records of its recordings carry (what the header says with no name set -- two when its recordings + * disagree) and the cut's name for it. A name set for a slug no clip is from is listed too (`clips: 0`), + * so it can be cleared. + * + * @returns {Promise<Array<{ slug: string, clips: number, recordNames: string[], name: string | null }>>} + */ +export async function channelsOfCut(dir, m, { channelsDir = null } = {}) { + if (!m) return []; + const root = channelsDir ?? channelsDirFor(dir, m, { shadowExists: await hasShadowChannels(dir) }); + const names = m.render?.channelNames && typeof m.render.channelNames === "object" ? m.render.channelNames : {}; + const prov = m.provenance ?? {}; + /** @type {Map<string, { slug: string, clips: number, recordNames: string[], name: string | null }>} */ + const out = new Map(); + const docs = new Map(); + for (const e of clipsOf(m)) { + const slug = channelFor(m, e); + if (!slug) continue; + const row = out.get(slug) ?? { slug, clips: 0, recordNames: [], name: typeof names[slug] === "string" ? names[slug] : null }; + row.clips += 1; + out.set(slug, row); + const key = `${slug}/${e.video}`; + if (!docs.has(key)) { + const file = e.video ? cuePathFor(m, e, root) : null; + docs.set(key, file ? await readCues(file).catch(() => null) : null); + } + // What the record says, with neither the clip's own nor the cut's name. + const said = channelName({ channel: e.channel }, docs.get(key) ?? {}, prov); + if (said && !row.recordNames.includes(said)) row.recordNames.push(said); + } + for (const [slug, name] of Object.entries(names)) { + if (!out.has(slug)) out.set(slug, { slug, clips: 0, recordNames: [], name: typeof name === "string" ? name : null }); + } + return [...out.values()]; +} + +/** * Is the QR origin a defect? A SET origin that is dead (localhost, a LAN * address) always is: it is the archive the cut names, whatever links it * today. A MISSING one only when a code the cut draws is built from it @@ -1884,7 +1922,10 @@ export async function readClipDetail(dir, { manifest = null } = {}) { // the answer walks the clip's override, the record, the sweep's own // display name and the slug, and a preview that re-implemented that walk // is exactly the drift `attribution.mjs` exists to prevent. - sourceChannel: channelName(e, doc ?? {}, m.provenance ?? {}), + // The cut's own name for the channel (render.channelNames) is part of that walk. + sourceChannel: channelName(e, doc ?? {}, m.provenance ?? {}, m.render?.channelNames), + // What it would say WITHOUT the clip's own channelTitle: the clip bench's placeholder for that field. + sourceChannelDefault: channelName({ ...e, channelTitle: undefined }, doc ?? {}, m.provenance ?? {}, m.render?.channelNames), punctuationRate: doc?.punctuationRate ?? null, endCueText: endCue?.text ?? null, endsSentence, diff --git a/umtool/lib/report/knobsCli.mjs b/umtool/lib/report/knobsCli.mjs @@ -13,7 +13,9 @@ // (`blur.on=` clears the whole blur; report-to-video clip-blur.mjs) // fx=<json> fx.zoom fx.receipts fx.punch fx.quote fx.punchIn fx.speakers // (the clip's effects; `fx=` clears them all; report-to-video fx.mjs) +// umtool set <project> <clip> channelTitle=… what the header calls the clip's channel (`channelTitle=` clears) // umtool look <project> key=value … factcheck.stamp.<k>, factcheck.verdicts.<V>.<k>, factcheck.tally.<k>, +// channelNames.<slug>=<name> (the cut's name for a channel; `=` clears), // deck.markers=<json>, deck.markerLayout=…, deck.claims=<json>, variants=<json>, // and the look's keys (transition=0.3, …) // umtool variants <project> [--take <t>] [--list] [--json] make the encode ladder (or list it) @@ -65,7 +67,7 @@ export const SIDE_SET_KEYS = Object.freeze(["side", "side.item", "side.post", "s export const KIT_SET_KEYS = Object.freeze(["qr", "qr.corner", "qr.links", "name", "promo", "promo.lead", "promo.fade", "promo.hold", "zooms", "coldOpen", "coldOpen.from", "coldOpen.to", "censor", "censor.boxes", "censor.style", "censor.strength", "censor.from", "censor.to"]); const SET_KEYS = [ "claim", ...CLAIM_KNOBS.map((k) => `claim.${k}`), ...MARK_KEYS, ...AUDIO_KNOBS.map((k) => `audio.${k}`), ...BLUR_KNOBS.map((k) => `blur.${k}`), "layout", ...REVIEW_KEYS, - ...FX_KEYS, ...GAP_KEYS, ...GAP_CUE_SET_KEYS, "chat", "hideModules", "shelfNote", "chapter", + ...FX_KEYS, ...GAP_KEYS, ...GAP_CUE_SET_KEYS, "chat", "hideModules", "shelfNote", "chapter", "channelTitle", // The vertical format (lane vertical): the clip's 9:16 crop and layout, and its side post. ...VERTICAL_SET_KEYS, ...SIDE_SET_KEYS, // The clip kit (lane clip-kit): its code and its name in a batch of shorts. @@ -115,6 +117,9 @@ export const SET_USAGE = [ " `note` slot) over this entry's span, coming and going with it; any entry; `shelfNote=` none.", " chapter='The weigh-in' names this entry in the chapter list (out/chapters, youtube.txt) in place of its on-screen", " title or the line derived from its record: one line, ≤ 100 characters; any entry; `chapter=` none.", + " channelTitle='Synth Channel' is what the header, the deck's source line and the chapter list call this clip's", + " channel, over the cut's name for it (umtool look <p> channelNames.<slug>=…) and the record's uploader name:", + " one line, ≤ 60 characters, no control character; `channelTitle=` the cut's / the record's again.", " --take <t>: the entry knobs (not claim.* or marks) land in takes/<t>/take.json's patch, an undo point first", " (`umtool timeline <p> --take <t> undo`); the project's manifest is untouched.", " vertical.crop='[x,y,w,h]' (fractions of the source: the 9:16 box a vertical render cuts; vertical.aspect the", @@ -170,6 +175,10 @@ export const LOOK_USAGE = [ " on one quiet line under the rail; .size .opacity .fade .color (auto|section|#hex|palette key); false or `=` is off", " pair=<json> | pair.<key>=…, chapter=<json> | chapter.<key>=…, status=<json> | status.<key>=…, chat=<json> | chat.<key>=…: the story modules", " (render.chrome.pair / .chapter / .status, docs/knobs.md \"Modules\"), checked by the build's rules", + " channelNames.<slug>='Synth Channel': every clip of that channel is called that on screen in this cut (the deck's", + " source line, the header, the chapter list, a short's end card), over the record's uploader name; a clip's own", + " channelTitle still wins (umtool set). ≤ 60 characters, one line. `channelNames.<slug>=` clears one, `channelNames=`", + " all; channelNames='{\"<slug>\":\"…\"}' merges. A slug no clip of the cut is from is written and warned about.", " variants='[{\"name\":\"master\"},{\"name\":\"720p\",\"height\":720,\"crf\":23},{\"name\":\"fit24\",\"maxMiB\":24}]'", ` the look: ${LOOK_KEYS.join(", ")} (a JSON value each)`, " `key=` clears it (the default).", @@ -282,6 +291,11 @@ export async function setCommand(args, { root = REPORTS_ROOT, out = (s) => conso entryPatch.shelfNote = value === null || value === undefined ? null : String(value); continue; } + if (key === "channelTitle") { + // What the header calls the clip's channel (manifest.mjs patchClipEntry checks it); words whatever they parse as. + entryPatch.channelTitle = value === null || value === undefined ? null : String(value); + continue; + } if (key === "chapter") { // The entry's name in the chapter list (manifest.mjs parseEntryChapter checks it); words whatever they parse as. entryPatch.chapter = value === null || value === undefined ? null : String(value); @@ -388,6 +402,7 @@ export async function setCommand(args, { root = REPORTS_ROOT, out = (s) => conso if ("hideModules" in entryPatch) results.hideModules = result.entry.hideModules ?? null; if ("shelfNote" in entryPatch) results.shelfNote = result.entry.shelfNote ?? null; if ("chapter" in entryPatch) results.chapter = result.entry.chapter ?? null; + if ("channelTitle" in entryPatch) results.channelTitle = result.entry.channelTitle ?? null; if ("audio" in entryPatch) results.audio = result.entry.audio ?? null; if ("blur" in entryPatch) results.blur = result.entry.blur ?? null; if ("layout" in entryPatch) results.layout = result.entry.layout ?? "clip"; @@ -433,6 +448,7 @@ export async function setCommand(args, { root = REPORTS_ROOT, out = (s) => conso if ("hideModules" in results) out(`${clipId}${results.take ? ` (take ${results.take.id})` : ""}: hideModules ${results.hideModules ? `${results.hideModules.join(", ")} (hidden over its span)` : "none"}`); if ("shelfNote" in results) out(`${clipId}${results.take ? ` (take ${results.take.id})` : ""}: shelfNote ${results.shelfNote ? JSON.stringify(results.shelfNote) + " (on the shelf over its span)" : "none"}`); if ("chapter" in results) out(`${clipId}${results.take ? ` (take ${results.take.id})` : ""}: chapter ${results.chapter ? JSON.stringify(results.chapter) + " (its name in the chapter list)" : "none (named by its on-screen title, else its record)"}`); + if ("channelTitle" in results) out(`${clipId}${results.take ? ` (take ${results.take.id})` : ""}: channelTitle ${results.channelTitle ? JSON.stringify(results.channelTitle) + " (its channel's name on screen)" : "none (the cut's name for its channel, else the record's)"}`); if (results.take?.undo) out(` undo point: ${results.take.undo} (umtool timeline ${project.id} --take ${results.take.id} undo)`); if ("chat" in results) out(`${clipId}: chat ${results.chat === true ? "on (its video's live_chat.cues.json beside the footage; the build says if there is none)" : results.chat === false ? "off" : "default (off)"}`); if ("fx" in results) out(`${clipId}: fx ${results.fx ? JSON.stringify(results.fx) : "none"}`); @@ -650,11 +666,23 @@ export async function lookCommand(args, { root = REPORTS_ROOT, out = (s) => cons const deck = pairs.filter(([k]) => k.startsWith("deck.")); const variants = pairs.filter(([k]) => k === "variants"); const look = pairs.filter(([k]) => LOOK_KEYS.includes(k)); + // The cut's name for ONE channel (render.channelNames.<slug>, lane channel-title): merged into the look's + // channelNames patch -- words whatever they parse as, `=` clears that slug. + const chanNames = pairs.filter(([k]) => k.startsWith("channelNames.")); + for (const [k, v] of chanNames) { + const slug = k.slice("channelNames.".length); + if (!slug) throw new CliError("channelNames.<slug>=<name>: name the channel's slug"); + const at = look.findIndex(([x]) => x === "channelNames"); + const cur = at >= 0 && look[at][1] && typeof look[at][1] === "object" ? look[at][1] : {}; + const next = { ...cur, [slug]: v === null || v === undefined ? null : String(v) }; + if (at >= 0) look[at] = ["channelNames", next]; + else look.push(["channelNames", next]); + } // The story modules (release 39): `pair=<json>`, `pair.style=…`, likewise chapter and status. const STORY = ["pair", "chapter", "status", "chat"]; const isStory = (k) => STORY.includes(k.split(".")[0]); const story = pairs.filter(([k]) => isStory(k)); - const unknown = pairs.filter(([k]) => !k.startsWith("factcheck.") && !k.startsWith("deck.") && k !== "variants" && !LOOK_KEYS.includes(k) && !isStory(k)); + const unknown = pairs.filter(([k]) => !k.startsWith("factcheck.") && !k.startsWith("deck.") && !k.startsWith("channelNames.") && k !== "variants" && !LOOK_KEYS.includes(k) && !isStory(k)); if (unknown.length) throw new CliError(`not a knob here: ${unknown.map(([k]) => k).join(", ")}\n\n${LOOK_USAGE}`); for (const [k] of deck) if (k.split(".").some((p) => !p)) throw new CliError(`${k}: name one of the deck's own keys (deck.<key>=<json>, or deck.<key>.<field>=…)`); const done = {}; @@ -699,13 +727,16 @@ export async function lookCommand(args, { root = REPORTS_ROOT, out = (s) => cons const r = await write((token) => updateVariants(project.dir, variants[0][1], { token })); done.variants = r.variants; } + let warnings = []; if (look.length) { const r = await write((token) => updateRender(project.dir, Object.fromEntries(look), { token })); done.look = r.look; + warnings = r.warnings ?? []; } - if (json) out(JSON.stringify({ ok: true, ...done, editNotes: notes }, null, 2)); + if (json) out(JSON.stringify({ ok: true, ...done, ...(warnings.length ? { warnings } : {}), editNotes: notes }, null, 2)); else { for (const [k, v] of Object.entries(done)) out(`${k}: ${v === null || v === undefined ? "(default)" : JSON.stringify(v)}`); + for (const w of warnings) out(`WARN ${w}`); const n = noted(notes); if (n) out(n); } @@ -824,6 +855,8 @@ export function knobsOf(manifest) { variantsDefault: !Array.isArray(manifest?.render?.variants), // render.blur "off": the uncensored variant (every clip's blur not drawn). blurOff: manifest?.render?.blur === "off", + // The cut's names for its channels (render.channelNames), as written. + channelNames: isObj(manifest?.render?.channelNames) ? manifest.render.channelNames : {}, }; } @@ -857,6 +890,7 @@ export function knobsLines(manifest) { } lines.push(` variants ${k.variants.map((v) => v.name).join(", ")}${k.variantsDefault ? " (default)" : ""}`); if (k.blurOff) lines.push(" blur off (render.blur: the uncensored variant — no clip is blurred)"); + if (Object.keys(k.channelNames).length) lines.push(` channels ${Object.entries(k.channelNames).map(([a, b]) => `${a}=${JSON.stringify(b)}`).join(" ")}`); return lines; } diff --git a/umtool/lib/report/knobsCli.test.mjs b/umtool/lib/report/knobsCli.test.mjs @@ -399,3 +399,51 @@ test("umtool set chapter='…': an entry's name in the chapter list, any entry; assert.equal(await run("chapter", "x01", "chapter=", "--take", "a9"), 0, lines.join("\n")); assert.equal("chapter" in (await resolveTakeManifest(dir, "a9")).manifest.timeline[2], false); }); + +test("umtool set channelTitle=…: the clip's own channel name, trimmed; `channelTitle=` clears it; a control character or > 60 is refused", async () => { + const dir = await project("chantitle"); + const { lines, run } = runner(setCommand); + assert.equal(await run("chantitle", "c02", "channelTitle= Synth Channel "), 0, lines.join("\n")); + assert.equal((await read(dir)).timeline[1].channelTitle, "Synth Channel", "trimmed"); + assert.match(lines.at(-1), /c02: channelTitle "Synth Channel"/); + assert.equal(await run("chantitle", "c02", "channelTitle=2031"), 0, lines.join("\n")); + assert.equal((await read(dir)).timeline[1].channelTitle, "2031", "words whatever they parse as"); + assert.equal(await run("chantitle", "c02", "channelTitle=Synth\u0007Channel"), 1); + assert.match(lines.at(-1), /control character/); + assert.equal(await run("chantitle", "c02", "channelTitle=Synth\nChannel"), 1); + assert.match(lines.at(-1), /control character/); + assert.equal(await run("chantitle", "c02", `channelTitle=${"x".repeat(61)}`), 1); + assert.match(lines.at(-1), /at most 60/); + assert.equal((await read(dir)).timeline[1].channelTitle, "2031", "a refused write changes nothing"); + assert.equal(await run("chantitle", "c02", "channelTitle="), 0); + assert.equal("channelTitle" in (await read(dir)).timeline[1], false); + assert.match(lines.at(-1), /c02: channelTitle none/); +}); + +test("umtool look channelNames.<slug>=…: one channel's name for the whole cut; `channelNames.<slug>=` clears one, `channelNames=` all", async () => { + const dir = await project("channames"); + const m = await read(dir); + m.timeline.push({ type: "clip", id: "c03", channel: "guest-chan", video: "v3", start: 1, end: 5 }); + await writeFile(path.join(dir, "video.manifest.json"), JSON.stringify(m, null, 2) + "\n"); + const { lines, run } = runner(lookCommand); + assert.equal(await run("channames", "channelNames.chan=Synth Channel"), 0, lines.join("\n")); + assert.deepEqual((await read(dir)).render.channelNames, { chan: "Synth Channel" }); + assert.equal(await run("channames", "channelNames.guest-chan=2031"), 0, lines.join("\n")); + assert.deepEqual((await read(dir)).render.channelNames, { chan: "Synth Channel", "guest-chan": "2031" }, "merged; words whatever they parse as"); + // A slug no clip of the cut uses: written, and warned about. + assert.equal(await run("channames", "channelNames.other-chan=Nobody"), 0, lines.join("\n")); + assert.equal((await read(dir)).render.channelNames["other-chan"], "Nobody"); + assert.match(lines.join("\n"), /WARN .*other-chan/); + // A control character: refused, nothing written. + assert.notEqual(await run("channames", "channelNames.chan=Synth\u0000Channel"), 0); + assert.match(lines.at(-1), /control character/); + assert.equal((await read(dir)).render.channelNames.chan, "Synth Channel"); + assert.equal(await run("channames", "channelNames.other-chan="), 0, lines.join("\n")); + assert.deepEqual((await read(dir)).render.channelNames, { chan: "Synth Channel", "guest-chan": "2031" }); + // The JSON form, and clearing the lot. + assert.equal(await run("channames", 'channelNames={"chan":null}'), 0, lines.join("\n")); + assert.deepEqual((await read(dir)).render.channelNames, { "guest-chan": "2031" }); + assert.ok(knobsLines(await read(dir)).some((l) => /channels\s+guest-chan="2031"$/.test(l)), "umtool show prints them"); + assert.equal(await run("channames", "channelNames="), 0, lines.join("\n")); + assert.equal("channelNames" in ((await read(dir)).render ?? {}), false); +}); diff --git a/umtool/lib/report/look.test.mjs b/umtool/lib/report/look.test.mjs @@ -46,7 +46,7 @@ const read = async (dir) => JSON.parse(await readFile(path.join(dir, MANIFEST_NA test("updateRender: the look's keys only, null removes one, the build's checks refuse a bad value", async () => { const p = await project({ transition: 0.4, crf: 21 }); try { - assert.deepEqual(LOOK_KEYS, ["headerHeight", "footerHeight", "qr", "transition", "transitionStyle", "loudness", "captions", "room", "slide", "blur", "intro", "format", "vertical", "mode", "basic", "tallWindows", "desktop", "promo", "zooms", "censor", "gapCue"]); + assert.deepEqual(LOOK_KEYS, ["headerHeight", "footerHeight", "qr", "transition", "transitionStyle", "loudness", "captions", "room", "slide", "blur", "intro", "format", "vertical", "mode", "basic", "tallWindows", "desktop", "promo", "zooms", "censor", "gapCue", "channelNames"]); const token = await manifestToken(p.dir); const r = await updateRender(p.dir, { headerHeight: 0, footerHeight: 0, qr: false, transition: 0.5, transitionStyle: "fadeblack", diff --git a/umtool/lib/report/manifest.mjs b/umtool/lib/report/manifest.mjs @@ -62,6 +62,7 @@ import { validateFxEntries } from "umtool-report-to-video/fx"; import { validateClipAudio } from "umtool-report-to-video/clip-audio"; import { GAP_WHY_VALUES, editGaps, gapOwnKeys, parseGapSpec, validateGaps } from "umtool-report-to-video/gaps"; import { gapCueErrors, patchGapCue } from "yt-dlp-transcript-common/lib/report/gapCue.mjs"; +import { channelNameProblem, channelNamesWarnings } from "yt-dlp-transcript-common/lib/report/channelNames.mjs"; import { BLUR_CAPTION_DEFAULT, BLUR_STRENGTH, validateClipBlur, validateClipBlurEntries } from "umtool-report-to-video/clip-blur"; import { CLAIM_KNOBS, CLAIM_MARKS_MAX, claimKnobsOf, claimKnobValue, freshMarkId, marksCopyOf, normalizeClaimKnobPatch, rawMarksOf, setMarks, stampingEntryId, @@ -462,6 +463,18 @@ export function patchClipEntry(manifest, clipId, patch, { edit = "trim", now = n else delete entry[k]; } + // What the header calls the clip's channel (attribution.mjs channelName: over the cut's render.channelNames and the + // record's uploader name). One line of words, at most 60 (common channelNames.mjs); empty deletes it. + if (patch.channelTitle !== undefined) { + const raw = patch.channelTitle === null ? "" : String(patch.channelTitle); + if (!raw.trim()) delete entry.channelTitle; + else { + const p = channelNameProblem(raw); + if (p) throw new Error(`channelTitle: ${p}`); + entry.channelTitle = raw.trim(); + } + } + if (patch.date !== undefined) { const v = String(patch.date ?? "").trim(); if (!v) delete entry.date; @@ -1940,7 +1953,7 @@ export async function updateRenderKeys(dir, { unset = [], chrome = null } = {}, * @param {string} dir * @param {Record<string, unknown>} patch * @param {{ token?: string | null }} [opts] - * @returns {Promise<{ look: Record<string, unknown>, token: string | null }>} + * @returns {Promise<{ look: Record<string, unknown>, token: string | null, snapshot?: Record<string, unknown>, warnings?: string[] }>} */ export async function updateRender(dir, patch, { token = null } = {}) { if (!isObj(patch)) throw new RenderRefused(["the patch must be an object of render keys"]); @@ -1967,7 +1980,9 @@ export async function updateRender(dir, patch, { token = null } = {}) { // it changes it (`gapCue: null` on a cut with none is no edit). const snapshot = "gapCue" in patch && JSON.stringify(render.gapCue ?? null) !== cueBefore ? await autoSnapshot(dir, "gaps") : null; const nextToken = await writeManifestAtomic(dir, manifest); - return { look: lookOf(render), token: nextToken, ...(snapshot ? { snapshot } : {}) }; + // A name for a channel no clip of the cut is from (render.channelNames): written, and said (common channelNames.mjs). + const warnings = "channelNames" in patch ? channelNamesWarnings(manifest) : []; + return { look: lookOf(render), token: nextToken, ...(snapshot ? { snapshot } : {}), ...(warnings.length ? { warnings } : {}) }; }); } diff --git a/umtool/lib/report/onscreen.mjs b/umtool/lib/report/onscreen.mjs @@ -291,7 +291,7 @@ function previewScheduleOf({ variantManifest, built, draft, metas, postsDraft, c const e = patchedEntries[i]; const meta = metas[i] ?? null; const status = subtitleStatusOn(deck.subtitle) ? clipSourceStatus(e, variantManifest.sourceStatus, provenance) : ""; - const { title, subtitle, subtitleParts, subtitleLines, subtitleLinesParts } = deckText(e, meta, provenance, deck, built.multiChannel, status); + const { title, subtitle, subtitleParts, subtitleLines, subtitleLinesParts } = deckText(e, meta, provenance, deck, built.multiChannel, status, render.channelNames); const keepBuilt = e.type === "clip" && e.onscreen?.subtitle === undefined && !meta; // A two-line subtitle's lines, and the line's parts by token, go with the subtitle they were cut from. const { subtitleLines: builtLines, subtitleParts: builtParts, subtitleLinesParts: builtLinesParts, ...seg } = s; diff --git a/umtool/lib/report/verticalCli.mjs b/umtool/lib/report/verticalCli.mjs @@ -176,7 +176,7 @@ export async function endCardOf({ render, knobs = {}, provenance = {}, timeline const V = await import("umtool-report-to-video/vertical"); if (!V.stackedDeckWanted({ ...render, format: "vertical", vertical: { ...(render?.vertical ?? {}), ...knobs } })) return null; const { endCardSources } = await import("umtool-report-to-video/outro"); - return { qrUrl: provenance.qrLink ?? provenance.siteOrigin ?? null, sources: endCardSources(timeline, schedule) }; + return { qrUrl: provenance.qrLink ?? provenance.siteOrigin ?? null, sources: endCardSources(timeline, schedule, render?.channelNames ?? null, provenance) }; } /** The heavy slot (report-to-video/heavy-gate.mjs), loaded at run time: `(cmd, fn) => …` with a declared estimate. */ diff --git a/umtool/report-to-video/attribution.mjs b/umtool/report-to-video/attribution.mjs @@ -56,6 +56,24 @@ export function uploadDateToIso(d) { } /** + * The cut's own name for this clip's channel (`render.channelNames[slug]`, + * the slug the clip's `channel`, else the sweep's), or "" when it gives none. + * A name that is not words is no name: the build's validator refuses it, and + * a preview must not draw "[object Object]" meanwhile. + * + * @param {{ channel?: string|null }} entry + * @param {{ channelSlug?: string|null }} [provenance] + * @param {Record<string, unknown> | null} [names] + */ +export function cutChannelName(entry, provenance = {}, names = null) { + if (!names || typeof names !== "object") return ""; + const slug = String(entry?.channel ?? provenance?.channelSlug ?? "").trim(); + if (!slug || !Object.prototype.hasOwnProperty.call(names, slug)) return ""; + const v = names[slug]; + return typeof v === "string" ? v.trim() : ""; +} + +/** * WHO is speaking, for the head of the header line. * * A compilation routinely spans several channels -- a streamer's own channel, @@ -63,12 +81,17 @@ export function uploadDateToIso(d) { * makes the viewer work out which of them they are watching from the furniture. * So the channel comes first and every clip in a cut reads the same way. * - * Four answers, in order, and each exists because the one after it is wrong + * Five answers, in order, and each exists because the one after it is wrong * somewhere: * * 1. `entry.channelTitle` — the per-clip override. A record's uploader name * can be a handle, a rebrand or an ALL-CAPS mirror name; this is the * author saying what to call it in this cut. + * 1b. `names[slug]` — the CUT's name for the clip's channel + * (`render.channelNames`, common lib/report/channelNames.mjs). Two + * recordings of one channel can carry two uploader names (the old one + * and the current one); this says once which every clip of it shows. + * Absent or empty: the answer is what it was before the key existed. * 2. `meta.channel` — the uploader name the cue record already carries, local * or from a published shard. Free: the record is loaded for the title and * the upload date anyway, so no lookup is added to a build. @@ -81,10 +104,13 @@ export function uploadDateToIso(d) { * @param {{ channelTitle?: string|null, channel?: string|null }} entry * @param {{ channel?: string|null }} [meta] * @param {{ channel?: string|null, channelSlug?: string|null }} [provenance] + * @param {Record<string, unknown> | null} [names] the cut's `render.channelNames` */ -export function channelName(entry, meta = {}, provenance = {}) { +export function channelName(entry, meta = {}, provenance = {}, names = null) { const override = String(entry?.channelTitle ?? "").trim(); if (override) return override; + const cut = cutChannelName(entry, provenance, names); + if (cut) return cut; const record = String(meta?.channel ?? "").trim(); if (record) return record; const slug = String(entry?.channel ?? provenance?.channelSlug ?? "").trim(); @@ -113,9 +139,10 @@ export function channelName(entry, meta = {}, provenance = {}) { * @param {{ title?: string|null, date?: string|null, cite?: number|null, start?: number|null, channel?: string|null, channelTitle?: string|null }} entry * @param {{ title?: string|null, uploadDate?: string|null, channel?: string|null }} meta * @param {{ channel?: string|null, channelSlug?: string|null }} [provenance] + * @param {Record<string, unknown> | null} [names] the cut's `render.channelNames` */ -export function attributionLine(entry, meta, provenance = {}) { - const { channel, title, date, at } = attributionParts(entry, meta, provenance); +export function attributionLine(entry, meta, provenance = {}, names = null) { + const { channel, title, date, at } = attributionParts(entry, meta, provenance, names); // A cut with no channel to name anywhere reproduces the old line exactly, // rather than opening on a stray separator. const head = [channel, title].filter((s) => String(s ?? "").length > 0).join(" · "); @@ -130,11 +157,13 @@ export function attributionLine(entry, meta, provenance = {}) { * header; the deck's subtitle (`deckSubtitle`) picks from them. One resolver, * so the two can never disagree about a clip's date or channel. * + * `names` is the cut's `render.channelNames` (channelName's 1b). + * * @returns {{ channel: string, title: string, date: string, at: number }} */ -export function attributionParts(entry, meta, provenance = {}) { +export function attributionParts(entry, meta, provenance = {}, names = null) { return { - channel: channelName(entry, meta, provenance), + channel: channelName(entry, meta, provenance, names), title: entry.title ?? cleanTitle(meta.title), date: entry.date ?? uploadDateToIso(meta.uploadDate), at: entry.cite ?? entry.start ?? 0, diff --git a/umtool/report-to-video/attribution.test.mjs b/umtool/report-to-video/attribution.test.mjs @@ -80,6 +80,46 @@ test("channelName: the four answers, in order", () => { assert.equal(channelName({}, {}, {}), ""); }); +test("channelName: the cut's per-channel name sits between the clip's own and the record's", () => { + const prov = { channelSlug: "own-chan", channel: "Own Channel" }; + const names = { "synth-chan": "Synth Channel", "own-chan": "Own Renamed" }; + // 1. the clip's own channelTitle still wins + assert.equal(channelName({ channelTitle: "Clip Says", channel: "synth-chan" }, { channel: "OLD UPLOADER" }, prov, names), "Clip Says"); + // 2. the project's name for the clip's channel beats the record's uploader name + assert.equal(channelName({ channel: "synth-chan" }, { channel: "OLD UPLOADER" }, prov, names), "Synth Channel"); + // ... and the sweep's own display name, for a clip of the sweep's channel (no `channel` of its own) + assert.equal(channelName({}, {}, prov, names), "Own Renamed"); + // ... and the bare slug + assert.equal(channelName({ channel: "synth-chan" }, {}, {}, names), "Synth Channel"); + // 3. a channel the map does not name falls through as before + assert.equal(channelName({ channel: "other" }, { channel: "Other Uploader" }, prov, names), "Other Uploader"); + // a blank name in the map is no name + assert.equal(channelName({ channel: "synth-chan" }, { channel: "OLD" }, prov, { "synth-chan": " " }), "OLD"); +}); + +test("channelName / attributionLine: no names (absent, null, {}) is today's answer exactly", () => { + const cases = [ + [{ channelTitle: "Destiny", channel: "x" }, { channel: "Y" }, { channelSlug: "omnibased", channel: "OmniBased" }], + [{ channel: "destiny" }, { channel: "Destiny" }, {}], + [{ channel: "omnibased" }, {}, { channelSlug: "omnibased", channel: "OmniBased" }], + [{ channel: "destiny", title: "T", date: "2026-01-02", cite: 75 }, {}, {}], + ]; + for (const [e, m, p] of cases) { + for (const names of [undefined, null, {}]) { + assert.equal(channelName(e, m, p, names), channelName(e, m, p)); + assert.equal(attributionLine(e, m, p, names), attributionLine(e, m, p)); + assert.deepEqual(attributionParts(e, m, p, names), attributionParts(e, m, p)); + } + } +}); + +test("attributionLine / attributionParts: the per-channel name reaches the header line and the parts", () => { + const e = { channel: "synth-chan", title: "Stream", date: "2031-03-01", cite: 2100 }; + const names = { "synth-chan": "Synth Channel" }; + assert.equal(attributionLine(e, { channel: "SYNTH OLD" }, {}, names), "Synth Channel · Stream · 2031-03-01 @ 35:00"); + assert.equal(attributionParts(e, { channel: "SYNTH OLD" }, {}, names).channel, "Synth Channel"); +}); + test("attributionLine: a cut that can name no channel reads as it always did", () => { assert.equal( attributionLine({ title: "Monday Mail #11", date: "2016-09-12", cite: 32989 }, {}), diff --git a/umtool/report-to-video/build-video.mjs b/umtool/report-to-video/build-video.mjs @@ -853,7 +853,7 @@ export function audioPosterParts({ posterIdx, box, render }) { * at the cut's fps, so the picture ends where the sound does. */ async function audioPosterInput({ entry, meta, provenance, render, outDir, box, seconds }) { - const parts = attributionParts(entry, meta ?? {}, provenance ?? {}); + const parts = attributionParts(entry, meta ?? {}, provenance ?? {}, render.channelNames); const card = { id: `${entry.id}.poster`, style: "chapter", @@ -1774,9 +1774,10 @@ async function buildClipSegment(entry, meta, render, dirs, opts, chrome, nodes, // a VOD mirror is often years after the stream. A clip may carry // `channelTitle`, `date` (the stream's own YYYY-MM-DD) and `title` (a display // title) to override the record's. - await replaceFile(attribPath, attributionLine(entry, meta, provenance)); + // `render.channelNames` (the cut's own name for a channel) sits between the clip's channelTitle and the record's. + await replaceFile(attribPath, attributionLine(entry, meta, provenance, render.channelNames)); // A brand draws the line's head -- the channel -- in the foreground colour. - const who = render.brand ? channelName(entry, meta, provenance) : ""; + const who = render.brand ? channelName(entry, meta, provenance, render.channelNames) : ""; const channelPath = who ? path.join(outDir, "segments", `${entry.id}.channel.txt`) : null; if (channelPath) await replaceFile(channelPath, who); @@ -1962,7 +1963,7 @@ async function buildClipSegment(entry, meta, render, dirs, opts, chrome, nodes, const graph = verticalClipGraph({ geo, srcW: sw, srcH: sh, crop: entry.vertical?.crop ?? null, blur: [...(await blurPicture(sw, sh)), ...zoom], side, fps: render.fps, W: width, H: height, }); - const tag = sourceTagText({ channel: channelName(entry, meta, provenance), date: entry.date ?? uploadDateToIso(meta.uploadDate) }); + const tag = sourceTagText({ channel: channelName(entry, meta, provenance, render.channelNames), date: entry.date ?? uploadDateToIso(meta.uploadDate) }); // The promo's timing for the captions (the card itself is drawn below): from when, over how long, into which band. const promoSpec = dirs.vertical.promoFor === entry.id ? promoOf(entry, render, segSeconds) : null; const promoNow = promoSpec ? { from: Math.max(0, segSeconds - promoSpec.lead), fade: promoSpec.fade, captions: promoSpec.captions, band: promoBand({ width, height, captions: promoSpec.captions }).band } : null; @@ -6484,7 +6485,7 @@ export async function segmentOffsets(segments, D, fps) { * the deck an `onscreen` value is not drawn, so it does not name a chapter * either: a manifest without `render.chrome` builds exactly as it did. */ -export async function chapterTitle(entry, index, provenance, { deck = false } = {}) { +export async function chapterTitle(entry, index, provenance, { deck = false, names = null } = {}) { if (entry.chapter) return entry.chapter; if (deck && entry.onscreen?.title) return entry.onscreen.title; // A teaser is named by its own words, with or without the deck. @@ -6517,7 +6518,7 @@ export async function chapterTitle(entry, index, provenance, { deck = false } = // while you watch. The channel is in both for the same reason: a chapter // list for a cut spanning three mirrors has to say which one each jump // lands in. - const who = channelName(entry, meta, provenance); + const who = channelName(entry, meta, provenance, names); const date = entry.date ?? uploadDateToIso(meta.uploadDate); const title = String(entry.title ?? meta.title ?? clipLabel(entry)); const tail = `${date} — ${title.length > 60 ? `${title.slice(0, 57)}…` : title}`.trim(); @@ -6765,7 +6766,7 @@ export function foldIntroChapter(chapters, entries) { // Returns the chapters it muxed (`{ chapters: [{ start, end, title }], total }`, // seconds) -- the list out/youtube.txt's Chapters are made from -- or null // when the cut is one segment and gets none. -async function muxChapters(finalPath, entries, segments, D, outDir, provenance, fps, deck = false, joins = null, { disclosure = null } = {}) { +async function muxChapters(finalPath, entries, segments, D, outDir, provenance, fps, deck = false, joins = null, { disclosure = null, names = null } = {}) { if (segments.length < 2) return null; // The cut's own offsets: under the deck a held clip is longer in the cut // than its file, and every chapter after it starts that much later. @@ -6777,7 +6778,7 @@ async function muxChapters(finalPath, entries, segments, D, outDir, provenance, // rather than on the outgoing one mid-dissolve. const start = i === 0 ? 0 : starts[i] + D; const end = i === entries.length - 1 ? total : starts[i + 1] + D; - const title = await chapterTitle(entries[i], i, provenance, { deck }); + const title = await chapterTitle(entries[i], i, provenance, { deck, names }); // `section`: the entry opens one of the cut's sections (a card) -- what // out/youtube.txt's Chapters keep (youtube.mjs youtubeChapters). // `id` and `cutStart` (where its segment starts, before the crossfade): @@ -7694,7 +7695,7 @@ export async function buildVideo({ manifestPath, opts = {}, out, only, fetchOnly } // Under the deck the cut's offsets include the holds: measured, not written. const joins = deck ? segmentJoins(await measureChromeSchedule({ manifest, entries, segments: segs, D })) : null; - const muxed = await muxChapters(finalPath, entries, segs, D, outDir, provenance, render.fps, deckOn(render), joins, { disclosure: await readCutDisclosure(narrationStore, manifest, " ") }); + const muxed = await muxChapters(finalPath, entries, segs, D, outDir, provenance, render.fps, deckOn(render), joins, { disclosure: await readCutDisclosure(narrationStore, manifest, " "), names: render.channelNames ?? null }); await writeYoutubeText(manifest, entries, outRoot, variant, muxed); return { out: finalPath, failures: [] }; } @@ -7731,7 +7732,7 @@ export async function buildVideo({ manifestPath, opts = {}, out, only, fetchOnly // gone. Put them back, or --rail-only quietly ships a chapterless cut. const muxed = opts.noChapters ? null - : await muxChapters(out, entries, segs, D, outDir, provenance, render.fps, deckOn(render), null, { disclosure: await readCutDisclosure(narrationStore, manifest, " ") }); + : await muxChapters(out, entries, segs, D, outDir, provenance, render.fps, deckOn(render), null, { disclosure: await readCutDisclosure(narrationStore, manifest, " "), names: render.channelNames ?? null }); await writeYoutubeText(manifest, entries, outRoot, variant, muxed, opts.noChapters ? "--no-chapters" : null); } EMIT("done", { out, failures: [] }); @@ -7926,7 +7927,7 @@ export async function buildVideo({ manifestPath, opts = {}, out, only, fetchOnly // The overlay re-encodes, so the chapters on the previous final are gone. const muxed = opts.noChapters ? null - : await muxChapters(dirs.final, entries, segs, D, outDir, provenance, render.fps, deckOn(render), joins, { disclosure: await readCutDisclosure(narrationStore, manifest, " ") }); + : await muxChapters(dirs.final, entries, segs, D, outDir, provenance, render.fps, deckOn(render), joins, { disclosure: await readCutDisclosure(narrationStore, manifest, " "), names: render.channelNames ?? null }); await writeYoutubeText(manifest, entries, outRoot, variant, muxed, opts.noChapters ? "--no-chapters" : null); await reportSync({ outDir, final: dirs.final, entries, segments: segs, D, render, joins }); await pruneFrames(); @@ -8118,7 +8119,7 @@ export async function buildVideo({ manifestPath, opts = {}, out, only, fetchOnly const muxed = opts.noChapters ? null - : await muxChapters(final, entries, segments, D, outDir, provenance, render.fps, deckOn(render), joins, { disclosure: await readCutDisclosure(narrationStore, manifest, " ") }); + : await muxChapters(final, entries, segments, D, outDir, provenance, render.fps, deckOn(render), joins, { disclosure: await readCutDisclosure(narrationStore, manifest, " "), names: render.channelNames ?? null }); await writeYoutubeText(manifest, entries, outRoot, variant, muxed, opts.noChapters ? "--no-chapters" : null); await reportSync({ outDir, final, entries, segments, D, render, joins }); diff --git a/umtool/report-to-video/channel-names.test.mjs b/umtool/report-to-video/channel-names.test.mjs @@ -0,0 +1,86 @@ +// render.channelNames (lane channel-title): the cut's own name for a channel, +// reaching every place a clip's channel is printed -- the deck's subtitle, the +// stacked deck's source line, a short's end card, the analysis item's +// citation -- and, absent, leaving every one of them exactly as it was. +// +// Run with: pnpm test:scripts +import assert from "node:assert/strict"; +import test from "node:test"; + +import { deckSchedule, deckText, resolveDeck, stackedSegmentFields } from "./deck.mjs"; +import { endCardSources } from "./outro.mjs"; +import { analysisSource } from "./modules/analysis.mjs"; + +const PALETTE = { bg: "#12101a", fg: "#f4f1ea", muted: "#9a93ad", accent: "#a97bff", amber: "#ffc860" }; +const BASE = { width: 1920, height: 1080, fps: 30, transition: 0.5, palette: PALETTE, chrome: { engine: "hyperframes", layout: "deck", deck: {} } }; +const PROV = { siteOrigin: "https://example.test", channelSlug: "synth-chan", channel: "Synth Sweep" }; +// Two recordings of ONE channel whose records carry two uploader names, and a guest. +const CLIPS = [ + { id: "c1", type: "clip", channel: "synth-chan", video: "a", start: 60, end: 70, date: "2031-03-01" }, + { id: "c2", type: "clip", channel: "synth-chan", video: "b", start: 0, end: 20, date: "2031-04-01" }, + { id: "c3", type: "clip", channel: "guest-chan", video: "c", start: 0, end: 6, date: "2031-05-01" }, +]; +const METAS = [ + { title: "Old stream", uploadDate: "20310301", channel: "SYNTH OLD NAME" }, + { title: "New stream", uploadDate: "20310401", channel: "Synth Channel" }, + { title: "Guest show", uploadDate: "20310501", channel: "Guest Show" }, +]; +const DURS = [10, 20, 6]; +const sched = (render) => deckSchedule({ entries: CLIPS, durs: DURS, D: 0.5, render, provenance: PROV, metas: METAS }); + +test("deckSchedule: render.channelNames absent, empty, or naming no clip's channel -- the schedule is what it was", () => { + const before = sched(BASE); + assert.deepEqual(sched({ ...BASE, channelNames: {} }), before); + assert.deepEqual(sched({ ...BASE, channelNames: { "unused-chan": "Nobody" } }), before); + assert.equal(before.multiChannel, true); + assert.match(before.segments[0].subtitle, /^SYNTH OLD NAME · /, "the record's name, as before"); +}); + +test("deckSchedule: one channel's name for the whole cut -- both recordings say it, the guest is untouched", () => { + const before = sched(BASE); + const after = sched({ ...BASE, channelNames: { "synth-chan": "Synth Channel" } }); + assert.match(after.segments[0].subtitle, /^Synth Channel · Old stream · /); + assert.match(after.segments[1].subtitle, /^Synth Channel · New stream · /); + assert.equal(after.segments[2].subtitle, before.segments[2].subtitle); + // Only the channel's words moved: the rest of the schedule is the same. + const strip = (d) => JSON.stringify(d).replaceAll("SYNTH OLD NAME", "Synth Channel"); + assert.equal(strip(after), strip(before)); + // A clip's own channelTitle still beats the cut's name. + const own = deckSchedule({ + entries: [{ ...CLIPS[0], channelTitle: "Clip Own" }, ...CLIPS.slice(1)], durs: DURS, D: 0.5, + render: { ...BASE, channelNames: { "synth-chan": "Synth Channel" } }, provenance: PROV, metas: METAS, + }); + assert.match(own.segments[0].subtitle, /^Clip Own · /); +}); + +test("deckText and stackedSegmentFields take the names; without them they say what they said", () => { + const deck = resolveDeck(BASE); + const a = deckText(CLIPS[0], METAS[0], PROV, deck, true, ""); + assert.deepEqual(deckText(CLIPS[0], METAS[0], PROV, deck, true, "", undefined), a); + assert.match(deckText(CLIPS[0], METAS[0], PROV, deck, true, "", { "synth-chan": "Synth Channel" }).subtitle, /^Synth Channel · /); + const s = stackedSegmentFields(CLIPS[0], METAS[0], PROV, deck); + assert.equal(s.vsource.channel, "SYNTH OLD NAME"); + assert.equal(stackedSegmentFields(CLIPS[0], METAS[0], PROV, deck, { "synth-chan": "Synth Channel" }).vsource.channel, "Synth Channel"); +}); + +test("endCardSources: the cut's name for a clip with no schedule part; a clip's own title first; absent as before", () => { + const timeline = [ + { type: "clip", id: "a", channel: "synth-chan", video: "v1", start: 61 }, + { type: "clip", id: "b", channel: "synth-chan", video: "v2", start: 5, channelTitle: "Clip Own" }, + { type: "clip", id: "c", channel: "guest-chan", video: "v3", start: 7 }, + ]; + assert.deepEqual(endCardSources(timeline), [{ date: "", label: "1:01" }, { date: "", label: "Clip Own · 0:05" }, { date: "", label: "0:07" }]); + assert.deepEqual(endCardSources(timeline, null, { "synth-chan": "Synth Channel" }), [ + { date: "", label: "Synth Channel · 1:01" }, + { date: "", label: "Clip Own · 0:05" }, + { date: "", label: "0:07" }, + ]); +}); + +test("analysisSource: the analysis item's citation names the channel by the cut's name", () => { + const manifest = { provenance: PROV, render: { ...BASE }, timeline: [...CLIPS, { type: "analysis", id: "x1", audio: { clip: "c1", start: 62 } }] }; + const entry = manifest.timeline[3]; + assert.equal(analysisSource(entry, manifest, METAS[0]).parts.channel, "SYNTH OLD NAME"); + const named = { ...manifest, render: { ...BASE, channelNames: { "synth-chan": "Synth Channel" } } }; + assert.equal(analysisSource(entry, named, METAS[0]).parts.channel, "Synth Channel"); +}); diff --git a/umtool/report-to-video/deck.mjs b/umtool/report-to-video/deck.mjs @@ -1300,9 +1300,12 @@ const sameTitle = (a, b) => titleKey(a) === titleKey(b); * its two lines too (`subtitleLines`, deckSubtitleLines) -- never an entry's * own `onscreen.subtitle`, which is the one line its author typed. A clip's * `onscreen.title` that only repeats its source's title (sameTitle) is - * dropped when the two lines show that title. + * dropped when the two lines show that title. `names`: the cut's + * `render.channelNames` (attribution.mjs channelName), absent as before. + * + * @param {Record<string, unknown> | null} [names] */ -export function deckText(entry, meta, provenance, deck, multiChannel, status = "") { +export function deckText(entry, meta, provenance, deck, multiChannel, status = "", names = null) { const o = entry.onscreen ?? {}; let title = o.title ?? ""; let subtitle = o.subtitle; @@ -1317,7 +1320,7 @@ export function deckText(entry, meta, provenance, deck, multiChannel, status = " if (entry.type === "clip") { // The source status (source-status.mjs), when the deck draws it and the // stamp names a state: else no key, and the parts are what they were. - const parts = { ...attributionParts(entry, meta ?? {}, provenance), ...(status ? { status } : {}) }; + const parts = { ...attributionParts(entry, meta ?? {}, provenance, names), ...(status ? { status } : {}) }; subtitle = deckSubtitle(parts, deck.subtitle, multiChannel); subtitleParts = deckSubtitleParts(parts, deck.subtitle, multiChannel); if (two) subtitleLines = deckSubtitleLines(parts, deck.subtitle, multiChannel); @@ -1539,7 +1542,7 @@ export function deckSchedule({ multiChannel, ...(feed ? { layout: "feed" } : {}), segments: entries.map((e, i) => { - const { title, subtitle, subtitleParts, subtitleLines, subtitleLinesParts } = deckText(e, metas[i] ?? null, provenance, deck, multiChannel, statusOf(e)); + const { title, subtitle, subtitleParts, subtitleLines, subtitleLinesParts } = deckText(e, metas[i] ?? null, provenance, deck, multiChannel, statusOf(e), render.channelNames); return { id: e.id, type: e.type, @@ -1578,7 +1581,7 @@ export function deckSchedule({ ...(finIds.has(e.id) && resolveFinale(render).pips === false ? { noPip: true } : {}), // Only in the stacked vertical deck (vertical-deck.mjs): a clip's source line in its parts (channel, // title, date, the clock at its start), and a twocrop clip's layout -- its strip and its small QR. - ...(stacked ? stackedSegmentFields(e, metas[i] ?? null, provenance, deck) : {}), + ...(stacked ? stackedSegmentFields(e, metas[i] ?? null, provenance, deck, render.channelNames) : {}), }; }), // The finale: present only when the cut has one. @@ -1649,11 +1652,13 @@ export function deckSchedule({ * A segment's fields only the stacked vertical deck's page reads: a clip's * source line in its four parts (`vsource`: channel, title -- the deck's own * title when the entry sets one --, date, the clock at its start) and a - * twocrop clip's layout (`vlayout`). + * twocrop clip's layout (`vlayout`). `names`: the cut's `render.channelNames`. + * + * @param {Record<string, unknown> | null} [names] */ -export function stackedSegmentFields(entry, meta, provenance, deck) { +export function stackedSegmentFields(entry, meta, provenance, deck, names = null) { if (entry?.type !== "clip") return {}; - const p = attributionParts(entry, meta ?? {}, provenance); + const p = attributionParts(entry, meta ?? {}, provenance, names); const title = String(entry.onscreen?.title ?? "").trim() || String(p.title ?? "").trim(); return { vsource: { diff --git a/umtool/report-to-video/modules/analysis.mjs b/umtool/report-to-video/modules/analysis.mjs @@ -24,7 +24,7 @@ export function analysisSource(entry, manifest, meta = null) { const at = { ...clip, cite: Number(a.start), start: Number(a.start) }; const links = resolveDeck(manifest?.render ?? {}).qr?.links; return { - parts: attributionParts(at, meta ?? {}, manifest?.provenance ?? {}), + parts: attributionParts(at, meta ?? {}, manifest?.provenance ?? {}, manifest?.render?.channelNames), url: deckQrUrl(at, manifest?.provenance ?? {}, { ...(links ? { links } : {}), meta }), }; } diff --git a/umtool/report-to-video/modules/panel.mjs b/umtool/report-to-video/modules/panel.mjs @@ -18,8 +18,8 @@ import { MODULES } from "./index.mjs"; const isObj = (v) => v !== null && typeof v === "object" && !Array.isArray(v); -/** Look keys whose writer merges a patch into what it holds (common look.mjs applyLookPatch): the gap mark's. */ -const MERGED_LOOK_KEYS = new Set(["gapCue"]); +/** Look keys whose writer merges a patch into what it holds (common look.mjs applyLookPatch): the gap mark's, the channel names. */ +const MERGED_LOOK_KEYS = new Set(["gapCue", "channelNames"]); /** Where a module's ui keys are rooted. */ export function uiBase(m) { diff --git a/umtool/report-to-video/outro.mjs b/umtool/report-to-video/outro.mjs @@ -31,6 +31,7 @@ import path from "node:path"; import { promisify } from "node:util"; import { FONTCONFIG_FILE } from "./brand.mjs"; +import { cutChannelName } from "./attribution.mjs"; const execFileP = promisify(execFile); const exists = (p) => access(p).then(() => true, () => false); @@ -219,14 +220,16 @@ export function endCardDate(d) { /** * The sources an end card lists: each clip of `timeline` once (by video), in order -- its date, its channel and - * the time it is from, from the build's schedule (a stacked deck's `vsource`) else what the entry says of itself. - * Pure. + * the time it is from, from the build's schedule (a stacked deck's `vsource`) else what the entry says of itself -- + * its own `channelTitle`, else the cut's name for its channel (`names`, the cut's `render.channelNames`). Pure. * * @param {Array<Record<string, any>>} timeline * @param {{ segments?: Array<Record<string, any>> } | null} [schedule] + * @param {Record<string, unknown> | null} [names] + * @param {{ channelSlug?: string | null }} [provenance] * @returns {Array<{ date: string, label: string }>} */ -export function endCardSources(timeline, schedule = null) { +export function endCardSources(timeline, schedule = null, names = null, provenance = {}) { const bySeg = new Map((Array.isArray(schedule?.segments) ? schedule.segments : []).map((x) => [x.id, x])); const seen = new Set(); const out = []; @@ -236,7 +239,7 @@ export function endCardSources(timeline, schedule = null) { if (seen.has(key)) continue; seen.add(key); const v = bySeg.get(e.id)?.vsource ?? bySeg.get(String(e.id).replace(/~\d+$/, ""))?.vsource ?? null; - const channel = String(v?.channel ?? e.channelTitle ?? "").trim(); + const channel = String(v?.channel ?? (String(e.channelTitle ?? "").trim() || cutChannelName(e, provenance, names))).trim(); const at = Number(e.cite ?? e.start); const clock = v?.clock ?? (Number.isFinite(at) ? hmsOf(at) : ""); const label = [channel, clock].filter(Boolean).join(" · ");