Archilyzer · Source

archilyzer

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

commit e28ee6a4d127288df9dfb4ba4a02da6025687dd6
parent c6f2fe0532d5a9076469428160331f2094c24c3a
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Sun,  1 Nov 2026 22:30:03 -0500

umtool chapters from the deck's markers: youtube.mjs markerChapters -- each top-level marker (a level-2 subsection is no chapter) at the second the segment after its clip starts, the opening titled deck.sectionTitle.first (or export --first; with neither the first section takes 0:00), YouTube's rules kept with what was merged said by name -- in the build's out/youtube.txt and `umtool export --format chapters` alike; replaces the hand chapters script, row for row on Ember draft-24 (fixture); the export now reads a cut that opens on the brand intro (its chapter folded into the next) instead of refusing it as "a different cut"

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

Diffstat:
Mumtool/bin/umtool.mjs | 10+++++++---
Mumtool/docs/cli.md | 2+-
Mumtool/docs/report-video.md | 11++++++++++-
Aumtool/lib/report/export-chapters.test.mjs | 87+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mumtool/lib/report/export.mjs | 69+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------
Mumtool/report-to-video/build-video.mjs | 20++++++++++++++++++--
Aumtool/report-to-video/fixtures/ember-draft-24-chapters.json | 23+++++++++++++++++++++++
Mumtool/report-to-video/youtube.mjs | 131+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
Mumtool/report-to-video/youtube.test.mjs | 52+++++++++++++++++++++++++++++++++++++++++++++++++++-
9 files changed, 384 insertions(+), 21 deletions(-)

