// recording-ids.mjs (lane one-clock): a cited Rumble embed id is asked for by // its directory, and the settings' whole-recording list decides whole or window. // // Run with: pnpm test:scripts import assert from "node:assert/strict"; import test from "node:test"; import path from "node:path"; import os from "node:os"; import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises"; import { isWholeRecording, localVideoId, mappedLine, recordingPlatform, wholeRecordingPlatforms, withLocalIds } from "./recording-ids.mjs"; async function corpus() { const root = await mkdtemp(path.join(os.tmpdir(), "rec-ids-")); const channelsDir = path.join(root, "channels"); await mkdir(path.join(channelsDir, "rc", "data", "v7fxp3e"), { recursive: true }); await writeFile(path.join(channelsDir, "rc", "config.json"), JSON.stringify({ platform: "rumble" })); await writeFile(path.join(channelsDir, "rc", "data", "v7fxp3e", "metadata.info.json"), JSON.stringify({ id: "v7drc5w" })); await mkdir(path.join(channelsDir, "yt"), { recursive: true }); await writeFile(path.join(channelsDir, "yt", "config.json"), JSON.stringify({ url: "https://www.youtube.com/@x" })); return { root, channelsDir }; } test("ids: an embed id becomes its directory; items keep everything else; the mapping is said once", async () => { const c = await corpus(); try { assert.equal(await localVideoId({ channelsDir: c.channelsDir, slug: "rc", id: "v7drc5w" }), "v7fxp3e"); assert.equal(await localVideoId({ channelsDir: c.channelsDir, slug: "rc", id: "v7fxp3e" }), "v7fxp3e"); const { items, mapped } = await withLocalIds( [ { slug: "rc", id: "v7drc5w", from: 1, to: 2, clipId: "c43" }, { slug: "rc", id: "v7drc5w", from: 5, to: 9, clipId: "c44" }, { slug: "yt", id: "abcdefghijk", from: 1, to: 2 }, ], { channelsDir: c.channelsDir }, ); assert.deepEqual(items.map((i) => i.id), ["v7fxp3e", "v7fxp3e", "abcdefghijk"]); assert.deepEqual(items[0], { slug: "rc", id: "v7fxp3e", from: 1, to: 2, clipId: "c43" }); assert.deepEqual(mapped, [{ slug: "rc", cited: "v7drc5w", dir: "v7fxp3e" }]); assert.equal(mappedLine(mapped), "rc/v7drc5w → v7fxp3e"); } finally { await rm(c.root, { recursive: true, force: true }); } }); test("whole or window: the channel's platform (else the page URL's) against the settings' list", async () => { const c = await corpus(); try { const none = path.join(c.root, "missing-settings.json"); assert.deepEqual(wholeRecordingPlatforms(none), ["rumble"]); const listed = path.join(c.root, "settings.json"); await writeFile(listed, JSON.stringify({ clips: { wholeRecordingPlatforms: ["Rumble", "youtube", "rumble", ""] } })); assert.deepEqual(wholeRecordingPlatforms(listed), ["rumble", "youtube"]); await writeFile(listed, JSON.stringify({ clips: { wholeRecordingPlatforms: [] } })); assert.deepEqual(wholeRecordingPlatforms(listed), []); assert.equal(await recordingPlatform({ channelsDir: c.channelsDir, slug: "rc" }), "rumble"); assert.equal(await recordingPlatform({ channelsDir: c.channelsDir, slug: "yt" }), "youtube"); assert.equal(await recordingPlatform({ channelsDir: c.channelsDir, slug: "nope", webpageUrl: "https://rumble.com/v1-x.html" }), "rumble"); assert.equal(await isWholeRecording({ channelsDir: c.channelsDir, slug: "rc", platforms: ["rumble"] }), true); assert.equal(await isWholeRecording({ channelsDir: c.channelsDir, slug: "yt", platforms: ["rumble"] }), false); assert.equal(await isWholeRecording({ channelsDir: c.channelsDir, slug: "rc", platforms: [] }), false); } finally { await rm(c.root, { recursive: true, force: true }); } });