Archilyzer · Source

archilyzer

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

commit 78c026bcdcaac1c3c79a121ab985f8b4e0aa00c2
parent bf1353e556bb0f3770f65e95635cdb5e165aa45b
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Mon, 19 Oct 2026 12:19:55 -0400

clips: site-less links and the site-less look -- a channel on no site links each clip's platform page, no header/QR, fades through black, -16 LUFS

With no siteOrigin and the channel on no public site (a site.json listing
it with a siteUrl), every clip the seed or a proposal pass writes carries
citeUrl = the recording's webpage_url at its cite (watchUrlAt: YouTube
t=<s>s, Twitch t=<h>h<m>m<s>s, Rumble start=<s>, else t=<s>); a moved
clip's derived link follows its cite, a link somebody wrote stays. The seed
sets provenance.channel from the metadata, and for a site-less cut the
render keys headerHeight 0, footerHeight 0, qr false, transition 0.5,
transitionStyle fadeblack, loudness {target: -16} (lane C validates and
renders loudness; nothing refuses the key today). An empty siteOrigin is no
dead-origin decision when every clip links itself and there is no card or
post (report.mjs originUnused).

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

Diffstat:
Mcommon/lib/clips/assist.d.mts | 5++++-
Mcommon/lib/clips/assist.mjs | 57+++++++++++++++++++++++++++++++++++++++++++++++++--------
Acommon/lib/clips/links.test.ts | 43+++++++++++++++++++++++++++++++++++++++++++
Mumtool/e2e/create.spec.ts | 13++++++++++++-
Mumtool/lib/projects/report.mjs | 21++++++++++++++++++---
Mumtool/lib/projects/scaffold.mjs | 24++++++++++++++++++++----
Mumtool/lib/report/reactions-r36.test.mjs | 66++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mumtool/lib/report/reactions.mjs | 62+++++++++++++++++++++++++++++++++++++++++++++++++++++---------
8 files changed, 265 insertions(+), 26 deletions(-)

