// A CLIP WINDOW FROM THE STORED MEDIA URL (release 32 R5). // // Odysee answers 429 to yt-dlp's page/API lookup (`[lbry] … HTTP Error 429`) on // the first request of a run, hours apart, with cookies — and a fetch-windows job // then stops and the platform is held. But every Odysee record's // metadata.info.json already names its media: ONE format whose `url` is on the // platform's CDN (`player.odycdn.com`), a different endpoint from the lookup. The // operator approved cutting a window from that URL instead, for this case, opt-in // per request (`storedUrl` on a fetch-windows body): // // never the default: nothing changes. // fallback the page first, as always; on a rate limit (or a held / cooling // platform) the window is cut from the stored URL. // only straight to the stored URL: no page or API request at all. // // TRUSTED ONLY ON A NAMED ALLOWLIST. A stored URL is a string a platform handed // yt-dlp months ago; fetching it bypasses the extractor. So it is used only for a // platform in STORED_URL_PLATFORMS, only on that platform's CDN hosts, only when // the record names exactly one http(s) format (or none and a top-level `url`) — // never a manifest, never a host off the list, never credentials in the URL. // // Pure: the reader of the file is storedMediaUrl-server.ts. import { detectPlatform } from "./platform"; export const STORED_URL_MODES = ["never", "fallback", "only"] as const; export type StoredUrlMode = (typeof STORED_URL_MODES)[number]; export function isStoredUrlMode(v: unknown): v is StoredUrlMode { return (STORED_URL_MODES as readonly unknown[]).includes(v); } export const STORED_URL_PLATFORMS = ["odysee"] as const; export type StoredUrlPlatform = (typeof STORED_URL_PLATFORMS)[number]; export function isStoredUrlPlatform(v: unknown): v is StoredUrlPlatform { return (STORED_URL_PLATFORMS as readonly unknown[]).includes(v); } // THE UI'S WORDS (release 32 R6): every surface that offers the stored URL — the // editor's Fetch missing evidence, umtool's Fetch clip and the benches — says it // with this label and this help, and asks with STORED_URL_UI_MODE. A person's // tick asks "fallback": the page first, as always, and the stored file only when // the platform refuses the lookup (or is held or cooling down) — so ticking it // for a platform that is answering changes nothing. `only` stays for the CLI and // the MCP, which can say why they skip the page. export const STORED_URL_LABEL = "Cut from the stored media URL"; export const STORED_URL_UI_MODE: StoredUrlMode = "fallback"; const PLATFORM_NAMES: Readonly> = { odysee: "Odysee" }; export const STORED_URL_HELP = `${STORED_URL_PLATFORMS.map((p) => PLATFORM_NAMES[p]).join(", ")} only. When the platform refuses ` + "the page lookup (a rate limit, or it is on hold), the seconds are cut straight from the video file " + "address the archive saved with the record, the way the platform's own player reads it. " + "Off: the page is asked as usual, and a refusal stops the fetch."; // Per platform: which hosts are its CDN, and the Referer its player sends (the // stored format's own `http_headers.Referer`, pinned here rather than read from // the file). const CDN: Readonly boolean; referer: string }>> = { odysee: { host: (h) => h.endsWith(".odycdn.com"), referer: "https://odysee.com/" }, }; export type StoredMediaUrl = { url: string; host: string; platform: StoredUrlPlatform; referer: string; }; // Why a window was cut from the stored URL: the page lookup rate-limited (this // run, or a cooldown), the platform is held, or the request said `only`. export type StoredUrlWhy = "rate-limited" | "held" | "only"; // The browser user agent a stored media URL is read with: the player's, not // yt-dlp's (release 32). Shared by the clip cut (ytdlp/fetchWindowManaged.ts) // and the whole-file ranged download (ytdlp/storedUrlDownload.ts). Since the // derived Firefox UA (2026-10-31) this is only the FALLBACK, for a machine with // no Firefox: storedMediaUserAgent() (storedMediaUrl-server.ts) sends this // machine's Firefox, which stays current where this Chrome 141 ages. Nothing // required Chrome — the 2026-10-16 measurement needed "a browser user agent"; // no cookies go with these reads, so it need not match a cookie jar either. export const STORED_MEDIA_USER_AGENT = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36"; // The headers the platform's own player sends with a read of its CDN: the page's // Referer and Origin and a browser user agent. No cookies, no token. export function storedMediaHeaders( stored: Pick, userAgent: string = STORED_MEDIA_USER_AGENT, ): Record { return { "User-Agent": userAgent, Referer: stored.referer, Origin: new URL(stored.referer).origin, Accept: "*/*", }; } // A WHOLE FILE FROM THE STORED URL (release 32 R7, ytdlp/storedUrlDownload.ts): // Odysee's CDN serves the player's ranged reads of a file, but allows ONE new // original file per platform after a rest (measured 2026-10-16: the next, a // minute later, answered 429). So two stored-URL downloads on one platform are // at least this far apart — the batch waits rather than 429s. Kept in the // platform pacing state (jobs/platformGap.ts) under storedUrlGapKey. export const STORED_URL_NEW_FILE_GAP_MS = 20 * 60_000; export function storedUrlGapKey(platform: string): string { return `stored-url:${platform}`; } // The mode a download runs with: the request's, else the channel's // `storedUrlDownloads`, else never. export function resolveStoredUrlMode( request: StoredUrlMode | undefined, channel: StoredUrlMode | undefined, ): StoredUrlMode { return request ?? channel ?? "never"; } export function storedUrlWhyText(why: StoredUrlWhy, platform: string): string { if (why === "only") return "(asked: only)"; return `— ${platform} lookup ${why === "held" ? "held" : "rate-limited"}`; } const DIRECT_PROTOCOLS = new Set(["http", "https"]); function directUrl(raw: unknown, protocol: unknown): URL | null { if (typeof raw !== "string") return null; // yt-dlp's `protocol` names how the format is fetched: anything but a plain // http(s) GET (m3u8, dash, …) is not "one direct file". if (protocol !== undefined && !(typeof protocol === "string" && DIRECT_PROTOCOLS.has(protocol))) { return null; } let u: URL; try { u = new URL(raw); } catch { return null; } if (u.protocol !== "https:" && u.protocol !== "http:") return null; if (u.username || u.password) return null; return u; } // The stored media URL of a record's parsed metadata.info.json, or null. export function storedMediaUrlFromInfo(info: unknown): StoredMediaUrl | null { if (!info || typeof info !== "object" || Array.isArray(info)) return null; const r = info as Record; const page = typeof r.webpage_url === "string" ? r.webpage_url : typeof r.original_url === "string" ? r.original_url : null; const platform = page ? detectPlatform(page) : null; if (!isStoredUrlPlatform(platform)) return null; let u: URL | null; if (Array.isArray(r.formats) && r.formats.length > 0) { // A SINGLE FORMAT: more than one is a ladder of variants, and picking among // them is the extractor's job. if (r.formats.length !== 1) return null; const f = r.formats[0] as Record | null; if (!f || typeof f !== "object") return null; u = directUrl(f.url, f.protocol); } else { u = directUrl(r.url, r.protocol); } if (!u) return null; const host = u.hostname.toLowerCase(); const cdn = CDN[platform]; if (!cdn.host(host)) return null; return { url: u.href, host, platform, referer: cdn.referer }; }