// WHAT A RUMBLE CHANNEL IS CREATED WITH. Rumble refuses yt-dlp without the // Firefox cookie jar and Firefox impersonation, and every working Rumble channel // carries the same three keys. They are the DEFAULT for a new Rumble channel // (2026-11-02), so a channel made from a bare Rumble URL works on its first // fetch instead of ending in a 403 nobody can explain. // // A default, never an override: a key the request SETS (a value, or "" meaning // none) is left alone. Only `--impersonate firefox` joins extra args that were // given — appended, never duplicated. import type { ChannelConfig } from "./channelConfig"; export const RUMBLE_COOKIES_FROM_BROWSER = "firefox"; export const RUMBLE_COOKIE_MODE = "always"; export const RUMBLE_IMPERSONATE_ARGS: ReadonlyArray = ["--impersonate", "firefox"]; // The prose a missing key is reported with (serviceCookies' Rumble 403 line). export const RUMBLE_NEEDS_TEXT = "Rumble needs cookies from firefox, cookieMode always and --impersonate firefox"; // What of the three keys a Rumble channel's config lacks, as short phrases. The config is the // source of truth: a channel with cookiesFromBrowser "chrome" is not missing it. export function rumbleMissingKeys( config: Pick, ): string[] { const missing: string[] = []; if (!config.cookiesFromBrowser?.trim()) missing.push("no cookiesFromBrowser"); if (config.cookieMode !== "always") missing.push(config.cookieMode ? `cookieMode ${config.cookieMode}` : "no cookieMode"); if (!hasImpersonate(config.ytdlpExtraArgs)) missing.push("no --impersonate in ytdlpExtraArgs"); return missing; } export function hasImpersonate(args: ReadonlyArray | undefined): boolean { return (args ?? []).some((a) => a === "--impersonate" || a.startsWith("--impersonate=")); } // `explicit` names the keys the request set on purpose (present, even blank). // The default fills the others. export function withRumbleDefaults( config: ChannelConfig, explicit: { cookiesFromBrowser?: boolean; cookieMode?: boolean; ytdlpExtraArgs?: boolean } = {}, ): ChannelConfig { if (config.platform !== "rumble") return config; const next: ChannelConfig = { ...config }; if (!explicit.cookiesFromBrowser && !next.cookiesFromBrowser) { next.cookiesFromBrowser = RUMBLE_COOKIES_FROM_BROWSER; } if (!explicit.cookieMode && !next.cookieMode) next.cookieMode = RUMBLE_COOKIE_MODE; if (!explicit.ytdlpExtraArgs || (next.ytdlpExtraArgs?.length ?? 0) > 0) { if (!hasImpersonate(next.ytdlpExtraArgs)) { next.ytdlpExtraArgs = [...(next.ytdlpExtraArgs ?? []), ...RUMBLE_IMPERSONATE_ARGS]; } } return next; }