commit 5663717e438bd0ea7b8fd2e8b2daa629d5d22436
parent fe2982232e3212c83da982d958eb4855da3164c3
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Mon, 9 Nov 2026 14:14:16 -0500
umtool: the share line, and Rumble's folder id mapped to its embed id in one helper
shareLine.mjs: a clip's share line -- its platform page at the first second it plays
(watchUrlAt: YouTube t=<s>s, Rumble start=<s>) and its archive moment
(archiveMomentUrl). siteVideoFor (common videoDir-server.mjs recordIdOfVideoDir, the
folder's metadata.info.json id) is the one mapping from a Rumble URL-slug folder to the
embed id the archive serves, and its three callers: the share line; umtool links --fix
(a QR naming the folder id is dead, its fix the embed id's link and the clip's
siteVideo); umtool timeline insert <rumble-ch>/<folder> (the clip written with its
siteVideo). updateClip takes siteVideo.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Diffstat:
8 files changed, 343 insertions(+), 7 deletions(-)
diff --git a/common/lib/videoDir-server.mjs b/common/lib/videoDir-server.mjs
@@ -194,6 +194,29 @@ export async function resolveVideoDirId(channelsDir, slug, recordId, opts = {})
}
/**
+ * THE OTHER WAY ROUND: the id the ARCHIVE serves a recording under, from the
+ * directory it lives in on this disk (`resolveVideoDirId`'s inverse, for
+ * Rumble). On a Rumble channel a directory named for the URL slug holds a
+ * record whose id -- its metadata.info.json `id`, the EMBED id the archive
+ * keys by -- is another: that id is returned (a QR, a share line, an inserted
+ * clip's `siteVideo` must name it; 4 and 8 Nov the QR named the folder id).
+ * Every other directory, and a Rumble one whose metadata names itself or
+ * nothing, is its own id. Only a Rumble-shaped id costs a read.
+ * @param {string} channelsDir
+ * @param {string} slug
+ * @param {string} dirId
+ * @param {{ platform?: string | null }} [opts]
+ * @returns {Promise<string>}
+ */
+export async function recordIdOfVideoDir(channelsDir, slug, dirId, opts = {}) {
+ if (!RUMBLE_ID_RE.test(dirId)) return dirId;
+ const platform = opts.platform !== undefined ? opts.platform : await readChannelPlatform(channelsDir, slug);
+ if (platform !== "rumble") return dirId;
+ const id = idOfHead(await readHead(path.join(/* turbopackIgnore: true */ channelsDir, slug, "data", dirId, "metadata.info.json")));
+ return id && RUMBLE_ID_RE.test(id) ? id : dirId;
+}
+
+/**
* The directory a record lives in: `<channelsDir>/<slug>/data/<dir id>`.
* @param {string} channelsDir
* @param {string} slug
diff --git a/common/lib/videoDirId.test.ts b/common/lib/videoDirId.test.ts
@@ -18,7 +18,7 @@ import {
twitchVodDirId,
twitchVodRecordId,
} from "./videoId";
-import { resolveVideoDir, resolveVideoDirId, resolveVideoDirIdSync, resolveVideoDirSync } from "./videoDir-server.mjs";
+import { recordIdOfVideoDir, resolveVideoDir, resolveVideoDirId, resolveVideoDirIdSync, resolveVideoDirSync } from "./videoDir-server.mjs";
const N = "1234567890";
const META = { id: `v${N}`, webpage_url: `https://www.twitch.tv/videos/${N}` };
@@ -133,6 +133,11 @@ test("a Rumble embed id resolves to the URL-slug directory whose metadata names
// The slug id is its own directory; an id nobody names stays as it is.
assert.equal(await resolveVideoDirId(root, "rc", "v7fxp3e"), "v7fxp3e");
assert.equal(await resolveVideoDirId(root, "rc", "v9zzzzz"), "v9zzzzz");
+ // The inverse: the URL-slug directory's record id, the embed id the archive serves (lane output-modes).
+ assert.equal(await recordIdOfVideoDir(root, "rc", "v7fxp3e"), "v7drc5w");
+ assert.equal(await recordIdOfVideoDir(root, "rc", "v9zzzzz"), "v9zzzzz", "no metadata: itself");
+ assert.equal(await recordIdOfVideoDir(root, "rc", "dQw4w9WgXcQ"), "dQw4w9WgXcQ", "not Rumble-shaped: no read");
+ assert.equal(await recordIdOfVideoDir(root, "rc", "v7fxp3e", { platform: "youtube" }), "v7fxp3e", "not a Rumble channel");
// A directory added later is found once data/ changes.
mkdirSync(path.join(data, "v7gwn3w"));
writeFileSync(path.join(data, "v7gwn3w", "metadata.info.json"), JSON.stringify({ id: "v7eqa6e" }));
diff --git a/umtool/lib/report/linkCheck.mjs b/umtool/lib/report/linkCheck.mjs
@@ -90,6 +90,12 @@ export function linksOf(m) {
return out;
}
+/** An archive link with its `?v=<channel>/<from>` id swapped for `to`, everything else as it was. Pure. */
+export function withArchiveId(url, from, to) {
+ const esc = String(from).replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
+ return String(url).replace(new RegExp(`([?&]v=[^&#]*?)(%2F|/)${esc}(?=&|#|$)`, "i"), `$1$2${to}`);
+}
+
/** A fetch that gives up: a site that hangs is a site that does not answer. */
function withTimeout(fetchImpl, ms) {
return (url, init = {}) => fetchImpl(url, { ...init, signal: AbortSignal.timeout(ms) });
@@ -105,16 +111,22 @@ const errText = (e) => {
* Resolve the links. Pure over `fetchImpl` (and the cache dir).
*
* @param {Array<{ clip: string, url: string }>} links
- * @param {{ fetchImpl?: typeof fetch, cacheDir?: string | null, now?: () => Date, log?: (s: string) => void, gapMs?: number, sleep?: (ms: number) => Promise<void> }} [opts]
+ * `siteIdOf({clip, channel, id})`: the id the archive serves a recording
+ * under when the link names the corpus's own (a Rumble URL-slug directory:
+ * its embed id, shareLine.mjs siteVideoFor), else null -- a link to the folder
+ * id is then dead with the embed id's link as its `fix` and `fixSiteVideo`.
+ *
+ * @param {{ fetchImpl?: typeof fetch, cacheDir?: string | null, now?: () => Date, log?: (s: string) => void, gapMs?: number, sleep?: (ms: number) => Promise<void>,
+ * siteIdOf?: (q: { clip: string, channel: string, id: string }) => Promise<string | null> }} [opts]
* @returns {Promise<{
* version: 1, checkedAt: string, fetched: number,
* origins: Record<string, { state: "ok" | "unreachable" | "no-corpus", error?: string, generatedAt?: string | null, title?: string | null }>,
- * links: Array<{ clip: string, url: string, state: "ok" | "dead" | "unverified" | "direct", origin?: string, why?: string, fix?: string }>,
+ * links: Array<{ clip: string, url: string, state: "ok" | "dead" | "unverified" | "direct", origin?: string, why?: string, fix?: string, fixSiteVideo?: string }>,
* }>}
*/
export async function checkLinks(
links,
- { fetchImpl = globalThis.fetch, cacheDir = DEFAULT_CACHE_DIR, now = () => new Date(), log = () => {}, gapMs = LINK_GAP_MS, sleep = (ms) => new Promise((r) => setTimeout(r, ms)) } = {},
+ { fetchImpl = globalThis.fetch, cacheDir = DEFAULT_CACHE_DIR, now = () => new Date(), log = () => {}, gapMs = LINK_GAP_MS, sleep = (ms) => new Promise((r) => setTimeout(r, ms)), siteIdOf = null } = {},
) {
let fetched = 0;
/** host -> when its last request was sent (ms) */
@@ -215,12 +227,18 @@ export async function checkLinks(
if (page === undefined) {
// The Twitch trap: the corpus directory is the bare id, the site's record is `v<id>`.
const alt = /^\d+$/.test(a.id) && s2p[`v${a.id}`] !== undefined ? `v${a.id}` : null;
+ // The Rumble trap: the corpus directory is the URL slug, the site's record the embed id (siteIdOf).
+ const embed = !alt && siteIdOf ? await siteIdOf({ clip, channel: a.channel, id: a.id }).catch(() => null) : null;
+ const rumble = embed && embed !== a.id && s2p[embed] !== undefined ? embed : null;
out.push({
clip, url, state: "dead", origin: a.origin,
why: alt
? `"${a.id}" is not a record on ${host}; the site's record is "${alt}"`
- : `"${a.id}" is not published in ${a.channel} on ${host}${origins[a.origin].generatedAt ? ` (deployed ${origins[a.origin].generatedAt.slice(0, 10)})` : ""}`,
+ : rumble
+ ? `"${a.id}" is the recording's folder (its Rumble URL slug), not a record on ${host}; the site's record is its embed id "${rumble}"`
+ : `"${a.id}" is not published in ${a.channel} on ${host}${origins[a.origin].generatedAt ? ` (deployed ${origins[a.origin].generatedAt.slice(0, 10)})` : ""}`,
...(alt ? { fix: url.replace(/([?&]v=[^&#]*?)(%2F|\/)(\d+)(?=&|#|$)/i, `$1$2v$3`) } : {}),
+ ...(rumble ? { fix: withArchiveId(url, a.id, rumble), fixSiteVideo: rumble } : {}),
});
continue;
}
@@ -243,6 +261,30 @@ export async function checkLinks(
}
/**
+ * A project's `siteIdOf` for checkLinks: the clip's recording, when the link
+ * names it as the corpus keeps it, looked up in the project's channels trees
+ * (its shadow, then the corpus behind it) for the id the archive serves
+ * (shareLine.mjs siteVideoFor: a Rumble folder's embed id).
+ * @param {string} dir
+ * @param {Record<string, any>} manifest
+ */
+export async function projectSiteIdOf(dir, manifest) {
+ const [{ channelsLayersFor, hasShadowChannels }, { siteVideoFor }] = await Promise.all([import("../projects/report.mjs"), import("./shareLine.mjs")]);
+ const layers = channelsLayersFor(dir, manifest, { shadowExists: await hasShadowChannels(dir) });
+ const byId = new Map((manifest?.timeline ?? []).filter((e) => e?.type === "clip").map((e) => [e.id, e]));
+ return async ({ clip, id }) => {
+ const e = byId.get(clip);
+ if (!e || e.siteVideo || String(e.video) !== id) return null;
+ const slug = e.channel ?? manifest?.provenance?.channelSlug ?? null;
+ for (const d of layers) {
+ const got = await siteVideoFor({ channelsDir: d, slug, video: id });
+ if (got) return got;
+ }
+ return null;
+ };
+}
+
+/**
* Check the project's links now and record the answer in out/links.json.
*
* @param {string} dir
@@ -250,7 +292,7 @@ export async function checkLinks(
* @param {{ fetchImpl?: typeof fetch, cacheDir?: string | null, now?: () => Date, log?: (s: string) => void }} [opts]
*/
export async function runLinkCheck(dir, manifest, opts = {}) {
- const doc = await checkLinks(linksOf(manifest), opts);
+ const doc = await checkLinks(linksOf(manifest), { siteIdOf: await projectSiteIdOf(dir, manifest), ...opts });
const file = linksFile(dir);
await mkdir(path.dirname(file), { recursive: true });
const tmp = `${file}.tmp-${process.pid}`;
diff --git a/umtool/lib/report/linksCli.mjs b/umtool/lib/report/linksCli.mjs
@@ -82,6 +82,15 @@ export async function linksCommand(args, { root = REPORTS_ROOT, out = (s) => con
if (flags.has("--fix")) {
for (const l of doc.links) {
if (l.state !== "dead" || !l.fix) continue;
+ // A Rumble folder id (linkCheck.mjs siteIdOf): the clip names the embed id the archive serves (`siteVideo`),
+ // and a citeUrl that was the dead link moves with it; a QR built from the moment needs nothing else.
+ if (l.fixSiteVideo) {
+ const e = (m.timeline ?? []).find((x) => x?.id === l.clip);
+ const patch = { siteVideo: l.fixSiteVideo, ...(e?.citeUrl === l.url ? { citeUrl: l.fix } : {}) };
+ await withEditNotes(project, () => updateClip(project.dir, l.clip, patch));
+ fixed.push({ clip: l.clip, from: l.url, to: l.fix, siteVideo: l.fixSiteVideo });
+ continue;
+ }
await withEditNotes(project, () => updateClip(project.dir, l.clip, { citeUrl: l.fix }));
fixed.push({ clip: l.clip, from: l.url, to: l.fix });
}
@@ -95,7 +104,7 @@ export async function linksCommand(args, { root = REPORTS_ROOT, out = (s) => con
out(JSON.stringify({ ok: dead === 0, project: project.id, ...doc, ...(flags.has("--fix") ? { fixed } : {}) }, null, 2));
return dead ? 1 : 0;
}
- for (const f of fixed) out(`fixed ${f.clip}: ${f.from} -> ${f.to}`);
+ for (const f of fixed) out(`fixed ${f.clip}: ${f.from} -> ${f.to}${f.siteVideo ? ` (siteVideo ${f.siteVideo}: the Rumble embed id)` : ""}`);
out(`${project.id} · ${linksSummary(doc)}`);
out(`recorded in out/links.json (umtool check ${project.id} reads it)`);
return dead ? 1 : 0;
diff --git a/umtool/lib/report/manifest.mjs b/umtool/lib/report/manifest.mjs
@@ -455,6 +455,16 @@ export function patchClipEntry(manifest, clipId, patch, { edit = "trim", now = n
}
}
+ // The id the ARCHIVE serves the recording under, when it is not the clip's
+ // `video` (a Rumble URL-slug directory's embed id: shareLine.mjs siteVideoFor,
+ // `umtool links --fix`). Empty removes it.
+ if (patch.siteVideo !== undefined) {
+ const v = String(patch.siteVideo ?? "").trim();
+ if (!v) delete entry.siteVideo;
+ else if (!/^[A-Za-z0-9._-]{1,128}$/.test(v)) throw new Error(`siteVideo must be a recording id (letters, digits, . _ -), not \`${v}\``);
+ else entry.siteVideo = v;
+ }
+
// ---- the CUT, inside the extent ------------------------------------------
//
// `start`/`end` is the reviewed EXTENT -- how much of this recording is
diff --git a/umtool/lib/report/shareLine.mjs b/umtool/lib/report/shareLine.mjs
@@ -0,0 +1,107 @@
+// THE SHARE LINE (lane output-modes): what a person pastes when they share a
+// clip -- the recording's own page at the moment (`watchUrlAt`, the link
+// policy's rule: YouTube `t=<s>s`, Twitch `t=<h>h<m>m<s>s`, Rumble
+// `start=<s>`, else `t=<s>`, over the record's webpage_url), and its moment on
+// the archive (`archiveMomentUrl`, site-links.mjs: the corner QR's and the
+// deck's). The moment is the first second the clip plays (its cut, else its
+// start), floored.
+//
+// RUMBLE'S TWO IDS: a channel downloaded from page URLs keeps a recording
+// under its URL SLUG while the archive serves the EMBED id. `siteVideoFor`
+// (common videoDir-server.mjs recordIdOfVideoDir: the directory's
+// metadata.info.json `id`) is the ONE mapping, and its three callers are this
+// line, `umtool links --fix` (linkCheck.mjs: a Rumble QR naming the folder id
+// is fixed to the embed id) and `umtool timeline insert <rumble-ch>/<folder>`
+// (timelineCli.mjs insertClip: the clip is written with its `siteVideo`). A
+// clip that pins `siteVideo` already is never looked up.
+//
+// Plain ESM: the CLI runs it under bare node; the app's share-line route too.
+import { recordIdOfVideoDir, resolveVideoDirId } from "yt-dlp-transcript-common/lib/videoDir-server.mjs";
+import { watchUrlAt } from "yt-dlp-transcript-common/lib/clips/assist.mjs";
+import { archiveMomentUrl } from "umtool-report-to-video/site-links";
+import { webpageReader } from "./linkPolicy.mjs";
+
+const fin = (v) => typeof v === "number" && Number.isFinite(v);
+
+/**
+ * The archive's id for `<slug>/<video>` when it is NOT the id the corpus keeps
+ * it under (a Rumble URL-slug directory: its embed id), else null. `video` may
+ * be either id: an embed id finds its directory first (resolveVideoDirId).
+ * @param {{ channelsDir: string | null, slug: string | null, video: string | null }} o
+ * @returns {Promise<string | null>}
+ */
+export async function siteVideoFor({ channelsDir, slug, video }) {
+ if (!channelsDir || !slug || !video) return null;
+ const dir = await resolveVideoDirId(channelsDir, slug, String(video)).catch(() => String(video));
+ const id = await recordIdOfVideoDir(channelsDir, slug, dir).catch(() => dir);
+ return id !== String(video) ? id : null;
+}
+
+/** The second a clip's share line opens at: the first it plays, floored. */
+export const shareSecondOf = (e) => Math.max(0, Math.floor(Number(fin(e?.cutStart) ? e.cutStart : e?.start) || 0));
+
+/** The line itself: the platform's page, then the archive's moment (either may be missing). */
+export function shareLineText({ platform = null, archive = null } = {}) {
+ return [platform, archive ? `archive: ${archive}` : null].filter(Boolean).join(" · ");
+}
+
+/**
+ * A clip's share line. Pure over its readers: `webpageOf(slug, video)` (the
+ * record's webpage_url) and `siteVideoOf(slug, video)` (the archive's id, or
+ * null when it is the clip's own).
+ *
+ * @param {Record<string, any>} manifest
+ * @param {Record<string, any>} entry a clip
+ * @param {{ origin?: string | null, webpageOf?: (slug: string, video: string) => Promise<string | null>, siteVideoOf?: (slug: string, video: string) => Promise<string | null> }} [o]
+ * @returns {Promise<{ clip: string, seconds: number, platform: string | null, archive: string | null, text: string }>}
+ */
+export async function shareLineOf(manifest, entry, { origin = undefined, webpageOf = async () => null, siteVideoOf = async () => null } = {}) {
+ if (entry?.type !== "clip") throw new Error(`${entry?.id ?? "?"} is not a clip: a share line is a clip's`);
+ const seconds = shareSecondOf(entry);
+ const slug = entry.channel ?? manifest?.provenance?.channelSlug ?? null;
+ const video = entry.video == null ? null : String(entry.video);
+ const platform = slug && video ? watchUrlAt(await webpageOf(slug, video), seconds) : null;
+ const site = origin !== undefined ? origin : manifest?.provenance?.siteOrigin;
+ let archive = null;
+ if (typeof site === "string" && /^https?:\/\//i.test(site.trim()) && slug && video) {
+ const siteVideo = entry.siteVideo ?? (await siteVideoOf(slug, video));
+ archive = archiveMomentUrl({ ...entry, channel: slug, ...(siteVideo ? { siteVideo } : {}) }, manifest?.provenance, seconds, { origin: site.trim().replace(/\/+$/, "") });
+ }
+ return { clip: String(entry.id), seconds, platform, archive, text: shareLineText({ platform, archive }) };
+}
+
+/**
+ * The share line of a clip of a project's cut (or a take's): the clip named,
+ * else the cut's first clip. The readers are the project's channels trees
+ * (its shadow first, then the corpus behind it).
+ *
+ * @param {{ id: string, dir: string }} project
+ * @param {{ take?: string | null, clip?: string | null, manifest?: Record<string, any> | null, origin?: string | null }} [o]
+ */
+export async function projectShareLine(project, { take = null, clip = null, manifest = null, origin = undefined } = {}) {
+ const { readManifest, channelsLayersFor, hasShadowChannels } = await import("../projects/report.mjs");
+ let m = manifest;
+ if (!m && take) m = (await (await import("./takeManifest.mjs")).resolveTakeManifest(project.dir, take)).manifest;
+ if (!m) m = await readManifest(project.dir);
+ if (!m) throw new Error(`${project.id} has no video.manifest.json`);
+ const clips = (m.timeline ?? []).filter((e) => e?.type === "clip");
+ const entry = clip ? clips.find((e) => e.id === clip) : clips[0];
+ if (!entry) throw new Error(clip ? `no clip ${clip} in ${project.id}${take ? `'s take ${take}` : ""}` : `${project.id} has no clip to share`);
+ const layers = channelsLayersFor(project.dir, m, { shadowExists: await hasShadowChannels(project.dir) });
+ const readers = layers.map((d) => webpageReader(d));
+ const webpageOf = async (slug, video) => {
+ for (const r of readers) {
+ const u = await r(slug, video);
+ if (u) return u;
+ }
+ return null;
+ };
+ const siteVideoOf = async (slug, video) => {
+ for (const d of layers) {
+ const id = await siteVideoFor({ channelsDir: d, slug, video });
+ if (id) return id;
+ }
+ return null;
+ };
+ return shareLineOf(m, entry, { origin, webpageOf, siteVideoOf });
+}
diff --git a/umtool/lib/report/shareLine.test.mjs b/umtool/lib/report/shareLine.test.mjs
@@ -0,0 +1,116 @@
+// 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 <rumble-ch>/<folder>: 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");
+});
diff --git a/umtool/lib/report/timelineCli.mjs b/umtool/lib/report/timelineCli.mjs
@@ -447,6 +447,24 @@ export function attributionPatch(flags, convention = { deck: false, dateTitles:
}
/**
+ * The archive's id for a clip's recording when the corpus keeps it under
+ * another (a Rumble folder's embed id), looked up in the project's channels
+ * trees; null when it is the clip's own.
+ * @param {string} dir
+ * @param {Record<string, any>} manifest
+ * @param {Record<string, any>} entry
+ */
+export async function clipSiteVideo(dir, manifest, entry) {
+ const [{ channelsLayersFor, hasShadowChannels }, { siteVideoFor }] = await Promise.all([import("../projects/report.mjs"), import("./shareLine.mjs")]);
+ const slug = entry.channel ?? manifest?.provenance?.channelSlug ?? null;
+ for (const d of channelsLayersFor(dir, manifest, { shadowExists: await hasShadowChannels(dir) })) {
+ const id = await siteVideoFor({ channelsDir: d, slug, video: String(entry.video) });
+ if (id) return id;
+ }
+ return null;
+}
+
+/**
* INSERT ONE CLIP, as `timeline insert` does it: the entry (insertedClip, the
* clip it goes after lending its section, deck title and citation), written
* after `after` (insertEntry) -- or at the end of section `toSection` / after
@@ -475,6 +493,12 @@ export async function insertClip(project, manifest, clip, { after = null, at = n
} else like = insertNeighbour(tl, after, at);
// Into a section or a group the place names the section (the clip it goes after lends its field).
const entry = insertedClip(clip, like, { id, section: group !== null || toSection !== null ? null : section, lock, lockEnd });
+ // A Rumble recording named by its folder (its URL slug): the clip carries the embed id the archive serves
+ // (shareLine.mjs siteVideoFor), so its QR and its share line open the record (4 and 8 Nov: the QR named the folder id).
+ if (!entry.siteVideo && entry.video) {
+ const sv = await clipSiteVideo(project.dir, manifest, entry).catch(() => null);
+ if (sv) entry.siteVideo = sv;
+ }
const p = { ...patch };
// A deck title the clip already took from the clip before it is not a change to write.
if (p.onscreen !== undefined && JSON.stringify(p.onscreen) === JSON.stringify(entry.onscreen ?? null)) delete p.onscreen;