// settings.clips — how clip windows are fetched (controller/fetchWindows.ts). // Pure: the type, its defaults, the sanitizer settingsSchema.ts runs it through // and the per-field docs SETTINGS.md renders. import type { FieldDocs } from "./fieldDocs"; export type ClipsSettings = { wholeRecordingPlatforms: string[]; windowMaxHeight: number; }; // THE TALLEST A CLIP WINDOW MAY BE ASKED FOR (lib/clipWindow.ts, the height // tier). A CEILING, not a default: a request that names no `maxHeight` is cut // and fetched at 720 as it always was, and one that names more is clamped to // this. Bounds are the fetch cap's own (MIN/MAX_FETCH_MAX_HEIGHT). export const DEFAULT_WINDOW_MAX_HEIGHT = 1080; const WINDOW_MAX_HEIGHT_MIN = 144; const WINDOW_MAX_HEIGHT_MAX = 2160; // RUMBLE BY DEFAULT, on the evidence (2026-10-23): a window cut by a remote // seek into Rumble's HLS came out with its picture 1–4 s off its sound 26 times // in 205; a cut from the saved whole recording measured exactly in sync. One // whole download per video is also fewer requests to Rumble than a window // fetch per clip. export const DEFAULT_CLIPS_SETTINGS: ClipsSettings = { wholeRecordingPlatforms: ["rumble"], windowMaxHeight: DEFAULT_WINDOW_MAX_HEIGHT, }; export const CLIPS_SETTINGS_FIELD_DOCS: FieldDocs = { wholeRecordingPlatforms: "Platforms (as the URL names them: \"rumble\", \"youtube\", …) whose clip windows are cut from the WHOLE " + "recording instead of fetched by a remote seek: a fetch-windows run saves the video once to the saved-video " + "store (as \"Persist source video\" does, on the platform's download queue) and cuts every window of it " + "locally. A failed whole download fails its windows; it never falls back to a seek. A run's " + "`\"wholeRecording\": false` restores the seek for that run. Default [\"rumble\"] (a Rumble seek put the " + "picture 1–4 s off the sound in 26 of 205 windows); [] = every platform seeks.", windowMaxHeight: "The tallest source height, in pixels, a clip-window request may ask for (`maxHeight` on fetch-window, " + "fetch-windows, fetch_clip; umtool sends its project's `render.maxHeightSource` only when the project has " + "`render.tallWindows` on). A CEILING, not a default: a request with no `maxHeight` is fetched and cut at 720 as " + "before, and one asking more is clamped to this. A window asked above 720 is a separate cache entry beside the " + "720 one (`-.h.mp4`, the tier the smallest of 1080, 1440, 2160 at or above the ask, held to this), " + "cut from the saved copy when there is a taller one; the 720 window and every published site's evidence media " + "are never touched. Site-driven fetches (`fetch-windows {\"siteId\"}`, Fetch missing evidence) stay at 720. " + "Default 1080; 144–2160.", }; function sanitizeWindowMaxHeight(v: unknown): number { return typeof v === "number" && Number.isInteger(v) && v >= WINDOW_MAX_HEIGHT_MIN && v <= WINDOW_MAX_HEIGHT_MAX ? v : DEFAULT_WINDOW_MAX_HEIGHT; } export function sanitizeClips(value: unknown): ClipsSettings { const r = (value && typeof value === "object" && !Array.isArray(value) ? value : {}) as Record; const windowMaxHeight = sanitizeWindowMaxHeight(r.windowMaxHeight); const raw = r.wholeRecordingPlatforms; if (!Array.isArray(raw)) { return { wholeRecordingPlatforms: [...DEFAULT_CLIPS_SETTINGS.wholeRecordingPlatforms], windowMaxHeight }; } const out: string[] = []; for (const v of raw) { if (typeof v !== "string") continue; const p = v.trim().toLowerCase(); if (p && !out.includes(p)) out.push(p); } return { wholeRecordingPlatforms: out, windowMaxHeight }; } // The ceiling in force (settings may predate the field). export function windowMaxHeightOf(clips: Partial | undefined): number { return sanitizeWindowMaxHeight(clips?.windowMaxHeight); }