Archilyzer · Source

archilyzer

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

commit 2af8faaf85b21cd7b17f06408fa3add4aaabfd8a
parent 15355a042b774ec116542f9dfc02f2bbc2d16ba7
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Wed, 11 Nov 2026 06:18:32 -0500

local media: an invalid local_recording is skipped and logged, never thrown

Review should-fix. platformFromMetadata threw on a malformed `local_recording`,
and it sits under summarize(), which a dozen readers call (stats, the mirror
scan, the editor channel page, tags, composeReports, normalize): one bad file
would have broken each of them. It now answers "local" for any record carrying
the marker (relabelling it as a provider would build a YouTube URL from a
`local-...` id), warns once per id, and the index skips such a record with
"Skipping <slug>/<dir>: invalid local_recording metadata (...)", reading the
marker from the metadata itself since a fresh normalized summary lacks it.
localRecordingProblem() is the non-throwing form of the validator.

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

Diffstat:
Mcommon/controller/buildIndex.ts | 11+++++++++++
Mcommon/controller/buildIndexLocalRecording.test.ts | 13+++++++++++++
Mcommon/lib/localRecordingIntegration.test.ts | 9+++++++--
Mcommon/lib/localRecordingMetadata.ts | 12++++++++++++
Mcommon/lib/transcripts-server.ts | 20++++++++++++++++++--
5 files changed, 61 insertions(+), 4 deletions(-)

