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 }); } });