Archilyzer · Source

archilyzer

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

commit 6df0cbd86f042621576b6cf825c625c8e34e25b0
parent 5c79fc2d04cf5a9a7bdac1c8440a0e815649865d
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Sat, 10 Oct 2026 12:59:22 -0400

Merge r23/fixes (release 23 F1b: the Twitch join at compose's cited record, convert, umtool's cue paths and availability) into r23/integration

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

Diffstat:
Mcommon/bin/reports-convert.test.ts | 17+++++++++++++++++
Mcommon/lib/report/convert-server.ts | 5++++-
Mcommon/lib/videoDir-server.mjs | 60++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mcommon/lib/videoDirId.test.ts | 11++++++++++-
Mcommon/publish/composeReports.ts | 5++++-
Acommon/publish/composeReportsTwitch.test.ts | 57+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mplans/release-20.md | 24++++++++++++++++++++++++
Mumtool/lib/projects/report.mjs | 8+++++---
Mumtool/lib/report/raw-cache.test.mjs | 36+++++++++++++++++++++++++++++++++++-
Mumtool/report-to-video/check-availability.mjs | 6++++--
Aumtool/report-to-video/check-availability.test.mjs | 33+++++++++++++++++++++++++++++++++
11 files changed, 253 insertions(+), 9 deletions(-)