diff --git a/common/lib/clips/assist.d.mts b/common/lib/clips/assist.d.mts @@ -33,14 +33,16 @@ export type AssistClip = { cite: number; quote: string; assist: Assist; + citeUrl?: string; }; export function validateAssist(manifest: unknown): string[]; export function isAssistantClip(e: unknown): boolean; export function cutOf(e: { start: number; end: number; cutStart?: number; cutEnd?: number }): { start: number; end: number }; +export function watchUrlAt(url: string | null | undefined, seconds: number): string | null; export function clipFromProposal( p: { id: string; start: number; end: number; score: number; why: string }, - o: { id: string; channel: string; video: string; duration?: number; words?: Word[] }, + o: { id: string; channel: string; video: string; duration?: number; words?: Word[]; citeUrlAt?: ((s: number) => string | null) | null }, ): AssistClip; export function fixedClips(timeline: unknown[], o: { channel: string; video: string; isProtected?: (e: any) => boolean }): { id: string; start: number; end: number }[]; export function applyProposals( @@ -52,6 +54,7 @@ export function applyProposals( duration?: number; words?: Word[]; isProtected?: (e: any) => boolean; + citeUrlAt?: ((s: number) => string | null) | null; }, ): { timeline: any[]; diff --git a/common/lib/clips/assist.mjs b/common/lib/clips/assist.mjs @@ -91,17 +91,49 @@ export const isAssistantClip = (e) => isObj(e) && e.type === "clip" && isObj(e.a export const cutOf = (e) => (num(e?.cutStart) && num(e?.cutEnd) ? { start: e.cutStart, end: e.cutEnd } : { start: e.start, end: e.end }); /** + * A platform's watch page at a second (release 36: a clip of a channel that is + * on no site links its source there): YouTube `t=<s>s`, Twitch `t=<h>h<m>m<s>s`, + * Rumble `start=<s>`, anything else `t=<s>` — added with `&` or `?`, an + * existing one of the same name replaced. Null for a URL that is not one. + * @param {string | null | undefined} url the recording's `webpage_url` + * @param {number} seconds + * @returns {string | null} + */ +export function watchUrlAt(url, seconds) { + if (typeof url !== "string" || !/^https?:\/\//i.test(url)) return null; + let host; + try { + host = new URL(url).hostname.toLowerCase().replace(/^(?:www|m)\./, ""); + } catch { + return null; + } + const s = Math.max(0, Math.floor(Number(seconds) || 0)); + const youtube = host === "youtube.com" || host === "youtu.be" || host.endsWith(".youtube.com"); + const twitch = host === "twitch.tv" || host.endsWith(".twitch.tv"); + const key = host === "rumble.com" ? "start" : "t"; + const value = youtube ? `${s}s` : twitch ? `${Math.floor(s / 3600)}h${Math.floor((s % 3600) / 60)}m${s % 60}s` : String(s); + const hash = url.indexOf("#"); + const base = hash >= 0 ? url.slice(0, hash) : url; + const frag = hash >= 0 ? url.slice(hash) : ""; + // A targeted edit (no URLSearchParams round trip, which re-escapes every other parameter). + const stripped = base.replace(new RegExp(`([?&])${key}=[^&]*(&|$)`), (_m, a, b) => (b ? a : "")).replace(/[?&]$/, ""); + return `${stripped}${stripped.includes("?") ? "&" : "?"}${key}=${value}${frag}`; +} + +/** * A proposal as a clip entry (or the fields that change on one already in * the cut): the cut is the proposal; the window leaves WINDOW_PAD_S either - * side for trimming, inside the recording. + * side for trimming, inside the recording. `citeUrlAt` (release 36: a + * site-less channel) gives the clip a `citeUrl` at its cite. * @param {{ id: string, start: number, end: number, score: number, why: string }} p - * @param {{ id: string, channel: string, video: string, duration?: number, words?: { w: string, start: number, end: number }[] }} o + * @param {{ id: string, channel: string, video: string, duration?: number, words?: { w: string, start: number, end: number }[], citeUrlAt?: ((s: number) => string | null) | null }} o */ -export function clipFromProposal(p, { id, channel, video, duration = Infinity, words = [] }) { +export function clipFromProposal(p, { id, channel, video, duration = Infinity, words = [], citeUrlAt = null }) { const cutStart = round2(p.start); const cutEnd = round2(p.end); const start = round2(Math.max(0, cutStart - WINDOW_PAD_S)); const end = round2(Math.min(Number.isFinite(duration) && duration > 0 ? duration : Infinity, cutEnd + WINDOW_PAD_S)); + const link = citeUrlAt ? citeUrlAt(Math.floor(cutStart)) : null; return { type: "clip", id, @@ -121,6 +153,7 @@ export function clipFromProposal(p, { id, channel, video, duration = Infinity, w original: { start, end: Math.max(end, cutEnd), cutStart, cutEnd }, edits: [], }, + ...(link ? { citeUrl: link } : {}), }; } @@ -165,10 +198,15 @@ export function fixedClips(timeline, { channel, video, isProtected = () => false * Returns the timeline, the proposals with their `clipId` (null when unused), * and what changed. * @param {any[]} timeline + * With `citeUrlAt` (release 36: the channel is on no site), every clip the + * pass adds or moves carries `citeUrl` = the platform's page at its cite; a + * moved clip's link is re-pointed only when it is that derived link (or it has + * none) — a link somebody wrote stays. * @param {{ proposals: { id: string, start: number, end: number, score: number, why: string, used: boolean, fixedClip?: string }[], - * channel: string, video: string, duration?: number, words?: { w: string, start: number, end: number }[], isProtected?: (e: any) => boolean }} o + * channel: string, video: string, duration?: number, words?: { w: string, start: number, end: number }[], isProtected?: (e: any) => boolean, + * citeUrlAt?: ((s: number) => string | null) | null }} o */ -export function applyProposals(timeline, { proposals, channel, video, duration = Infinity, words = [], isProtected = () => false }) { +export function applyProposals(timeline, { proposals, channel, video, duration = Infinity, words = [], isProtected = () => false, citeUrlAt = null }) { const entries = (timeline ?? []).map((e) => (isObj(e) ? { ...e } : e)); const movable = (e) => isAssistantClip(e) && e.video === video && (e.channel ?? channel) === channel && !isProtected(e) && !(e.lock || e.lockStart || e.lockEnd || e.lockCut); const byProposal = new Map(); @@ -189,17 +227,20 @@ export function applyProposals(timeline, { proposals, channel, video, duration = if (p.fixedClip) return { ...p, clipId: p.fixedClip }; const have = byProposal.get(p.id); if (have) { - const fresh = clipFromProposal(p, { id: have.id, channel: have.channel ?? channel, video, duration, words }); + const fresh = clipFromProposal(p, { id: have.id, channel: have.channel ?? channel, video, duration, words, citeUrlAt }); const same = have.cutStart === fresh.cutStart && have.cutEnd === fresh.cutEnd && have.assist.score === fresh.assist.score && have.assist.why === fresh.assist.why; - if (same) changes.kept += 1; + // The derived link follows the cite; one written by somebody else stays. + const relink = !!fresh.citeUrl && have.citeUrl !== fresh.citeUrl && (!have.citeUrl || have.citeUrl === citeUrlAt?.(have.cite ?? Math.floor(have.cutStart ?? have.start))); + if (same && !relink) changes.kept += 1; else { Object.assign(have, { start: fresh.start, end: fresh.end, cutStart: fresh.cutStart, cutEnd: fresh.cutEnd, cite: fresh.cite, quote: fresh.quote }); + if (relink) have.citeUrl = fresh.citeUrl; have.assist = { ...have.assist, score: fresh.assist.score, why: fresh.assist.why, original: fresh.assist.original }; changes.updated.push(have.id); } return { ...p, clipId: have.id }; } - const clip = clipFromProposal(p, { id: nextClipId(used), channel, video, duration, words }); + const clip = clipFromProposal(p, { id: nextClipId(used), channel, video, duration, words, citeUrlAt }); out.push(clip); changes.added.push(clip.id); return { ...p, clipId: clip.id }; diff --git a/common/lib/clips/links.test.ts b/common/lib/clips/links.test.ts @@ -0,0 +1,43 @@ +import assert from "node:assert/strict"; +import test from "node:test"; +import { applyProposals, clipFromProposal, watchUrlAt } from "./assist.mjs"; + +test("watchUrlAt: the platform's page at a second, in its own form; an existing one replaced; not a URL, null", () => { + assert.equal(watchUrlAt("https://www.youtube.com/watch?v=abc", 128.9), "https://www.youtube.com/watch?v=abc&t=128s"); + assert.equal(watchUrlAt("https://www.youtube.com/watch?v=abc&t=5s", 3), "https://www.youtube.com/watch?v=abc&t=3s"); + assert.equal(watchUrlAt("https://youtu.be/abc", 4), "https://youtu.be/abc?t=4s"); + assert.equal(watchUrlAt("https://www.twitch.tv/videos/123", 3725), "https://www.twitch.tv/videos/123?t=1h2m5s"); + assert.equal(watchUrlAt("https://rumble.com/v2abc-title.html", 61), "https://rumble.com/v2abc-title.html?start=61"); + assert.equal(watchUrlAt("https://odysee.com/@a:1/b:2", 7), "https://odysee.com/@a:1/b:2?t=7"); + assert.equal(watchUrlAt("https://example.com/x?t=1&y=2#h", 8), "https://example.com/x?y=2&t=8#h"); + assert.equal(watchUrlAt("not a url", 3), null); + assert.equal(watchUrlAt(null, 3), null); +}); + +const P = (id: string, start: number, end: number, used = true) => ({ id, start, end, score: 0.5, why: "host laughs", used }); +const linkAt = (s: number) => watchUrlAt("https://www.youtube.com/watch?v=vid", s); + +test("applyProposals with citeUrlAt: added clips link their second; a moved clip's derived link follows it; a link somebody wrote stays", () => { + const clip = clipFromProposal(P("p001", 10.4, 20), { id: "r001", channel: "ch", video: "vid", citeUrlAt: linkAt }); + assert.equal(clip.citeUrl, "https://www.youtube.com/watch?v=vid&t=10s"); + assert.equal("citeUrl" in clipFromProposal(P("p001", 10.4, 20), { id: "r001", channel: "ch", video: "vid" }), false); + + const first = applyProposals([], { proposals: [P("p001", 10, 20), P("p002", 40, 50)], channel: "ch", video: "vid", citeUrlAt: linkAt }); + assert.deepEqual(first.timeline.map((e) => e.citeUrl), ["https://www.youtube.com/watch?v=vid&t=10s", "https://www.youtube.com/watch?v=vid&t=40s"]); + // A hand-written link (a mirror) on r002; r001 moves: its derived link follows, r002's stays. + const tl = first.timeline.map((e) => ({ ...e })); + tl[1].citeUrl = "https://mirror.example/x?t=40"; + const second = applyProposals(tl, { proposals: [P("p001", 12, 20), P("p002", 42, 50)], channel: "ch", video: "vid", citeUrlAt: linkAt }); + assert.deepEqual(second.timeline.map((e) => [e.id, e.cite, e.citeUrl]), [ + ["r001", 12, "https://www.youtube.com/watch?v=vid&t=12s"], + ["r002", 42, "https://mirror.example/x?t=40"], + ]); + // A clip from before the rule (no link) gains one even when nothing else moved; without the rule nothing changes. + const bare = first.timeline.map(({ citeUrl: _c, ...e }) => e); + const third = applyProposals(bare, { proposals: [P("p001", 10, 20), P("p002", 40, 50)], channel: "ch", video: "vid", citeUrlAt: linkAt }); + assert.deepEqual(third.changes.updated, ["r001", "r002"]); + assert.ok(third.timeline.every((e) => e.citeUrl)); + const plain = applyProposals(bare, { proposals: [P("p001", 10, 20), P("p002", 40, 50)], channel: "ch", video: "vid" }); + assert.equal(plain.changes.kept, 2); + assert.ok(plain.timeline.every((e) => !("citeUrl" in e))); +}); diff --git a/umtool/e2e/create.spec.ts b/umtool/e2e/create.spec.ts @@ -266,7 +266,13 @@ test("Highlights from a recording: the clip finder proposes clips marked by the test("Find clips from the editor (release 36): mode new with the worker token scaffolds the segment's project and analyzes it; asked again, the same project; a wrong token is refused", async ({ request }) => { // A synthetic stream that reacts to two narrated videos, with its chat replay; no sound. - writeReactionCorpus(path.join(FIXTURE, "channels"), { channel: "synth-two", video: "two001", two: true, chat: true }); + writeReactionCorpus(path.join(FIXTURE, "channels"), { + channel: "synth-two", + video: "two001", + two: true, + chat: true, + meta: { webpage_url: "https://www.youtube.com/watch?v=two001", channel: "Synth Two" }, + }); const ask = (data: Record<string, unknown>, token = "umtool-e2e-token") => request.post("/api/report/clips", { headers: { authorization: `Bearer ${token}` }, data }); const wrong = await ask({ mode: "new", slug: "p36-find", from: "synth-two/two001" }, "not-the-token"); @@ -277,6 +283,11 @@ test("Find clips from the editor (release 36): mode new with the worker token sc const made = await r.json(); expect(made).toMatchObject({ project: "p36-find", created: true, segment: "s2", scope: [1500, 2390], href: "/projects/p36-find/clips" }); expect(made.segments.map((s: { id: string }) => s.id)).toEqual(["s1", "s2"]); + // A channel on no site: each clip links its YouTube page at its second; the site-less look. + const m = manifestOf("p36-find"); + expect(m.provenance.channel).toBe("Synth Two"); + expect(m.render).toMatchObject({ headerHeight: 0, footerHeight: 0, qr: false, transition: 0.5, transitionStyle: "fadeblack", loudness: { target: -16 } }); + for (const c of m.timeline) expect(c.citeUrl).toBe(`https://www.youtube.com/watch?v=two001&t=${c.cite}s`); const done = async (id: string) => (await (await request.get(`/api/report/clips?job=${id}`)).json()).state; await expect.poll(() => done(made.jobId), { timeout: 60_000 }).toBe("done"); const summary = (await (await request.get("/api/report/clips?project=p36-find")).json()).reactions; diff --git a/umtool/lib/projects/report.mjs b/umtool/lib/projects/report.mjs @@ -91,6 +91,21 @@ const DEAD_ORIGIN = export const isDeadOrigin = (o) => !o || typeof o !== "string" || DEAD_ORIGIN.test(o); +/** + * A cut with NO siteOrigin whose every clip carries its own `citeUrl` (release + * 36: a site-less reactions cut links each clip's platform page), with no + * card and no post that would need the archive: no QR is built from the + * origin, so its absence is not a defect. A dead origin that IS set (localhost) + * still is one. + */ +export const originUnused = (m) => { + if (m?.provenance?.siteOrigin) return false; + const tl = Array.isArray(m?.timeline) ? m.timeline : []; + const clips = tl.filter((e) => e?.type === "clip"); + return clips.length > 0 && clips.every((c) => typeof c.citeUrl === "string" && /^https?:\/\//.test(c.citeUrl)) && !tl.some((e) => e?.type === "card") && !(Array.isArray(m?.posts) && m.posts.length); +}; +const originDead = (m) => isDeadOrigin(m?.provenance?.siteOrigin) && !originUnused(m); + const stat0 = (p) => stat(p).then((s) => s, () => null); export const manifestPath = (dir) => path.join(dir, MANIFEST_NAME); @@ -682,7 +697,7 @@ export async function summariseReport(ctx) { if (build.built) facts.push(`${(build.finalSize / 1e6).toFixed(0)} MB`); const flags = []; - if (isDeadOrigin(m?.provenance?.siteOrigin)) flags.push("dead QR origin"); + if (originDead(m)) flags.push("dead QR origin"); if (!m?.provenance?.channelSlug) flags.push("no channelSlug"); if (build.stale) flags.push("older than its manifest"); if (sourcesDead) flags.push(`${sourcesDead} dead source${sourcesDead === 1 ? "" : "s"}`); @@ -726,7 +741,7 @@ export async function summariseReport(ctx) { ...(sourcesMissing ? { "sources-missing": String(sourcesMissing) } : {}), ...(cueGaps ? { "cue-gaps": String(cueGaps) } : {}), ...(build.built ? { built: "1", "final-bytes": String(build.finalSize + build.fullSize) } : {}), - ...(isDeadOrigin(m?.provenance?.siteOrigin) ? { "dead-origin": "1" } : {}), + ...(originDead(m) ? { "dead-origin": "1" } : {}), }, // Kept for the project page and the decisions pass, so neither re-reads. manifest: m, @@ -827,7 +842,7 @@ export async function reportDecisions(ctx, summary) { // --- the manifest itself ------------------------------------------------- const origin = m.provenance?.siteOrigin; - if (isDeadOrigin(origin)) { + if (originDead(m)) { add( "manifest-invalid", "provenance.siteOrigin", diff --git a/umtool/lib/projects/scaffold.mjs b/umtool/lib/projects/scaffold.mjs @@ -17,6 +17,9 @@ export const SLUG_RE = /^[a-z0-9][a-z0-9-]*$/; export const CHANNEL_SLUG_RE = /^[A-Za-z0-9][A-Za-z0-9._-]*$/; export const SEEDS = ["chapters", "frames", "phrase", "reactions"]; +/** The render keys a site-less, one-video reactions cut starts with (release 36: the operator's choice on the first case). */ +export const SITELESS_LOOK = Object.freeze({ headerHeight: 0, footerHeight: 0, qr: false, transition: 0.5, transitionStyle: "fadeblack", loudness: Object.freeze({ target: -16 }) }); + /** * A manifest skeleton, and deliberately an EMPTY timeline. * @@ -247,9 +250,9 @@ const capNote = (max, kept, found) => * (common/lib/montage/phraseScan.mjs `capInstances`); the rest are listed in * phrase-scan.json as `skippedByCap`. No `max`: the output is what it was. * - * @param {{ root: string, slug: string, title?: string, from?: string | null, siteOrigin?: string | null, seed?: string | null, brand?: string | null, channelsDir?: string, timeline?: Record<string, unknown>[] | null, timelineFrom?: string | null, target?: number, phrase?: string | null, channels?: string[] | null, prefer?: string | null, exclude?: string | null, scan?: { instances: any[], hits: any[], dropped: any[], scanned: number } | null, max?: number | null, laughMin?: number, scope?: [number, number | null] | "auto" | null, segment?: string | null }} args + * @param {{ root: string, slug: string, title?: string, from?: string | null, siteOrigin?: string | null, seed?: string | null, brand?: string | null, channelsDir?: string, timeline?: Record<string, unknown>[] | null, timelineFrom?: string | null, target?: number, phrase?: string | null, channels?: string[] | null, prefer?: string | null, exclude?: string | null, scan?: { instances: any[], hits: any[], dropped: any[], scanned: number } | null, max?: number | null, laughMin?: number, scope?: [number, number | null] | "auto" | null, segment?: string | null, sitesDir?: string }} args */ -export async function scaffoldReportVideo({ root, slug, title, from = null, siteOrigin = null, seed = null, brand = null, channelsDir = GLOBAL_CHANNELS_DIR(), timeline = null, timelineFrom = null, target = undefined, phrase = null, channels = null, prefer = null, exclude = null, scan: given = null, max = null, laughMin = undefined, scope = null, segment = null }) { +export async function scaffoldReportVideo({ root, slug, title, from = null, siteOrigin = null, seed = null, brand = null, channelsDir = GLOBAL_CHANNELS_DIR(), timeline = null, timelineFrom = null, target = undefined, phrase = null, channels = null, prefer = null, exclude = null, scan: given = null, max = null, laughMin = undefined, scope = null, segment = null, sitesDir = undefined }) { if (!SLUG_RE.test(String(slug ?? ""))) { throw new Error(`"${slug}" will not route — use lower-case letters, digits and dashes`); } @@ -394,10 +397,23 @@ export async function scaffoldReportVideo({ root, slug, title, from = null, site channelsDir, channel: src.channel, video: src.video, ...(target !== undefined ? { target } : {}), ...(laughMin !== undefined ? { laughMin } : {}), ...(reactionsScope ? { scope: reactionsScope } : {}), ...(segment ? { segment: String(segment) } : {}), + siteOrigin: provenance.siteOrigin ?? null, + ...(sitesDir ? { sitesDir } : {}), }); doc.timeline = pass.timeline; - // Hard cuts: a highlights reel. - doc.render.transition = 0; + if (!doc.provenance.channel && pass.rec.meta?.channel) doc.provenance.channel = pass.rec.meta.channel; + if (pass.siteLess) { + // Release 36: a channel on no site — each clip links its platform page at + // its second (no QR to an archive that does not have it), and the look the + // operator chose for a one-video cut: no header, no QR, fades through black, + // even loudness (render.loudness is lane C's; until its validator lands it + // is a key the build ignores). + Object.assign(doc.render, SITELESS_LOOK, { loudness: { ...SITELESS_LOOK.loudness } }); + notes.push(`no site carries ${src.channel}: each clip links ${pass.rec.meta?.extractor ?? "its platform"}'s page at its second (citeUrl); the look: no header, no QR, ${SITELESS_LOOK.transition} s fades through black, ${SITELESS_LOOK.loudness.target} LUFS`); + } else { + // Hard cuts: a highlights reel. + doc.render.transition = 0; + } seeded = doc.timeline.length; reactionsSeeded = pass; const used = pass.doc.proposals.filter((p) => p.used); diff --git a/umtool/lib/report/reactions-r36.test.mjs b/umtool/lib/report/reactions-r36.test.mjs @@ -201,3 +201,69 @@ test("the route's caller: no header is the page, umtool's WORKER_TOKEN the edito assert.match(routeCaller("Bearer tok", "", "/api/report/clips").error, /holds no WORKER_TOKEN, so no editor can call it/); assert.equal(routeCaller("Basic x", "tok").ok, false); }); + +test("a channel on no site: each clip links its platform page, provenance.channel from the metadata, the site-less look; no dead-origin decision", async () => { + const meta = { webpage_url: "https://www.youtube.com/watch?v=react001", channel: "Synth Reacts Channel", extractor_key: "Youtube" }; + const f = await fixture({ meta }); + const { lintManifest } = await import("umtool-report-to-video/lint"); + const { decisionsFor, summarise } = await import("../projects/core.mjs"); + const { walkProjects } = await import("../projects/walk.mjs"); + const { SITELESS_LOOK } = await import("../projects/scaffold.mjs"); + try { + const r = await scaffoldReportVideo({ root: f.reportsRoot, slug: "siteless", from: "synth-reacts/react001", seed: "reactions", channelsDir: f.channelsDir, segment: "s1", target: 120, sitesDir: f.sitesDir }); + const m = JSON.parse(await readFile(path.join(r.dir, "video.manifest.json"), "utf8")); + assert.ok(m.timeline.length > 0); + for (const c of m.timeline) assert.equal(c.citeUrl, `https://www.youtube.com/watch?v=react001&t=${c.cite}s`); + assert.equal(m.provenance.channel, "Synth Reacts Channel"); + assert.equal(m.provenance.siteOrigin, ""); + assert.deepEqual( + { headerHeight: m.render.headerHeight, footerHeight: m.render.footerHeight, qr: m.render.qr, transition: m.render.transition, transitionStyle: m.render.transitionStyle, loudness: m.render.loudness }, + { ...SITELESS_LOOK, loudness: { target: -16 } }, + ); + assert.ok(r.notes.some((n) => /no site carries synth-reacts: each clip links Youtube's page/.test(n)), r.notes.join("\n")); + // The build's validators and lint take it (render.loudness is a key they do not refuse). + const lint = lintManifest(m, { validators: true }); + assert.deepEqual(lint.errors.filter((e) => /loudness|transition|qr|render/i.test(e)), []); + // No siteOrigin is not a defect here: every clip links itself. + const [ref] = (await walkProjects(f.reportsRoot)).filter((p) => p.id === "siteless"); + assert.ok(!(await decisionsFor(ref, f.reportsRoot)).some((d) => d.target === "provenance.siteOrigin")); + assert.ok(!(await summarise(ref, f.reportsRoot)).flags.includes("dead QR origin")); + + // A later pass keeps the rule: every clip it writes links itself. + await pointAt(r.dir, f.channelsDir); + assert.equal(await clipsCommand(["propose", "siteless", "--target", "300"], { reportsRoot: f.reportsRoot, ...quiet() }), 0); + const after = JSON.parse(await readFile(path.join(r.dir, "video.manifest.json"), "utf8")); + assert.ok(after.timeline.length > m.timeline.length); + for (const c of after.timeline) assert.equal(c.citeUrl, `https://www.youtube.com/watch?v=react001&t=${c.cite}s`); + } finally { + await rm(f.root, { recursive: true, force: true }); + } +}); + +test("a channel on a public site, or a recording with no watch page: no links written, hard cuts as before", async () => { + const meta = { webpage_url: "https://www.youtube.com/watch?v=react001", channel: "Synth Reacts Channel" }; + const f = await fixture({ meta }); + const g = await fixture(); + try { + await mkdir(path.join(f.sitesDir, "synthsite"), { recursive: true }); + await writeFile(path.join(f.sitesDir, "synthsite", "site.json"), JSON.stringify({ siteId: "synthsite", siteUrl: "https://synth.example", channels: [{ slug: "synth-reacts" }] })); + // A private site (no siteUrl) does not count. + await mkdir(path.join(g.sitesDir, "private"), { recursive: true }); + await writeFile(path.join(g.sitesDir, "private", "site.json"), JSON.stringify({ siteId: "private", channels: [{ slug: "synth-reacts" }] })); + const { channelOnPublicSite } = await import("./reactions.mjs"); + assert.equal(await channelOnPublicSite("synth-reacts", f.sitesDir), true); + assert.equal(await channelOnPublicSite("synth-reacts", g.sitesDir), false); + for (const [x, slug] of [[f, "onsite"], [g, "nopage"]]) { + const r = await scaffoldReportVideo({ root: x.reportsRoot, slug, from: "synth-reacts/react001", seed: "reactions", channelsDir: x.channelsDir, target: 120, sitesDir: x.sitesDir }); + const m = JSON.parse(await readFile(path.join(r.dir, "video.manifest.json"), "utf8")); + assert.equal(m.render.transition, 0, slug); + assert.equal(m.render.headerHeight, 56, slug); + assert.ok(m.timeline.every((c) => !("citeUrl" in c)), slug); + } + // The site's channel still gets its name from the metadata. + assert.equal(JSON.parse(await readFile(path.join(f.reportsRoot, "onsite", "video.manifest.json"), "utf8")).provenance.channel, "Synth Reacts Channel"); + } finally { + await rm(f.root, { recursive: true, force: true }); + await rm(g.root, { recursive: true, force: true }); + } +}); diff --git a/umtool/lib/report/reactions.mjs b/umtool/lib/report/reactions.mjs @@ -29,7 +29,7 @@ // nothing changes // // Nothing here calls a model but the local ones; nothing touches the network. -import { readFile, rename, stat, writeFile, mkdir } from "node:fs/promises"; +import { readdir, readFile, rename, stat, writeFile, mkdir } from "node:fs/promises"; import path from "node:path"; import { DEFAULT_PARAMS, @@ -41,7 +41,7 @@ import { normalizeParams, wordsFromCues, } from "yt-dlp-transcript-common/lib/clips/clips.mjs"; -import { applyProposals, fixedClips } from "yt-dlp-transcript-common/lib/clips/assist.mjs"; +import { applyProposals, fixedClips, watchUrlAt } from "yt-dlp-transcript-common/lib/clips/assist.mjs"; import { REACTIONS_FILE, operatorRoles, readReactions, writeReactions } from "yt-dlp-transcript-common/lib/clips/reactions.mjs"; import { embedSpans, resolveTagger, runAudioScan, speakerCentroids } from "yt-dlp-transcript-common/lib/clips/scan.mjs"; import { SEGMENT_MIN_S, findSegments, pickSegment } from "yt-dlp-transcript-common/lib/clips/segments.mjs"; @@ -54,6 +54,7 @@ import { clipMomentKey, readMontageRulings } from "umtool-report-to-video/montag import { REPORTS_ROOT, resolveProject } from "../projects/core.mjs"; import { kindMakesTakes } from "../projects/kinds.mjs"; import { channelsDirFor, hasShadowChannels, readManifest } from "../projects/report.mjs"; +import { SITES_DIR } from "../paths.mjs"; import { replaceManifest, manifestToken, StaleToken } from "./manifest.mjs"; import { REPO_ROOT } from "../paths.mjs"; import { UMTOOL_DIR } from "./driver.mjs"; @@ -262,7 +263,7 @@ function scanInputs(scans) { * @param {{ rec: any, scans?: any, params?: Record<string, unknown>, operator?: Record<string, string>, previous?: any, * timeline?: any[], isProtected?: (e: any) => boolean, audio?: { path: string, kind: string } | null, now?: Date }} o */ -export function proposalPass({ rec, scans = null, params = {}, operator = {}, previous = null, timeline = [], isProtected = () => false, audio = null, now = new Date() }) { +export function proposalPass({ rec, scans = null, params = {}, operator = {}, previous = null, timeline = [], isProtected = () => false, audio = null, now = new Date(), citeUrlAt = null }) { const { laughScan, centroids, laughVoices } = scanInputs(scans); const segments = recordingSegments(rec, operator); const fixed = fixedClips(timeline, { channel: rec.channel, video: rec.video, isProtected }); @@ -279,7 +280,7 @@ export function proposalPass({ rec, scans = null, params = {}, operator = {}, pr fixed, chat: rec.chat ?? null, }); - const applied = applyProposals(timeline, { proposals: a.proposals, channel: rec.channel, video: rec.video, duration: a.duration, words: cleanWords(rec.words), isProtected }); + const applied = applyProposals(timeline, { proposals: a.proposals, channel: rec.channel, video: rec.video, duration: a.duration, words: cleanWords(rec.words), isProtected, citeUrlAt }); const madeAt = now.toISOString(); const doc = { version: 1, @@ -312,6 +313,47 @@ export function proposalPass({ rec, scans = null, params = {}, operator = {}, pr return { doc, timeline: applied.timeline, changes: applied.changes, analysis: a }; } +// ---- site-less links (release 36 B3) --------------------------------------------------- + +/** + * Whether a channel is on a public site: in a `site.json`'s `channels` (or + * `citedChannels`) with a `siteUrl` to link to. A private site (no siteUrl) + * does not count: nobody else can open its links. + * @param {string} channel + * @param {string} [sitesDir] + */ +export async function channelOnPublicSite(channel, sitesDir = SITES_DIR) { + let ids; + try { + ids = await readdir(sitesDir); + } catch { + return false; + } + for (const id of ids) { + const site = await readJson(path.join(/* turbopackIgnore: true */ sitesDir, id, "site.json")); + if (!site || typeof site.siteUrl !== "string" || !site.siteUrl.trim()) continue; + const pool = [...(Array.isArray(site.channels) ? site.channels.map((c) => c?.slug) : []), ...(Array.isArray(site.citedChannels) ? site.citedChannels : [])]; + if (pool.includes(channel)) return true; + } + return false; +} + +/** + * The link rule for a pass: with no siteOrigin and the channel on no public + * site, each clip the pass writes links its platform page at its cite + * (watchUrlAt over the recording's `webpage_url`); else null (the QR's link + * is the site's, as before). + * @returns {Promise<((s: number) => string | null) | null>} + */ +export async function siteLessLinks(rec, manifest, { sitesDir = SITES_DIR } = {}) { + const origin = manifest?.provenance?.siteOrigin; + if (typeof origin === "string" && origin.trim()) return null; + const url = rec.meta?.webpageUrl ?? null; + if (!watchUrlAt(url, 0)) return null; + if (await channelOnPublicSite(rec.channel, sitesDir)) return null; + return (s) => watchUrlAt(url, s); +} + // ---- auto-scope (release 36 B1) ----------------------------------------------------- /** The host the operator named, if any (`{index: role}`). */ @@ -402,13 +444,14 @@ async function rulingsGuard(dir, manifest) { * what it returns; `umtool clips analyze` then runs the scans and re-proposes. * @param {{ channelsDir: string, channel: string, video: string, target?: number }} o */ -export async function seedReactions({ channelsDir, channel, video, target, laughMin, scope, segment = null }) { +export async function seedReactions({ channelsDir, channel, video, target, laughMin, scope, segment = null, siteOrigin = null, sitesDir = SITES_DIR }) { const rec = await loadRecording({ channelsDir, channel, video }); + const citeUrlAt = await siteLessLinks(rec, { provenance: { siteOrigin: siteOrigin ?? "" } }, { sitesDir }); const notes = []; const given = { ...(target !== undefined ? { target } : {}), ...(laughMin !== undefined ? { laughMin } : {}), ...(scope ? { scope } : {}), ...(segment ? { segment } : {}) }; const params = resolveParams(rec, given, {}, (n) => notes.push(n)); - const pass = proposalPass({ rec, params: { ...params, ...(params.scope === "all" ? { scope: null } : {}) } }); - return { ...pass, rec, notes }; + const pass = proposalPass({ rec, params: { ...params, ...(params.scope === "all" ? { scope: null } : {}) }, citeUrlAt }); + return { ...pass, rec, notes, siteLess: !!citeUrlAt }; } /** @@ -419,7 +462,7 @@ export async function seedReactions({ channelsDir, channel, video, target, laugh * @param {{ project: { id: string, dir: string }, from?: { channel: string, video: string } | null, params?: Record<string, unknown>, * host?: number | null, wordsFile?: string | null, scans?: any, audio?: any, dry?: boolean, now?: Date }} o */ -export async function proposeProject({ project, from = null, params = {}, host = null, wordsFile = null, scans = undefined, audio = null, engine = null, dry = false, now = new Date(), say = () => {} }) { +export async function proposeProject({ project, from = null, params = {}, host = null, wordsFile = null, scans = undefined, audio = null, engine = null, dry = false, now = new Date(), say = () => {}, sitesDir = SITES_DIR }) { for (let attempt = 0; ; attempt += 1) { const token = await manifestToken(project.dir); const manifest = await readManifest(project.dir); @@ -440,7 +483,8 @@ export async function proposeProject({ project, from = null, params = {}, host = const merged = mergeParams(sameSource ? previous.params : null, resolveParams(rec, params, operator, attempt === 0 ? say : () => {})); const s = scans === undefined ? await readScans(project.dir, rec.channel, rec.video) : scans; const isProtected = await rulingsGuard(project.dir, manifest); - const passOf = (sc) => proposalPass({ rec, scans: sc, params: merged, operator, previous: sameSource ? previous : null, timeline: manifest.timeline ?? [], isProtected, audio, now }); + const citeUrlAt = await siteLessLinks(rec, manifest, { sitesDir }); + const passOf = (sc) => proposalPass({ rec, scans: sc, params: merged, operator, previous: sameSource ? previous : null, timeline: manifest.timeline ?? [], isProtected, audio, now, citeUrlAt }); let pass = passOf(s); // Each laugh's voice (release 35, the live case): embedded once and kept in // the voices scan, so a pass with a new laughMin or scope embeds only the new ones.