diff --git a/common/controller/buildIndex.ts b/common/controller/buildIndex.ts @@ -175,6 +175,7 @@ import { import { tagsForSite } from "../lib/curatedTags"; import { compileRecordedDateRule, deriveRecordedDate } from "../lib/recordedDate"; import { loadTranscribeOutcome } from "../lib/transcribeOutcome-server"; +import { localRecordingProblem } from "../lib/localRecordingMetadata"; // v10: multi-site build. Shared per-channel transcript/subs pages are written // once; per-site summaries + subs manifests are filtered selections. Bumped to @@ -1106,6 +1107,16 @@ export async function buildIndex({ log(`Skipping ${s.channelSlug}/${s.videoDir}: no upload_date`); return; } + // A local recording enters only when its marker validates — read + // from the metadata itself, since a fresh normalized summary does not + // carry it (lib/transcripts-server.ts, platformFromMetadata). + if (summary.platform === "local") { + const problem = localRecordingProblem(JSON.parse(await readFile(s.metaPath, "utf8"))); + if (problem) { + log(`Skipping ${s.channelSlug}/${s.videoDir}: invalid local_recording metadata (${problem})`); + return; + } + } // The channel's recorded-date rule, applied to the summary as it // stands (a normalized one included): set when it reads a date, and // never carried over from an older derivation. diff --git a/common/controller/buildIndexLocalRecording.test.ts b/common/controller/buildIndexLocalRecording.test.ts @@ -104,3 +104,16 @@ test("invalid local metadata cannot create a corpus record", async () => { } assert.equal(readdirSync(dataDirectory).includes(id),false); }); + +test("a malformed local_recording written past the importer is skipped with a log line, not thrown", async () => { + const id = "local-" + "d".repeat(32); + const dir = path.join(dataDirectory, id); + writeJson(path.join(dir, "metadata.info.json"), {...metadata(id), local_recording: {version: 99}}); + writeFileSync(path.join(dir, "transcript.en.vtt"), transcript); + const logs: string[] = []; + await buildIndex({paths, onLog: line => logs.push(line)}); + assert.ok(!summaries().some(s => s.id === id)); + assert.ok(logs.some(line => line.includes(`${id}: invalid local_recording metadata`)), logs.join("\n")); + assert.ok(!logs.some(line => line.includes("Failed to process")), logs.join("\n")); + rmSync(dir, {recursive: true, force: true}); +}); diff --git a/common/lib/localRecordingIntegration.test.ts b/common/lib/localRecordingIntegration.test.ts @@ -1,6 +1,6 @@ import { test } from "node:test"; import assert from "node:assert/strict"; -import { prepareManualLocalRecordingMetadata, prepareLocalRecordingMetadata, requireLocalRecordingMetadata } from "./localRecordingMetadata"; +import { prepareManualLocalRecordingMetadata, prepareLocalRecordingMetadata, requireLocalRecordingMetadata, localRecordingProblem } from "./localRecordingMetadata"; import { summarize, platformFromMetadata, toDisplaySummary } from "./transcripts-server"; import { defaultWebpageUrl, PLATFORM_VALUES } from "./platform"; @@ -42,8 +42,13 @@ test("a local marker is validated, not used to hide invalid or contradictory met {local_recording: {...value.local_recording, privatePath: "/private/archive"}}, ]) { assert.throws(() => requireLocalRecordingMetadata({...value, ...change})); - assert.throws(() => platformFromMetadata({...value, ...change})); + assert.ok(localRecordingProblem({...value, ...change})); + // Never a throw, and never relabelled as a provider: the index skips it. + assert.equal(platformFromMetadata({...value, ...change}), "local"); + assert.equal(summarize("classroom", id, {...value, ...change}).webpageUrl, + "webpage_url" in change ? change.webpage_url : ""); } + assert.equal(localRecordingProblem(value), null); }); test("online metadata retains its provider and date rules even with a local-looking ID", () => { diff --git a/common/lib/localRecordingMetadata.ts b/common/lib/localRecordingMetadata.ts @@ -143,3 +143,15 @@ export function requireLocalRecordingMetadata(value: unknown): LocalRecordingMet } else if (mark.recordedDateSource !== undefined) return invalid(); return raw as LocalRecordingMetadata; } + +// The same rule as requireLocalRecordingMetadata, as a value: null when the +// metadata is a valid local recording, else why not. For the readers that +// must not throw on one bad file (platformFromMetadata, the index). +export function localRecordingProblem(value: unknown): string | null { + try { + requireLocalRecordingMetadata(value); + return null; + } catch (error) { + return (error as Error).message || "Invalid local recording metadata"; + } +} diff --git a/common/lib/transcripts-server.ts b/common/lib/transcripts-server.ts @@ -1,4 +1,4 @@ -import { requireLocalRecordingMetadata } from "./localRecordingMetadata"; +import { localRecordingProblem } from "./localRecordingMetadata"; import { readFile } from "node:fs/promises"; import path from "node:path"; import { formatDate, formatDuration } from "./format"; @@ -90,9 +90,17 @@ export function loadRawMetadataFromDir( // been — the generic extractor (a podcast episode imported by its enclosure // URL) still lands there, and changing that would relabel records already // published. +// +// A LOCAL RECORDING (lib/localRecordingMetadata.ts) carries a `local_recording` +// marker and is "local" — even when the marker does not validate: relabelling +// it as a provider would build a YouTube URL from a `local-…` id. Never a +// throw (a dozen summarize() callers would fall over on one bad file): an +// invalid marker is warned once per id here, and the index skips the record +// with a log line (controller/buildIndex.ts, localRecordingProblem). export function platformFromMetadata(meta: RawMetadata): Platform { if (meta.local_recording !== undefined) { - requireLocalRecordingMetadata(meta); + const problem = localRecordingProblem(meta); + if (problem) warnInvalidLocalRecording(meta, problem); return "local"; } const key = meta.extractor_key ?? meta.extractor ?? ""; @@ -300,3 +308,11 @@ export function toDisplaySummary( : {}), }; } + +const warnedLocalRecordings = new Set<string>(); +function warnInvalidLocalRecording(meta: RawMetadata, problem: string): void { + const key = typeof meta.id === "string" ? meta.id : JSON.stringify(meta.title ?? null); + if (warnedLocalRecordings.has(key)) return; + warnedLocalRecordings.add(key); + console.warn(`Invalid local_recording metadata for ${key}: ${problem}; the index skips it.`); +}