diff --git a/umtool/bin/umtool.mjs b/umtool/bin/umtool.mjs @@ -54,7 +54,7 @@ // move clips/ and every share-*/, then set the switch // umtool snapshot <project> [--label L] copy the manifest into revisions/ // umtool diff <project> <snapshot> what changed since that snapshot -// umtool export <project> --format toc-bbcode|toc-markdown|description|chapters [--variant V] +// umtool export <project> --format toc-bbcode|toc-markdown|description|chapters [--variant V] [--first TITLE] // umtool export <project> <clip> [--raw] [--take T] [--open] [--json] one clip, clean, into // <project>/exports/: the cut's edges, gaps out, mute (--raw: the whole fetched window) // umtool check-sources [<project>…] prints the re-check chain @@ -698,10 +698,14 @@ async function cmdExport() { if (!format && positional[1]) return cmdExportClip(p, positional[1]); if (!format) die(`--format is one of ${EXPORT_FORMATS.join(", ")} — or name a clip: umtool export ${p.id} <clip> [--raw] [--open]`); try { - const r = await exportProject(p.dir, format, val("--variant") ? { variant: val("--variant") } : {}); + const r = await exportProject(p.dir, format, { + ...(val("--variant") ? { variant: val("--variant") } : {}), + ...(val("--first") ? { first: val("--first") } : {}), + }); if (json) return out(r); process.stdout.write(r.text); if (r.offsets.note) console.error(`# ${r.offsets.note}`); + for (const n of r.notes ?? []) console.error(`# ${n}`); } catch (e) { die(e?.message ?? String(e)); } @@ -852,7 +856,7 @@ function usage() { " out/ to the media root (UMTOOL_MEDIA_DIR) and back; run when nothing is building", " umtool snapshot <project> [--label L] copy the manifest into revisions/", " umtool diff <project> <snapshot> what changed since that snapshot", - " umtool export <project> --format toc-bbcode|toc-markdown|description|chapters [--variant V]", + " umtool export <project> --format toc-bbcode|toc-markdown|description|chapters [--variant V] [--first TITLE]", " umtool export <project> <clip> [--raw] [--take T] [--open] one clip, clean, into <project>/exports/:", " the cut's edges, its gaps out, its mute; --raw the whole fetched window; --open shows it", " umtool check-sources [<project>…] prints the re-check chain (never-checked/old when no args)", diff --git a/umtool/docs/cli.md b/umtool/docs/cli.md @@ -44,7 +44,7 @@ Inbox cannot disagree about what is wrong with one. | `storage deliverables <project> --to media\|local [--dry-run] [--json]` | `clips/` and every `share-*/` to the media root and back, then `storage.deliverables` in the manifest; refused while a build step, a cut or a share batch (by `--project` id, name or directory, as the app starts them) or the report's own scripts run in the project — a hand-run command that is none of these is not seen; **exit 1** on any failure (the switch is then left as it was) | | `snapshot <project> [--label L]` | copy the manifest into `revisions/` | | `diff <project> <snapshot>` | added / removed / moved / window / retyped, by entry id | -| `export <project> --format toc-bbcode\|toc-markdown\|description\|chapters [--variant V]` | the posting artifacts, from the build's chapter offsets | +| `export <project> --format toc-bbcode\|toc-markdown\|description\|chapters [--variant V] [--first TITLE]` | the posting artifacts, from the build's chapter offsets. A deck with markers: `chapters` are its top-level sections (subsections left out) at the second each section's first segment starts, YouTube's rules kept (0:00 first, each ≥ 10 s, at least three; what was merged is said on stderr); the opening is titled `deck.sectionTitle.first`, or `--first TITLE`, else the first section takes 0:00 | | `check-sources [<project>…]` | **prints** the re-check chain; with no args, the never-checked and >30 d projects | | `corrections <project>` | what the report got wrong (the clip bench's sixth field) and the walk's coverage, as markdown for the next pass | | `chain <article> <n> [--from <step>] [--dry] [--final] [--draft-all [--model M]]` | an iteration to a video: the Iterations tab's **Make the video** (`--draft-all`: Draft everything) | diff --git a/umtool/docs/report-video.md b/umtool/docs/report-video.md @@ -2199,7 +2199,16 @@ variant with anything on disk). All derived from the manifest plus the build's offsets — `out/<variant>/chapters.ffmeta` when present, else `segmentOffsets()` over the segments, else a refusal with the reason. `toc-bbcode` reproduces the hand-made `toc.bbcode.txt` shape; `description` adds the source list; `chapters` -is YouTube's form and includes cards. Cite URLs follow the QR's rule. A cut +is YouTube's form and includes cards. **A cut whose deck has markers** gets its +SECTIONS as chapters instead, in `chapters` and in the build's `out/youtube.txt` +alike (youtube.mjs `markerChapters`): each top-level marker (a `level: 2` +subsection is left out) at the second the segment after its clip starts in +the master (the deck's `schedule.json`), the opening titled +`deck.sectionTitle.first` (or `--first TITLE`; with neither, the first section +takes 0:00), then YouTube's rules — 0:00 first, each at least 10 s, at least +three — with what had to be merged printed on stderr (`# …`). A cut that opens +on the brand intro reads the build's folded intro chapter back (the intro and +the clip after it both at 0). Cite URLs follow the QR's rule. A cut with a narrated card (`narration`, below) ends its `description` and `chapters` with the editor's disclosure line, `Narration: synthetic voice (Kokoro-82M · af_heart)`. diff --git a/umtool/lib/report/export-chapters.test.mjs b/umtool/lib/report/export-chapters.test.mjs @@ -0,0 +1,87 @@ +// `umtool export --format chapters` on a cut whose deck has markers: its +// top-level sections at the second each one's first segment starts (the deck +// schedule's), YouTube's rules kept, what was merged said -- the hand +// script's rows for Ember draft-24 (report-to-video/fixtures). A deck without +// markers lists every entry, as it always did. +// +// Run with: pnpm test:scripts +import assert from "node:assert/strict"; +import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs"; +import { tmpdir } from "node:os"; +import path from "node:path"; +import test from "node:test"; + +import { exportProject } from "./export.mjs"; + +const EMBER = JSON.parse(readFileSync(new URL("../../report-to-video/fixtures/ember-draft-24-chapters.json", import.meta.url), "utf8")); + +const FFMETA = (n) => + [";FFMETADATA1", "", ...Array.from({ length: n }, (_, i) => ["[CHAPTER]", "TIMEBASE=1/1000", `START=${i * 5000}`, `END=${(i + 1) * 5000}`, `title=Entry ${i + 1}`, ""]).flat()].join("\n"); + +/** A built cut: the fixture's segments as its timeline (the brand intro is the schedule's own), its deck's markers. */ +function project(root, deck) { + const dir = path.join(root, `p-${Math.random().toString(36).slice(2)}`); + mkdirSync(path.join(dir, "out", "sourced"), { recursive: true }); + const timeline = EMBER.segments.slice(1).map(([id], i) => ({ id, type: "clip", video: `v${i}`, start: 0, end: 5 })); + writeFileSync(path.join(dir, "video.manifest.json"), JSON.stringify({ + slug: "s", title: "A cut", provenance: { siteOrigin: "https://example.test", channelSlug: "chan" }, + render: { fps: 30, transition: EMBER.transition, chrome: { engine: "hyperframes", layout: "deck", deck } }, timeline, + })); + writeFileSync(path.join(dir, "out", "sourced", "chapters.ffmeta"), FFMETA(timeline.length)); + writeFileSync(path.join(dir, "out", "sourced", "schedule.json"), JSON.stringify({ + version: 1, kind: "deck", fps: 30, transition: EMBER.transition, total: EMBER.total, + segments: EMBER.segments.map(([id, start]) => ({ id, start })), + })); + return dir; +} + +test("chapters from the deck's markers: Ember draft-24's 13 rows, the opening titled by --first or deck.sectionTitle.first", async (t) => { + const root = mkdtempSync(path.join(tmpdir(), "umtool-export-chapters-")); + t.after(() => rmSync(root, { recursive: true, force: true })); + const dir = project(root, { markers: EMBER.markers }); + const r = await exportProject(dir, "chapters", { first: EMBER.first }); + assert.deepEqual(r.text.trimEnd().split("\n"), EMBER.expected); + assert.deepEqual(r.notes, []); + // The deck's own first section's title does the same. + const titled = project(root, { markers: EMBER.markers, sectionTitle: { first: EMBER.first } }); + assert.deepEqual((await exportProject(titled, "chapters")).text.trimEnd().split("\n"), EMBER.expected); + // None: the first section takes 0:00, and the note says so. + const bare = await exportProject(dir, "chapters"); + assert.deepEqual(bare.text.trimEnd().split("\n"), ["0:00 Sex appeal", ...EMBER.expected.slice(2)]); + assert.match(bare.notes.join("\n"), /the opening has no title/); +}); + +test("chapters: subsections left out; a deck without markers lists every entry as before", async (t) => { + const root = mkdtempSync(path.join(tmpdir(), "umtool-export-chapters-")); + t.after(() => rmSync(root, { recursive: true, force: true })); + const subs = project(root, { markers: [...EMBER.markers, { after: "tj1", label: "A subsection", level: 2 }] }); + const r = await exportProject(subs, "chapters", { first: EMBER.first }); + assert.deepEqual(r.text.trimEnd().split("\n"), EMBER.expected); + const plain = project(root, {}); + const lines = (await exportProject(plain, "chapters")).text.trimEnd().split("\n"); + assert.equal(lines.length, EMBER.segments.length - 1); + assert.match(lines[0], /^00:00 /); +}); + +test("a cut that opens on the brand intro: the build folded its chapter into the next, and the export reads it so (no 'different cut' refusal)", async (t) => { + const root = mkdtempSync(path.join(tmpdir(), "umtool-export-chapters-")); + t.after(() => rmSync(root, { recursive: true, force: true })); + const dir = path.join(root, "intro"); + mkdirSync(path.join(dir, "out", "sourced"), { recursive: true }); + const timeline = [{ id: "brand-intro", type: "intro" }, ...[1, 2, 3].map((i) => ({ id: `c${i}`, type: "clip", video: `v${i}`, start: 0, end: 5 }))]; + writeFileSync(path.join(dir, "video.manifest.json"), JSON.stringify({ slug: "s", title: "A cut", provenance: { siteOrigin: "https://example.test", channelSlug: "chan" }, render: { fps: 30 }, timeline })); + writeFileSync(path.join(dir, "out", "sourced", "chapters.ffmeta"), FFMETA(3)); // 0, 5, 10: c1 (with the intro), c2, c3 + const lines = (await exportProject(dir, "chapters")).text.trimEnd().split("\n"); + assert.deepEqual(lines.map((l) => l.slice(0, 5)), ["00:00", "00:00", "00:05", "00:10"]); + // One chapter short of the entries WITHOUT an intro is still another cut. + writeFileSync(path.join(dir, "video.manifest.json"), JSON.stringify({ slug: "s", title: "A cut", render: { fps: 30 }, timeline: timeline.slice(1).concat({ id: "c4", type: "clip", video: "v4", start: 0, end: 5 }) })); + await assert.rejects(exportProject(dir, "chapters"), /describes a different cut/); +}); + +test("chapterMarkersOf: the deck's markers, and the opening's title only from a sectionTitle object", async () => { + const { chapterMarkersOf } = await import("umtool-report-to-video/build-video"); + const deck = (d) => ({ render: { chrome: { deck: d } } }); + assert.deepEqual(chapterMarkersOf(deck({ markers: EMBER.markers, sectionTitle: { first: "Open" } })), { markers: EMBER.markers, first: "Open" }); + assert.deepEqual(chapterMarkersOf(deck({ markers: EMBER.markers, sectionTitle: false })), { markers: EMBER.markers, first: null }); + assert.deepEqual(chapterMarkersOf({}), { markers: null, first: null }); +}); diff --git a/umtool/lib/report/export.mjs b/umtool/lib/report/export.mjs @@ -16,10 +16,11 @@ // Plain ESM, so `umtool export` runs from a terminal. import { readFile, readdir, stat } from "node:fs/promises"; import path from "node:path"; -import { DEFAULT_VARIANT, selectVariant, segmentOffsets } from "umtool-report-to-video/build-video"; +import { DEFAULT_VARIANT, chapterMarkersOf, selectVariant, segmentOffsets } from "umtool-report-to-video/build-video"; import { citeUrlFor, channelFor, readAvailability, readManifest } from "../projects/report.mjs"; import { teaserTitle } from "umtool-report-to-video/deck"; import { narrationDir, readCutDisclosure } from "umtool-report-to-video/narration-store"; +import { chapterLines, hasChapterMarkers, markerChapters } from "umtool-report-to-video/youtube"; import { outDirState } from "./storage.mjs"; export const EXPORT_FORMATS = ["toc-bbcode", "toc-markdown", "description", "chapters"]; @@ -69,7 +70,8 @@ const titleOf = (e, i) => /** * Deliverable-second offsets for every entry of the chosen variant. - * @returns {Promise<{ starts: number[], source: "ffmeta"|"schedule"|"segments", file: string, note?: string } | { error: string }>} + * `total` is the cut's length when the source says it. + * @returns {Promise<{ starts: number[], total?: number, source: "ffmeta"|"schedule"|"segments", file: string, note?: string } | { error: string }>} */ export async function chapterOffsets(dir, manifest, variant) { const entries = manifest.timeline ?? []; @@ -85,7 +87,13 @@ export async function chapterOffsets(dir, manifest, variant) { for (const file of ffmetaCandidates) { const text = await readFile(file, "utf8").catch(() => null); if (text === null) continue; - const chapters = parseFfmeta(text); + let chapters = parseFfmeta(text); + // The brand intro has no chapter of its own: the build folds it into the + // one after it (build-video foldIntroChapter), which starts at 0. It is + // read back the same way -- the intro and the entry after it both at 0. + if (entries[0]?.type === "intro" && entries.length > 1 && chapters.length === entries.length - 1) { + chapters = [{ start: 0, end: chapters[0]?.start ?? 0, title: "" }, ...chapters]; + } if (chapters.length !== entries.length) { return { error: @@ -93,7 +101,8 @@ export async function chapterOffsets(dir, manifest, variant) { "it describes a different cut; rebuild (a chapters-only build is enough)", }; } - return { starts: chapters.map((c) => c.start), source: "ffmeta", file }; + const end = chapters.at(-1)?.end; + return { starts: chapters.map((c) => c.start), ...(Number.isFinite(end) ? { total: end } : {}), source: "ffmeta", file }; } // No ffmeta, but a deck schedule for this cut: its starts are the cut's own, @@ -105,6 +114,7 @@ export async function chapterOffsets(dir, manifest, variant) { const D = sched.transition ?? 0; return { starts: sched.segments.map((x, i) => (i === 0 ? 0 : x.start + D)), + ...(Number.isFinite(sched.total) ? { total: sched.total } : {}), source: "schedule", file: path.join(outDir, variant, "schedule.json"), note: "no chapters.ffmeta; offsets from the deck's schedule.json", @@ -122,10 +132,11 @@ export async function chapterOffsets(dir, manifest, variant) { } const render = manifest.render ?? {}; const D = render.transition ?? 0.5; - const { starts } = await segmentOffsets(entries.map((e) => path.join(segDir, `${e.id}.mp4`)), D, render.fps); + const { starts, total } = await segmentOffsets(entries.map((e) => path.join(segDir, `${e.id}.mp4`)), D, render.fps); // Land just past the crossfade, as muxChapters does. return { starts: starts.map((s, i) => (i === 0 ? 0 : s + D)), + ...(Number.isFinite(total) ? { total } : {}), source: "segments", file: segDir, note: `no chapters.ffmeta; offsets computed from the segments assuming a ${D}s crossfade — a hard-cut build would be earlier by that much per entry`, @@ -137,10 +148,12 @@ export async function chapterOffsets(dir, manifest, variant) { /** * @param {string} dir * @param {string} format one of EXPORT_FORMATS - * @param {{ variant?: string }} [opts] - * @returns {Promise<{ text: string, format: string, variant: string, offsets: { source: string, file: string, note?: string } }>} + * `first` (chapters): the opening's title, over the deck's `sectionTitle.first`. + * + * @param {{ variant?: string, first?: string | null }} [opts] + * @returns {Promise<{ text: string, format: string, variant: string, offsets: { source: string, file: string, note?: string }, notes: string[] }>} */ -export async function exportProject(dir, format, { variant = DEFAULT_VARIANT } = {}) { +export async function exportProject(dir, format, { variant = DEFAULT_VARIANT, first = null } = {}) { if (!EXPORT_FORMATS.includes(format)) throw new Error(`format must be one of ${EXPORT_FORMATS.join(", ")}`); const whole = await readManifest(dir); if (!whole) throw new Error("no manifest"); @@ -162,7 +175,14 @@ export async function exportProject(dir, format, { variant = DEFAULT_VARIANT } = const disclosure = await readCutDisclosure(narrationDir(path.join(dir, "out")), m, "\n"); let text; - if (format === "toc-bbcode") { + /** @type {string[]} */ + const notes = []; + // A deck with markers: the chapters are its sections (youtube.mjs + // markerChapters), placed by the deck schedule's segment starts. + const chaptersFromMarkers = format === "chapters" ? await deckChapters(dir, m, variant, off, first, notes) : null; + if (chaptersFromMarkers) { + text = chapterLines(chaptersFromMarkers).join("\n") + "\n" + (disclosure ? `\n${disclosure}\n` : ""); + } else if (format === "toc-bbcode") { text = [ `[b]${m.title}${m.subtitle ? ` — ${m.subtitle}` : ""}[/b]`, "", @@ -207,7 +227,36 @@ export async function exportProject(dir, format, { variant = DEFAULT_VARIANT } = ...(disclosure ? [disclosure, ""] : []), ].join("\n"); } - return { text, format, variant, offsets: { source: off.source, file: off.file, ...(off.note ? { note: off.note } : {}) } }; + return { text, format, variant, offsets: { source: off.source, file: off.file, ...(off.note ? { note: off.note } : {}) }, notes }; +} + +/** + * The chapters a cut's deck markers make (youtube.mjs markerChapters), or + * null when the deck has none (the entries are listed as before) or too few + * survive YouTube's rules (said in `notes`). Placed by the deck's + * `out/<variant>/schedule.json` -- each section where its first segment + * starts, as the hand script placed them -- else by the export's offsets. + * + * @param {string} dir + * @param {any} m the variant's manifest + * @param {string} variant + * @param {{ starts: number[], total?: number }} off + * @param {string | null} first + * @param {string[]} notes + */ +async function deckChapters(dir, m, variant, off, first, notes) { + const { markers, first: deckFirst } = chapterMarkersOf(m); + if (!hasChapterMarkers(markers)) return null; + const sched = await readFile(path.join(dir, "out", variant, "schedule.json"), "utf8").then((t) => JSON.parse(t), () => null); + const fromSchedule = sched?.kind === "deck" && Array.isArray(sched.segments) && sched.segments.every((x) => typeof x?.id === "string" && Number.isFinite(x?.start)); + const segments = fromSchedule + ? sched.segments.map((x) => ({ id: x.id, start: x.start })) + : (m.timeline ?? []).map((e, i) => ({ id: e.id, start: off.starts[i] })); + const total = fromSchedule && Number.isFinite(sched.total) ? sched.total : off.total ?? null; + const r = markerChapters({ markers, segments, total, first: first ?? deckFirst }); + notes.push(...r.notes); + if (!r.chapters) notes.push("the deck's markers make no chapter list YouTube takes: every entry is listed instead"); + return r.chapters; } /** Which variants have anything on disk to export from, for the UI's row. */ diff --git a/umtool/report-to-video/build-video.mjs b/umtool/report-to-video/build-video.mjs @@ -5672,7 +5672,9 @@ async function muxChapters(finalPath, entries, segments, D, outDir, provenance, const title = await chapterTitle(entries[i], i, provenance, { deck }); // `section`: the entry opens one of the cut's sections (a card) -- what // out/youtube.txt's Chapters keep (youtube.mjs youtubeChapters). - all.push({ start, end, title, section: entries[i]?.type === "card" }); + // `id` and `cutStart` (where its segment starts, before the crossfade): + // what the deck's markers place their chapters by (youtube.mjs markerChapters). + all.push({ start, end, title, section: entries[i]?.type === "card", id: entries[i]?.id, cutStart: starts[i] }); } const chapters = foldIntroChapter(all, entries); for (const c of chapters) { @@ -5738,7 +5740,9 @@ async function writeYoutubeText(manifest, entries, outRoot, variant, muxed, why await writeSocialText(manifest, outRoot); const youtube = manifest.publish?.youtube; if (!youtube?.title) return null; - const { chapters, note } = muxed ? youtubeChapters(muxed.chapters, muxed.total) : { chapters: null, note: `no chapters: ${why ?? "the cut is one segment"}` }; + const { chapters, note } = muxed + ? youtubeChapters(muxed.chapters, muxed.total, chapterMarkersOf(manifest)) + : { chapters: null, note: `no chapters: ${why ?? "the cut is one segment"}` }; const text = composeYoutubeText({ youtube, chapters, sources: youtubeSources(entries, manifest.provenance) }); const file = path.join(outRoot, youtubeTextName(variant)); await writeFile(file, text, "utf8"); @@ -5747,6 +5751,18 @@ async function writeYoutubeText(manifest, entries, outRoot, variant, muxed, why } /** + * What a cut's YouTube chapters are placed by when its deck has markers + * (youtube.mjs markerChapters): the markers, and the opening's title + * (`deck.sectionTitle.first`, when the section title is set as an object). + */ +export function chapterMarkersOf(manifest) { + const deck = manifest?.render?.chrome?.deck; + const st = deck?.sectionTitle; + const first = st && typeof st === "object" && typeof st.first === "string" ? st.first : null; + return { markers: Array.isArray(deck?.markers) ? deck.markers : null, first }; +} + +/** * The hard-cut concat's list, as written. Absolute: the concat demuxer resolves * a relative entry against the LIST's directory, so a relative `--out` named * every segment twice over and the hard-cut concat failed to open its first diff --git a/umtool/report-to-video/fixtures/ember-draft-24-chapters.json b/umtool/report-to-video/fixtures/ember-draft-24-chapters.json @@ -0,0 +1,23 @@ +{ + "about": "The minimum of EmberParadox 'in her own words' take draft-24 that its chapters are made from: each deck marker's clip and the segment after it, where each starts in the master (out/sourced/schedule.json), the master's length, and the 13 rows the hand script (night1030 chapters.py) printed for it, its opening title as that script supplied it.", + "total": 1790, + "transition": 0.4, + "segments": [["brand-intro", 0], ["v01t", 163.333], ["ow2", 176.1], ["g01", 290], ["gn1", 299.333], ["d01", 312.833], ["rf1", 324.867], ["mk1", 360.567], ["tj1", 377.9], ["lj2", 562.9], ["n02", 588], ["p02", 681.9], ["ts1", 693.1], ["tr6", 860.233], ["fn4", 877.567], ["fn1", 925.7], ["r01", 935.967], ["u01", 1090.1], ["x01", 1109.733], ["ws1", 1258.633], ["sr1a", 1272.167], ["ks2", 1542.4], ["bk1", 1570.3], ["bk3", 1641.333], ["ho3", 1684.067]], + "markers": [{"after": "v01t", "label": "Sex appeal", "color": "#e070d0"}, {"after": "g01", "label": "Not a character", "color": "#f2a65a"}, {"after": "d01", "label": "Leaves it open", "color": "#ffc861"}, {"after": "mk1", "label": "Why does it matter?", "color": "#c4a1ff"}, {"after": "lj2", "label": "Why the voice changer", "color": "#6fc3ff"}, {"after": "p02", "label": "On trans issues", "color": "#7fdc9a"}, {"after": "tr6", "label": "On Finnster", "color": "#5fd1c9"}, {"after": "fn1", "label": "26–28 October", "color": "#ff7a59"}, {"after": "u01", "label": "After the reveal", "color": "#f78fb3"}, {"after": "ws1", "label": "Kirsche, Side Scrollers", "color": "#a3e635"}, {"after": "ks2", "label": "Her books", "color": "#e8d9b0"}, {"after": "bk3", "label": "The book, read aloud", "color": "#9fb3c8"}], + "first": "As an anime girl, as a woman", + "expected": [ + "0:00 As an anime girl, as a woman", + "2:56 Sex appeal", + "4:59 Not a character", + "5:24 Leaves it open", + "6:17 Why does it matter?", + "9:48 Why the voice changer", + "11:33 On trans issues", + "14:37 On Finnster", + "15:35 26–28 October", + "18:29 After the reveal", + "21:12 Kirsche, Side Scrollers", + "26:10 Her books", + "28:04 The book, read aloud" + ] +} diff --git a/umtool/report-to-video/youtube.mjs b/umtool/report-to-video/youtube.mjs @@ -46,11 +46,24 @@ const oneLine = (s) => String(s ?? "").replace(/\s+/g, " ").trim(); * span): `{ chapters, note }` -- `chapters` null when the block is left out, * `note` saying what was folded or why the block is left out. * - * @param {Array<{ start: number, end?: number, title: string, section?: boolean }> | null | undefined} list + * With the deck's `markers` (and the opening's title, `first`), the chapters + * are its sections (markerChapters) when the list names each entry (`id`) and + * where its segment starts in the cut (`cutStart`). + * + * @param {Array<{ start: number, end?: number, title: string, section?: boolean, id?: string, cutStart?: number }> | null | undefined} list * @param {number | null} [total] + * @param {{ markers?: Array<{ after?: string, label?: string, level?: number }> | null, first?: string | null }} [opts] */ -export function youtubeChapters(list, total = null) { +export function youtubeChapters(list, total = null, { markers = null, first = null } = {}) { if (!Array.isArray(list) || !list.length) return { chapters: null, note: "no chapters: the build made none" }; + // A deck with markers: its sections are the chapters (markerChapters), at + // the second each section's first segment starts in the cut (`cutStart`, + // before the crossfade it lands after). The list must say which entry each + // chapter is (`id`): the build's does. + if (hasChapterMarkers(markers) && list.every((c) => typeof c?.id === "string" && Number.isFinite(c?.cutStart))) { + const r = markerChapters({ markers, segments: list.map((c) => ({ id: c.id, start: c.cutStart })), total, first }); + return { chapters: r.chapters, note: r.notes.join("; ") }; + } // The build's list has a chapter per segment (a player's navigation). A // description's chapters are the cut's SECTIONS: when the list says which // entries open one (`section`: a title or chapter card), every other entry @@ -86,6 +99,118 @@ export function youtubeChapters(list, total = null) { return { chapters: kept, note: foldNote }; } +// ---- chapters from the deck's markers (2026-11-02) ------------------------ +// +// A cut whose deck carries markers (`render.chrome.deck.markers`) has its +// sections named already: the rail's flags. Its chapters are those -- each +// TOP-LEVEL marker (a `level: 2` subsection is a tick inside its section, not +// a chapter) at the second the section after it starts in the master: the +// start of the segment after the clip it follows (`after`), where the +// dissolve into that section begins. The stretch before the first marker is +// the opening, titled `deck.sectionTitle.first` (the section title's "first +// section's title"); with none, the opening takes the first section's label +// and that section starts at 0:00. Replaces the hand script that read +// schedule.json and the markers (night1030 chapters.py), row for row. + +/** Does this deck have a marker a chapter can be made of (top-level, labelled)? */ +export function hasChapterMarkers(markers) { + return Array.isArray(markers) && markers.some((m) => m && m.level !== 2 && oneLine(m.label)); +} + +/** + * YouTube's rules over a list in order (`{ start, title }`, seconds), with + * what had to change said by name: the first at 0:00 (a list that does not + * start there is left out), each at least ten seconds (one that starts under + * ten seconds after the chapter before it is merged into that one -- but an + * OPENING under ten seconds gives 0:00 to the chapter after it), the last + * ten seconds before `total` too, at least three. + * + * @param {Array<{ start: number, title: string }>} list + * @param {number | null} total + * @returns {{ chapters: Array<{ start: number, title: string }> | null, notes: string[] }} + */ +export function youtubeChapterRules(list, total = null) { + const notes = []; + const all = list.map((c) => ({ start: Math.floor(Number(c.start)), title: oneLine(c.title) || "Chapter" })); + if (!all.length) return { chapters: null, notes: ["no chapters: none to make"] }; + if (all[0].start !== 0) return { chapters: null, notes: [`no chapters: the first starts at ${chapterStamp(all[0].start)}, not 0:00`] }; + const min = YOUTUBE_CHAPTERS.minSeconds; + const kept = [all[0]]; + for (const c of all.slice(1)) { + const prev = kept.at(-1); + const gap = c.start - prev.start; + if (gap >= min) { + kept.push(c); + continue; + } + if (kept.length === 1 && prev.start === 0) { + notes.push(`the opening “${prev.title}” runs ${gap} s, under ${min}: “${c.title}” starts at 0:00, not ${chapterStamp(c.start)}`); + kept[0] = { start: 0, title: c.title }; + continue; + } + notes.push(`“${c.title}” (${chapterStamp(c.start)}) is ${gap} s after “${prev.title}”, under ${min}: merged into it`); + } + const end = Number.isFinite(Number(total)) && total !== null ? Math.floor(Number(total)) : null; + while (end !== null && kept.length > 1 && end - kept.at(-1).start < min) { + const last = kept.pop(); + notes.push(`“${last.title}” (${chapterStamp(last.start)}) runs ${end - last.start} s to the end, under ${min}: merged into “${kept.at(-1).title}”`); + } + if (kept.length < YOUTUBE_CHAPTERS.min) { + notes.unshift(`no chapters: ${kept.length} of at least ${YOUTUBE_CHAPTERS.min}`); + return { chapters: null, notes }; + } + return { chapters: kept, notes }; +} + +/** + * The chapters a cut's deck markers make, by YouTube's rules + * (youtubeChapterRules): `{ chapters, notes }`, `chapters` null when the deck + * has no top-level labelled marker in the cut, or too few survive. + * + * @param {object} o + * @param {Array<{ after?: string, label?: string, level?: number }>} o.markers `deck.markers` + * @param {Array<{ id: string, start: number }>} o.segments the master's segments in order, each where it starts (schedule.json's) + * @param {number | null} [o.total] the master's length + * @param {string | null} [o.first] the opening's title (`deck.sectionTitle.first`) + */ +export function markerChapters({ markers, segments, total = null, first = null }) { + const notes = []; + const index = new Map((segments ?? []).map((s, i) => [s.id, i])); + const rows = []; + for (const m of Array.isArray(markers) ? markers : []) { + if (!m || m.level === 2) continue; + const label = oneLine(m.label); + const after = String(m.after ?? "").trim(); + if (!label) continue; + const i = index.get(after); + if (i === undefined) { + notes.push(`“${label}” follows ${after || "no clip"}, which is not in the cut: no chapter`); + continue; + } + const next = segments[i + 1]; + if (!next) { + notes.push(`“${label}” follows the cut's last segment: no chapter`); + continue; + } + rows.push({ start: Number(next.start), title: label }); + } + if (!rows.length) return { chapters: null, notes: [...notes, "no chapters: no labelled top-level marker in the cut"] }; + rows.sort((a, b) => a.start - b.start); + const opening = oneLine(first); + if (opening) rows.unshift({ start: 0, title: opening }); + else if (Math.floor(rows[0].start) !== 0) { + notes.push(`the opening has no title (deck.sectionTitle.first): “${rows[0].title}” starts at 0:00, not ${chapterStamp(rows[0].start)}`); + rows[0] = { ...rows[0], start: 0 }; + } + const r = youtubeChapterRules(rows, total); + return { chapters: r.chapters, notes: [...notes, ...r.notes] }; +} + +/** The chapter block's lines (`0:00 Title`), as out/youtube.txt and `umtool export --format chapters` print them. */ +export function chapterLines(chapters) { + return (chapters ?? []).map((c) => `${chapterStamp(c.start)} ${oneLine(c.title)}`); +} + /** * A clip's moment link: its `citeUrl` when it has one, else the archive's page * at the cited second (`cite`, else `start`) -- the link the citation makes @@ -129,7 +254,7 @@ export function composeYoutubeText({ youtube, chapters = null, sources = [] }) { const parts = [title]; const description = String(youtube?.description ?? "").trim(); if (description) parts.push(description); - if (chapters?.length) parts.push(["Chapters", ...chapters.map((c) => `${chapterStamp(c.start)} ${oneLine(c.title)}`)].join("\n")); + if (chapters?.length) parts.push(["Chapters", ...chapterLines(chapters)].join("\n")); if (sources.length) parts.push(["Sources", ...sources].join("\n")); return `${parts.join("\n\n")}\n`; } diff --git a/umtool/report-to-video/youtube.test.mjs b/umtool/report-to-video/youtube.test.mjs @@ -6,7 +6,7 @@ import { test } from "node:test"; import assert from "node:assert/strict"; import { readFile } from "node:fs/promises"; import { - chapterStamp, composeYoutubeText, momentLinkOf, youtubeChapters, youtubePreview, youtubeSources, youtubeTextName, YOUTUBE_CHAPTERS, + chapterLines, chapterStamp, composeYoutubeText, markerChapters, momentLinkOf, youtubeChapterRules, youtubeChapters, youtubePreview, youtubeSources, youtubeTextName, YOUTUBE_CHAPTERS, } from "./youtube.mjs"; const FULL = new URL("../../common/testing/draft/manifests/full.video.manifest.json", import.meta.url); @@ -105,3 +105,53 @@ test("youtubeChapters: with sections marked, the clips fold into the section tha // Too few sections: the block is left out rather than listing clips. assert.equal(youtubeChapters(list.filter((c) => c.title !== "Insulinoma"), 130).chapters, null); }); + +// ---- chapters from the deck's markers (2026-11-02) ------------------------ + +const EMBER = JSON.parse(await (await import("node:fs/promises")).readFile(new URL("./fixtures/ember-draft-24-chapters.json", import.meta.url), "utf8")); +const emberSegments = EMBER.segments.map(([id, start]) => ({ id, start })); + +test("markerChapters: Ember draft-24's 12 markers make the hand script's 13 rows, row for row", () => { + const r = markerChapters({ markers: EMBER.markers, segments: emberSegments, total: EMBER.total, first: EMBER.first }); + assert.deepEqual(chapterLines(r.chapters), EMBER.expected); + assert.deepEqual(r.notes, []); +}); + +test("markerChapters: subsections are no chapters; an untitled opening gives 0:00 to the first section; what YouTube's rules merge is said", () => { + const markers = [ + ...EMBER.markers.slice(0, 3), + { after: "rf1", label: "A subsection", level: 2 }, + { after: "rf1", label: "Too close" }, // a segment 5.1 s after "Leaves it open" starts + { after: "nope", label: "Gone" }, + { after: "ho3", label: "After the last" }, + { after: "mk1", label: "" }, + ]; + const segments = emberSegments.flatMap((s) => (s.id === "rf1" ? [s, { id: "rf1b", start: 330 }] : [s])); + const r = markerChapters({ markers, segments, total: EMBER.total }); + assert.deepEqual(chapterLines(r.chapters), ["0:00 Sex appeal", "4:59 Not a character", "5:24 Leaves it open"]); + assert.ok(!chapterLines(r.chapters).some((l) => l.includes("A subsection"))); + const said = r.notes.join("\n"); + assert.match(said, /“Gone” follows nope, which is not in the cut/); + assert.match(said, /“After the last” follows the cut's last segment/); + assert.match(said, /the opening has no title \(deck\.sectionTitle\.first\): “Sex appeal” starts at 0:00, not 2:56/); + assert.match(said, /“Too close” \(5:30\) is 6 s after “Leaves it open”, under 10: merged into it/); +}); + +test("youtubeChapterRules: a short opening gives 0:00 to the next; a short last one is merged; under three is left out", () => { + const r = youtubeChapterRules([{ start: 0, title: "Open" }, { start: 4.7, title: "First" }, { start: 30, title: "Second" }, { start: 60, title: "Third" }, { start: 95, title: "Tail" }], 100); + assert.deepEqual(r.chapters.map((c) => [c.start, c.title]), [[0, "First"], [30, "Second"], [60, "Third"]]); + assert.match(r.notes.join("\n"), /the opening “Open” runs 4 s, under 10: “First” starts at 0:00, not 0:04/); + assert.match(r.notes.join("\n"), /“Tail” \(1:35\) runs 5 s to the end, under 10: merged into “Third”/); + const two = youtubeChapterRules([{ start: 0, title: "A" }, { start: 30, title: "B" }], 60); + assert.equal(two.chapters, null); + assert.match(two.notes[0], /^no chapters: 2 of at least 3/); +}); + +test("youtubeChapters: a build's list with ids and cut starts, under a deck with markers, is the markers' chapters", () => { + const list = emberSegments.map((s, i) => ({ start: i === 0 ? 0 : s.start + 0.4, title: `seg ${s.id}`, id: s.id, cutStart: s.start })); + const r = youtubeChapters(list, EMBER.total, { markers: EMBER.markers, first: EMBER.first }); + assert.deepEqual(chapterLines(r.chapters), EMBER.expected); + // No markers: as before, one per entry folded by the ten-second rule. + const plain = youtubeChapters(list, EMBER.total); + assert.equal(plain.chapters[1].title, "seg v01t"); +});