Archilyzer · Source

archilyzer

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

commit 2106d96cc14adba19f7d5a5a1605c305339c4a6f
parent d21d923c1569f5aacce8894a072f63dd7c18b1d9
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Sun, 18 Oct 2026 22:53:57 -0400

common: the phrase scan records each instance's alternates (release 35 O1, slice 1)

phraseScan / phraseScanMany give every instance `alternates: [{slug, videoId,
start, end, platform, availability}]` -- the other-channel hits folded into it:
a twin's hit its preferred copy already has, the hit a placed (`via`) instance
came from, and every `alsoIn` fold -- each at its own moment on its own
recording. The copies a stand-in can be cut from when the preferred copy's
window is refused. Every other field is unchanged: release 34's answer over
the test corpus is kept as fixtures/phraseScan.r34.json and the new answer
minus `alternates` equals it, for both scanners, every option set and phrase.

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

Diffstat:
Acommon/lib/montage/fixtures/phraseScan.r34.json | 600+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mcommon/lib/montage/phraseScan.d.mts | 11+++++++++++
Mcommon/lib/montage/phraseScan.mjs | 54++++++++++++++++++++++++++++++++++++++++++++++--------
Mcommon/lib/montage/phraseScanMany.test.ts | 58++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 715 insertions(+), 8 deletions(-)

