Archilyzer · Source

archilyzer

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

commit a3cc8e5c5d6a7b5c9e1c0ce9ac58d502cedbe970
parent b705a4e8f35f54195af810b71fdf7357f9192ebf
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Thu, 15 Oct 2026 17:19:34 -0400

common: a clean refetch retires a salvage transcript (release 30 lane Q, operator ruling) — when a corrupt full source's refetch comes back clean and its transcript is a salvage (transcribe-outcome.json `salvaged`), transcript.json, transcript.cues.json and transcribe-outcome.json go through removeMediaFile, the clean refetch's corruptRefetches entry keeps what was retired (`retiredSalvage`: the salvage and its transcribedAt), and the snapshot puts the video back in downloadedNoTranscript for the transcription lane; any other transcript is left alone

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

Diffstat:
Mcommon/lib/downloadOutcome.ts | 4++++
Mcommon/ytdlp/corruptRefetch.test.ts | 59+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mcommon/ytdlp/corruptRefetch.ts | 43+++++++++++++++++++++++++++++++++++++++++--
3 files changed, 104 insertions(+), 2 deletions(-)

diff --git a/common/lib/downloadOutcome.ts b/common/lib/downloadOutcome.ts @@ -3,6 +3,7 @@ import type { Availability, DownloadFailureClass } from "./availability"; import type { ChannelHandling } from "./channelConfig"; +import type { TranscriptSalvage } from "./transcribeOutcome"; export type DownloadOutcomeStatus = | "ok" @@ -127,6 +128,9 @@ export type CorruptRefetch = { // (null: it could not be measured). kept?: "new" | "previous"; decodedSeconds?: { previous: number | null; new: number | null }; + // clean: the salvage transcript made from the replaced file, retired so the + // transcription lane makes a full one from the clean audio — what it was. + retiredSalvage?: TranscriptSalvage & { transcribedAt: string }; }; export type DownloadOutcomeRecord = { diff --git a/common/ytdlp/corruptRefetch.test.ts b/common/ytdlp/corruptRefetch.test.ts @@ -34,6 +34,7 @@ import { } from "./corruptRefetch"; import { downloadOneManaged } from "./downloadOneManaged"; import { destinationExists } from "./runYtdlp"; +import { generateChannelSnapshot } from "../controller/channelSnapshot"; const ID = "H64QQZuw-aA"; const PATHS = { ffmpegBin: "ffmpeg", ffprobeBin: "ffprobe" }; @@ -302,3 +303,61 @@ test("the whole path: a 429 at the prefetch leaves the video corrupt-full-source assert.match(log, /stays corrupt-full-source/); await rm(f.root, { recursive: true, force: true }); }); + +test("a clean refetch retires a salvage transcript: the video is downloaded-not-transcribed again", async () => { + const f = await fixture(); + const channelDir = path.join(f.channelsDir, "c"); + await writeFile( + path.join(channelDir, "config.json"), + JSON.stringify({ handling: "transcribe", url: "https://www.youtube.com/@c/videos" }), + ); + await writeFile(path.join(channelDir, "playlist"), `https://www.youtube.com/watch?v=${ID}\n`); + await writeFile(path.join(f.videoDir, "metadata.info.json"), JSON.stringify({ id: ID, duration: 6000 })); + const salvaged = { source: "audio.mp4", decodedSeconds: 2335, totalSeconds: 6000, gaps: [[2335, 6000]] }; + await writeFile(path.join(f.videoDir, "transcript.json"), "{}"); + await writeFile(path.join(f.videoDir, "transcript.cues.json"), "{}"); + await writeFile( + path.join(f.videoDir, "transcribe-outcome.json"), + JSON.stringify({ videoId: ID, transcribedAt: "2026-10-15T00:00:00.000Z", salvaged }), + ); + const paths = { channelsDir: f.channelsDir } as Paths; + const before = await generateChannelSnapshot(paths, "c"); + assert.deepEqual(before.buckets.salvagedTranscript, [ID]); + + const { ctx: c, log } = ctx(); + const plan = await prepareCorruptRefetch(f.videoDir, c); + assert.ok(plan); + await writeFile(path.join(f.videoDir, "audio.mp4"), "NEW-CLEAN"); + await settleCorruptRefetch(plan, outcome({ status: "ok-audio-checked" }), c); + for (const name of ["transcript.json", "transcript.cues.json", "transcribe-outcome.json"]) { + assert.equal(existsSync(path.join(f.videoDir, name)), false, `${name} retired`); + } + assert.match(log.join(""), /Retired the salvage transcript/); + const disk = await readOutcome(f.videoDir); + assert.deepEqual(disk.corruptRefetches?.[0].retiredSalvage, { + ...salvaged, + transcribedAt: "2026-10-15T00:00:00.000Z", + }); + const after = await generateChannelSnapshot(paths, "c"); + assert.deepEqual(after.buckets.downloadedNoTranscript, [ID]); + assert.deepEqual(after.buckets.salvagedTranscript, []); + assert.deepEqual(after.buckets.corruptFullSource, []); + await rm(f.root, { recursive: true, force: true }); +}); + +test("a clean refetch leaves a transcript that is not a salvage alone", async () => { + const f = await fixture(); + await writeFile(path.join(f.videoDir, "transcript.json"), "{}"); + await writeFile( + path.join(f.videoDir, "transcribe-outcome.json"), + JSON.stringify({ videoId: ID, transcribedAt: "2026-10-15T00:00:00.000Z" }), + ); + const { ctx: c } = ctx(); + const plan = await prepareCorruptRefetch(f.videoDir, c); + assert.ok(plan); + await writeFile(path.join(f.videoDir, "audio.mp4"), "NEW-CLEAN"); + await settleCorruptRefetch(plan, outcome({ status: "ok-audio-checked" }), c); + assert.ok(existsSync(path.join(f.videoDir, "transcript.json"))); + assert.equal((await readOutcome(f.videoDir)).corruptRefetches?.[0].retiredSalvage, undefined); + await rm(f.root, { recursive: true, force: true }); +}); diff --git a/common/ytdlp/corruptRefetch.ts b/common/ytdlp/corruptRefetch.ts @@ -52,6 +52,12 @@ import { tierVideoDir, } from "../lib/mediaTier-server"; import { scanDecodable } from "../lib/salvageAudio-server"; +import { loadTranscribeOutcome } from "../lib/transcribeOutcome-server"; +import { + TRANSCRIBE_OUTCOME_FILENAME, + type TranscriptSalvage, +} from "../lib/transcribeOutcome"; +import { CUES_JSON_FILENAME, WHISPER_FILENAME } from "../lib/videoStatus"; export const CORRUPT_KEPT_SUFFIX = ".corrupt-kept"; @@ -158,6 +164,34 @@ async function resolveLeftovers(videoDir: string, entries: string[], ctx: Ctx): } } +// A SALVAGE TRANSCRIPT OUTLIVES ITS FILE (operator ruling, 2026-10-15): when a +// refetch comes back clean and the video's transcript is a salvage +// (transcribe-outcome.json `salvaged`), the transcript, its cues and its +// outcome go — through removeMediaFile, the one remover of a video-dir entry — +// and the video is downloaded-not-transcribed again, for the lane to redo from +// the clean audio. What was retired is returned for the refetch's record. +// Any other transcript (a clean one, a caption track) is left alone. +async function retireSalvagedTranscript( + videoDir: string, + onLog: (line: string) => void, +): Promise<(TranscriptSalvage & { transcribedAt: string }) | null> { + const entries = await readdir(videoDir).catch(() => [] as string[]); + if (!entries.includes(WHISPER_FILENAME) || !entries.includes(TRANSCRIBE_OUTCOME_FILENAME)) { + return null; + } + const record = await loadTranscribeOutcome(videoDir); + const salvaged = record?.salvaged; + if (!record || !salvaged) return null; + for (const name of [WHISPER_FILENAME, CUES_JSON_FILENAME, TRANSCRIBE_OUTCOME_FILENAME]) { + await removeMediaFile(videoDir, name); + } + onLog( + `Retired the salvage transcript (${salvaged.decodedSeconds}s of ${salvaged.totalSeconds}s, ` + + `${salvaged.gaps.length} gap(s)): the clean audio is transcribed again in full.\n`, + ); + return { ...salvaged, transcribedAt: record.transcribedAt }; +} + // Before a managed download: when this video's outcome is corrupt-full-source, // move its kept media aside and say so. Null when the video is anything else // (or has no outcome) — the download is then an ordinary one. Throws when the @@ -223,12 +257,17 @@ export async function settleCorruptRefetch( for (const name of asides) await removeMediaFile(videoDir, name + CORRUPT_KEPT_SUFFIX); }; - // CLEAN: the new file stands, the kept one goes. + // CLEAN: the new file stands, the kept one goes — and a salvage transcript + // made from it is retired, so the transcription lane makes a full one. if (outcome.status.startsWith("ok") && fresh.length > 0) { await removeAsides(); + const retiredSalvage = await retireSalvagedTranscript(videoDir, ctx.onLog); const record: DownloadOutcomeRecord = { ...outcome, - corruptRefetches: [...history, { ...base, result: "clean" }], + corruptRefetches: [ + ...history, + { ...base, result: "clean", ...(retiredSalvage ? { retiredSalvage } : {}) }, + ], }; await writeDownloadOutcome(videoDir, record); ctx.onLog(