commit f1008fbd7f60e85494326cd1b5b86b8fdfb4c725
parent 5c79fc2d04cf5a9a7bdac1c8440a0e815649865d
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Sat, 10 Oct 2026 12:56:41 -0400
common: release 23 F1b — the Twitch join at the four remaining readers
readCitedRecord (compose), the report converters' diskCuesOf, umtool's
cuePathFor and clipWindowDirs, and check-availability's cueMeta each joined a
record's id to data/<id>/ directly, so a Twitch v<n> citation read nothing.
Each now resolves the record's directory (lib/videoDir-server.mjs, which gains
a synchronous form for cuePathFor). Records keep the ids they are cited by.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Diffstat:
10 files changed, 229 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/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/);
+});