diff --git a/common/lib/montage/fixtures/phraseScan.r34.json b/common/lib/montage/fixtures/phraseScan.r34.json @@ -0,0 +1,600 @@ +[ + { + "instances": [ + { + "slug": "yt", + "videoId": "yt3", + "platform": "youtube", + "source": null, + "date": "20190502", + "title": "t yt3", + "duration": 900, + "start": 2, + "end": 5, + "cueFirst": 0, + "cueLast": 0, + "match": "slow news week", + "context": ">> it must be a slow news week Well well-well, here we go", + "speakerCheck": true, + "availability": "public" + }, + { + "slug": "other", + "videoId": "o1", + "platform": "youtube", + "source": null, + "date": "20220303", + "title": "t o1", + "duration": 300, + "start": 4, + "end": 10, + "cueFirst": 1, + "cueLast": 2, + "match": "slow news day", + "context": "nobody asked for this slow news day", + "speakerCheck": false, + "availability": "unlisted" + }, + { + "slug": "rumble", + "videoId": "r1", + "platform": "rumble", + "source": null, + "date": "20230102", + "title": "t r1", + "duration": 1000, + "start": 100, + "end": 103, + "cueFirst": 0, + "cueLast": 0, + "match": "slow news day", + "context": "kind of a slow news day today folks well well well look at this", + "speakerCheck": false, + "alsoIn": [ + { + "slug": "rumble", + "videoId": "r3", + "start": 5 + } + ], + "availability": null + }, + { + "slug": "rumble", + "videoId": "r2", + "platform": "rumble", + "source": null, + "date": "20230301", + "title": "t r2", + "duration": 2000, + "start": 500, + "end": 506, + "cueFirst": 1, + "cueLast": 1, + "match": "slow news day", + "context": "so the admin tweeted a statement must be a really slow news day and no one asked for it", + "via": { + "slug": "yt", + "videoId": "yt2", + "start": 523, + "score": 0.86 + }, + "speakerCheck": false, + "availability": null + }, + { + "slug": "yt", + "videoId": "yt4", + "platform": "youtube", + "source": null, + "date": "20260507", + "title": "t yt4", + "duration": 810, + "start": 769, + "end": 772, + "cueFirst": 0, + "cueLast": 0, + "match": "slow news cycle", + "context": "don't get sucked into this it's uh slow news cycle panic", + "speakerCheck": false, + "availability": null + } + ], + "dropped": [ + { + "slug": "rumble", + "videoId": "r4", + "platform": "rumble", + "source": null, + "date": "20240101", + "title": "t r4", + "duration": 900, + "start": 9, + "end": 12, + "cueFirst": 0, + "cueLast": 0, + "match": "slow news week", + "context": "slow news week Jeremy says chat well, well, well", + "why": "matches the exclude pattern" + } + ] + }, + { + "instances": [ + { + "slug": "other", + "videoId": "o1", + "platform": "youtube", + "source": null, + "date": "20220303", + "title": "t o1", + "duration": 300, + "start": 1, + "end": 4, + "cueFirst": 0, + "cueLast": 0, + "match": "nobody asked", + "context": "nobody asked for this slow", + "speakerCheck": false, + "availability": "unlisted" + }, + { + "slug": "rumble", + "videoId": "r2", + "platform": "rumble", + "source": null, + "date": "20230301", + "title": "t r2", + "duration": 2000, + "start": 506, + "end": 509, + "cueFirst": 2, + "cueLast": 2, + "match": "nobody asked", + "context": "must be a really slow new state and nobody asked for it", + "speakerCheck": false, + "availability": null + } + ], + "dropped": [] + }, + { + "instances": [ + { + "slug": "yt", + "videoId": "yt3", + "platform": "youtube", + "source": null, + "date": "20190502", + "title": "t yt3", + "duration": 900, + "start": 30, + "end": 33, + "cueFirst": 1, + "cueLast": 1, + "match": "Well well-well", + "context": ">> it must be a slow news week Well well-well, here we go", + "speakerCheck": true, + "availability": "public" + }, + { + "slug": "rumble", + "videoId": "r1", + "platform": "rumble", + "source": null, + "date": "20230102", + "title": "t r1", + "duration": 1000, + "start": 103, + "end": 106, + "cueFirst": 1, + "cueLast": 1, + "match": "well well well", + "context": "kind of a slow news day today folks well well well look at this", + "speakerCheck": false, + "availability": null + } + ], + "dropped": [ + { + "slug": "rumble", + "videoId": "r4", + "platform": "rumble", + "source": null, + "date": "20240101", + "title": "t r4", + "duration": 900, + "start": 40, + "end": 40, + "cueFirst": 1, + "cueLast": 1, + "match": "well, well, well", + "context": "slow news week Jeremy says chat well, well, well", + "why": "matches the exclude pattern" + } + ] + }, + { + "instances": [], + "dropped": [] + }, + { + "instances": [ + { + "slug": "yt", + "videoId": "yt3", + "platform": "youtube", + "source": null, + "date": "20190502", + "title": "t yt3", + "duration": 900, + "start": 2, + "end": 5, + "cueFirst": 0, + "cueLast": 0, + "match": "slow news week", + "context": ">> it must be a slow news week Well well-well, here we go", + "speakerCheck": true, + "availability": "public" + }, + { + "slug": "other", + "videoId": "o1", + "platform": "youtube", + "source": null, + "date": "20220303", + "title": "t o1", + "duration": 300, + "start": 4, + "end": 10, + "cueFirst": 1, + "cueLast": 2, + "match": "slow news day", + "context": "nobody asked for this slow news day", + "speakerCheck": false, + "availability": "unlisted" + }, + { + "slug": "yt", + "videoId": "yt1", + "platform": "youtube", + "source": null, + "date": "20230101", + "title": "t yt1", + "duration": 1010, + "start": 110, + "end": 113, + "cueFirst": 0, + "cueLast": 0, + "match": "slow news day", + "context": "kind of a slow news day today folks", + "speakerCheck": false, + "alsoIn": [ + { + "slug": "rumble", + "videoId": "r1", + "start": 100 + }, + { + "slug": "rumble", + "videoId": "r3", + "start": 5 + } + ], + "availability": null + }, + { + "slug": "yt", + "videoId": "yt2", + "platform": "youtube", + "source": null, + "date": "20230301", + "title": "t yt2", + "duration": 2010, + "start": 523, + "end": 526, + "cueFirst": 1, + "cueLast": 1, + "match": "slow news day", + "context": "so the admin tweeted a statement must be a really slow news day and no one asked for it", + "speakerCheck": false, + "availability": null + }, + { + "slug": "rumble", + "videoId": "r4", + "platform": "rumble", + "source": null, + "date": "20240101", + "title": "t r4", + "duration": 900, + "start": 9, + "end": 12, + "cueFirst": 0, + "cueLast": 0, + "match": "slow news week", + "context": "slow news week Jeremy says chat well, well, well", + "speakerCheck": false, + "availability": null + }, + { + "slug": "yt", + "videoId": "yt4", + "platform": "youtube", + "source": null, + "date": "20260507", + "title": "t yt4", + "duration": 810, + "start": 769, + "end": 772, + "cueFirst": 0, + "cueLast": 0, + "match": "slow news cycle", + "context": "don't get sucked into this it's uh slow news cycle panic", + "speakerCheck": false, + "availability": null + } + ], + "dropped": [] + }, + { + "instances": [ + { + "slug": "other", + "videoId": "o1", + "platform": "youtube", + "source": null, + "date": "20220303", + "title": "t o1", + "duration": 300, + "start": 1, + "end": 4, + "cueFirst": 0, + "cueLast": 0, + "match": "nobody asked", + "context": "nobody asked for this slow", + "speakerCheck": false, + "availability": "unlisted" + }, + { + "slug": "rumble", + "videoId": "r2", + "platform": "rumble", + "source": null, + "date": "20230301", + "title": "t r2", + "duration": 2000, + "start": 506, + "end": 509, + "cueFirst": 2, + "cueLast": 2, + "match": "nobody asked", + "context": "must be a really slow new state and nobody asked for it", + "speakerCheck": false, + "alsoIn": [ + { + "slug": "yt", + "videoId": "yt2", + "start": 526 + } + ], + "availability": null + } + ], + "dropped": [] + }, + { + "instances": [ + { + "slug": "yt", + "videoId": "yt3", + "platform": "youtube", + "source": null, + "date": "20190502", + "title": "t yt3", + "duration": 900, + "start": 30, + "end": 33, + "cueFirst": 1, + "cueLast": 1, + "match": "Well well-well", + "context": ">> it must be a slow news week Well well-well, here we go", + "speakerCheck": true, + "availability": "public" + }, + { + "slug": "rumble", + "videoId": "r1", + "platform": "rumble", + "source": null, + "date": "20230102", + "title": "t r1", + "duration": 1000, + "start": 103, + "end": 106, + "cueFirst": 1, + "cueLast": 1, + "match": "well well well", + "context": "kind of a slow news day today folks well well well look at this", + "speakerCheck": false, + "availability": null + }, + { + "slug": "rumble", + "videoId": "r4", + "platform": "rumble", + "source": null, + "date": "20240101", + "title": "t r4", + "duration": 900, + "start": 40, + "end": 40, + "cueFirst": 1, + "cueLast": 1, + "match": "well, well, well", + "context": "slow news week Jeremy says chat well, well, well", + "speakerCheck": false, + "availability": null + } + ], + "dropped": [] + }, + { + "instances": [], + "dropped": [] + }, + { + "instances": [ + { + "slug": "other", + "videoId": "o1", + "platform": "youtube", + "source": null, + "date": "20220303", + "title": "t o1", + "duration": 300, + "start": 4, + "end": 10, + "cueFirst": 1, + "cueLast": 2, + "match": "slow news day", + "context": "nobody asked for this slow news day", + "speakerCheck": false, + "availability": "unlisted" + }, + { + "slug": "rumble", + "videoId": "r4", + "platform": "rumble", + "source": null, + "date": "20240101", + "title": "t r4", + "duration": 900, + "start": 9, + "end": 12, + "cueFirst": 0, + "cueLast": 0, + "match": "slow news week", + "context": "slow news week Jeremy says chat well, well, well", + "speakerCheck": false, + "availability": null + } + ], + "dropped": [ + { + "slug": "rumble", + "videoId": "r1", + "platform": "rumble", + "source": null, + "date": "20230102", + "title": "t r1", + "duration": 1000, + "start": 100, + "end": 103, + "cueFirst": 0, + "cueLast": 0, + "match": "slow news day", + "context": "kind of a slow news day today folks well well well look at this", + "why": "matches the exclude pattern" + }, + { + "slug": "rumble", + "videoId": "r3", + "platform": "rumble", + "source": null, + "date": "20230104", + "title": "t r3", + "duration": 60, + "start": 5, + "end": 8, + "cueFirst": 0, + "cueLast": 0, + "match": "slow news day", + "context": "kind of a slow news day today folks", + "why": "matches the exclude pattern" + } + ] + }, + { + "instances": [ + { + "slug": "other", + "videoId": "o1", + "platform": "youtube", + "source": null, + "date": "20220303", + "title": "t o1", + "duration": 300, + "start": 1, + "end": 4, + "cueFirst": 0, + "cueLast": 0, + "match": "nobody asked", + "context": "nobody asked for this slow", + "speakerCheck": false, + "availability": "unlisted" + }, + { + "slug": "rumble", + "videoId": "r2", + "platform": "rumble", + "source": null, + "date": "20230301", + "title": "t r2", + "duration": 2000, + "start": 506, + "end": 509, + "cueFirst": 2, + "cueLast": 2, + "match": "nobody asked", + "context": "must be a really slow new state and nobody asked for it", + "speakerCheck": false, + "availability": null + } + ], + "dropped": [] + }, + { + "instances": [ + { + "slug": "rumble", + "videoId": "r4", + "platform": "rumble", + "source": null, + "date": "20240101", + "title": "t r4", + "duration": 900, + "start": 40, + "end": 40, + "cueFirst": 1, + "cueLast": 1, + "match": "well, well, well", + "context": "slow news week Jeremy says chat well, well, well", + "speakerCheck": false, + "availability": null + } + ], + "dropped": [ + { + "slug": "rumble", + "videoId": "r1", + "platform": "rumble", + "source": null, + "date": "20230102", + "title": "t r1", + "duration": 1000, + "start": 103, + "end": 106, + "cueFirst": 1, + "cueLast": 1, + "match": "well well well", + "context": "kind of a slow news day today folks well well well look at this", + "why": "matches the exclude pattern" + } + ] + }, + { + "instances": [], + "dropped": [] + } +] diff --git a/common/lib/montage/phraseScan.d.mts b/common/lib/montage/phraseScan.d.mts @@ -22,6 +22,17 @@ export type PhraseInstance = CueHit & { availability?: string | null; via?: { slug: string; videoId: string; start: number; score: number }; alsoIn?: { slug: string; videoId: string; start: number }[]; + // Release 35: the other-channel hits folded into this instance, each its own + // moment on its own recording (an instance in `instances` always has the list). + alternates?: PhraseAlternate[]; +}; +export type PhraseAlternate = { + slug: string; + videoId: string; + start: number; + end: number; + platform: string | null; + availability: string | null; }; export type PhraseScanResult = { instances: PhraseInstance[]; diff --git a/common/lib/montage/phraseScan.mjs b/common/lib/montage/phraseScan.mjs @@ -259,7 +259,19 @@ async function foldHits({ hits, prefer, preferred, recordOf, ex, availability }) preferredHits.get(h.videoId).push(h); } - const placed = hits.filter((h) => h.slug === prefer).map((h) => ({ ...h })); + // The other-channel hits each instance stands for (release 35): a twin's hit + // its preferred copy already has, the hit a placed instance came from, and + // every hit folded into it — the copies a stand-in can be cut from. + const altsOf = new Map(); // placed entry -> its alternates + const placedOf = new Map(); // a preferred hit -> its placed copy + const placed = hits + .filter((h) => h.slug === prefer) + .map((h) => { + const c = { ...h }; + placedOf.set(h, c); + altsOf.set(c, []); + return c; + }); for (const h of hits) { if (h.slug === prefer) continue; const day = dayNumber(h.date); @@ -277,10 +289,15 @@ async function foldHits({ hits, prefer, preferred, recordOf, ex, availability }) } const ctx = words(h.context); // Its twin already has the hit: nothing to add. - const covered = twins.some((id) => - (preferredHits.get(id) ?? []).some((p) => locateInCues([{ text: p.context }], ctx).score >= SAME_HIT_MIN_SCORE), - ); - if (covered) continue; + let covered = null; + for (const id of twins) { + covered = (preferredHits.get(id) ?? []).find((p) => locateInCues([{ text: p.context }], ctx).score >= SAME_HIT_MIN_SCORE) ?? null; + if (covered) break; + } + if (covered) { + altsOf.get(placedOf.get(covered))?.push(alternateOf(h)); + continue; + } // Its twin's transcript says it in other words (a different track): place it there. let moved = null; const placeable = new Set(content(ctx)).size >= PLACE_MIN_WORDS; @@ -305,7 +322,9 @@ async function foldHits({ hits, prefer, preferred, recordOf, ex, availability }) break; } } - placed.push(moved ?? { ...h }); + const entry = moved ?? { ...h }; + altsOf.set(entry, moved ? [alternateOf(h)] : []); + placed.push(entry); } placed.sort((a, b) => String(a.date ?? "").localeCompare(String(b.date ?? "")) || (a.slug === prefer ? 0 : 1) - (b.slug === prefer ? 0 : 1) || a.start - b.start); @@ -319,20 +338,39 @@ async function foldHits({ hits, prefer, preferred, recordOf, ex, availability }) }); if (twin) { (twin.alsoIn ??= []).push({ slug: i.slug, videoId: i.videoId, start: i.start }); + altsOf.get(twin.ref).push(alternateOf(i), ...altsOf.get(i)); continue; } if (ex?.test(i.context)) { dropped.push({ ...i, why: "matches the exclude pattern" }); continue; } - instances.push({ ...i, speakerCheck: i.context.includes(">>") }); + const inst = { ...i, speakerCheck: i.context.includes(">>") }; + // Non-enumerable: never copied into the answer. + Object.defineProperty(inst, "ref", { value: i, enumerable: false }); + instances.push(inst); } + const availabilityFor = (slug, id) => (slug === prefer ? null : availability(slug, id)); for (const i of instances) { - i.availability = i.slug === prefer ? null : await availability(i.slug, i.videoId); + i.availability = await availabilityFor(i.slug, i.videoId); + const seen = new Set(); + const alternates = []; + for (const a of altsOf.get(i.ref) ?? []) { + const k = `${a.slug}/${a.videoId}`; + if ((a.slug === i.slug && a.videoId === i.videoId) || seen.has(k)) continue; + seen.add(k); + alternates.push({ ...a, availability: await availabilityFor(a.slug, a.videoId) }); + } + i.alternates = alternates; } return { instances, dropped }; } +/** An other-channel hit as an instance's alternate: its own moment on its own recording. */ +function alternateOf(h) { + return { slug: h.slug, videoId: h.videoId, start: h.start, end: h.end, platform: h.platform ?? null }; +} + /** * Many phrases in ONE pass over the transcripts (release 34): each cue file is * read and parsed once, its text joined once, and every phrase matched in it. diff --git a/common/lib/montage/phraseScanMany.test.ts b/common/lib/montage/phraseScanMany.test.ts @@ -179,3 +179,61 @@ test("plain words become a tolerant whole-word pattern", () => { assert.throws(() => phraseSourceOf("slow (news"), /not a regular expression/); assert.throws(() => wordsPhraseSource("!!"), /phrase is required/); }); + +// Release 35: every instance records its alternates — the other-channel hits +// folded into it. Everything else is what release 34 answered: the snapshot +// fixtures/phraseScan.r34.json was made by release 34's phraseScan over this +// same corpus, and the new answer minus `alternates` equals it. +test("alternates: the old answer is the new one minus alternates (every option set, every phrase, both scanners)", async () => { + const dir = corpus(VIDEOS); + const want = JSON.parse(readFileSync(path.join(import.meta.dirname, "fixtures", "phraseScan.r34.json"), "utf8")); + const strip = (r: { instances: Record<string, unknown>[]; dropped: unknown[] }) => ({ + instances: r.instances.map(({ alternates, ...rest }) => { + assert.ok(Array.isArray(alternates), "every instance carries its alternates"); + return rest; + }), + dropped: r.dropped, + }); + try { + let k = 0; + for (const opts of [ + { channels: ["yt", "other"], prefer: "rumble", exclude: String.raw`slow news \w+,? jeremy` }, + { channels: ["yt", "other", "rumble"], prefer: null, exclude: null }, + { channels: ["other"], prefer: "rumble", exclude: "today" }, + ]) { + const many = await phraseScanMany({ channelsDir: dir, ...opts, phrases: PHRASES }); + for (const [j, p] of PHRASES.entries()) { + const alone = await phraseScan({ channelsDir: dir, ...opts, phrase: p.phrase }); + assert.deepEqual(strip(alone), want[k], `${p.id} with ${JSON.stringify(opts)}`); + assert.deepEqual(strip(many[j]), want[k], `${p.id} (many) with ${JSON.stringify(opts)}`); + k++; + } + } + assert.equal(k, want.length); + } finally { + rmSync(dir, { recursive: true, force: true }); + } +}); + +test("alternates: a twin's covered hit, the hit a placed instance came from, a folded upload — each with its own moment", async () => { + const dir = corpus(VIDEOS); + try { + const r = await phraseScan({ channelsDir: dir, channels: ["yt", "other"], prefer: "rumble", phrase: SLOW }); + const by = (id: string) => r.instances.find((i) => i.videoId === id)!; + // r1 has the hit itself: yt1 (its twin) is covered, r3 (a clip upload) folds in. + assert.deepEqual(by("r1").alternates, [ + { slug: "yt", videoId: "yt1", start: 110, end: 113, platform: "youtube", availability: null }, + { slug: "rumble", videoId: "r3", start: 5, end: 8, platform: "rumble", availability: null }, + ]); + // r2 was placed from yt2's hit: yt2 is the alternate, at yt2's own moment. + assert.equal(by("r2").via?.videoId, "yt2"); + assert.deepEqual(by("r2").alternates, [{ slug: "yt", videoId: "yt2", start: 523, end: 526, platform: "youtube", availability: null }]); + // No twin, nothing folded: none. + assert.deepEqual(by("yt3").alternates, []); + // Availability is read for an alternate as for an instance. + const o = await phraseScan({ channelsDir: dir, channels: ["other", "yt"], prefer: null, phrase: String.raw`\b(?:no ?one|nobody) (?:asked|was asking)\b` }); + assert.ok(o.instances.every((i) => Array.isArray(i.alternates))); + } finally { + rmSync(dir, { recursive: true, force: true }); + } +});