Archilyzer · Source

archilyzer

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

commit bd87dda3f6ff1d17ade6a93c0dd2c57fdb9720a2
parent 4a923dec96cff2e4938a42ea2d0e89e89f95c83e
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Wed, 11 Nov 2026 18:47:59 -0500

lookouts: a shared title needs shared text to be one recording, and a video with no transcript is named

Review of slice 1. Two same-titled recordings of the same length (a daily
show) were folded on title and runtime alone, so one was never read: with
both transcripts in hand a title match now also needs a Jaccard of 0.1; with
one empty the title and runtime still decide. A video listed as
no-transcript carried no title and no URL: both are read from
metadata.info.json by byte search, as the dates are. Pilot week unchanged:
6 of 6 duplicate uploads, 18 of 18 cut-downs.

Co-Authored-By: Claude <noreply@anthropic.com>

Diffstat:
Mcommon/controller/lookoutPlan.test.ts | 13+++++++++++--
Mcommon/controller/lookoutPlan.ts | 42+++++++++++++++++++++++++++++++++++++-----
Mcommon/lib/lookout.test.ts | 14+++++++++++++-
Mcommon/lib/lookout.ts | 12+++++++++++-
4 files changed, 72 insertions(+), 9 deletions(-)

diff --git a/common/controller/lookoutPlan.test.ts b/common/controller/lookoutPlan.test.ts @@ -69,6 +69,7 @@ async function writeVideo(channelsDir: string, v: VideoFixture): Promise<void> { formats: [{ format_id: "1", url: "https://example.invalid/f" }], duration: v.duration, live_status: v.liveStatus ?? "not_live", + webpage_url: `https://example.invalid/watch/${v.dir}`, upload_date: v.uploadDate, }; if (v.timestamp !== undefined) meta.timestamp = v.timestamp; @@ -255,6 +256,9 @@ test("the stream is listed once, on its local date, with its twin and its cut-do ["NoCues00001", "no-transcript"], ], ); + const bare = plan.skipped.find((k) => k.video === "NoCues00001")!; + assert.equal(bare.title, "Not Transcribed", "named from its metadata"); + assert.equal(bare.url, "https://example.invalid/watch/NoCues00001"); assert.ok(!keys.includes("alpha-rumble/v1latenight"), "aired 2 Nov in New York"); assert.ok(s.chunks > 1, "a two-hour stream is several chunks"); assert.equal(plan.estimate.readCalls, plan.read.reduce((n, r) => n + r.chunks, 0)); @@ -343,7 +347,7 @@ test("metaDatesOf reads the scalars wherever yt-dlp put them", () => { // nested timestamp earlier is not taken, nor a storyboard fragment's duration. const yt = '{"id": "a", "formats": [{"format_id": "sb0", "fragments": [{"url": "u", "duration": 496.98}, {"url": "u", "duration": 250.02}]}], ' + - '"comments": [{"timestamp": 1600000000}], "duration": 747, "live_status": "not_live", ' + + '"comments": [{"timestamp": 1600000000}], "duration": 747, "live_status": "not_live", "webpage_url": "https://example.invalid/a", ' + '"upload_date": "20261106", "timestamp": 1793993883, "is_live": false}'; assert.deepEqual(metaDatesOf(yt), { releaseTimestamp: null, @@ -351,10 +355,12 @@ test("metaDatesOf reads the scalars wherever yt-dlp put them", () => { uploadDate: "20261106", liveStatus: "not_live", duration: 747, + title: null, + webpageUrl: "https://example.invalid/a", }); // Rumble's order: timestamp early, release_timestamp later, upload_date last. const rumble = - '{"id": "v", "timestamp": 1793754765, "duration": 12970, "live_status": "was_live", ' + + '{"id": "v", "title": "She said \\"no\\" \\u2014 caf\u00c3\u00a9", "timestamp": 1793754765, "duration": 12970, "live_status": "was_live", ' + '"release_timestamp": 1793755253, "upload_date": "20261104"}'; assert.deepEqual(metaDatesOf(rumble), { releaseTimestamp: 1793755253, @@ -362,5 +368,8 @@ test("metaDatesOf reads the scalars wherever yt-dlp put them", () => { uploadDate: "20261104", liveStatus: "was_live", duration: 12970, + // Escapes decoded, and the file's UTF-8 bytes (a string argument stands for them, one char a byte). + title: 'She said "no" — café', + webpageUrl: null, }); }); diff --git a/common/controller/lookoutPlan.ts b/common/controller/lookoutPlan.ts @@ -135,8 +135,34 @@ export type MetaDates = { uploadDate: string | null; liveStatus: string | null; duration: number | null; + /** The record's title and page URL — what a video with no transcript is listed by. */ + title: string | null; + webpageUrl: string | null; }; +// The JSON string after the first `"<key>":` in `buf`, decoded (escapes and +// UTF-8); null when it is absent, not a string, or longer than `max` bytes. +function stringOf(buf: Buffer, key: string, max = 4096): string | null { + const at = buf.indexOf(`"${key}":`, 0, "latin1"); + if (at < 0) return null; + let i = at + key.length + 3; + while (i < buf.length && (buf[i] === 0x20 || buf[i] === 0x0a || buf[i] === 0x0d || buf[i] === 0x09)) i++; + if (buf[i] !== 0x22) return null; + const end = Math.min(buf.length, i + 1 + max); + for (let j = i + 1; j < end; j++) { + if (buf[j] === 0x5c) j++; + else if (buf[j] === 0x22) { + try { + const v: unknown = JSON.parse(buf.toString("utf8", i, j + 1)); + return typeof v === "string" && v.trim() ? v : null; + } catch { + return null; + } + } + } + return null; +} + // The value after `"<key>":` at byte `at` of `buf` (whitespace skipped): a // number's digits, or a string's contents — never more than 64 bytes. function valueAt(buf: Buffer, at: number, key: string): string | null { @@ -163,7 +189,8 @@ function last(buf: Buffer, key: string, before = buf.length): { at: number; valu /** * The dating fields of a metadata.info.json, found by byte search — a YouTube * record is megabytes of formats and caption URLs, and only these five scalars - * are wanted, so the file is never decoded or parsed. `release_timestamp` is + * (and the title and page URL, two short strings) are wanted, so the file is + * never decoded whole or parsed. `release_timestamp` is * taken wherever it is (no nested object carries one); `duration` is the last * before `upload_date` (formats' fragments carry their own); `timestamp` is the one * right after the last `upload_date` (yt-dlp's top-level order) when it is @@ -193,6 +220,10 @@ export function metaDatesOf(input: Buffer | string): MetaDates { uploadDate, liveStatus: live && /^[a-z_]+$/.test(live) ? live : null, duration: num(duration ?? undefined), + // yt-dlp writes `id` then `title` first, before any nested object; the + // page URL has no nested namesake (`webpage_url_basename` is another key). + title: stringOf(buf, "title"), + webpageUrl: stringOf(buf, "webpage_url"), }; } @@ -332,13 +363,14 @@ export async function planLookout( channel: c.channel, video: c.video, id: c.video, - title: "", + // From the metadata: all a video with no transcript has to be named by. + title: c.meta?.title ?? "", platform: "", airDate: c.air.date, airAt: c.air.at, dateSource: c.air.source, duration: c.headDuration ?? c.meta?.duration ?? null, - url: null, + url: c.meta?.webpageUrl ?? null, ...over, }); @@ -376,10 +408,10 @@ export async function planLookout( const duration = (typeof doc.duration === "number" && doc.duration > 0 ? doc.duration : null) ?? c.meta?.duration ?? lastEnd; const video = brief(c, { id: typeof doc.id === "string" ? doc.id : c.video, - title: typeof doc.title === "string" ? doc.title : "", + title: typeof doc.title === "string" && doc.title ? doc.title : (c.meta?.title ?? ""), platform: typeof doc.platform === "string" ? doc.platform : "", duration, - url: typeof doc.webpageUrl === "string" && doc.webpageUrl ? doc.webpageUrl : null, + url: typeof doc.webpageUrl === "string" && doc.webpageUrl ? doc.webpageUrl : (c.meta?.webpageUrl ?? null), }); if (video.platform === "local" || LOCAL_RECORDING_ID_RE.test(video.id)) { other++; diff --git a/common/lib/lookout.test.ts b/common/lib/lookout.test.ts @@ -77,7 +77,7 @@ test("a twin upload with the same title and runtime is folded, the first on the const ws = text(1, 2000); const groups = foldRecordings([ vid("b/yt", { words: ws, title: "Big News!", duration: 824, airAt: "2026-11-04T15:00:00.000Z" }), - vid("a/rumble", { words: ws.map((w, i) => (i % 3 === 0 ? "zz" : w)), title: "BIG NEWS", platform: "rumble", duration: 825, airAt: "2026-11-04T14:00:00.000Z" }), + vid("a/rumble", { words: ws.map((w, i) => (i % 12 === 0 ? "zz" : w)), title: "BIG NEWS", platform: "rumble", duration: 825, airAt: "2026-11-04T14:00:00.000Z" }), ]); assert.equal(groups.length, 1); assert.equal(groups[0]!.primary, "a/rumble"); @@ -99,6 +99,18 @@ test("a re-titled mirror is caught by its text; a same-titled different video is vid("a/ep2", { words: text(4, 2000), title: "Daily Show", duration: 1000 }), ]); assert.equal(series.length, 2); + // The same title and the same runtime, unrelated text: two episodes, both read. + const episodes = foldRecordings([ + vid("a/mon", { words: text(5, 2000), title: "Daily Show", duration: 900 }), + vid("a/tue", { words: text(6, 2000), title: "Daily Show", duration: 905 }), + ]); + assert.equal(episodes.length, 2); + // ...unless one has no text to compare: then the title and runtime decide. + const silent = foldRecordings([ + vid("a/mon", { words: text(5, 2000), title: "Daily Show", duration: 900 }), + vid("b/copy", { words: [], title: "Daily Show", duration: 905 }), + ]); + assert.equal(silent.length, 1); // Near-identical text but runtimes far apart is not a twin (it may be a cut-down; see below). const apart = foldRecordings([ vid("a/x", { words: ws, duration: 600 }), diff --git a/common/lib/lookout.ts b/common/lib/lookout.ts @@ -17,6 +17,9 @@ // match or whose transcripts are near-duplicates (5-word shingle Jaccard ≥ // 0.35, the duplicate detector's own threshold: two ASR engines over the // same audio land at 0.35–0.60). A re-titled mirror is caught by the text. +// A title match alone is not enough when both have text: two episodes of +// a show with one title and one length share none, so it also needs a +// Jaccard of 0.1. // - a CUT-DOWN of a stream — a shorter upload whose text is an excerpt of a // long recording in the window — is a video under 30 minutes at least 40 % // of whose shingles are in one stream (the pilot's measured rule). It is @@ -154,6 +157,8 @@ export function inWindow(date: string, w: Pick<LookoutWindow, "from" | "to">): b export const LOOKOUT_SHINGLE_SIZE = DEFAULT_SHINGLE_SIZE; /** Duplicate uploads: transcripts at least this similar (Jaccard) are one recording. */ export const TWIN_TEXT_THRESHOLD = DEFAULT_NEAR_THRESHOLD; +/** Duplicate uploads with the same title: their transcripts still share at least this much (Jaccard), when both have text. */ +export const TWIN_TITLE_TEXT_FLOOR = 0.1; /** Duplicate uploads: runtimes within this fraction of the longer. */ export const TWIN_DURATION_RATIO = DEFAULT_TITLE_DURATION_RATIO; /** A recording this long or longer is a stream other uploads may be cut from. */ @@ -235,7 +240,12 @@ export function foldRecordings(videos: readonly DedupeVideo[]): RecordingGroup[] const ta = titleKeys.get(a.key)!; const titleMatch = ta !== "" && ta === titleKeys.get(b.key); const score = jaccard(a.shingles as Set<string>, b.shingles as Set<string>); - if (!titleMatch && score < TWIN_TEXT_THRESHOLD) continue; + // A title is not a recording: a daily show keeps one title and much the + // same runtime. With both transcripts in hand a title match still needs + // some shared text; with one empty there is only the title to go on. + const titleTwin = + titleMatch && (a.shingles.size === 0 || b.shingles.size === 0 || score >= TWIN_TITLE_TEXT_FLOOR); + if (!titleTwin && score < TWIN_TEXT_THRESHOLD) continue; uf.union(a.key, b.key); twinEdge.set(`${a.key}\n${b.key}`, { score, titleMatch }); twinEdge.set(`${b.key}\n${a.key}`, { score, titleMatch });