// OPEN THE PLAYER'S PAGE FIRST (release 32 R7, the orchestrator's live finding // of 2026-10-17): Odysee's CDN serves a stream's original file to a connection // only AFTER a player has opened that video's page. Cold ranged reads with the // player's headers got 429 (four windows, 20–40 minutes apart); right after a // headless Chromium page view of the same video — the odysee.com page, ~10 s, // play, ~8 s — the player's own requests got 200/206 and the ranged cut landed. // How long the unlock lasts is unknown. // // So a stored-URL download opens the page before its first ranged read, and // once more on a refusal mid-file before giving up (storedUrlDownload.ts). The // opener is a named, injected step: tests pass a fake (never a browser), the // managed download passes `openPlayerPage` for a platform in // PAGE_OPEN_PLATFORMS. No cookies, a fresh context each time. import { importPlaywright } from "../social/playwrightRuntime"; import { assertNetworkAllowed } from "../lib/noNetwork.mjs"; export const PAGE_OPEN_PLATFORMS: readonly string[] = ["odysee"]; // What the measured open did: let the page load, press play, let it play. export const PAGE_OPEN_SETTLE_MS = 10_000; export const PAGE_OPEN_PLAY_MS = 8_000; export const PAGE_OPEN_GOTO_TIMEOUT_MS = 45_000; export type PageOpenResult = { ok: boolean; // The statuses of the player's own requests of the platform's CDN, in order. mediaStatuses: number[]; error?: string; }; export type PageOpener = (opts: { pageUrl: string; // The CDN host whose responses say whether the player was served. cdnHost: string; signal: AbortSignal; onLog: (s: string) => void; }) => Promise; // A wait the signal ends early (resolves, never rejects). export function abortableWait(ms: number, signal: AbortSignal): Promise { return new Promise((resolve) => { if (signal.aborted) return resolve(); const t = setTimeout(() => { signal.removeEventListener("abort", onAbort); resolve(); }, ms); const onAbort = () => { clearTimeout(t); resolve(); }; signal.addEventListener("abort", onAbort, { once: true }); }); } // The real opener: headless Chromium (the workspace's Playwright), the video's // page, a click on play, a few seconds of playing. Never throws: a page that // could not be opened is `ok: false` with the reason, and the caller reads on // regardless (the CDN may serve it anyway). export const openPlayerPage: PageOpener = async ({ pageUrl, cdnHost, signal, onLog }) => { const mediaStatuses: number[] = []; // ARCHILYZER_NO_NETWORK (lib/noNetwork.mjs), first and by name: set by every // test harness, it holds however the test file was started. try { assertNetworkAllowed("the Odysee player-page opener", pageUrl); } catch (e) { onLog(`${(e as Error).message}\n`); return { ok: false, mediaStatuses, error: (e as Error).message }; } // NEVER A BROWSER UNDER A TEST RUNNER (release 32 R9). node's runner (and // tsx --test) sets NODE_TEST_CONTEXT in every test file's process: a test // that reaches the real opener — an editor route test running the whole cut — // gets "not opened" and reads on, instead of a headless browser on the // network. Tests that exercise the open inject their own opener. if (process.env.NODE_TEST_CONTEXT) { onLog(`Not opening the player's page under a test runner (${pageUrl}).\n`); return { ok: false, mediaStatuses, error: "not opened under a test runner" }; } // Nor on the e2e server (which sets E2E_ODYSEE_PAGE_FIXTURE on every slot). if (process.env.E2E_ODYSEE_PAGE_FIXTURE) { onLog(`Not opening the player's page on the e2e server (${pageUrl}).\n`); return { ok: false, mediaStatuses, error: "not opened on the e2e server" }; } let browser: { close: () => Promise } | null = null; try { const { chromium } = await importPlaywright(); const b = await chromium.launch({ headless: true }); browser = b; const ctx = await b.newContext({}); const page = await ctx.newPage(); page.on("response", ((r: { url: () => string; status: () => number }) => { try { if (new URL(r.url()).hostname === cdnHost) mediaStatuses.push(r.status()); } catch { /* not a URL */ } }) as never); onLog(`Opening the player's page first (${pageUrl}).\n`); await page.goto(pageUrl, { waitUntil: "domcontentloaded", timeout: PAGE_OPEN_GOTO_TIMEOUT_MS }).catch(() => {}); await abortableWait(PAGE_OPEN_SETTLE_MS, signal); if (!signal.aborted) { await page .evaluate( `(() => { const b = document.querySelector(".vjs-big-play-button, [aria-label*='Play']"); if (b) { b.click(); return; } const v = document.querySelector("video"); if (v) { v.muted = true; v.play().catch(() => {}); } })()`, ) .catch(() => {}); await abortableWait(PAGE_OPEN_PLAY_MS, signal); } const served = mediaStatuses.some((s) => s === 200 || s === 206); onLog( `The player's page was open ${Math.round((PAGE_OPEN_SETTLE_MS + PAGE_OPEN_PLAY_MS) / 1000)}s; ` + `its media requests answered ${mediaStatuses.length ? mediaStatuses.join(",") : "nothing"}.\n`, ); return { ok: served, mediaStatuses, ...(served ? {} : { error: "the player's media requests were not served" }) }; } catch (err) { const error = (err as Error).message; onLog(`Could not open the player's page: ${error}\n`); return { ok: false, mediaStatuses, error }; } finally { await browser?.close().catch(() => {}); } }; // THE CLIP CUT'S PAGE STATE FOR ONE RUN (release 32 R9). A fetch-windows run // opens a video's page before the first cut of that video, and again only on // a refusal that follows a cut served since the last open (the unlock may // have lapsed) — never twice in a row: a refusal straight after an open means // the open did not unlock the file, and another will not either. Keyed by the // video's PAGE url. A run that passes none gets a fresh one per window (a // single-window job opens the page before its one cut). export type StoredPageSession = { pages: Map; opens: number; }; export function newStoredPageSession(): StoredPageSession { return { pages: new Map(), opens: 0 }; }