#!/usr/bin/env node // THE MANIFEST LINT — what a render would get wrong that no validator refuses, // said before a single frame is drawn. // // node umtool/report-to-video/lint.mjs [--variant sourced|full] [--final] [--json] // node umtool/report-to-video/build-video.mjs --lint [--variant …] // // Both print every warning and error and exit 1 on an error. A build runs the // same lint after its validators and before anything renders: its errors // refuse the build, its warnings are notes. A run that renders nothing (a // bench fetch, the thumbnail, --chapters-only) is not held up by it, and // `--only ` lints that one entry. // // ERRORS // - an image whose `src` is not relative to the manifest (absolute, or `~`) // or names no file beside it: a timeline `image` entry's `src`, each of its // `panels[].src`, and under the deck a post's `shot` and `logo`. The // manifest is checked in beside its pictures, and a path that resolves on // one machine renders nowhere else; // - a QR below MIN_QR_PX_PER_MODULE_720P pixels per module once the cut is // watched at 720p, or a link too long for a QR at all; // - everything the manifest validators say -- validateThreadEntries, // validateFlipEntries, validateStatsEntries and validateMontage (threads.mjs, // flips.mjs, stats.mjs, montage.mjs), validateNarration // (narration.mjs), validatePodcast (build-podcast.mjs), and the cut edits, teasers, claims and posts validators // a build runs first -- so `--lint` alone reports what a build would // refuse, all at once; // - a narrated card not approved on its current words when the cut has a // narration review (narration-review.mjs): rejected, edited since it was // approved, or not reviewed -- the last two pass with `--narration-unreviewed`; // - in a `--final` build, a DRAFTED field (drafts-review.mjs: an entry's // on-screen text, a card's narration, a teaser's lines, the cut's order, // the flips, the threads, the YouTube text) not approved on its current // value -- `--drafts-unreviewed` lets the unapproved through, never a // rejected one; // - a `drafted` mark that is malformed or where no field may be drafted, and // a `publish` block that is not `{ youtube: { title, description } }` // (drafted.mjs `validateDrafted`, `validatePublish`); // - an analysis item's refusals (analysis-plan.mjs), each naming its row: a // row not in the ledger, a band outside the series, a pace end missing, an // empty reading, an audio clip unknown or a span outside its window, held // over 8 s without audio, a vertical cut; // - a narrated card whose `seconds` is a number shorter than its narration // needs (the lead, the words, the tail). The words' length is known once // the voice is synthesized: the build checks it then, and `--lint` reads // the kept narrations (out/narration/) and checks those it finds. // WARNINGS // - a narrated cut with no narration review at all: a cut narrated before // reviews existed builds as it did, and is told so; // - in a preview or fast build, the drafted fields not approved yet (one // line), and each rejected one: a final build refuses them; // - a `drafted` mark whose field is gone (an orphan): umtool's next write // drops it; // - a teaser line over TEASER_HOUSE_CHARS -- an overline's or a kicker's // first tier, or any line's break: house style, not a fit. (A title's // first tier is held to the same 34 by the frame itself, TEASER_LIMITS.fit, // and validateTeasers refuses it.) // - an analysis item's pace row ending on a bound (drawn over/under), a // number typed into its words, its audio span heard twice in the cut; // - a QR under WARN_QR_PX_PER_MODULE_720P pixels per module at 720p: it // scans on a good screen with a steady hand, not reliably. // - a promise outcome's `stampNote` (a ledger row's words under its stamp on the promise clock) longer than // the stamp's one line holds (measure-extras.mjs STAMP_NOTE.fit); // - a tally label wider than its cell: drawn smaller, down to // TALLY_LABEL_FLOOR, then cut with an ellipsis (factcheck.mjs // fitTallyLabel) -- the chrome is never refused for it. // // THE QR ARITHMETIC. A QR's side is (17 + 4·version) modules plus its quiet // zone on each side (`render.qr.quiet`, 3 as qrencode is run here). The // version is the smallest that holds the link in byte mode at the ECC level // (`render.qr.ecc`, M) -- qrencode may pick a denser mode for part of a URL, // so this errs towards a bigger symbol, the safe side for a lint. The deck's // and the posts' codes are resized to their `size`, quiet zone included // (compose-chrome qrPng), on a `render.height`-px frame: at 720p that is // size·720/height px over the modules. The rail's tile is resized to // `rail.qrSize` the same way. The corner code of a cut without the deck is // qrencode's own `scale` px per module, unresized. // // THE LINKS, AS FAR AS THEY ARE KNOWN BEFORE THE BUILD. A deck QR under // `qr.links: "original"` needs the record's page, which the build reads; the // lint measures the archive link instead. A post's archive page needs the // archive channel the build's resolver finds (post-links.mjs); until then the // lint measures the longer of the post's own url and its archive page under // the manifest's channel slug, the build's two outcomes. // // Pure but for the existence of an image file (`exists`, injectable). import { existsSync } from "node:fs"; import path from "node:path"; import { validateVideoEntries } from "./video-entry.mjs"; import { deckOn, deckQrUrl, estimateSchedule, postArchiveUrl, postNativeId, postQrUrl, resolveDeck, teaserLines, validateChrome, validateCutEdits, validateDeckMarkers, validatePosts, validateTeasers, deckClaimNotes, validateDeckClaims, } from "./deck.mjs"; import { tallyLabelNotes, validateClaims } from "./factcheck.mjs"; import { stampNoteWarnings } from "./measure-extras.mjs"; import { validateClipAudioEntries } from "./clip-audio.mjs"; import { validateClipBlurEntries } from "./clip-blur.mjs"; import { validateGapEntries } from "./gaps.mjs"; import { postItemFiles, validatePostItems } from "./post-item.mjs"; import { wordZoomTimes } from "./word-zoom.mjs"; import { postAvatarFiles, validatePostAvatars } from "./post-avatars.mjs"; import { validatePostNarrationRender } from "./post-narration.mjs"; import { validatePostCombos } from "./post-combo.mjs"; import { validateThreadReadWarnings, validateThreadReads } from "./post-thread.mjs"; import { validateFinaleEntries } from "./finale.mjs"; import { validateThreadEntries } from "./threads.mjs"; import { validateFlipEntries } from "./flips.mjs"; import { validateStatsEntries } from "./stats.mjs"; import { validateChatEntries } from "./chat.mjs"; import { validateMontage } from "./montage.mjs"; import { validateAssist } from "yt-dlp-transcript-common/lib/clips/assist.mjs"; import { basicOn } from "yt-dlp-transcript-common/lib/report/look.mjs"; import { validateFxEntries } from "./fx.mjs"; import { validateTransitionStyle } from "./transition.mjs"; import { validateLook } from "./look.mjs"; // The stacked vertical deck (vertical-deck.mjs): what it leaves out, and a twocrop band drawn past its source's pixels. import { stackedLeftOut } from "./modules/index.mjs"; import { analysisSource, analysisWarnings, validateAnalysisEntries } from "./modules/analysis.mjs"; import { ANALYSIS_BOX } from "./chrome-analysis.mjs"; import { verticalOn, verticalRender } from "./vertical.mjs"; import { ENLARGE_WARN, STACKED_QR_SHARE, STACKED_QR_SMALL_SHARE, clipTwoCrop, stackedOn, twoCropEnlargement } from "./vertical-deck.mjs"; import { roomWindowWarnings } from "./room.mjs"; import { qrUrlFor } from "./render-cards.mjs"; import { archiveMomentUrl } from "./site-links.mjs"; import { clipQrUrl, coldOpenNote, cornerQrOf, desktopQrOf, expiringLinkNote, validateClipKit, verticalQrOf } from "./clip-kit.mjs"; import { validatePromo } from "./promo-card.mjs"; import { validateZooms } from "./clip-zoom.mjs"; import { validateCensor } from "./clip-censor.mjs"; import { cardNarrationSeconds, hasNarration, narrationsOf, validateNarration } from "./narration.mjs"; import { validatePodcast } from "./build-podcast.mjs"; import { draftsReviewFromNarration, draftsReviewProblems, readDraftsReview } from "./drafts-review.mjs"; import { orphanDrafts, publishWarnings, validateDrafted, validatePublish } from "yt-dlp-transcript-common/lib/report/drafted.mjs"; export const TEASER_HOUSE_CHARS = 34; export const MIN_QR_PX_PER_MODULE_720P = 1.5; export const WARN_QR_PX_PER_MODULE_720P = 2.0; // Byte-mode capacity (bytes) per version 1-20, at L / M / Q / H (ISO/IEC 18004). const BYTE_CAPACITY = { L: [17, 32, 53, 78, 106, 134, 154, 192, 230, 271, 321, 367, 425, 458, 520, 586, 644, 718, 792, 858], M: [14, 26, 42, 62, 84, 106, 122, 152, 180, 213, 251, 287, 331, 362, 412, 450, 504, 560, 624, 666], Q: [11, 20, 32, 46, 60, 74, 86, 108, 130, 151, 177, 203, 241, 258, 292, 322, 364, 394, 442, 482], H: [7, 14, 24, 34, 44, 58, 64, 84, 98, 119, 137, 155, 177, 194, 220, 250, 280, 310, 338, 382], }; /** The smallest QR version holding `text` in byte mode at `ecc`, or null past version 20. */ export function qrVersion(text, ecc = "M") { const bytes = Buffer.byteLength(String(text), "utf8"); const caps = BYTE_CAPACITY[String(ecc).toUpperCase()] ?? BYTE_CAPACITY.M; const i = caps.findIndex((c) => c >= bytes); return i < 0 ? null : i + 1; } /** A QR's side in modules, quiet zone included. */ export function qrModules(version, quiet = 3) { return 17 + 4 * version + 2 * quiet; } /** Pixels per module once a `px`-wide code on a `height`-px frame is watched at 720p. */ export function pxPerModuleAt720(px, modules, height = 1080) { return (px * (720 / height)) / modules; } // A post's QR link at its LONGEST: under "archive" with no channel resolved // yet, the build will draw either its archive page or, when the archive does // not have it, its own url. function postQrUrlForLint(post, provenance, links) { const known = postQrUrl(post, provenance, { links }); if (links === "original" || post.siteUrl || post.siteChannel) return known; const origin = typeof provenance?.siteOrigin === "string" ? provenance.siteOrigin.trim() : ""; const id = postNativeId(post); if (!origin || !id) return known; const archive = postArchiveUrl(origin, provenance.channelSlug ?? "channel", id); return !known || archive.length > String(known).length ? archive : known; } /** * Every QR the cut will draw, as `{ where, id, source, url, px, perModule }` * -- `id` the timeline entry's (or the post's), `source` "entry" or "post", * `px` the drawn width on the frame, or null for the corner code, which is * `perModule` native pixels per module, unresized. * * `metaOf(entry)` is a clip's record metadata (`{ webpageUrl }`) when the * caller has it: under the deck's `qr.links: "original"` a clip with no * `citeUrl` links its record's own page, and falls back to the archive link * only when the record names none (deckQrUrl). Without it the archive link is * measured, as before. * * @param {any} manifest a cut, as selectVariant returns it * @param {{ only?: string|null, metaOf?: ((entry: any) => ({ webpageUrl?: string|null } | null)) | null }} [opts] */ export function qrsOf(manifest, { only = null, metaOf = null } = {}) { const render = manifest.render ?? {}; const provenance = manifest.provenance ?? {}; const timeline = (manifest.timeline ?? []).filter((e) => e && (!only || e.id === only)); const out = []; // A basic-mode cut is the footage alone (basic.mjs): it draws no code, so none is measured -- nor counted as built // from the origin (originQrsOf, the Inbox's Blocking siteOrigin card: a quick clip on no public site raises none). if (basicOn(render)) return out; // An analysis item's code (chrome-analysis.mjs): its audio clip's, drawn on its own page whatever the chrome. for (const e of timeline) { const src = e.type === "analysis" ? analysisSource(e, manifest) : null; if (src?.url) out.push({ where: `timeline ${e.id} (the analysis item's QR)`, id: e.id, source: "entry", url: src.url, px: Math.round((ANALYSIS_BOX.qr * (Number(render.width) || 1920)) / 1280) }); } if (deckOn(render)) { const d = resolveDeck(render); if (d.qr?.show) { for (const e of timeline) { const url = deckQrUrl(e, provenance, { links: d.qr.links, meta: metaOf?.(e) ?? null }); // The stacked vertical deck draws its own (vertical-deck.mjs): the source block's, a twocrop clip's small one. const px = stackedOn(render) ? Math.round(render.width * (clipTwoCrop(e) ? STACKED_QR_SMALL_SHARE : STACKED_QR_SHARE)) : Number(d.qr.size); if (url) out.push({ where: `timeline ${e.id} (the deck's QR)`, id: e.id, source: "entry", url, px }); } } // `posts.qr: false` draws no code on any post card. if (d.posts?.show && d.posts.qr !== false && Array.isArray(manifest.posts)) { for (const p of manifest.posts) { if (!p || (only && p.attachTo !== only)) continue; const url = postQrUrlForLint(p, provenance, d.posts.links); if (url) out.push({ where: `posts ${p.id ?? "?"} (its QR)`, id: p.id ?? null, source: "post", url, px: Number(d.posts.qrSize) }); } } return out; } // A 9:16 short's code (clip-kit.mjs, render.vertical.qr): each clip's, at the top of the safe area. if (verticalOn(render) && !stackedOn(render)) { for (const e of timeline) { const vq = e.type === "clip" ? verticalQrOf(e, render) : null; if (!vq || (e.src != null && !e.citeUrl)) continue; const url = clipQrUrl(e, provenance, { links: vq.links, at: e.cutStart ?? e.start, channelUrl: render.promo?.url ?? null, webpageUrl: metaOf?.(e)?.webpageUrl ?? null }); if (url) out.push({ where: `timeline ${e.id} (its QR)`, id: e.id, source: "entry", url, links: vq.links, px: Math.round((Number(render.width) || 1080) * vq.size) }); } } // A desktop clip's code (vertical.mjs desktopRender; render.desktop.qr), in its corner. if (render.desktopBuild === true) { for (const e of timeline) { const dq = e.type === "clip" ? desktopQrOf(e, render) : null; if (!dq || (e.src != null && !e.citeUrl)) continue; const url = clipQrUrl(e, provenance, { links: dq.links, at: e.cutStart ?? e.start, channelUrl: render.promo?.url ?? null, webpageUrl: metaOf?.(e)?.webpageUrl ?? null }); if (url) out.push({ where: `timeline ${e.id} (its QR)`, id: e.id, source: "entry", url, links: dq.links, px: Math.round((Number(render.width) || 1920) * dq.size) }); } } if (render.qr === false) return out; if (render.rail) { // The rail's foot: a tile per entry (a card's is the sweep's link), the // code resized to rail.qrSize. const px = Number(render.rail.qrSize ?? 132); for (const e of timeline) { const url = qrUrlFor(e, provenance); if (url) out.push({ where: `timeline ${e.id} (its rail QR)`, id: e.id, source: "entry", url, px }); } return out; } // The corner code: a clip's (its citeUrl, else its moment on the archive; // none for a `src` clip without a citeUrl), and a still's citeUrl. const scale = Number(render.qr?.scale ?? 4); for (const e of timeline) { let url = null; let links = "cite"; if (e.type === "clip") { if (e.src != null && !e.citeUrl) continue; // The clip kit (clip-kit.mjs): a clip's `qr: false` draws none; `links` "moment" / "channel" another link. const cq = cornerQrOf(e, render); if (!cq) continue; links = cq.links; url = clipQrUrl(e, provenance, { links, at: e.cutStart ?? e.start, channelUrl: render.promo?.url ?? null, webpageUrl: metaOf?.(e)?.webpageUrl ?? null }); } else if (e.type === "image" && e.citeUrl) { url = e.citeUrl; } if (url) out.push({ where: `timeline ${e.id} (its corner QR)`, id: e.id, source: "entry", url, px: null, perModule: scale, ...(links !== "cite" ? { links } : {}) }); } return out; } // A stand-in archive origin no real link starts with: what originQrsOf puts in // `provenance.siteOrigin` to see which links the real rules build from it. const ORIGIN_PROBE = "https://site-origin.probe.invalid"; /** * The QRs the cut draws whose link is built from `provenance.siteOrigin`: the * ones an absent origin turns into `undefined/?v=…` (or, a rail card's, an * empty code) and a localhost one into a link that resolves nowhere. Every * other code links something of its own -- a clip's `citeUrl`, its record's * page under the deck's `qr.links: "original"`, a still's `citeUrl`, a card's * `provenance.qrLink` -- or is not drawn (`render.qr: false`, the deck's * `qr.show: false`, a `src` clip with no `citeUrl`, `posts.qr: false`). * * Not a second copy of the link rules: it runs qrsOf -- the build's own * deckQrUrl, qrUrlFor and postQrUrl -- with the origin set to a probe, and * keeps the codes whose link begins with it. A post is the one exception: with * NO origin its code links the post itself (postQrUrl), so a post depends on * the origin only when one is set. * * @param {any} manifest * @param {{ only?: string|null, metaOf?: ((entry: any) => ({ webpageUrl?: string|null } | null)) | null }} [opts] * @returns {{ where: string, id: string|null, source: "entry"|"post" }[]} */ export function originQrsOf(manifest, { only = null, metaOf = null } = {}) { const provenance = manifest?.provenance ?? {}; const origin = typeof provenance.siteOrigin === "string" ? provenance.siteOrigin.trim() : ""; const probe = { ...manifest, provenance: { ...provenance, siteOrigin: ORIGIN_PROBE } }; return qrsOf(probe, { only, metaOf }) .filter((q) => String(q.url).startsWith(ORIGIN_PROBE) && (origin || q.source !== "post")) .map(({ where, id, source }) => ({ where, id, source })); } /** * Every picture the cut reads from beside the manifest, as `{ where, src }`. * Posts' shots and logos only under the deck, the one place posts are drawn. */ export function imageSrcsOf(manifest, { only = null } = {}) { const out = []; for (const e of manifest.timeline ?? []) { if (e?.type === "post" && (!only || e.id === only)) { out.push(...postItemFiles(e)); continue; } if (e?.type !== "image" || (only && e.id !== only)) continue; if (typeof e.src === "string") out.push({ where: `timeline ${e.id}`, src: e.src }); if (Array.isArray(e.panels)) { e.panels.forEach((p, i) => { if (typeof p?.src === "string") out.push({ where: `timeline ${e.id}.panels[${i}]`, src: p.src }); }); } } // The authors' pictures a post item's card draws (post-avatars.mjs). if (!only || (manifest.timeline ?? []).some((e) => e?.id === only && e.type === "post")) out.push(...postAvatarFiles(manifest)); if (deckOn(manifest.render) && Array.isArray(manifest.posts)) { for (const p of manifest.posts) { if (!p || (only && p.attachTo !== only)) continue; for (const key of ["shot", "logo"]) { if (typeof p[key] === "string" && p[key]) out.push({ where: `posts ${p.id ?? "?"}.${key}`, src: p[key] }); } } } return out; } /** The validators a build runs before it renders, as one list of sentences. */ /** * The deck schedule the effects' shift check reads at lint time: estimated * from the manifest (deck.mjs estimateSchedule), or `false` -- left to the * build -- when there is no deck or it cannot be estimated (the manifest's * other validators say why). */ function fxLintSchedule(whole) { if (!deckOn(whole?.render)) return false; try { return estimateSchedule(whole); } catch { return false; } } export function validatorErrors(whole) { const errors = [ ...validateCutEdits(whole), ...validateTeasers(whole), ...validateVideoEntries(whole), ...validateClaims(whole), ...validateClipAudioEntries(whole), ...validateThreadEntries(whole), ...validateFlipEntries(whole), ...validateNarration(whole), // The podcast's settings: its render refuses them, and `--lint` says so first. ...validatePodcast(whole), // Release 28: where a field says it was drafted, and the publish block. ...validateDrafted(whole), ...validatePublish(whole), // Release 31: the stats region's `stats` keys and render.chrome.stats. ...validateStatsEntries(whole), // A clip's `chat` and render.chrome.chat (chat.mjs). ...validateChatEntries(whole), // The clip kit: a clip's `qr` and `name`, render.qr's corner and links (clip-kit.mjs); the channel promo (promo-card.mjs). ...validateClipKit(whole), ...validatePromo(whole), ...validateZooms(whole), ...validateCensor(whole), // Release 33: render.montage, its keys and what it does not combine with. ...validateMontage(whole), // Release 35: a clip's `assist` (the clip finder's provenance; the render ignores it). ...validateAssist(whole), // Release 35: the effects' entry fields, clip lists and THEN/NOW pairs. // The popup posts' shift against the effects: only where they coincide, on // the estimated schedule (the build checks again on the measured one). ...validateFxEntries(whole, { schedule: fxLintSchedule(whole) }), // Release 35: the crossfade's look between clips. ...validateTransitionStyle(whole), // Release 36: render.captions, render.loudness and a clip's vertical crop. ...validateLook(whole), // An analysis item (analysis-plan.mjs): its rows in the ledger, its band, pace, audio and length. ...validateAnalysisEntries(whole), // The deck finale: each entry's `layout` and the one run (finale.mjs). ...validateFinaleEntries(whole), // A clip's blurred picture and the cut's render.blur (clip-blur.mjs). ...validateClipBlurEntries(whole), // Seconds taken out of a clip's middle (gaps.mjs). ...validateGapEntries(whole), // A post as a timeline item (post-item.mjs): its archived words, its attachments, its hold. ...validatePostItems(whole), // A post item's word zooms each need a time: `at`, or its take's word timings (the build refuses the same). ...(whole.timeline ?? []).filter((e) => e?.type === "post" && Array.isArray(e.fx)).flatMap((e) => wordZoomTimes(e, whole.render).filter((t) => t.error).map((t) => String(t.error))), ...validatePostAvatars(whole), // A narrated post item's mix (post-narration.mjs): the cut's knobs. ...validatePostNarrationRender(whole.render), // Never narrate hidden text (post-thread.mjs): every part of a read is of a text its card shows. ...validateThreadReads(whole), // The combo counter (post-combo.mjs): render.posts.combo and each post item's `combo`. ...validatePostCombos(whole), ]; if (deckOn(whole.render)) { errors.push(...validatePosts(whole.posts, whole.timeline ?? [], whole.render).map((m) => `posts: ${m}`)); // render.chrome itself (deck.finale included), as the build refuses it. const { chrome, ...rest } = whole.render; errors.push(...validateChrome(chrome, rest)); // The deck's markers against the whole timeline, as the build refuses them. errors.push(...validateDeckMarkers(whole)); // And its claim checks (claims.mjs): each names a clip in it, and a verdict. errors.push(...validateDeckClaims(whole)); } return errors; } /** * The narrated cards whose authored `seconds` is shorter than their narration * needs, as errors. `secondsById` maps a card id to its synthesized * narration's seconds; a card not in it (not synthesized yet) is not judged. * * @param {any} manifest the cut * @param {Map} secondsById * @param {{ only?: string|null }} [opts] */ export function narrationLengthErrors(manifest, secondsById, { only = null } = {}) { const out = []; for (const e of manifest.timeline ?? []) { if (!hasNarration(e) || (only && e.id !== only) || !secondsById.has(e.id)) continue; const words = secondsById.get(e.id); const { need, short } = cardNarrationSeconds(e, words, manifest.render); if (short) { out.push( `timeline ${e.id}: seconds is ${e.seconds}, and its narration needs ${need}s ` + `(${Number(words).toFixed(2)}s of words plus the lead and the tail) — set "auto" or at least ${need}`, ); } } return out; } /** * The lint of one cut. * * @param {any} manifest the cut, as selectVariant returns it * @param {{ manifestDir?: string, whole?: any, exists?: (p: string) => boolean, * only?: string|null, validators?: boolean, narrationSeconds?: Map | null, * narrationReview?: { exists: boolean, rows: object, error?: string } | null, narrationUnreviewed?: boolean, * draftsReview?: { exists: boolean, rows: object, narration?: boolean, error?: string } | null, * final?: boolean, draftsUnreviewed?: boolean }} [opts] * `whole` is the manifest as written (what the validators read); * `validators: false` leaves them out (a build has run them already); * `only` lints one timeline entry (and the posts attached to it); * `narrationSeconds` the kept narrations' seconds by card id (null: not read); * `draftsReview` the cut's drafts review (drafts-review.mjs `readDraftsReview`; * null: not read -- `narrationReview`, release 25's shape, is read as one); * `final` a final build (drafted fields not approved refuse it); * `draftsUnreviewed` / `narrationUnreviewed` let the unapproved through. * @returns {{ errors: string[], warnings: string[] }} */ /** A twocrop clip's warnings: past ENLARGE_WARN on a 16:9 source, or in a cut that does not play the stacked deck. */ export function stackedLintWarnings(manifest, { only = null } = {}) { const out = []; const render = manifest?.render ?? {}; const vr = verticalOn(render) ? verticalRender(render) : null; const sh = Number(render.maxHeightSource) || 1080; const sw = Math.round((sh * 16) / 9); for (const e of manifest?.timeline ?? []) { if (e?.type !== "clip" || (only && e.id !== only)) continue; const crops = clipTwoCrop(e); if (!crops) continue; if (!vr || !stackedOn(vr)) { if (vr) out.push(`timeline ${e.id}.vertical.layout "twocrop" is the stacked deck's: this vertical cut has none (render.vertical.deck "bare", or no deck), so it plays in the cut's clip layout`); continue; } twoCropEnlargement(crops, sw, sh, vr).forEach((x, i) => { if (x > ENLARGE_WARN) out.push(`timeline ${e.id}.vertical.crops[${i}] is drawn ${x}× its source's pixels at ${sw}x${sh} (past ${ENLARGE_WARN}×: it will look soft) -- a wider crop`); }); } return out; } export function lintManifest(manifest, { manifestDir, whole = manifest, exists = existsSync, only = null, validators = true, narrationSeconds = null, narrationReview = null, narrationUnreviewed = false, draftsReview = null, final = false, draftsUnreviewed = false, } = {}) { const errors = []; const warnings = []; const render = manifest.render ?? {}; // A code's size at 720p is read off the frame's SHORT side: a 9:16 frame's width (a vertical cut plays 720 wide // at 720p), a landscape frame's height as it always was. const height = Math.min(Number(render.height) || 1080, Number(render.width) || Infinity); // The social posts and the video's URL are not the video's: a problem there // is said, never a refusal (release 29 G2's review). warnings.push(...publishWarnings(whole)); // The deck's claim checks said at a second their clip does not play (claims.mjs). if (!only) warnings.push(...deckClaimNotes(whole)); // Room at the clips' edges (render.room): a fetched window it can reach past. warnings.push(...roomWindowWarnings(only ? { ...manifest, timeline: (manifest.timeline ?? []).filter((e) => e?.id === only) } : manifest)); // A narrated post's read that says a link aloud (post-thread.mjs threadReadWarnings), with its fix. warnings.push(...validateThreadReadWarnings(only ? { ...manifest, timeline: (manifest.timeline ?? []).filter((e) => e?.id === only) } : manifest)); // THE STACKED VERTICAL DECK: each module the cut sets up that has no vertical form, left out (a note, never a // refusal); a twocrop clip's band drawn past ENLARGE_WARN times its source's pixels (a 16:9 source of the cut's // `maxHeightSource`, 1080 by default: the build says it again from the real one); a twocrop where no stacked deck plays it. if (!only) warnings.push(...stackedLeftOut(manifest)); // A tally label wider than its cell, drawn smaller or cut (factcheck.mjs fitTallyLabel): said, never refused. if (!only) warnings.push(...tallyLabelNotes(render)); warnings.push(...stackedLintWarnings(manifest, { only })); // A promise outcome's own stamp words (a ledger row's `stampNote`) longer than the stamp's line holds. if (!only) warnings.push(...stampNoteWarnings(whole)); // An analysis item: a bound pace row, a number typed into words, its audio heard twice (analysis-plan.mjs). warnings.push(...analysisWarnings(manifest, { only })); // A cold open outside what reads best (clip-kit.mjs): a note. for (const e of manifest.timeline ?? []) { if (only && e?.id !== only) continue; const n = coldOpenNote(e, `timeline ${e?.id}`); if (n) warnings.push(n); } // The channel promo's portrait (promo-card.mjs): a picture of the project's, there. { const pf = whole?.render?.promo?.portrait?.file; if (typeof pf === "string" && manifestDir && !path.isAbsolute(pf) && !exists(path.resolve(manifestDir, pf))) { errors.push(`render.promo.portrait: "${pf}" names no file of the project (umtool promo

