commit d682870141d9237ef20f23100baa3d332f0ed8cb
parent ca1330dfcb5d08a5084c9711159590a75a29fd34
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Fri, 6 Nov 2026 21:06:45 -0500
common: a Rumble embed id resolves to its URL-slug directory (resolveVideoDirId)
The archive and every manifest cite a Rumble video by its EMBED id (yt-dlp's
`id`, v7drc5w); a channel downloaded from its page URLs names the directory
for the URL slug (v7fxp3e). Asked by the embed id, every fetch went to a
data/<embed>/ that did not exist: no saved video, no metadata, the URL guessed
as the embed page (6 Nov: c43's re-fetch got a Rumble 403), persist-videos
"unknown". On a Rumble channel an id with no directory of its own is now
looked up in the channel's metadata (the head of each metadata.info.json,
indexed once per process, grown when data/ changes); unknown ids stay as they
are, and no other platform's id is guessed at. Checked read-only against the
corpus: all 26 cited embed ids of 6 Nov map to the slug dirs persist-videos
was given by hand (6.5 s to index 8,169 dirs cold, then instant).
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Diffstat:
2 files changed, 179 insertions(+), 8 deletions(-)
diff --git a/common/lib/videoDir-server.mjs b/common/lib/videoDir-server.mjs
@@ -3,11 +3,135 @@
// (b)). Plain JS for umtool's bare-node scripts; server-only (node:fs). It
// never computes a path from the cwd: every root arrives as an argument.
-import { readFileSync, statSync } from "node:fs";
-import { readFile, stat } from "node:fs/promises";
+import { closeSync, openSync, readdirSync, readFileSync, readSync, statSync } from "node:fs";
+import { open, readdir, readFile, stat } from "node:fs/promises";
import path from "node:path";
import { channelConfigPlatform, pickVideoDirId, twitchVodDirId } from "./videoDirId.mjs";
+// ---- Rumble's two ids (lane one-clock) -----------------------------------------
+//
+// A Rumble video has two ids (AGENTS.md). yt-dlp's `id` — what the archive
+// serves, what every report and manifest cites — is the EMBED id (`v7drc5w`);
+// a channel downloaded from its page URLs names the DIRECTORY for the URL slug
+// (`v7fxp3e`, from https://rumble.com/v7fxp3e-title.html). An embed id has no
+// directory, so every fetch asked by it went to a `data/<embed>/` that did not
+// exist: no saved video found, no metadata, the URL guessed as the embed page
+// (a 403 on 6 Nov), the persist "unknown". So on a RUMBLE channel an id with
+// no directory of its own is looked up in the channel's metadata: the
+// directory whose metadata.info.json `id` is that id. The index is built once
+// per process from the head of each file (yt-dlp writes `id` first) and grows
+// by the directories it has not read when `data/` changes; an id it does not
+// know stays as it is.
+
+const RUMBLE_ID_RE = /^v[0-9a-z]{4,9}$/;
+const HEAD_BYTES = 512;
+const ID_IN_HEAD_RE = /"id"\s*:\s*"([^"]+)"/;
+
+/** @type {Map<string, { mtimeMs: number, seen: Set<string>, byId: Map<string, string> }>} */
+const rumbleIndexes = new Map();
+
+/** @param {string} head @returns {string | null} */
+function idOfHead(head) {
+ const m = ID_IN_HEAD_RE.exec(head);
+ return m ? m[1] : null;
+}
+
+/** @param {string} file */
+async function readHead(file) {
+ let fh;
+ try {
+ fh = await open(file, "r");
+ const buf = Buffer.alloc(HEAD_BYTES);
+ const { bytesRead } = await fh.read(buf, 0, HEAD_BYTES, 0);
+ return buf.subarray(0, bytesRead).toString("utf8");
+ } catch {
+ return "";
+ } finally {
+ await fh?.close().catch(() => {});
+ }
+}
+
+/** @param {string} file */
+function readHeadSync(file) {
+ let fd = -1;
+ try {
+ fd = openSync(file, "r");
+ const buf = Buffer.alloc(HEAD_BYTES);
+ const n = readSync(fd, buf, 0, HEAD_BYTES, 0);
+ return buf.subarray(0, n).toString("utf8");
+ } catch {
+ return "";
+ } finally {
+ if (fd >= 0) closeSync(fd);
+ }
+}
+
+/**
+ * The directory of a Rumble channel holding the record `id` (its embed id), or
+ * null when no directory's metadata names it.
+ * @param {string} dataDir
+ * @param {string} id
+ * @returns {Promise<string | null>}
+ */
+export async function rumbleDirIdByMetadata(dataDir, id) {
+ let st;
+ try {
+ st = await stat(dataDir);
+ } catch {
+ return null;
+ }
+ let idx = rumbleIndexes.get(dataDir);
+ if (!idx) {
+ idx = { mtimeMs: -1, seen: new Set(), byId: new Map() };
+ rumbleIndexes.set(dataDir, idx);
+ }
+ if (idx.mtimeMs !== st.mtimeMs) {
+ const names = await readdir(dataDir).catch(() => /** @type {string[]} */ ([]));
+ for (const name of names) {
+ if (idx.seen.has(name)) continue;
+ idx.seen.add(name);
+ const metaId = idOfHead(await readHead(path.join(/* turbopackIgnore: true */ dataDir, name, "metadata.info.json")));
+ if (metaId && metaId !== name && !idx.byId.has(metaId)) idx.byId.set(metaId, name);
+ }
+ idx.mtimeMs = st.mtimeMs;
+ }
+ return idx.byId.get(id) ?? null;
+}
+
+/**
+ * `rumbleDirIdByMetadata`, synchronously.
+ * @param {string} dataDir
+ * @param {string} id
+ * @returns {string | null}
+ */
+export function rumbleDirIdByMetadataSync(dataDir, id) {
+ let st;
+ try {
+ st = statSync(dataDir);
+ } catch {
+ return null;
+ }
+ let idx = rumbleIndexes.get(dataDir);
+ if (!idx) {
+ idx = { mtimeMs: -1, seen: new Set(), byId: new Map() };
+ rumbleIndexes.set(dataDir, idx);
+ }
+ if (idx.mtimeMs !== st.mtimeMs) {
+ let names = /** @type {string[]} */ ([]);
+ try {
+ names = readdirSync(dataDir);
+ } catch {}
+ for (const name of names) {
+ if (idx.seen.has(name)) continue;
+ idx.seen.add(name);
+ const metaId = idOfHead(readHeadSync(path.join(/* turbopackIgnore: true */ dataDir, name, "metadata.info.json")));
+ if (metaId && metaId !== name && !idx.byId.has(metaId)) idx.byId.set(metaId, name);
+ }
+ idx.mtimeMs = st.mtimeMs;
+ }
+ return idx.byId.get(id) ?? null;
+}
+
/** @param {string} p */
async function isDir(p) {
try {
@@ -36,8 +160,10 @@ export async function readChannelPlatform(channelsDir, slug) {
/**
* The directory id a record lives in, on this disk. Only a `v<digits>` id
- * costs a read (the channel's config when no platform is given, and two
- * stats); every other id is returned as it is.
+ * (Twitch) or a Rumble-shaped `v<5-10 of a-z0-9>` id costs a read (the
+ * channel's config when no platform is given, then stats; a Rumble embed id
+ * with no directory, the channel's metadata index); every other id is returned
+ * as it is.
* @param {string} channelsDir
* @param {string} slug
* @param {string} recordId
@@ -46,9 +172,15 @@ export async function readChannelPlatform(channelsDir, slug) {
* @returns {Promise<string>}
*/
export async function resolveVideoDirId(channelsDir, slug, recordId, opts = {}) {
- if (twitchVodDirId(recordId) === null) return recordId;
+ const rumbleShaped = RUMBLE_ID_RE.test(recordId);
+ if (twitchVodDirId(recordId) === null && !rumbleShaped) return recordId;
const platform = opts.platform !== undefined ? opts.platform : await readChannelPlatform(channelsDir, slug);
- if (platform !== "twitch") return recordId;
+ if (platform === "rumble" && rumbleShaped) {
+ const dataDir = path.join(/* turbopackIgnore: true */ channelsDir, slug, "data");
+ if (await isDir(path.join(/* turbopackIgnore: true */ dataDir, recordId))) return recordId;
+ return (await rumbleDirIdByMetadata(dataDir, recordId)) ?? recordId;
+ }
+ if (platform !== "twitch" || twitchVodDirId(recordId) === null) return recordId;
const dataDir = path.join(/* turbopackIgnore: true */ channelsDir, slug, "data");
const n = /** @type {string} */ (twitchVodDirId(recordId));
const [hasN, hasV] = await Promise.all([
@@ -97,7 +229,8 @@ function isDirSync(p) {
* @returns {string}
*/
export function resolveVideoDirIdSync(channelsDir, slug, recordId, opts = {}) {
- if (twitchVodDirId(recordId) === null) return recordId;
+ const rumbleShaped = RUMBLE_ID_RE.test(recordId);
+ if (twitchVodDirId(recordId) === null && !rumbleShaped) return recordId;
let platform = opts.platform;
if (platform === undefined) {
try {
@@ -108,7 +241,12 @@ export function resolveVideoDirIdSync(channelsDir, slug, recordId, opts = {}) {
platform = null;
}
}
- if (platform !== "twitch") return recordId;
+ if (platform === "rumble" && rumbleShaped) {
+ const dataDir = path.join(/* turbopackIgnore: true */ channelsDir, slug, "data");
+ if (isDirSync(path.join(/* turbopackIgnore: true */ dataDir, recordId))) return recordId;
+ return rumbleDirIdByMetadataSync(dataDir, recordId) ?? recordId;
+ }
+ if (platform !== "twitch" || twitchVodDirId(recordId) === null) return recordId;
const dataDir = path.join(/* turbopackIgnore: true */ channelsDir, slug, "data");
return pickVideoDirId(recordId, {
platform,
diff --git a/common/lib/videoDirId.test.ts b/common/lib/videoDirId.test.ts
@@ -113,3 +113,36 @@ test("the synchronous resolver gives the same answers (release 23 F1b)", () => {
const yt = channel("yt-sync", { handling: "youtube", platform: "youtube" }, [N]);
assert.equal(resolveVideoDirIdSync(yt, "yt-sync", `v${N}`), `v${N}`);
});
+
+// RUMBLE'S TWO IDS (lane one-clock): a manifest cites the EMBED id, the
+// directory is named for the URL slug; on a Rumble channel the embed id is
+// found through the directory's metadata.info.json `id`.
+test("a Rumble embed id resolves to the URL-slug directory whose metadata names it", async () => {
+ const root = mkdtempSync(path.join(tmpdir(), "rumble-ids-"));
+ try {
+ const data = path.join(root, "rc", "data");
+ mkdirSync(path.join(data, "v7fxp3e"), { recursive: true });
+ writeFileSync(path.join(root, "rc", "config.json"), JSON.stringify({ platform: "rumble", url: "https://rumble.com/c/X" }));
+ writeFileSync(
+ path.join(data, "v7fxp3e", "metadata.info.json"),
+ JSON.stringify({ id: "v7drc5w", title: "t", webpage_url: "https://rumble.com/v7fxp3e-t.html" }),
+ );
+ assert.equal(await resolveVideoDirId(root, "rc", "v7drc5w"), "v7fxp3e");
+ assert.equal(resolveVideoDirIdSync(root, "rc", "v7drc5w"), "v7fxp3e");
+ assert.equal(await resolveVideoDir(root, "rc", "v7drc5w"), path.join(data, "v7fxp3e"));
+ // 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");
+ // 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" }));
+ assert.equal(await resolveVideoDirId(root, "rc", "v7eqa6e"), "v7gwn3w");
+ assert.equal(resolveVideoDirIdSync(root, "rc", "v7eqa6e"), "v7gwn3w");
+ // Not a Rumble channel: never guessed at.
+ writeFileSync(path.join(root, "rc", "config.json"), JSON.stringify({ platform: "youtube" }));
+ assert.equal(await resolveVideoDirId(root, "rc", "v7drc5w"), "v7drc5w");
+ assert.equal(await resolveVideoDirId(root, "rc", "v7drc5w", { platform: "rumble" }), "v7fxp3e");
+ } finally {
+ rmSync(root, { recursive: true, force: true });
+ }
+});