commit 67dbaa8d701d5a5f254456667c55061607c99507
parent 97a9ac02ac6d65bc1411c56deb351e5079602246
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Wed, 11 Nov 2026 06:52:05 -0500
local media: every clip door refuses a local library channel or recording, in one sentence
Review should-fix (platform "local": clip windows / fetch-window / report
video must refuse clearly). A local media library channel (a library and no
URL) or a local recording (id local-<32 hex>, platform "local") has no online
source. lib/localMedia.ts localMediaFetchRefusal says so in one sentence
("... with no online source, so no clip can be fetched for it."), checked at:
- fetchWindowAction and fetchFullSourceAction (POST /api/media/fetch-window,
the MCP's fetch_clip): 409, before the window cache and before a
caller-supplied webpageUrl is used;
- planFetchWindows (POST /api/ops/fetch-windows, `pnpm ops fetch-windows`,
`umtool fetch`, the site's Fetch missing evidence): the item is unresolved;
- the fetch-windows job itself, as failure class "local-media" (its Retry and
find-copy skip the planner);
- missingEvidenceWindows: unfetchable "local-media", not missing;
- umtool's own clip fetch (build-video fetchClip) and its availability probe,
which would have run yt-dlp on an empty URL and called the source dead
(umtool/report-to-video/local-recording.mjs, the same sentence; the
readiness inbox files it under unfetchable).
Tests at each door. Online records of a channel that also has a library fetch
as before.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat:
14 files changed, 254 insertions(+), 3 deletions(-)
diff --git a/common/controller/fetchWindows.test.ts b/common/controller/fetchWindows.test.ts
@@ -836,3 +836,18 @@ test("one clock: a window held ON the map's clock is answered from the cache", a
assert.equal(r.cached.length, 1);
assert.equal(c.cuts.length, 0);
});
+
+// lane/local-media: the job-level backstop. A local library channel's item and
+// a local recording's are failed "local-media" before any URL is looked up.
+test("a local media library channel and a local recording fail local-media, and the run goes on", async () => {
+ const LOCAL = { ...CONFIG, url: undefined, localMedia: { sourceId: "library-1", directory: "/mnt/library" } };
+ const h = harness({ readChannelConfig: async (_p, slug) => (slug === "lib" ? LOCAL : CONFIG) });
+ const r = await go(
+ await corpus(),
+ [{ ...item("v1", "/ok"), slug: "lib" }, { ...item("v1", "/ok"), id: "local-" + "b".repeat(32) }, item("v2", "/ok")],
+ h,
+ );
+ assert.deepEqual(r.failed.map((f) => f.class), ["local-media", "local-media"]);
+ for (const f of r.failed) assert.match(f.message ?? "", /no online source, so no clip can be fetched/);
+ assert.equal(r.fetched.length, 1);
+});
diff --git a/common/controller/fetchWindows.ts b/common/controller/fetchWindows.ts
@@ -1,4 +1,5 @@
import path from "node:path";
+import { localMediaFetchRefusal } from "../lib/localMedia";
import type { Paths } from "../lib/paths";
import type { ChannelConfig } from "../lib/channelConfig";
import type { SiteSettings } from "../lib/settings";
@@ -236,7 +237,10 @@ export type FetchWindowsFailureClass =
// aside, not kept.
| "desynced"
// No page URL to fetch from.
- | "no-url";
+ | "no-url"
+ // A local media library channel or a local recording: no online source
+ // (lib/localMedia.ts localMediaFetchRefusal).
+ | "local-media";
export type FetchWindowsFailure = {
item: FetchWindowsItem;
@@ -757,6 +761,13 @@ export async function fetchWindows({
progress();
continue;
}
+ const localRefusal = localMediaFetchRefusal(item.slug, config, item.id);
+ if (localRefusal) {
+ fail(item, "local-media", localRefusal);
+ done += 1;
+ progress();
+ continue;
+ }
const unreadable = await textProblem(item.slug);
if (unreadable) {
fail(item, "unreachable", unreadable);
diff --git a/common/lib/localMedia.test.ts b/common/lib/localMedia.test.ts
@@ -29,3 +29,14 @@ test("references reject cross-platform traversal and unknown formats", () => {
for (const value of [null, [], { ...ref("a.mp4"), version: 2 }, { ...ref("a.mp4"), kind: "managed" },
{ ...ref("a.mp4"), sourceId: "../x" }]) assert.equal(coerceExternalMediaReference(value), null);
});
+
+test("localMediaFetchRefusal: a library channel with no URL, or a local recording anywhere", async () => {
+ const { localMediaFetchRefusal } = await import("./localMedia");
+ const lib = { localMedia: { sourceId: "library-1", directory: "/mnt/library" } };
+ assert.equal(localMediaFetchRefusal("lib", lib),
+ '"lib" is a local media library channel with no online source, so no clip can be fetched for it.');
+ assert.equal(localMediaFetchRefusal("lib", { ...lib, url: "https://www.youtube.com/@x" }, "dQw4w9WgXcQ"), null);
+ assert.match(localMediaFetchRefusal("lib", { url: "https://www.youtube.com/@x" }, "local-" + "c".repeat(32))!, /is a local recording/);
+ assert.equal(localMediaFetchRefusal("yt", { url: "https://www.youtube.com/@x" }, "dQw4w9WgXcQ"), null);
+ assert.equal(localMediaFetchRefusal("nourl", {}), null);
+});
diff --git a/common/lib/localMedia.ts b/common/lib/localMedia.ts
@@ -44,3 +44,24 @@ export function coerceExternalMediaReference(value: unknown): ExternalMediaRefer
|| !/\.mp4$/i.test(relativePath)) return null;
return { version: 1, kind: "external", sourceId: value.sourceId, relativePath };
}
+
+// A source-less recording's record id (lib/localRecordingDetails.ts assigns it).
+export const LOCAL_RECORDING_ID_RE = /^local-[0-9a-f]{32}$/;
+
+// A LOCAL MEDIA LIBRARY channel (a library and no online URL) or a local
+// recording in any channel has no online source: a clip window, a full-source
+// fetch or a report video's clip cannot be fetched for it. One sentence, the
+// same at every door (the editor's fetch-window and fetch-windows, the
+// fetch-windows job, the evidence planner, umtool's own fetch); null when the
+// fetch may go ahead. Private playback of the local originals is slice 4.
+export function localMediaFetchRefusal(
+ slug: string,
+ config: { localMedia?: unknown; url?: string | null } | null | undefined,
+ id?: string,
+): string | null {
+ const localChannel = !!config?.localMedia && !config.url?.trim();
+ const localRecord = typeof id === "string" && LOCAL_RECORDING_ID_RE.test(id);
+ if (!localChannel && !localRecord) return null;
+ return `${localRecord ? `"${id}" is a local recording` : `"${slug}" is a local media library channel`}` +
+ " with no online source, so no clip can be fetched for it.";
+}
diff --git a/common/publish/reportMedia.ts b/common/publish/reportMedia.ts
@@ -42,6 +42,7 @@
// a channel whose media tier is not reachable (lib/channelMedia.ts) is
// reported as unreachable, with the reason, rather than as missing.
+import { localMediaFetchRefusal } from "../lib/localMedia";
import type { Dirent } from "node:fs";
import { readdir, rm } from "node:fs/promises";
import path from "node:path";
@@ -498,7 +499,7 @@ export type EvidenceWindow = {
reason?: string;
};
-export type UnfetchableReason = "not-in-site" | "unreachable" | "gone" | "members-only" | "audio-only" | "too-long";
+export type UnfetchableReason = "not-in-site" | "unreachable" | "gone" | "members-only" | "audio-only" | "too-long" | "local-media";
export type UnfetchableEvidenceWindow = EvidenceWindow & {
why: UnfetchableReason;
@@ -568,6 +569,11 @@ export async function missingEvidenceWindows(
continue;
}
const config = await configOf(slug);
+ const localRefusal = localMediaFetchRefusal(slug, config, id);
+ if (localRefusal) {
+ unfetchable("local-media", localRefusal);
+ continue;
+ }
const audioOnly = isAudioOnlyPlatform(config?.platform);
const source = await resolveEvidenceSource({
channelsDir: paths.channelsDir,
diff --git a/common/publish/reportMediaLocal.test.ts b/common/publish/reportMediaLocal.test.ts
@@ -0,0 +1,67 @@
+// lane/local-media: a site's evidence read lists a cited local recording, and
+// every window of a local media library channel, as UNFETCHABLE ("local-media",
+// lib/localMedia.ts's sentence) — not missing, which a fetch would try to fill.
+// Synthetic ids; nothing is fetched or cut.
+//
+// Run with: pnpm --filter yt-dlp-transcript-common exec tsx --test publish/reportMediaLocal.test.ts
+
+import { after, 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";
+
+const ROOT = mkdtempSync(path.join(tmpdir(), "report-media-local-"));
+Object.assign(process.env, {
+ TRANSCRIPTS_DIR: path.join(ROOT, "transcripts"),
+ SAVED_VIDEOS_DIR: path.join(ROOT, "saved-videos"),
+ SITES_DIR: path.join(ROOT, "transcripts", "sites"),
+ SETTINGS_FILE: path.join(ROOT, "settings.json"),
+ EXPORT_PUBLIC_DIR: path.join(ROOT, "public"),
+ EXPORT_INDEX_DIR: path.join(ROOT, ".export-index"),
+ EXPORT_BUILDS_DIR: path.join(ROOT, ".export-builds"),
+ ARCHILYZER_CONFIG_DIR: path.join(ROOT, "config"),
+});
+after(() => rmSync(ROOT, { recursive: true, force: true }));
+
+const { getPaths } = await import("../lib/paths");
+const { missingEvidenceWindows } = await import("./reportMedia");
+
+const paths = getPaths();
+const SITE = "demo-site";
+const LIB = "library";
+const ONLINE = "online";
+const LOCAL_ID = "local-" + "e".repeat(32);
+const writeJson = (file: string, value: unknown) => {
+ mkdirSync(path.dirname(file), { recursive: true });
+ writeFileSync(file, JSON.stringify(value, null, 2));
+};
+writeJson(path.join(paths.channelsDir, LIB, "config.json"), {
+ handling: "youtube", name: "Library", localMedia: { sourceId: "library-1", directory: "/mnt/library" },
+});
+writeJson(path.join(paths.channelsDir, ONLINE, "config.json"), {
+ handling: "youtube", name: "Online", url: "https://www.youtube.com/@online",
+});
+for (const [ch, id] of [[LIB, LOCAL_ID], [LIB, "aaaaaaaaaaa"], [ONLINE, "bbbbbbbbbbb"]]) {
+ writeJson(path.join(paths.channelsDir, ch, "data", id, "metadata.info.json"), { id, duration: 600 });
+}
+writeJson(path.join(paths.sitesDir, SITE, "site.json"), {
+ title: "Demo", channels: [{ slug: LIB }, { slug: ONLINE }], search: false, reports: ["r1"],
+});
+writeJson(path.join(paths.sitesDir, SITE, "reports", "r1", "report.json"), {
+ format: "archilyzer-report", version: 1, id: "r1", kind: "sweep", title: "Report r1",
+ citations: {
+ c01: { kind: "video", channel: LIB, id: LOCAL_ID, start: 10, end: 12, quote: "one" },
+ c02: { kind: "video", channel: LIB, id: "aaaaaaaaaaa", start: 10, end: 12, quote: "two" },
+ c03: { kind: "video", channel: ONLINE, id: "bbbbbbbbbbb", start: 10, end: 12, quote: "three" },
+ },
+ sections: [{ id: "s1", title: "One", body: "[c01](cite:c01) [c02](cite:c02) [c03](cite:c03)" }],
+});
+
+test("a local recording and a local library channel's windows are unfetchable, the online one missing", async () => {
+ const r = await missingEvidenceWindows(paths, SITE);
+ assert.deepEqual(r.problems, []);
+ assert.deepEqual(r.unfetchable.map((w) => [w.id, w.why]).sort(), [["aaaaaaaaaaa", "local-media"], [LOCAL_ID, "local-media"]]);
+ for (const w of r.unfetchable) assert.match(w.message, /no online source, so no clip can be fetched for it\./);
+ assert.deepEqual(r.missing.map((w) => w.id), ["bbbbbbbbbbb"]);
+});
diff --git a/editor/app/channels/[slug]/videos/[id]/videoActions.ts b/editor/app/channels/[slug]/videos/[id]/videoActions.ts
@@ -1,5 +1,6 @@
"use server";
+import { localMediaFetchRefusal } from "yt-dlp-transcript-common/lib/localMedia";
import path from "node:path";
import { lstat, readdir, readFile, rm, stat } from "node:fs/promises";
import { revalidatePath } from "next/cache";
@@ -1609,6 +1610,9 @@ export async function fetchWindowAction(req: {
}
const r = await loadConfigOrError(slug);
if (!r.ok) return { ok: false, status: 404, error: r.error };
+ // Before the cache: a local library's recording has no window to hold.
+ const localRefusal = localMediaFetchRefusal(slug, r.config, req.videoId);
+ if (localRefusal) return { ok: false, status: 409, error: localRefusal };
const paths = getPaths();
// From here on the video is named by its directory: the cache, the job, the
// page revalidated (a Twitch record's v<n> is data/<n>/).
@@ -1969,6 +1973,8 @@ export async function fetchFullSourceAction(req: {
const { slug } = req;
const r = await loadConfigOrError(slug);
if (!r.ok) return { ok: false, status: 404, error: r.error };
+ const localRefusal = localMediaFetchRefusal(slug, r.config, req.videoId);
+ if (localRefusal) return { ok: false, status: 409, error: localRefusal };
const paths = getPaths();
const videoId = await recordDirIdOf(slug, req.videoId, r.config);
const videoDir = videoDirOf(slug, videoId);
diff --git a/editor/app/channels/[slug]/videos/fetchWindowLocalMedia.test.ts b/editor/app/channels/[slug]/videos/fetchWindowLocalMedia.test.ts
@@ -0,0 +1,70 @@
+import test from "node:test";
+import assert from "node:assert/strict";
+import { mkdir, mkdtemp, readdir, rm, writeFile } from "node:fs/promises";
+import os from "node:os";
+import path from "node:path";
+
+// Run with:
+// pnpm -C editor exec tsx --test "app/channels/*/videos/fetchWindowLocalMedia.test.ts"
+//
+// The editor's fetch doors refuse a local media library channel and a local
+// recording with one sentence (lib/localMedia.ts localMediaFetchRefusal), before
+// the window cache and before any job: fetch-window, full source, and the
+// fetch-windows planner. Nothing reaches the network.
+
+const ROOT = await mkdtemp(path.join(os.tmpdir(), "fetch-window-local-"));
+process.env.TRANSCRIPTS_DIR = ROOT;
+process.env.SETTINGS_FILE = path.join(ROOT, "settings.json");
+await writeFile(process.env.SETTINGS_FILE, JSON.stringify({ minFreeDiskGB: 0 }));
+const LOCAL_ID = "local-" + "a".repeat(32);
+async function channel(slug: string, config: Record<string, unknown>, ids: string[]) {
+ await mkdir(path.join(ROOT, "channels", slug), { recursive: true });
+ await writeFile(path.join(ROOT, "channels", slug, "config.json"), JSON.stringify(config));
+ for (const id of ids) {
+ await mkdir(path.join(ROOT, "channels", slug, "data", id), { recursive: true });
+ await writeFile(path.join(ROOT, "channels", slug, "data", id, "metadata.info.json"),
+ JSON.stringify({ id, title: id, webpage_url: `https://www.youtube.com/watch?v=${id}` }));
+ }
+}
+// A Local Archive channel (no URL), holding a provider-metadata record too.
+await channel("library", { name: "Library", handling: "youtube", sourceKind: "video",
+ localMedia: { sourceId: "library-1", directory: "/mnt/library" } }, [LOCAL_ID, "aaaaaaaaaaa"]);
+// An online channel with a library: its online records fetch as before, its local one does not.
+await channel("hybrid", { name: "Hybrid", handling: "youtube", url: "https://www.youtube.com/@hybrid",
+ localMedia: { sourceId: "library-1", directory: "/mnt/library" } }, [LOCAL_ID]);
+
+const { fetchWindowAction, fetchFullSourceAction } = await import("./[id]/videoActions");
+const { fetchWindowsAction } = await import("./fetchWindowsAction");
+test.after(() => rm(ROOT, { recursive: true, force: true }));
+
+const SENTENCE = /with no online source, so no clip can be fetched for it\./;
+
+test("fetch-window and full source refuse a local library channel and a local recording", async () => {
+ for (const [slug, videoId, who] of [["library", "aaaaaaaaaaa", /"library" is a local media library channel/],
+ ["library", LOCAL_ID, /is a local recording/], ["hybrid", LOCAL_ID, /is a local recording/]] as const) {
+ const w = await fetchWindowAction({ slug, videoId, from: 5, to: 15, provenance: { requestedBy: "test" } });
+ assert.equal(w.ok, false, JSON.stringify(w));
+ if (w.ok) continue;
+ assert.equal(w.status, 409);
+ assert.match(w.error, SENTENCE);
+ assert.match(w.error, who);
+ const f = await fetchFullSourceAction({ slug, videoId, provenance: { requestedBy: "test" } });
+ assert.equal(f.ok, false);
+ if (!f.ok) assert.match(f.error, SENTENCE);
+ }
+ // Nothing was made: no clips/ dir, no job.
+ assert.deepEqual(await readdir(path.join(ROOT, "channels", "library", "data", LOCAL_ID)), ["metadata.info.json"]);
+});
+
+test("the fetch-windows planner puts a local item in unresolved with the sentence", async () => {
+ const r = await fetchWindowsAction({
+ items: [{ slug: "library", id: "aaaaaaaaaaa", from: 5, to: 15 }, { slug: "hybrid", id: LOCAL_ID, from: 5, to: 15 }],
+ requestedBy: "test",
+ dryRun: true,
+ });
+ assert.ok(r.ok, JSON.stringify(r));
+ if (!r.ok) return;
+ assert.equal(r.unresolved.length, 2);
+ for (const u of r.unresolved) assert.match(u.error, SENTENCE);
+ assert.deepEqual(r.groups, []);
+});
diff --git a/editor/app/channels/[slug]/videos/fetchWindowsAction.ts b/editor/app/channels/[slug]/videos/fetchWindowsAction.ts
@@ -1,5 +1,6 @@
"use server";
+import { localMediaFetchRefusal } from "yt-dlp-transcript-common/lib/localMedia";
import path from "node:path";
import { getPaths } from "yt-dlp-transcript-common/lib/paths";
import { getSettings } from "yt-dlp-transcript-common/lib/settings";
@@ -216,6 +217,11 @@ async function planFetchWindows(
unresolved.push({ item, error: `Channel "${item.slug}" not found` });
continue;
}
+ const localRefusal = localMediaFetchRefusal(item.slug, config, item.id);
+ if (localRefusal) {
+ unresolved.push({ item, error: localRefusal });
+ continue;
+ }
// The item names a RECORD; its directory may be another id — a Twitch
// record's v<n> is data/<n>/ (release 23 F1). The item keeps its id.
const dirId = await resolveVideoDirId(paths.channelsDir, item.slug, item.id, {
diff --git a/umtool/report-to-video/build-video.mjs b/umtool/report-to-video/build-video.mjs
@@ -125,6 +125,7 @@
//
// Requires: yt-dlp, ffmpeg/ffprobe, ImageMagick with Pango.
+import { localRecordingFetchRefusal } from "./local-recording.mjs";
import { presetManifest } from "./presets.mjs";
// The basic output mode (render.mode "basic"): the footage alone, cut and spliced in basic.mjs.
import { renderBasic } from "./basic.mjs";
@@ -1365,6 +1366,8 @@ async function fetchClip(entry, meta, render, local, opts) {
// thing in a build, and the two cuts overlap almost entirely.
const name = rawWindowName(entry.video, from, to);
const dest = path.join(rawDir, name);
+ const localRefusal = localRecordingFetchRefusal(entry.video, meta.platform);
+ if (localRefusal) throw new Error(localRefusal);
if (opts.noNetwork) throw new Error(`--no-network set and no local source covers ${name}`);
if (opts.skipFetch) throw new Error(`--skip-fetch set and no cached window covers ${name}`);
diff --git a/umtool/report-to-video/check-availability.mjs b/umtool/report-to-video/check-availability.mjs
@@ -36,6 +36,7 @@
// --allow-missing Exit 0 even when a source is gone (report only)
// --max-age <days> Reuse a recorded verdict younger than this (default: 0)
+import { localRecordingFetchRefusal } from "./local-recording.mjs";
import { execFile } from "node:child_process";
import { promisify } from "node:util";
import { readFile, stat, writeFile } from "node:fs/promises";
@@ -107,7 +108,7 @@ 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 };
+ return { title: d.title, webpageUrl: d.webpageUrl, duration: d.duration, ...(d.platform ? { platform: d.platform } : {}) };
}
/** A source's verdict, as the inbox, the CLI and the build read it: true, false, or null (not checked). */
@@ -221,6 +222,12 @@ export async function checkAvailability(manifestPath, {
};
continue;
}
+ // A local recording has no source to probe (an empty URL would read as dead).
+ const localRefusal = localRecordingFetchRefusal(w.video, meta.platform);
+ if (localRefusal) {
+ rows[i] = { ...w, ok: false, state: "local-media", title: meta.title, url: null, checkedAt: iso(), error: localRefusal };
+ continue;
+ }
probes.push({ i, w, meta, platform: detectPlatform(meta.webpageUrl) ?? "other" });
}
diff --git a/umtool/report-to-video/local-recording.mjs b/umtool/report-to-video/local-recording.mjs
@@ -0,0 +1,15 @@
+// A LOCAL RECORDING (a record the editor's local media import made, platform
+// "local", id `local-<32 hex>`) has no online source: umtool's own clip fetch
+// and its availability probe refuse it with the editor's sentence
+// (common/lib/localMedia.ts localMediaFetchRefusal), rather than run yt-dlp on
+// an empty URL. A local library channel's other records are refused at the
+// editor's doors, which umtool fetch goes through.
+
+export const LOCAL_RECORDING_ID_RE = /^local-[0-9a-f]{32}$/;
+
+/** @returns {string|null} why no clip can be fetched, or null when one may be. */
+export function localRecordingFetchRefusal(videoId, platform) {
+ const id = String(videoId ?? "");
+ if (platform !== "local" && !LOCAL_RECORDING_ID_RE.test(id)) return null;
+ return `"${id}" is a local recording with no online source, so no clip can be fetched for it.`;
+}
diff --git a/umtool/report-to-video/local-recording.test.mjs b/umtool/report-to-video/local-recording.test.mjs
@@ -0,0 +1,12 @@
+import assert from "node:assert/strict";
+import test from "node:test";
+import { localRecordingFetchRefusal } from "./local-recording.mjs";
+
+test("a local recording is refused by id or by platform; anything else may fetch", () => {
+ const id = "local-" + "a".repeat(32);
+ assert.equal(localRecordingFetchRefusal(id, null),
+ `"${id}" is a local recording with no online source, so no clip can be fetched for it.`);
+ assert.match(localRecordingFetchRefusal("anything", "local"), /local recording with no online source/);
+ assert.equal(localRecordingFetchRefusal("dQw4w9WgXcQ", "youtube"), null);
+ assert.equal(localRecordingFetchRefusal("local-short", null), null);
+});
diff --git a/umtool/report-to-video/render-cards.mjs b/umtool/report-to-video/render-cards.mjs
@@ -1014,6 +1014,7 @@ export const SOURCE_TAG = {
restricted: "age-restricted",
"geo-blocked": "geo-blocked",
"no-cues": "no archived transcript",
+ "local-media": "local recording, not clipped",
maybe_missing: "source unreachable",
};