commit be80f309748f92ce95b2dac9b3262e54b7efebba
parent 1560889ecd1d1e20fb6f242786edd53022b52bd5
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Sat, 10 Oct 2026 12:21:42 -0400
channels: release 23 F2 — Transcribe reads a saved container before it downloads audio
whisperVideoAction (the video page's Transcribe, and `pnpm ops
transcribe-one {slug, id}`, which calls it) asks transcriptionContainer
(controller/transcribeOne.ts) before the disk gate and the
download-one-audio path: a source-media.<ext> in the video dir, else the
saved-video store's container, with sound is transcribed as it is — the
worker resolves it non-strict — and the job log says "transcribing from the
saved container <file> — nothing downloaded". A pointer whose container
cannot be read is refused with savedWindowSource's sentence (the media
guard's), never downloaded around; a container with no sound, or none, takes
the download path as before.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Diffstat:
4 files changed, 336 insertions(+), 2 deletions(-)
diff --git a/common/controller/transcribeOne.ts b/common/controller/transcribeOne.ts
@@ -22,6 +22,8 @@ import { pickPreferredAudio } from "../lib/mediaFiles";
import { resolveSavedVideo } from "../lib/savedVideo-server";
import { writeTranscribeOutcome } from "../lib/transcribeOutcome-server";
import { writeFileAtomic } from "../lib/jsonFile-server";
+import { probeMedia } from "../lib/evidenceClip-server";
+import { savedWindowSource } from "../lib/savedVideoWindow-server";
const { pathExists, readdir, rename } = fs;
@@ -50,6 +52,58 @@ async function resolveAudioFile(
return null;
}
+// A CONTAINER TO TRANSCRIBE FROM, before any audio download (release 23 F2).
+//
+// The page's Transcribe (and `pnpm ops transcribe-one`) used to download the
+// audio whenever no extracted audio was on disk — even for a video whose whole
+// source is in the saved-video store, which resolveAudioFile above already
+// transcribes from. This answers the question first, in resolveAudioFile's
+// order (`findSourceMedia(entries) ?? the saved-video pointer`):
+// container a container with sound: transcribe it, download nothing.
+// no-audio the container has no sound: the download path, as before.
+// unreadable a saved-video pointer whose container cannot be read (its
+// drive is not mounted or not answering, the file is gone, the
+// store is mid-move): REFUSED with the media guard's sentence
+// (savedWindowSource's), never a download in its place.
+// none no container at all: the download path, as before.
+// A `source-media.<ext>` in the video dir that ffprobe cannot read is passed
+// over for the pointer, as if it were not there.
+export type TranscriptionContainer =
+ | { kind: "container"; file: string; from: "video-dir" | "saved-video" }
+ | { kind: "no-audio"; file: string }
+ | { kind: "unreadable"; error: string }
+ | { kind: "none" };
+
+export async function transcriptionContainer(opts: {
+ paths: Pick<Paths, "transcriptsDir" | "savedVideosDir" | "ffprobeBin">;
+ slug: string;
+ videoDir: string;
+ entries: string[];
+}): Promise<TranscriptionContainer> {
+ const local = findSourceMedia(opts.entries);
+ if (local) {
+ const file = path.join(opts.videoDir, local);
+ const p = await probeMedia(file, opts.paths.ffprobeBin);
+ if (p) return p.hasAudio ? { kind: "container", file, from: "video-dir" } : { kind: "no-audio", file };
+ }
+ // The pointer, through the window path's own reader: its drive watchdog, its
+ // store-move check and its refusal sentence. [0, 0] is a window every
+ // readable container holds, so the answer is "none", "unreadable" or
+ // "covers" with the container's probe.
+ const saved = await savedWindowSource({
+ paths: opts.paths,
+ slug: opts.slug,
+ videoDir: opts.videoDir,
+ from: 0,
+ to: 0,
+ });
+ if (saved.kind === "unreadable") return { kind: "unreadable", error: saved.error };
+ if (saved.kind !== "covers") return { kind: "none" };
+ return saved.probe.hasAudio
+ ? { kind: "container", file: saved.container, from: "saved-video" }
+ : { kind: "no-audio", file: saved.container };
+}
+
// The audio we resolved at the top of the run is gone NOW.
//
// Another lane removed it mid-transcription — today that means the backfill's
diff --git a/common/controller/transcriptionContainer.test.ts b/common/controller/transcriptionContainer.test.ts
@@ -0,0 +1,116 @@
+// transcriptionContainer (release 23 F2): before the page's Transcribe
+// downloads audio, a container already here — a source-media.<ext> in the
+// video dir, else the saved-video store's — is transcribed instead; a pointer
+// whose container cannot be read is refused with the media guard's sentence;
+// a container with no sound, or none at all, takes the download path.
+//
+// Real ffprobe over tiny lavfi containers (a second at 160×90).
+//
+// Run with: pnpm --filter yt-dlp-transcript-common exec tsx --test controller/transcriptionContainer.test.ts
+
+import { after, before, test } from "node:test";
+import assert from "node:assert/strict";
+import { execFileSync } from "node:child_process";
+import { copyFile, mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
+import { tmpdir } from "node:os";
+import path from "node:path";
+import type { Paths } from "../lib/paths";
+import { transcriptionContainer } from "./transcribeOne";
+
+const SLUG = "demo-channel";
+let ROOT = "";
+let WITH_SOUND = "";
+let SILENT = "";
+
+const ff = (args: string[]) => execFileSync("ffmpeg", ["-nostdin", "-v", "error", "-y", ...args]);
+
+before(async () => {
+ ROOT = await mkdtemp(path.join(tmpdir(), "transcription-container-"));
+ WITH_SOUND = path.join(ROOT, "with-sound.mp4");
+ SILENT = path.join(ROOT, "silent.mp4");
+ ff([
+ "-f", "lavfi", "-i", "testsrc=size=160x90:rate=10:duration=1",
+ "-f", "lavfi", "-i", "sine=frequency=440:duration=1",
+ "-c:v", "libx264", "-preset", "ultrafast", "-pix_fmt", "yuv420p", "-c:a", "aac", "-shortest", WITH_SOUND,
+ ]);
+ ff([
+ "-f", "lavfi", "-i", "testsrc=size=160x90:rate=10:duration=1",
+ "-c:v", "libx264", "-preset", "ultrafast", "-pix_fmt", "yuv420p", SILENT,
+ ]);
+});
+after(() => rm(ROOT, { recursive: true, force: true }));
+
+async function video(): Promise<{ paths: Paths; videoDir: string; store: string }> {
+ const root = await mkdtemp(path.join(ROOT, "t-"));
+ const paths = {
+ transcriptsDir: path.join(root, "transcripts"),
+ savedVideosDir: path.join(root, "transcripts", "saved-videos"),
+ ffprobeBin: "ffprobe",
+ } as Paths;
+ const videoDir = path.join(paths.transcriptsDir, "channels", SLUG, "data", "abc123");
+ const store = path.join(paths.savedVideosDir, SLUG, "abc123");
+ await mkdir(videoDir, { recursive: true });
+ await mkdir(store, { recursive: true });
+ return { paths, videoDir, store };
+}
+
+async function point(videoDir: string, store: string, file: string | null): Promise<string> {
+ if (file) await copyFile(file, path.join(store, "source-media.mp4"));
+ await writeFile(
+ path.join(videoDir, "saved-video.json"),
+ JSON.stringify({ storedAt: "", dir: store, file: "source-media.mp4", bytes: 1 }),
+ );
+ return path.join(store, "source-media.mp4");
+}
+
+const ask = (paths: Paths, videoDir: string, entries: string[]) =>
+ transcriptionContainer({ paths, slug: SLUG, videoDir, entries });
+
+test("a saved container with sound is transcribed from, not downloaded around", async () => {
+ const { paths, videoDir, store } = await video();
+ const file = await point(videoDir, store, WITH_SOUND);
+ assert.deepEqual(await ask(paths, videoDir, ["saved-video.json"]), { kind: "container", file, from: "saved-video" });
+});
+
+test("a pointer whose container cannot be read is refused with the media guard's sentence", async () => {
+ const { paths, videoDir, store } = await video();
+ const file = await point(videoDir, store, null);
+ const r = await ask(paths, videoDir, ["saved-video.json"]);
+ assert.equal(r.kind, "unreadable");
+ assert.equal(
+ r.kind === "unreadable" ? r.error : "",
+ `Channel "${SLUG}": media is not reachable — its saved video ${file} is not there (drive not mounted?)`,
+ );
+});
+
+test("no container at all: the download path", async () => {
+ const { paths, videoDir } = await video();
+ assert.deepEqual(await ask(paths, videoDir, ["metadata.info.json"]), { kind: "none" });
+});
+
+test("a container with no sound: the download path", async () => {
+ const { paths, videoDir, store } = await video();
+ const file = await point(videoDir, store, SILENT);
+ assert.deepEqual(await ask(paths, videoDir, ["saved-video.json"]), { kind: "no-audio", file });
+});
+
+test("a source-media container in the video dir comes first, as resolveAudioFile reads it", async () => {
+ const { paths, videoDir, store } = await video();
+ await point(videoDir, store, SILENT);
+ await copyFile(WITH_SOUND, path.join(videoDir, "source-media.mp4"));
+ assert.deepEqual(await ask(paths, videoDir, ["saved-video.json", "source-media.mp4"]), {
+ kind: "container",
+ file: path.join(videoDir, "source-media.mp4"),
+ from: "video-dir",
+ });
+ // A silent one there is the download path (the worker would read it first).
+ await copyFile(SILENT, path.join(videoDir, "source-media.mp4"));
+ assert.deepEqual(await ask(paths, videoDir, ["saved-video.json", "source-media.mp4"]), {
+ kind: "no-audio",
+ file: path.join(videoDir, "source-media.mp4"),
+ });
+ // One ffprobe cannot read is passed over for the pointer.
+ await writeFile(path.join(videoDir, "source-media.mp4"), "not a container");
+ await point(videoDir, store, WITH_SOUND);
+ assert.equal((await ask(paths, videoDir, ["saved-video.json", "source-media.mp4"])).kind, "container");
+});
diff --git a/editor/app/channels/[slug]/videos/[id]/videoActions.ts b/editor/app/channels/[slug]/videos/[id]/videoActions.ts
@@ -59,7 +59,10 @@ import {
removeMediaFile,
removeVideoDirMedia,
} from "yt-dlp-transcript-common/lib/mediaTier-server";
-import { transcribeWithWorker } from "yt-dlp-transcript-common/controller/transcribeOne";
+import {
+ transcribeWithWorker,
+ transcriptionContainer,
+} from "yt-dlp-transcript-common/controller/transcribeOne";
import { findVideoSourceUrl } from "yt-dlp-transcript-common/controller/undownloadedVideos";
import {
loadSavedVideo,
@@ -459,7 +462,26 @@ export async function whisperVideoAction(
const audioFormat = r.config.audioFormat ?? "mp3";
const entries = await readdir(videoDir).catch(() => [] as string[]);
const hasAudio = entries.some(isRealAudioFile);
- if (!hasAudio) {
+ // NO AUDIO, BUT A CONTAINER (release 23 F2): a source-media.<ext> here or
+ // the saved-video store's container is transcribed as it is — the worker
+ // resolves it (resolveAudioFile) — and nothing is downloaded. A pointer
+ // whose container cannot be read is refused with the media guard's
+ // sentence, never downloaded around; a container with no sound takes the
+ // download path below.
+ const held = hasAudio
+ ? null
+ : await transcriptionContainer({ paths, slug, videoDir, entries });
+ if (held?.kind === "unreadable") throw new Error(held.error);
+ if (held?.kind === "container") {
+ onLog(
+ `No audio on disk for ${videoId}; transcribing from ` +
+ `${held.from === "saved-video" ? "the saved container" : "the source container"} ` +
+ `${held.file} — nothing downloaded.`,
+ );
+ } else if (!hasAudio) {
+ if (held?.kind === "no-audio") {
+ onLog(`The container ${held.file} has no sound; downloading the audio instead.`);
+ }
// Only this branch writes bytes. Transcribing audio that is already on
// disk produces a transcript.json measured in kilobytes, so a low disk
// is no reason to refuse it — the gate belongs on the fetch, not on the
diff --git a/editor/app/channels/[slug]/videos/[id]/whisperFromContainer.test.ts b/editor/app/channels/[slug]/videos/[id]/whisperFromContainer.test.ts
@@ -0,0 +1,142 @@
+import test from "node:test";
+import assert from "node:assert/strict";
+import { execFileSync } from "node:child_process";
+import { chmod, copyFile, mkdir, mkdtemp, readFile, 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/*/whisperFromContainer.test.ts"
+//
+// The page's Transcribe — and `pnpm ops transcribe-one {slug, id}`, which
+// calls the same action — over a video with no audio on disk (release 23 F2):
+// a saved container with sound transcribed from it, nothing downloaded
+// (the e2e fake whisper-cli does the work);
+// a pointer whose file is gone refused with the media guard's sentence,
+// nothing downloaded;
+// no container the download path, as before;
+// a container with no sound the download path, as before.
+// The download path's yt-dlp is a fake that records its argv and fails, so
+// "downloaded" is a recorded argv, never the network.
+
+const ROOT = await mkdtemp(path.join(os.tmpdir(), "whisper-from-container-"));
+const SLUG = "demo-channel";
+const YTDLP_LOG = path.join(ROOT, "ytdlp-argv.jsonl");
+const FAKE_YTDLP = path.join(ROOT, "fake-ytdlp.mjs");
+await writeFile(
+ FAKE_YTDLP,
+ `#!/usr/bin/env node
+import { appendFileSync } from "node:fs";
+appendFileSync(${JSON.stringify(YTDLP_LOG)}, JSON.stringify(process.argv.slice(2)) + "\\n");
+process.stderr.write("ERROR: fake yt-dlp: no network in this test\\n");
+process.exit(1);
+`,
+);
+await chmod(FAKE_YTDLP, 0o755);
+
+process.env.TRANSCRIPTS_DIR = ROOT;
+process.env.SETTINGS_FILE = path.join(ROOT, "settings.json");
+process.env.YTDLP_BIN = FAKE_YTDLP;
+process.env.WHISPER_BIN = path.resolve("e2e/fixtures/bin/fake-whisper.mjs");
+process.env.WHISPER_MODEL = "/dev/null";
+delete process.env.FFPROBE_BIN;
+delete process.env.FFMPEG_BIN;
+
+await writeFile(process.env.SETTINGS_FILE, JSON.stringify({ minFreeDiskGB: 0 }));
+await mkdir(path.join(ROOT, "channels", SLUG), { recursive: true });
+await writeFile(
+ path.join(ROOT, "channels", SLUG, "config.json"),
+ JSON.stringify({ name: "Demo", handling: "transcribe", url: "https://www.youtube.com/@demo", platform: "youtube" }),
+);
+
+const ff = (args: string[]) => execFileSync("ffmpeg", ["-nostdin", "-v", "error", "-y", ...args]);
+const WITH_SOUND = path.join(ROOT, "with-sound.mp4");
+const SILENT = path.join(ROOT, "silent.mp4");
+ff([
+ "-f", "lavfi", "-i", "testsrc=size=160x90:rate=10:duration=1",
+ "-f", "lavfi", "-i", "sine=frequency=440:duration=1",
+ "-c:v", "libx264", "-preset", "ultrafast", "-pix_fmt", "yuv420p", "-c:a", "aac", "-shortest", WITH_SOUND,
+]);
+ff(["-f", "lavfi", "-i", "testsrc=size=160x90:rate=10:duration=1", "-c:v", "libx264", "-preset", "ultrafast", "-pix_fmt", "yuv420p", SILENT]);
+
+// A video dir with metadata (so the download path has a URL) and, optionally,
+// a saved-video pointer to a container (a missing one when `file` is null).
+async function videoWith(id: string, container: string | null | undefined): Promise<string> {
+ const dir = path.join(ROOT, "channels", SLUG, "data", id);
+ await mkdir(dir, { recursive: true });
+ await writeFile(
+ path.join(dir, "metadata.info.json"),
+ JSON.stringify({ id, title: id, webpage_url: `https://www.youtube.com/watch?v=${id}` }),
+ );
+ if (container !== undefined) {
+ const store = path.join(ROOT, "saved-videos", SLUG, id);
+ await mkdir(store, { recursive: true });
+ if (container) await copyFile(container, path.join(store, "source-media.mp4"));
+ await writeFile(
+ path.join(dir, "saved-video.json"),
+ JSON.stringify({ storedAt: "", dir: store, file: "source-media.mp4", bytes: 1 }),
+ );
+ }
+ return dir;
+}
+
+const { whisperVideoAction } = await import("./videoActions");
+const { getRegistry } = await import("yt-dlp-transcript-common/jobs/registry");
+test.after(() => rm(ROOT, { recursive: true, force: true }));
+
+async function ytdlpCalls(): Promise<number> {
+ return (await readFile(YTDLP_LOG, "utf8").catch(() => "")).split("\n").filter(Boolean).length;
+}
+
+// Runs the action to its end: the job's status, and its log.
+async function transcribe(id: string): Promise<{ status: string; log: string }> {
+ const r = await whisperVideoAction(SLUG, id);
+ if (!r.ok) throw new Error(r.error);
+ // Drain the stream so the job is never held up on it.
+ void (async () => {
+ const reader = r.stream.getReader();
+ while (!(await reader.read()).done) {}
+ })();
+ await r.done;
+ const rec = getRegistry().get(r.jobId);
+ const log = rec?.logPath ? await readFile(rec.logPath, "utf8").catch(() => "") : "";
+ return { status: rec?.status ?? "?", log };
+}
+
+test("a saved container with sound is transcribed from, and nothing is downloaded", async () => {
+ const dir = await videoWith("held1", WITH_SOUND);
+ const before = await ytdlpCalls();
+ const r = await transcribe("held1");
+ assert.equal(r.status, "done", r.log);
+ assert.match(r.log, /No audio on disk for held1; transcribing from the saved container .*source-media\.mp4 — nothing downloaded\./);
+ assert.equal(await ytdlpCalls(), before, "no yt-dlp run");
+ const transcript = JSON.parse(await readFile(path.join(dir, "transcript.json"), "utf8"));
+ assert.ok(Array.isArray(transcript.transcription));
+});
+
+test("a pointer whose container is gone is refused with the guard's sentence, and nothing is downloaded", async () => {
+ await videoWith("gone1", null);
+ const before = await ytdlpCalls();
+ const r = await transcribe("gone1");
+ assert.equal(r.status, "failed", r.log);
+ assert.match(r.log, /Channel "demo-channel": media is not reachable — its saved video .*source-media\.mp4 is not there \(drive not mounted\?\)/);
+ assert.equal(await ytdlpCalls(), before, "no yt-dlp run");
+});
+
+test("no container: the download path, as before", async () => {
+ await videoWith("plain1", undefined);
+ const before = await ytdlpCalls();
+ const r = await transcribe("plain1");
+ assert.equal(r.status, "failed", r.log);
+ assert.match(r.log, /No audio on disk for plain1; downloading…/);
+ assert.equal(await ytdlpCalls(), before + 1);
+});
+
+test("a container with no sound: the download path, as before", async () => {
+ await videoWith("silent1", SILENT);
+ const before = await ytdlpCalls();
+ const r = await transcribe("silent1");
+ assert.equal(r.status, "failed", r.log);
+ assert.match(r.log, /The container .*source-media\.mp4 has no sound; downloading the audio instead\./);
+ assert.equal(await ytdlpCalls(), before + 1);
+});