--portrait-from @ grabs one)`); } } for (const { where, src } of imageSrcsOf(manifest, { only })) { if (path.isAbsolute(src) || src.startsWith("~")) { errors.push(`${where}: the image "${src}" must be a path relative to the manifest (it is checked in beside its pictures)`); } else if (manifestDir && !exists(path.resolve(manifestDir, src))) { errors.push(`${where}: the image "${src}" names no file beside the manifest`); } } for (const e of manifest.timeline ?? []) { if (e?.type !== "teaser" || (only && e.id !== only)) continue; teaserLines(e).forEach((l, i) => { // A TITLE's first tier past it does not fit the frame at all, which // validateTeasers refuses; the house style speaks for the other tiers. for (const [part, text] of [["", l.role === "title" ? null : l.head], [" break", l.sub]]) { if (text && text.length > TEASER_HOUSE_CHARS) { warnings.push( `timeline ${e.id}.lines[${i}]${part} "${text}" is ${text.length} characters; house style is at most ${TEASER_HOUSE_CHARS}`, ); } } }); } const ecc = render.qr?.ecc ?? "M"; const quiet = Number(render.qr?.quiet ?? 3); for (const q of qrsOf(manifest, { only })) { const version = qrVersion(q.url, ecc); if (version === null) { errors.push(`${q.where}: its link is ${Buffer.byteLength(q.url)} bytes, too long for a scannable QR (${q.url.slice(0, 80)}…)`); continue; } const modules = qrModules(version, quiet); const per = q.px === null ? q.perModule * (720 / height) : pxPerModuleAt720(q.px, modules, height); const what = `${q.where}: ${per.toFixed(2)} px per module at 720p ` + `(${q.px === null ? `scale ${q.perModule}` : `${q.px} px`} on a ${height}p frame, a version-${version} code, ${modules} modules)`; // A code that links a stream's VOD at its second, on a platform that deletes VODs: a note (clip-kit.mjs). // A code whose link is a Kick or Twitch VOD -- the moment, or a citeUrl that is one -- stops opening once the VOD // is deleted: a note (clip-kit.mjs expiringLinkNote). if (q.source === "entry") { const n = expiringLinkNote(q.url, q.where); if (n) warnings.push(n); } if (per < MIN_QR_PX_PER_MODULE_720P) { errors.push(`${what} — too small to scan; make it larger or the link shorter (at least ${MIN_QR_PX_PER_MODULE_720P})`); } else if (per < WARN_QR_PX_PER_MODULE_720P) { warnings.push(`${what} — scans only on a good screen; ${WARN_QR_PX_PER_MODULE_720P} is comfortable`); } } // The drafts review, narration's included: null when it was not read. { const review = draftsReview ?? draftsReviewFromNarration(narrationReview); const r = draftsReviewProblems(manifest, review, { final, only, allowUnreviewed: draftsUnreviewed, allowNarrationUnreviewed: narrationUnreviewed, }); errors.push(...r.errors); warnings.push(...r.warnings, ...r.notes); } // A mark whose field is gone: dropped by umtool's next write, said here. if (!only) for (const o of orphanDrafts(whole)) warnings.push(`${o.where}: its field is gone — the drafted mark is an orphan (umtool's next write drops it)`); if (narrationSeconds) { errors.push(...narrationLengthErrors(manifest, narrationSeconds, { only })); for (const e of manifest.timeline ?? []) { if (hasNarration(e) && (!only || e.id === only) && !narrationSeconds.has(e.id)) { warnings.push(`timeline ${e.id}: its narration is not synthesized yet — its length is checked once it is`); } } } if (validators && !only) errors.push(...validatorErrors(whole)); return { errors, warnings }; } /** * Lint a manifest file: read it, select the cut, lint it. A validator that * throws (a malformed manifest) is an error, not a crash. * * @returns {Promise<{ errors: string[], warnings: string[], variant: string }>} */ export async function lintManifestFile(manifestPath, { variant = "sourced", only = null, narrationUnreviewed = false, final = false, draftsUnreviewed = false, } = {}) { const { readFile } = await import("node:fs/promises"); const { selectVariant } = await import("./build-video.mjs"); const whole = JSON.parse(await readFile(manifestPath, "utf8")); const manifestDir = path.dirname(path.resolve(manifestPath)); try { const manifest = selectVariant(whole, variant); // The narrations already kept beside the build (out/narration/), so a // narrated card's authored seconds can be judged without asking for a voice. let narrationSeconds = null; if (narrationsOf(manifest).length) { const { narrationDir, readNarrationRecords } = await import("./narration-store.mjs"); const recs = await readNarrationRecords(narrationDir(path.join(manifestDir, "out")), narrationsOf(manifest)); narrationSeconds = new Map([...recs].map(([id, r]) => [id, r.seconds])); } const draftsReview = await readDraftsReview(manifestDir); const base = lintManifest(manifest, { manifestDir, whole, only, narrationSeconds, draftsReview, narrationUnreviewed, final, draftsUnreviewed }); // ANONYMITY (post-anon.mjs): what a read says, and what the pass cannot fix by itself. This video's characters // unread is an error: the build refuses it too. const { projectAnonymousSet } = await import("./project-characters-file.mjs"); const { anonymityProblems } = await import("./post-anon.mjs"); let anon; try { // The PROJECT's set (every variant; a take's own entries too), judged on what this cut draws and says. const { doc, set } = await projectAnonymousSet(manifestDir, whole); anon = anonymityProblems(manifest, doc, { set }); } catch (e) { anon = { errors: [e instanceof Error ? e.message : String(e)], warnings: [] }; } return { ...base, errors: [...base.errors, ...anon.errors], warnings: [...base.warnings, ...anon.warnings], variant }; } catch (err) { return { errors: [err?.message ?? String(err)], warnings: [], variant }; } } /** The lint's lines, as `--lint` and this file's CLI print them. */ export function lintReport({ errors, warnings }) { return [ ...warnings.map((w) => `warning: ${w}`), ...errors.map((e) => `ERROR: ${e}`), `${errors.length} error(s), ${warnings.length} warning(s)`, ]; } if (import.meta.url === `file://${process.argv[1]}`) { const argv = process.argv.slice(2); const flag = (n) => { const i = argv.indexOf(n); return i < 0 ? undefined : argv[i + 1]; }; const valued = new Set(["--variant"]); const manifestPath = argv.find((a, i) => !a.startsWith("--") && !valued.has(argv[i - 1])); if (!manifestPath) { console.error("usage: lint.mjs [--variant sourced|full] [--final] [--drafts-unreviewed] [--narration-unreviewed] [--json]"); process.exit(2); } lintManifestFile(manifestPath, { variant: flag("--variant") ?? "sourced", final: argv.includes("--final"), draftsUnreviewed: argv.includes("--drafts-unreviewed"), narrationUnreviewed: argv.includes("--narration-unreviewed"), }).then((r) => { if (argv.includes("--json")) console.log(JSON.stringify(r, null, 2)); else for (const line of lintReport(r)) console.log(line); process.exit(r.errors.length ? 1 : 0); }, (err) => { console.error(err?.message ?? err); process.exit(1); }); }