// recording-ids — which recording, and how to fetch it (lane one-clock). // // TWO THINGS umtool's fetch path must decide before it asks the editor: // // 1. THE DIRECTORY ID. A manifest cites a Rumble clip by its EMBED id (the // archive's), while the corpus names the video's directory for the URL // slug. Asked by the embed id, the editor looked in a `data//` that // does not exist: no saved video, no metadata, the URL guessed as the embed // page (6 Nov: a 403), persist-videos "unknown". common's resolveVideoDirId // maps the two through the channel's metadata (videoDir-server.mjs); this // asks it HERE, on the corpus this checkout reads, so every request names // the directory — whichever editor build answers. // // 2. WHOLE OR WINDOW. A clip on a whole-recording platform // (settings.clips.wholeRecordingPlatforms, default ["rumble"]) is never a // remote seek: it goes through fetch-windows, which saves the whole // recording once, measures its clock and cuts the window from it. A remote // Rumble seek put the picture 1–4 s off the sound, and the 6 Nov windows // played words 13 s away from their cues. // // Plain ESM for bare node (fetch-via-editor.mjs, lib/report/fetchWindows.mjs). import { readFileSync } from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; import { readChannelPlatform, resolveVideoDirId } from "yt-dlp-transcript-common/lib/videoDir-server.mjs"; import { detectPlatform } from "yt-dlp-transcript-common/lib/detectPlatform.mjs"; const REPO_ROOT = path.resolve(/* turbopackIgnore: true */ path.dirname(/* turbopackIgnore: true */ fileURLToPath(import.meta.url)), "..", ".."); /** The default when settings.json says nothing (common/lib/clipSettings.ts DEFAULT_CLIPS_SETTINGS). */ export const DEFAULT_WHOLE_RECORDING_PLATFORMS = Object.freeze(["rumble"]); /** The corpus whose directories the ids are resolved in: CHANNELS_DIR, else the checkout's. */ export function corpusChannelsDir(env = process.env) { return env.CHANNELS_DIR ?? path.join(/* turbopackIgnore: true */ REPO_ROOT, "transcripts", "channels"); } /** * settings.json's `clips.wholeRecordingPlatforms` (the editor's file: SETTINGS_FILE, * else the checkout's), normalized as clipSettings.ts does; the default when the * file or the key is absent. * @param {string} [file] * @returns {string[]} */ export function wholeRecordingPlatforms(file = process.env.SETTINGS_FILE ?? path.join(/* turbopackIgnore: true */ REPO_ROOT, "settings.json")) { let raw; try { raw = JSON.parse(readFileSync(file, "utf8"))?.clips?.wholeRecordingPlatforms; } catch { raw = undefined; } if (!Array.isArray(raw)) return [...DEFAULT_WHOLE_RECORDING_PLATFORMS]; const out = []; for (const p of raw) { const v = String(p ?? "").trim().toLowerCase(); if (v && !out.includes(v)) out.push(v); } return out; } /** * The directory id the corpus keeps a cited recording under (a Rumble embed id * → its URL slug's directory); the id itself when the corpus is not here or * names no other. * @param {{ channelsDir?: string, slug: string, id: string }} a */ export async function localVideoId({ channelsDir = corpusChannelsDir(), slug, id }) { if (!slug || !id) return id; try { return await resolveVideoDirId(channelsDir, slug, String(id)); } catch { return id; } } /** * The platform a clip's recording is on: its channel's (config.json, on this * corpus), else its own page URL's host. Null for neither. * @param {{ channelsDir?: string, slug: string, webpageUrl?: string | null }} a */ export async function recordingPlatform({ channelsDir = corpusChannelsDir(), slug, webpageUrl = null }) { const own = slug ? await readChannelPlatform(channelsDir, slug) : null; if (own) return String(own).toLowerCase(); const fromUrl = webpageUrl ? detectPlatform(webpageUrl) : null; return fromUrl ? String(fromUrl).toLowerCase() : null; } /** * Is this clip's recording one whose windows are cut from the whole recording? * @param {{ channelsDir?: string, slug: string, webpageUrl?: string | null, platforms?: string[] }} a */ export async function isWholeRecording({ channelsDir = corpusChannelsDir(), slug, webpageUrl = null, platforms = wholeRecordingPlatforms() }) { const p = await recordingPlatform({ channelsDir, slug, webpageUrl }); return !!p && platforms.includes(p); } /** * fetch-windows items with each `id` resolved to its directory id, and the ids * that changed (`{slug, cited, dir}`, once each) for the log. The editor's * route refuses an unknown item key, so the cited id travels beside, not in. * @template {{ slug: string, id: string }} I * @param {I[]} items * @param {{ channelsDir?: string }} [opts] * @returns {Promise<{ items: I[], mapped: { slug: string, cited: string, dir: string }[] }>} */ export async function withLocalIds(items, { channelsDir = corpusChannelsDir() } = {}) { const memo = new Map(); const out = []; const mapped = []; for (const it of items) { const key = `${it.slug}\u0000${it.id}`; if (!memo.has(key)) { const dir = await localVideoId({ channelsDir, slug: it.slug, id: it.id }); memo.set(key, dir); if (dir && dir !== it.id) mapped.push({ slug: it.slug, cited: it.id, dir }); } const dirId = memo.get(key); out.push(dirId && dirId !== it.id ? { ...it, id: dirId } : it); } return { items: out, mapped }; } /** "the-quartering-rumble/v7drc5w → v7fxp3e, …" */ export const mappedLine = (mapped) => mapped.map((m) => `${m.slug}/${m.cited} → ${m.dir}`).join(", ");