// The share line and Rumble's two ids (lane output-modes): a clip's platform // page at its moment and its archive moment, the Rumble folder id mapped to // the embed id the archive serves -- by the ONE helper the share line, `umtool // links --fix` and `umtool timeline insert` all call. Synthetic corpus. // // Run with: pnpm test:scripts import assert from "node:assert/strict"; import { mkdirSync, mkdtempSync, writeFileSync } from "node:fs"; import { readFile, rm } from "node:fs/promises"; import { tmpdir } from "node:os"; import path from "node:path"; import test from "node:test"; const ROOT = mkdtempSync(path.join(tmpdir(), "umtool-share-")); const CORPUS = path.join(ROOT, "channels"); process.env.CHANNELS_DIR = CORPUS; process.env.CHANNELS_FALLBACK = "0"; const { projectShareLine, shareLineOf, shareLineText, shareSecondOf, siteVideoFor } = await import("./shareLine.mjs"); const { checkLinks, projectSiteIdOf, withArchiveId } = await import("./linkCheck.mjs"); const { timelineCommand } = await import("./timelineCli.mjs"); test.after(() => rm(ROOT, { recursive: true, force: true })); const json = (file, doc) => { mkdirSync(path.dirname(file), { recursive: true }); writeFileSync(file, JSON.stringify(doc)); }; // A Rumble channel downloaded from page URLs: the folder is the URL slug, the record the embed id. json(path.join(CORPUS, "rc", "config.json"), { platform: "rumble", url: "https://rumble.com/c/Quartering" }); json(path.join(CORPUS, "rc", "data", "v7fn1ab", "metadata.info.json"), { id: "v7fn1aa", webpage_url: "https://rumble.com/v7fn1ab-a-title.html" }); // A YouTube channel. json(path.join(CORPUS, "yt", "config.json"), { platform: "youtube", url: "https://www.youtube.com/@x" }); json(path.join(CORPUS, "yt", "data", "n8G_ysDV2bA", "transcript.cues.json"), { webpageUrl: "https://www.youtube.com/watch?v=n8G_ysDV2bA", cues: [] }); function project(name, timeline, provenance = {}) { const dir = path.join(ROOT, "reports", name); json(path.join(dir, "video.manifest.json"), { schemaVersion: 1, slug: name, title: name, provenance: { siteOrigin: "https://jeralyzer.example", channelsDir: CORPUS, ...provenance }, render: {}, timeline }); return { id: name, dir }; } test("siteVideoFor: a Rumble folder's embed id; the embed id itself, a YouTube id, an unknown one: null", async () => { assert.equal(await siteVideoFor({ channelsDir: CORPUS, slug: "rc", video: "v7fn1ab" }), "v7fn1aa"); assert.equal(await siteVideoFor({ channelsDir: CORPUS, slug: "rc", video: "v7fn1aa" }), null, "the embed id is the archive's already"); assert.equal(await siteVideoFor({ channelsDir: CORPUS, slug: "yt", video: "n8G_ysDV2bA" }), null); assert.equal(await siteVideoFor({ channelsDir: CORPUS, slug: "rc", video: "v9zzzzz" }), null); assert.equal(await siteVideoFor({ channelsDir: null, slug: "rc", video: "v7fn1ab" }), null); }); test("shareLineOf: the platform's page at the first second played and the archive's moment", async () => { assert.equal(shareSecondOf({ start: 4130, cutStart: 4132.5 }), 4132); assert.equal(shareSecondOf({ start: 12.9 }), 12); const m = { provenance: { siteOrigin: "https://site.example/", channelSlug: "yt" } }; const line = await shareLineOf(m, { type: "clip", id: "c01", video: "n8G_ysDV2bA", start: 4130, end: 4180, cutStart: 4132.5 }, { webpageOf: async () => "https://www.youtube.com/watch?v=n8G_ysDV2bA" }); assert.deepEqual(line, { clip: "c01", seconds: 4132, platform: "https://www.youtube.com/watch?v=n8G_ysDV2bA&t=4132s", archive: "https://site.example/?v=yt%2Fn8G_ysDV2bA&t=4132", text: "https://www.youtube.com/watch?v=n8G_ysDV2bA&t=4132s ยท archive: https://site.example/?v=yt%2Fn8G_ysDV2bA&t=4132", }); const none = await shareLineOf({ provenance: {} }, { type: "clip", id: "c", channel: "yt", video: "x", start: 1, end: 2 }); assert.deepEqual([none.platform, none.archive, none.text], [null, null, ""]); assert.equal(shareLineText({ archive: "https://a/?v=x" }), "archive: https://a/?v=x"); await assert.rejects(shareLineOf(m, { type: "post", id: "p" }), /not a clip/); }); test("projectShareLine: a Rumble clip by its folder id -- start= on its page, the embed id on the archive", async () => { const p = project("sl-rumble", [{ type: "clip", id: "n01", channel: "rc", video: "v7fn1ab", start: 100.4, end: 110 }]); const line = await projectShareLine(p); assert.equal(line.platform, "https://rumble.com/v7fn1ab-a-title.html?start=100"); assert.equal(line.archive, "https://jeralyzer.example/?v=rc%2Fv7fn1aa&t=100"); // --site: another origin, the same moment. assert.equal((await projectShareLine(p, { origin: "https://other.example" })).archive, "https://other.example/?v=rc%2Fv7fn1aa&t=100"); await assert.rejects(projectShareLine(p, { clip: "zz" }), /no clip zz/); // A clip that pins its siteVideo is not looked up. const pinned = project("sl-pinned", [{ type: "clip", id: "n01", channel: "rc", video: "v7fn1ab", siteVideo: "v7pinned", start: 1, end: 2 }]); assert.equal((await projectShareLine(pinned)).archive, "https://jeralyzer.example/?v=rc%2Fv7pinned&t=1"); }); test("the link check: a QR naming the Rumble folder id is dead, its fix the embed id's link and siteVideo", async () => { assert.equal(withArchiveId("https://s.example/?v=rc%2Fv7fn1ab&t=3", "v7fn1ab", "v7fn1aa"), "https://s.example/?v=rc%2Fv7fn1aa&t=3"); const m = { provenance: { channelsDir: CORPUS, siteOrigin: "https://s.example" }, timeline: [{ type: "clip", id: "n01", channel: "rc", video: "v7fn1ab", start: 1, end: 2 }] }; const siteIdOf = await projectSiteIdOf(path.join(ROOT, "reports", "sl-rumble"), m); assert.equal(await siteIdOf({ clip: "n01", channel: "rc", id: "v7fn1ab" }), "v7fn1aa"); assert.equal(await siteIdOf({ clip: "n01", channel: "rc", id: "other" }), null, "a link naming another recording is not this clip's"); const docs = { "https://s.example/corpus.json": { channels: [{ slug: "rc", manifests: { transcripts: "https://s.example/data/rc/manifest.json" } }] }, "https://s.example/data/rc/manifest.json": { slugToPage: { v7fn1aa: 0 } }, }; const fetchImpl = async (url) => { const doc = docs[String(url)]; return doc ? new Response(JSON.stringify(doc), { status: 200, headers: { "content-type": "application/json" } }) : new Response("no", { status: 404 }); }; const doc = await checkLinks([{ clip: "n01", url: "https://s.example/?v=rc%2Fv7fn1ab&t=1" }], { fetchImpl, cacheDir: null, gapMs: 0, siteIdOf }); const l = doc.links[0]; assert.equal(l.state, "dead"); assert.match(l.why, /folder \(its Rumble URL slug\).*embed id "v7fn1aa"/); assert.equal(l.fix, "https://s.example/?v=rc%2Fv7fn1aa&t=1"); assert.equal(l.fixSiteVideo, "v7fn1aa"); }); test("umtool timeline insert /: the clip carries the embed id the archive serves", async () => { const p = project("ins-rumble", [{ type: "clip", id: "c01", channel: "rc", video: "v7fn1aa", start: 1, end: 3 }], { channelSlug: "rc" }); const lines = []; const code = await timelineCommand([p.dir, "insert", "--after", "c01", "rc/v7fn1ab@10-20", "--id", "n01"], { root: path.join(ROOT, "reports"), out: (s) => lines.push(s), err: (s) => lines.push(s) }); assert.equal(code, 0, lines.join("\n")); const m = JSON.parse(await readFile(path.join(p.dir, "video.manifest.json"), "utf8")); const n01 = m.timeline.find((e) => e.id === "n01"); assert.equal(n01.video, "v7fn1ab"); assert.equal(n01.siteVideo, "v7fn1aa"); const yt = project("ins-yt", [], { channelSlug: "yt" }); assert.equal(await timelineCommand([yt.dir, "insert", "--after", "-", "yt/n8G_ysDV2bA@10-20"], { root: path.join(ROOT, "reports"), out: () => {}, err: () => {} }), 0); const y = JSON.parse(await readFile(path.join(yt.dir, "video.manifest.json"), "utf8")); assert.equal(y.timeline[0].siteVideo, undefined, "a YouTube clip names nothing more"); }); test("umtool links --fix: one undo point, then the Rumble clip names its embed id (siteVideo)", async () => { const { linksCommand } = await import("./linksCli.mjs"); const p = project("links-rumble", [{ type: "clip", id: "n01", channel: "rc", video: "v7fn1ab", start: 100, end: 110, cite: 100 }], { channelSlug: "rc" }); const docs = { "https://jeralyzer.example/corpus.json": { channels: [{ slug: "rc", manifests: { transcripts: "https://jeralyzer.example/data/rc/manifest.json" } }] }, "https://jeralyzer.example/data/rc/manifest.json": { slugToPage: { v7fn1aa: 0 } }, "https://jeralyzer.example/data/rc/page-0000.json": [{ id: "v7fn1aa" }], }; const fetchImpl = async (url) => { const doc = docs[String(url)]; return doc ? new Response(JSON.stringify(doc), { status: 200, headers: { "content-type": "application/json" } }) : new Response("no", { status: 404 }); }; const lines = []; const code = await linksCommand([p.dir, "--fix"], { root: path.join(ROOT, "reports"), out: (s) => lines.push(s), err: () => {}, fetchImpl, cacheDir: null, gapMs: 0 }); const text = lines.join("\n"); assert.match(text, /fixed n01: .*v7fn1ab.* -> .*v7fn1aa.*siteVideo v7fn1aa/); assert.match(text, /undo point: revisions\/.*-auto-before-links-fix\.manifest\.json/); assert.equal(code, 0, text); const m = JSON.parse(await readFile(path.join(p.dir, "video.manifest.json"), "utf8")); assert.equal(m.timeline[0].siteVideo, "v7fn1aa"); const rel = /undo point: (\S+)/.exec(text)[1]; const before = JSON.parse(await readFile(path.join(p.dir, rel), "utf8")); assert.equal(before.timeline[0].siteVideo, undefined, "the undo point is the cut before the fix"); });