diff --git a/common/bin/reports-convert.test.ts b/common/bin/reports-convert.test.ts @@ -70,6 +70,23 @@ test("diskCuesOf reads a record's cues sorted; a missing record or an unsafe id } }); +test("diskCuesOf reads a Twitch v<n> record's cues from data/<n>/ (release 23 F1b)", async () => { + const t = tree(); + try { + const n = "2700000001"; + const dir = path.join(t.channels, "example-twitch", "data", n); + mkdirSync(dir, { recursive: true }); + writeFileSync(path.join(t.channels, "example-twitch", "config.json"), JSON.stringify({ handling: "transcribe", url: "https://www.twitch.tv/example" })); + writeFileSync(path.join(dir, "transcript.cues.json"), JSON.stringify({ id: `v${n}`, cues: [{ start: 1, end: 2, text: "hello" }] })); + const cuesOf = diskCuesOf(t.channels); + assert.deepEqual((await cuesOf("example-twitch", `v${n}`))?.map((c) => c.text), ["hello"]); + // The directory's own id reads the same file; nothing is rewritten. + assert.deepEqual((await cuesOf("example-twitch", n))?.map((c) => c.text), ["hello"]); + } finally { + t.done(); + } +}); + test("diskCuesOf: a channel whose text is not readable is a warning, not a read", async () => { const t = tree(); try { diff --git a/common/lib/report/convert-server.ts b/common/lib/report/convert-server.ts @@ -12,6 +12,7 @@ import { readdir, readFile } from "node:fs/promises"; import path from "node:path"; import { assertChannelTextReadable } from "../channelMedia"; +import { resolveVideoDir } from "../videoDir-server.mjs"; import { isSafeChannelSegment, isSafeIdSegment } from "../citations/moments"; import { readAllPosts, readSeenPostIds } from "../posts-server"; import type { Post } from "../posts"; @@ -52,7 +53,9 @@ export function diskCuesOf(channelsDir: string, warnings: string[] = []): CuesOf if (!(await readable(channel))) return null; let doc: unknown; try { - doc = JSON.parse(await readFile(path.join(channelsDir, channel, "data", id, "transcript.cues.json"), "utf8")); + // The record's directory: a Twitch v<n> is data/<n>/ (release 23 F1b). + const dir = await resolveVideoDir(channelsDir, channel, id); + doc = JSON.parse(await readFile(path.join(dir, "transcript.cues.json"), "utf8")); } catch { return null; } diff --git a/common/lib/videoDir-server.mjs b/common/lib/videoDir-server.mjs @@ -3,6 +3,7 @@ // (b)). Plain JS for umtool's bare-node scripts; server-only (node:fs). It // never computes a path from the cwd: every root arrives as an argument. +import { readFileSync, statSync } from "node:fs"; import { readFile, stat } from "node:fs/promises"; import path from "node:path"; import { channelConfigPlatform, pickVideoDirId, twitchVodDirId } from "./videoDirId.mjs"; @@ -72,3 +73,62 @@ export async function resolveVideoDir(channelsDir, slug, recordId, opts = {}) { const dirId = await resolveVideoDirId(channelsDir, slug, recordId, opts); return path.join(/* turbopackIgnore: true */ channelsDir, slug, "data", dirId); } + +// ---- the same, synchronously ------------------------------------------------ +// For a caller that is synchronous and shared too widely to turn async +// (umtool's cuePathFor). The rule is pickVideoDirId's; only a `v<digits>` id +// costs a read. + +/** @param {string} p */ +function isDirSync(p) { + try { + return statSync(p).isDirectory(); + } catch { + return false; + } +} + +/** + * `resolveVideoDirId`, synchronously. + * @param {string} channelsDir + * @param {string} slug + * @param {string} recordId + * @param {{ platform?: string | null }} [opts] + * @returns {string} + */ +export function resolveVideoDirIdSync(channelsDir, slug, recordId, opts = {}) { + if (twitchVodDirId(recordId) === null) return recordId; + let platform = opts.platform; + if (platform === undefined) { + try { + platform = channelConfigPlatform( + JSON.parse(readFileSync(path.join(/* turbopackIgnore: true */ channelsDir, slug, "config.json"), "utf8")), + ); + } catch { + platform = null; + } + } + if (platform !== "twitch") return recordId; + const dataDir = path.join(/* turbopackIgnore: true */ channelsDir, slug, "data"); + return pickVideoDirId(recordId, { + platform, + exists: (id) => isDirSync(path.join(/* turbopackIgnore: true */ dataDir, id)), + }); +} + +/** + * `resolveVideoDir`, synchronously. + * @param {string} channelsDir + * @param {string} slug + * @param {string} recordId + * @param {{ platform?: string | null }} [opts] + * @returns {string} + */ +export function resolveVideoDirSync(channelsDir, slug, recordId, opts = {}) { + return path.join( + /* turbopackIgnore: true */ channelsDir, + slug, + "data", + resolveVideoDirIdSync(channelsDir, slug, recordId, opts), + ); +} diff --git a/common/lib/videoDirId.test.ts b/common/lib/videoDirId.test.ts @@ -17,7 +17,7 @@ import { twitchVodDirId, twitchVodRecordId, } from "./videoId"; -import { resolveVideoDir, resolveVideoDirId } from "./videoDir-server.mjs"; +import { resolveVideoDir, resolveVideoDirId, resolveVideoDirIdSync, resolveVideoDirSync } from "./videoDir-server.mjs"; const N = "1234567890"; const META = { id: `v${N}`, webpage_url: `https://www.twitch.tv/videos/${N}` }; @@ -93,3 +93,12 @@ test("resolveVideoDirId: other platforms and other ids pass through", async () = // No config at all: never guessed. assert.equal(await resolveVideoDirId(path.join(ROOT, "none"), "nobody", `v${N}`), `v${N}`); }); + +test("the synchronous resolver gives the same answers (release 23 F1b)", () => { + const tw = channel("tw-sync", { handling: "transcribe", url: "https://www.twitch.tv/example" }, [N]); + assert.equal(resolveVideoDirIdSync(tw, "tw-sync", `v${N}`), N); + assert.equal(resolveVideoDirSync(tw, "tw-sync", `v${N}`), path.join(tw, "tw-sync", "data", N)); + assert.equal(resolveVideoDirIdSync(tw, "tw-sync", "dQw4w9WgXcQ"), "dQw4w9WgXcQ"); + const yt = channel("yt-sync", { handling: "youtube", platform: "youtube" }, [N]); + assert.equal(resolveVideoDirIdSync(yt, "yt-sync", `v${N}`), `v${N}`); +}); diff --git a/common/publish/composeReports.ts b/common/publish/composeReports.ts @@ -64,6 +64,7 @@ import { copyFile, mkdir, readdir, readFile, rm, stat, writeFile } from "node:fs import path from "node:path"; import { publishFileSizeProblem } from "../lib/builtExport"; import type { Paths } from "../lib/paths"; +import { resolveVideoDir } from "../lib/videoDir-server.mjs"; import { type Site } from "../lib/site"; import { isCitedOnlyChannel, @@ -276,7 +277,9 @@ export async function readCitedRecord( id: string, channelName?: string, ): Promise<CitedRecord | null> { - const dir = path.join(channelsDir, slug, "data", id); + // The record's directory: a Twitch record's v<n> is data/<n>/ (release 23 + // F1b). The record keeps the id it is cited by. + const dir = await resolveVideoDir(channelsDir, slug, id); const entries = await readdir(dir).catch(() => [] as string[]); if (entries.length === 0) return null; let summary: CitedRecord["summary"] | null = null; diff --git a/common/publish/composeReportsTwitch.test.ts b/common/publish/composeReportsTwitch.test.ts @@ -0,0 +1,57 @@ +// The Twitch join, option (b), in compose (release 23 F1b): a report cites a +// Twitch record by its `v<n>`, and readCitedRecord reads it from `data/<n>/` +// — the record keeps the id it is cited by. Synthetic ids. +// +// Run with: node_modules/.bin/tsx --test publish/composeReportsTwitch.test.ts + +import { test } from "node:test"; +import assert from "node:assert/strict"; +import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs"; +import { tmpdir } from "node:os"; +import path from "node:path"; +import { readCitedRecord } from "./composeReports"; + +const N = "2700000001"; +const VTT = + "WEBVTT\nKind: captions\nLanguage: en\n\n" + + "00:00:00.000 --> 00:00:05.000 align:start position:0%\n" + + "First<00:00:01.000><c> caption</c><00:00:02.000><c> line.</c>\n\n" + + "00:01:00.000 --> 00:01:50.000 align:start position:0%\n" + + "Second<00:01:10.000><c> caption</c><00:01:20.000><c> line.</c>\n"; + +function channel(root: string, slug: string, config: object): void { + const dir = path.join(root, slug, "data", N); + mkdirSync(dir, { recursive: true }); + writeFileSync(path.join(root, slug, "config.json"), JSON.stringify(config)); + writeFileSync( + path.join(dir, "metadata.info.json"), + JSON.stringify({ + id: `v${N}`, + title: "Example stream", + upload_date: "20260105", + duration: 120, + webpage_url: `https://www.twitch.tv/videos/${N}`, + extractor_key: "TwitchVod", + }), + ); + writeFileSync(path.join(dir, "transcript.en.vtt"), VTT); +} + +test("readCitedRecord reads a Twitch v<n> citation from data/<n>/, and the record keeps its id", async () => { + const root = mkdtempSync(path.join(tmpdir(), "compose-twitch-")); + try { + channel(root, "example-twitch", { handling: "transcribe", url: "https://www.twitch.tv/example" }); + const rec = await readCitedRecord(root, "example-twitch", `v${N}`); + assert.ok(rec, "the record is found"); + assert.equal(rec.summary.id, `v${N}`); + assert.equal(rec.summary.slug, `example-twitch/v${N}`); + assert.equal(rec.summary.platform, "twitch"); + assert.equal(rec.cues.length, 2); + + // A channel of another platform: a v-id is never mapped. + channel(root, "example-yt", { handling: "youtube", platform: "youtube" }); + assert.equal(await readCitedRecord(root, "example-yt", `v${N}`), null); + } finally { + rmSync(root, { recursive: true, force: true }); + } +}); diff --git a/plans/release-20.md b/plans/release-20.md @@ -185,6 +185,30 @@ pass, 11 fail — the same 11 fail on `d3296bab` without this change (`attachMed 2 — environment — and `fetchPosts.test.ts` 1, a drain timing that passes alone). Editor unit 239/239; `test:scripts` 759 pass, 3 skipped, 0 fail (the cwd-join trace guard among them). +#### F1b (release 23) — the four remaining readers + +F1's found-and-left list, closed after both lanes merged into `r23/integration` (`88c767ec`; `r23/fixes` +fast-forwarded to it). Each joined a record's id to `data/<id>/` directly; each now resolves the record's +directory, and every record keeps the id it is cited by: +- `publish/composeReports.ts` `readCitedRecord` — compose's read of a cited record (Lane 2's file; one call); +- `lib/report/convert-server.ts` `diskCuesOf` — the report converters' cue read; +- umtool `lib/projects/report.mjs` `cuePathFor` and `clipWindowDirs`' cue-duration probe (`cuePathFor` is + synchronous and has seven callers, so `lib/videoDir-server.mjs` gains `resolveVideoDirIdSync` / + `resolveVideoDirSync`, the same rule); +- umtool `report-to-video/check-availability.mjs` `cueMeta` (now exported, for its test). + +| Commit | What | +|---|---| +| `70ed4ae5` | `common:` F1b — the four readers, the synchronous resolver, a test per reader | + +**Gates.** tsc clean. New tests, each a Twitch `<n>` directory read through a `v<n>` record, ids asserted unchanged: +`publish/composeReportsTwitch.test.ts` 1 (and a non-Twitch channel's `v`-id is not mapped), `bin/reports-convert.test.ts` ++1, umtool `lib/report/raw-cache.test.mjs` +1 (`cuePathFor`, and `clipWindowDirs`' window and saved source with its +cue duration), umtool `report-to-video/check-availability.test.mjs` 1, `lib/videoDirId.test.ts` +1 (the synchronous +resolver). The compose, convert and umtool cases fail with the joins taken out (2 + 1). Common suite with +`TMPDIR` on `/home`: **3,702/3,702** — the 10 `attachMedia`/`preparePlayable` reds of F1 and F4 were `/tmp`'s 1.7 GB +tmpfs against attachMedia's 2 GiB free-space margin, not code. `test:scripts` 771 pass, 3 skipped. + ### D3's found-and-left, as shipped (release 23 F4) — the stats cache sees the caption-track pass Release 23 Lane 1, on `r23/fixes`. D3 left it: the caption-track pass re-reads a record's cues and writes the same diff --git a/umtool/lib/projects/report.mjs b/umtool/lib/projects/report.mjs @@ -12,9 +12,9 @@ import { SHADOW_CHANNELS as SOURCES_SHADOW_CHANNELS, channelsDirFor as sourcesChannelsDirFor, corpusWindowsOf, - videoDirOf, } from "umtool-report-to-video/sources"; import { rawCacheOf } from "../report/raw-cache.mjs"; +import { resolveVideoDirSync } from "yt-dlp-transcript-common/lib/videoDir-server.mjs"; import { deliverablesState, finishCommand, outDirState, leftoversOf } from "../report/storage.mjs"; import { CHANNELS_DIR, inside } from "../paths.mjs"; import { channelName, cleanTitle } from "umtool-report-to-video/attribution"; @@ -350,7 +350,8 @@ export const clipWindowDirs = async (m, channelsDir) => { const key = `${chan}/${e.video}`; if (seen.has(key)) continue; seen.add(key); - const cueFile = path.join(videoDirOf(root, chan, e.video), "transcript.cues.json"); + // The record's directory: a Twitch v<n> is data/<n>/ (release 23 F1b). + const cueFile = path.join(resolveVideoDirSync(root, chan, e.video), "transcript.cues.json"); const probe = async () => { const duration = Number((await readCues(cueFile))?.duration); return Number.isFinite(duration) && duration > 0 ? { duration } : null; @@ -364,7 +365,8 @@ export const clipWindowDirs = async (m, channelsDir) => { export const cuePathFor = (m, e, channelsDir) => { const chan = channelFor(m, e); if (!chan) return null; - return path.join(channelsDir ?? GLOBAL_CHANNELS_DIR(), chan, "data", e.video, "transcript.cues.json"); + // The record's directory: a Twitch v<n> is data/<n>/ (release 23 F1b). + return path.join(resolveVideoDirSync(channelsDir ?? GLOBAL_CHANNELS_DIR(), chan, e.video), "transcript.cues.json"); }; // --------------------------------------------------------------------------- diff --git a/umtool/lib/report/raw-cache.test.mjs b/umtool/lib/report/raw-cache.test.mjs @@ -10,7 +10,7 @@ import os from "node:os"; import { mkdir, mkdtemp, rm, symlink, writeFile } from "node:fs/promises"; import { rawCacheOf } from "./raw-cache.mjs"; -import { clipWindowDirs } from "../projects/report.mjs"; +import { clipWindowDirs, cuePathFor } from "../projects/report.mjs"; import { resolveLocalSource } from "umtool-report-to-video/sources"; const SLUG = "demo-channel"; @@ -99,3 +99,37 @@ test("clipWindowDirs: corpus windows and a saved source, and the render resolves await rm(f.root, { recursive: true, force: true }); } }); + +test("a Twitch v<n> clip reads its cue file and windows from data/<n>/, and keeps its id (release 23 F1b)", async () => { + const f = await fixture(); + try { + const n = "2700000001"; + const slug = "example-twitch"; + await mkdir(path.join(f.channelsDir, slug), { recursive: true }); + await writeFile(path.join(f.channelsDir, slug, "config.json"), JSON.stringify({ handling: "transcribe", url: "https://www.twitch.tv/example" })); + const dir = path.join(f.channelsDir, slug, "data", n); + await mkdir(path.join(dir, "clips"), { recursive: true }); + await touch(path.join(dir, "clips", "100.00-160.00.mp4")); + const store = path.join(f.root, "store", slug, n); + await mkdir(store, { recursive: true }); + await touch(path.join(store, "source-media.mp4")); + await writeFile(path.join(dir, "saved-video.json"), JSON.stringify({ dir: store, file: "source-media.mp4", bytes: 16 })); + await writeFile(path.join(dir, "transcript.cues.json"), JSON.stringify({ id: `v${n}`, duration: 1800, cues: [] })); + + const m = { + provenance: { channelSlug: slug }, + timeline: [ + { id: "c1", type: "clip", video: `v${n}`, start: 110, end: 120 }, + { id: "c2", type: "clip", video: `v${n}`, start: 1000, end: 1010 }, + ], + }; + assert.equal(cuePathFor(m, m.timeline[0], f.channelsDir), path.join(dir, "transcript.cues.json")); + const extra = await clipWindowDirs(m, f.channelsDir); + assert.deepEqual( + extra.map((e) => [e.video, e.windows.map((w) => [w.kind, w.name, w.from, w.to])]), + [[`v${n}`, [["corpus-window", "100.00-160.00.mp4", 100, 160], ["saved-video", "source-media.mp4", 0, 1800]]]], + ); + } finally { + await rm(f.root, { recursive: true, force: true }); + } +}); diff --git a/umtool/report-to-video/check-availability.mjs b/umtool/report-to-video/check-availability.mjs @@ -26,6 +26,7 @@ import { readFile, writeFile } from "node:fs/promises"; import path from "node:path"; import { DEFAULT_CHANNELS_DIR } from "./cues.mjs"; +import { resolveVideoDir } from "yt-dlp-transcript-common/lib/videoDir-server.mjs"; import { ensureWriteDir } from "../lib/report/storage.mjs"; // The per-platform yt-dlp args (Rumble's `--impersonate chrome`): the ONE table, // in common, plain JS so bare `node` can load it. @@ -65,8 +66,9 @@ export function simulateArgs(url) { ]; } -async function cueMeta(videoId, channelSlug) { - const p = path.join(CHANNELS_DIR, channelSlug, "data", videoId, "transcript.cues.json"); +export async function cueMeta(videoId, channelSlug) { + // The record's directory: a Twitch v<n> is data/<n>/ (release 23 F1b). + const p = path.join(await resolveVideoDir(CHANNELS_DIR, channelSlug, videoId), "transcript.cues.json"); const d = JSON.parse(await readFile(p, "utf8")); return { title: d.title, webpageUrl: d.webpageUrl, duration: d.duration }; } diff --git a/umtool/report-to-video/check-availability.test.mjs b/umtool/report-to-video/check-availability.test.mjs @@ -0,0 +1,33 @@ +// check-availability's local cue read (release 23 F1b): a Twitch record's +// `v<n>` reads its transcript.cues.json from `data/<n>/`. CHANNELS_DIR is read +// when the module loads, so it is set before the import. +// +// Run with: pnpm test:scripts +import assert from "node:assert/strict"; +import test from "node:test"; +import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises"; +import os from "node:os"; +import path from "node:path"; + +const ROOT = await mkdtemp(path.join(os.tmpdir(), "check-availability-")); +process.env.CHANNELS_DIR = ROOT; +const { cueMeta } = await import("./check-availability.mjs"); +test.after(() => rm(ROOT, { recursive: true, force: true })); + +test("cueMeta reads a Twitch v<n> record from data/<n>/", async () => { + const n = "2700000001"; + await mkdir(path.join(ROOT, "example-twitch", "data", n), { recursive: true }); + await writeFile(path.join(ROOT, "example-twitch", "config.json"), JSON.stringify({ handling: "transcribe", url: "https://www.twitch.tv/example" })); + await writeFile( + path.join(ROOT, "example-twitch", "data", n, "transcript.cues.json"), + JSON.stringify({ id: `v${n}`, title: "Example stream", webpageUrl: `https://www.twitch.tv/videos/${n}`, duration: 120, cues: [] }), + ); + assert.deepEqual(await cueMeta(`v${n}`, "example-twitch"), { + title: "Example stream", + webpageUrl: `https://www.twitch.tv/videos/${n}`, + duration: 120, + }); + // Another platform's v-id is not mapped: no file. + await writeFile(path.join(ROOT, "example-twitch", "config.json"), JSON.stringify({ handling: "youtube", platform: "youtube" })); + await assert.rejects(() => cueMeta(`v${n}`, "example-twitch"), /ENOENT/); +});