Archilyzer · Source

archilyzer

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

commit 14e66c7c4cc70706b4effcee350d2264e008ad95
parent 1c523befdde474edc25370caa871d709445baf46
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Wed, 11 Nov 2026 09:23:25 -0500

local media: no lane or download ever gets a URL for a local record

Review fix 4. findVideoSourceUrl (controller/undownloadedVideos.ts) is the one
resolver the download lane, the replace-auto-captions unit (with its
transcribe-handling override), transcribe-one's owed download, reacquire and
persist-videos ask for a page URL. Its last resort rebuilt a URL from the id
and the channel's platform, and `defaultWebpageUrl("local", id)` is "". It
now answers null for a local recording (id or `local_recording` marker), for
every record of a local media library channel (lib/localMedia.ts
localMediaFetchRefusal), and for an empty rebuilt URL.

And the transcription lane's opt-in replace-auto-captions bucket
(`autoSubsOnly`, drawn with replaceAutoSubs) no longer takes such a record when
its imported VTT sniffs as YouTube's speech recognition.

Tests: the resolver (local id in an online channel with a youtube playlist
line, the override config, no config, a library channel's provider record,
the marker alone, platform "local", and an online record unchanged); the
snapshot (an online ASR control is a candidate, the local and library records
are in no autoSubsOnly, download or undownloaded bucket; fails without the
guard).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Diffstat:
Mcommon/controller/channelSnapshot.test.ts | 44++++++++++++++++++++++++++++++++++++++++++++
Mcommon/controller/channelSnapshot.ts | 5++++-
Acommon/controller/findVideoSourceUrlLocal.test.ts | 57+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mcommon/controller/undownloadedVideos.ts | 11++++++++++-
4 files changed, 115 insertions(+), 2 deletions(-)

diff --git a/common/controller/channelSnapshot.test.ts b/common/controller/channelSnapshot.test.ts @@ -1062,3 +1062,47 @@ test("a skip-Shorts channel keeps its listed Shorts out of the work list and the await rm(keeping.dir, { recursive: true, force: true }); } }); + +// lane/local-media review fix 4: a local media library's record is never a +// replace-auto-captions candidate (the opt-in `autoSubsOnly` bucket the +// transcription lane draws with `replaceAutoSubs`), nor in any download bucket, +// even when its imported VTT sniffs as YouTube's speech recognition. +test("a local recording, and a local library channel's record, are in no acquisition bucket", async () => { + const dir = await mkdtemp(path.join(tmpdir(), "ttb-snap-local-")); + const ts = (s: number) => new Date(s * 1000).toISOString().slice(11, 23); + const asr = "WEBVTT\nKind: captions\nLanguage: en\n\n" + [1, 3, 5, 7, 9].map((a) => + `${ts(a)} --> ${ts(a + 2)} align:start position:0%\nword<${ts(a)}><c> more</c>\n`).join("\n"); + const local = "local-" + "c".repeat(32); + try { + const paths = { channelsDir: path.join(dir, "channels") } as Paths; + const record = async (slug: string, id: string, meta: unknown) => { + const videoDir = path.join(paths.channelsDir, slug, "data", id); + await mkdir(videoDir, { recursive: true }); + await writeFile(path.join(videoDir, "metadata.info.json"), JSON.stringify(meta)); + await writeFile(path.join(videoDir, "transcript.en.vtt"), asr); + }; + const channel = async (slug: string, config: unknown) => { + await mkdir(path.join(paths.channelsDir, slug), { recursive: true }); + await writeFile(path.join(paths.channelsDir, slug, "config.json"), JSON.stringify(config)); + await writeFile(path.join(paths.channelsDir, slug, "playlist"), ""); + }; + const lib = { sourceId: "library-1", directory: path.join(dir, "library") }; + await channel("hybrid", { handling: "youtube", url: "https://www.youtube.com/@hybrid", localMedia: lib }); + await record("hybrid", "onlineasr01", { id: "onlineasr01", webpage_url: "https://www.youtube.com/watch?v=onlineasr01" }); + await record("hybrid", local, { id: local, title: "Talk", local_recording: { version: 1, titleSource: "filename", inspection: "manual", durationSource: "unknown" } }); + await channel("archive", { handling: "youtube", sourceKind: "video", localMedia: lib }); + await record("archive", "providerasr", { id: "providerasr", webpage_url: "https://www.youtube.com/watch?v=providerasr" }); + + const hybrid = await generateChannelSnapshot(paths, "hybrid"); + assert.deepEqual(hybrid.buckets.autoSubsOnly, ["onlineasr01"], "the online control is a candidate"); + const archive = await generateChannelSnapshot(paths, "archive"); + assert.deepEqual(archive.buckets.autoSubsOnly, []); + for (const snap of [hybrid, archive]) { + for (const ids of [snap.buckets.downloadedNoTranscript, snap.buckets.partialDownloads, snap.undownloadedIds]) { + assert.ok(!ids.includes(local) && !ids.includes("providerasr"), JSON.stringify(ids)); + } + } + } finally { + await rm(dir, { recursive: true, force: true }); + } +}); diff --git a/common/controller/channelSnapshot.ts b/common/controller/channelSnapshot.ts @@ -1,4 +1,5 @@ import { writeJsonAtomic } from "../lib/jsonFile-server"; +import { localMediaFetchRefusal } from "../lib/localMedia"; import path from "node:path"; import type { Dirent } from "node:fs"; import { lstat, readdir, readFile, stat } from "node:fs/promises"; @@ -1583,7 +1584,9 @@ export async function generateChannelSnapshot( // provenance we can't prove ("unknown") is never a candidate, so a human // caption track is never scheduled for replacement. The corrupt-full-source // and failed-short-audio `continue`s above already excluded terminal videos. - const asrVtt = files.hasYtVtt && vttProvenance === "asr"; + // A local media library's record (lib/localMedia.ts) is never a + // replace-auto-captions candidate: it has no online source to fetch audio from. + const asrVtt = files.hasYtVtt && vttProvenance === "asr" && !localMediaFetchRefusal(slug, config, id); if (asrVtt && files.hasWhisper) { // Our transcript won; the old ASR VTT lingers as a backup. do-not-clean // dirs are excluded so the count matches what the manual purge removes. diff --git a/common/controller/findVideoSourceUrlLocal.test.ts b/common/controller/findVideoSourceUrlLocal.test.ts @@ -0,0 +1,57 @@ +import { test } from "node:test"; +import assert from "node:assert/strict"; +import { 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 type { ChannelConfig } from "../lib/channelConfig"; +import { findVideoSourceUrl } from "./undownloadedVideos"; +import { defaultWebpageUrl } from "../lib/platform"; + +// lane/local-media review fix 4: the one resolver every lane and door asks for a +// video's page URL — the download lane, the replace-auto-captions unit (which +// passes the channel with a transcribe-handling override), transcribe-one's +// owed download, reacquire, persist-videos — answers NULL for a local record, +// so `defaultWebpageUrl("local", id)` (which is "") never reaches yt-dlp. + +test("findVideoSourceUrl: null for a local recording, a local library channel and platform \"local\"", async () => { + const dir = await mkdtemp(path.join(tmpdir(), "source-url-local-")); + try { + const paths = { channelsDir: path.join(dir, "channels") } as Paths; + const local = "local-" + "d".repeat(32); + const write = async (slug: string, config: ChannelConfig, id: string, meta: unknown, playlist = "") => { + await mkdir(path.join(paths.channelsDir, slug, "data", id), { recursive: true }); + await writeFile(path.join(paths.channelsDir, slug, "config.json"), JSON.stringify(config)); + await writeFile(path.join(paths.channelsDir, slug, "playlist"), playlist); + await writeFile(path.join(paths.channelsDir, slug, "data", id, "metadata.info.json"), JSON.stringify(meta)); + }; + const lib = { sourceId: "library-1", directory: "/mnt/library" }; + const hybrid: ChannelConfig = { handling: "youtube", platform: "youtube", url: "https://www.youtube.com/@h", localMedia: lib }; + // A local recording in an online channel: a youtube platform would rebuild a URL from its id. + await write("hybrid", hybrid, local, { id: local, title: "Talk", local_recording: { version: 1 } }, + `https://www.youtube.com/watch?v=${local}\n`); + assert.equal(await findVideoSourceUrl(paths, "hybrid", local, hybrid), null); + // The replace-auto-captions unit's override config: still null. + assert.equal(await findVideoSourceUrl(paths, "hybrid", local, { ...hybrid, handling: "transcribe" }), null); + // No config passed: read from disk, still null. + assert.equal(await findVideoSourceUrl(paths, "hybrid", local), null); + // A local library channel's provider-metadata record: no online source either. + const archive: ChannelConfig = { handling: "youtube", sourceKind: "video", localMedia: lib }; + await write("archive", archive, "aaaaaaaaaaa", { id: "aaaaaaaaaaa", webpage_url: "https://www.youtube.com/watch?v=aaaaaaaaaaa" }); + assert.equal(await findVideoSourceUrl(paths, "archive", "aaaaaaaaaaa", archive), null); + // A record carrying the local marker under any id. + await write("hybrid", hybrid, "markedonly", { id: "markedonly", local_recording: { version: 1 } }); + assert.equal(await findVideoSourceUrl(paths, "hybrid", "markedonly", hybrid), null); + // A channel whose platform is "local": "" is not a URL. + const localPlatform: ChannelConfig = { handling: "youtube", platform: "local" }; + await mkdir(path.join(paths.channelsDir, "lp", "data", "x1"), { recursive: true }); + await writeFile(path.join(paths.channelsDir, "lp", "config.json"), JSON.stringify(localPlatform)); + assert.equal(defaultWebpageUrl("local", "x1"), ""); + assert.equal(await findVideoSourceUrl(paths, "lp", "x1", localPlatform), null); + // An online record of the online channel is unchanged. + await write("hybrid", hybrid, "dQw4w9WgXcQ", { id: "dQw4w9WgXcQ", webpage_url: "https://www.youtube.com/watch?v=dQw4w9WgXcQ" }); + assert.equal(await findVideoSourceUrl(paths, "hybrid", "dQw4w9WgXcQ", hybrid), "https://www.youtube.com/watch?v=dQw4w9WgXcQ"); + } finally { + await rm(dir, { recursive: true, force: true }); + } +}); diff --git a/common/controller/undownloadedVideos.ts b/common/controller/undownloadedVideos.ts @@ -1,4 +1,6 @@ import path from "node:path"; +import { readChannelConfig } from "./channels"; +import { localMediaFetchRefusal } from "../lib/localMedia"; import { readFile } from "node:fs/promises"; import type { Paths } from "../lib/paths"; import type { ChannelConfig } from "../lib/channelConfig"; @@ -25,10 +27,17 @@ export async function findVideoSourceUrl( config?: ChannelConfig, ): Promise<string | null> { const channelRoot = path.join(paths.channelsDir, slug); + // A LOCAL RECORDING, or any record of a local media library channel, has no + // online source (lib/localMedia.ts): null, so no lane, door or download ever + // hands yt-dlp a URL built for it — `defaultWebpageUrl("local", id)` is "". + if (localMediaFetchRefusal(slug, config ?? (await readChannelConfig(paths, slug).catch(() => null)), videoId)) { + return null; + } const metaPath = path.join(channelRoot, "data", videoId, "metadata.info.json"); try { const raw = await readFile(metaPath, "utf8"); const parsed = JSON.parse(raw); + if (parsed?.local_recording !== undefined) return null; if (typeof parsed?.webpage_url === "string" && parsed.webpage_url) { return parsed.webpage_url; } @@ -46,6 +55,6 @@ export async function findVideoSourceUrl( // playlist came up empty, so the exact original URL always wins when present. // Requires a known platform — we don't blindly guess one. const platform = config?.platform ?? detectPlatform(config?.url ?? null); - if (platform) return defaultWebpageUrl(platform, videoId); + if (platform) return defaultWebpageUrl(platform, videoId) || null; return null; }