commit 6cd24c1cf9f4b5dd46530a79a982d0eba5f1608c
parent ce175222b293d7fc4e2175ab746b3b17252741cb
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Fri, 16 Oct 2026 20:06:21 -0400
common: a stored media URL is read the way the site's own player reads it — ffmpeg with the page's Referer and Origin and a browser user agent, an input seek so only the window's ranged bytes are fetched, a frame-accurate re-encode; no yt-dlp (its generic extractor opens the URL with one unranged GET, which Odysee's CDN answers 429 while it serves the player's ranged requests 206, measured 2026-10-16); a 429/403 from it classified as before
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Diffstat:
2 files changed, 144 insertions(+), 68 deletions(-)
diff --git a/common/controller/fetchWindowsStoredUrl.test.ts b/common/controller/fetchWindowsStoredUrl.test.ts
@@ -43,10 +43,21 @@ if (url.includes("cdn429")) fail("ERROR: [generic] x: Unable to download webpage
writeFileSync(args[args.indexOf("-o") + 1], "mp4");
`,
);
+// ffmpeg cuts a STORED URL (an http input: logged like a yt-dlp run, the URL as
+// its target; a \`cdn429\` file answers 429) and probes the window (a local
+// input: counted).
await writeFile(
FFMPEG,
`#!/usr/bin/env node
-import { appendFileSync } from "node:fs";
+import { appendFileSync, writeFileSync } from "node:fs";
+const args = process.argv.slice(2);
+const input = args[args.indexOf("-i") + 1] ?? "";
+if (input.startsWith("http")) {
+ appendFileSync(process.env.FAKE_ARGS_LOG, JSON.stringify([...args, input]) + "\\n");
+ if (input.includes("cdn429")) { process.stderr.write("[https @ 0x1] HTTP error 429 Too Many Requests\\n" + input + ": Server returned 4XX Client Error\\n"); process.exit(1); }
+ writeFileSync(args[args.length - 1], "mp4");
+ process.exit(0);
+}
appendFileSync(process.env.FAKE_PROBES, "p\\n");
process.exit(0);
`,
@@ -163,9 +174,13 @@ test("fallback: the page 429s, the window is cut from the stored CDN URL after t
const s = await since(m);
assert.deepEqual(s.targets, [page("b1"), cdn("b1")]);
const cdnArgs = s.spawned[1];
- assert.equal(cdnArgs[cdnArgs.indexOf("--add-headers") + 1], "Referer:https://odysee.com/");
- assert.match(cdnArgs[cdnArgs.indexOf("-f") + 1], /\/b$/, "the copy path's lenient selector");
- assert.equal(cdnArgs[cdnArgs.indexOf("--download-sections") + 1], "*10.00-20.00");
+ // ffmpeg, read the way the site's player reads it: the page's Referer AND Origin,
+ // a browser user agent, an input seek to the window (ranged requests), the window's length.
+ assert.equal(cdnArgs[cdnArgs.indexOf("-headers") + 1], "Referer: https://odysee.com/\r\nOrigin: https://odysee.com\r\n");
+ assert.match(cdnArgs[cdnArgs.indexOf("-user_agent") + 1], /Chrome\//);
+ assert.ok(cdnArgs.indexOf("-ss") < cdnArgs.indexOf("-i"), "an input seek: only the window's bytes are fetched");
+ assert.equal(cdnArgs[cdnArgs.indexOf("-ss") + 1], "10.00");
+ assert.equal(cdnArgs[cdnArgs.indexOf("-t") + 1], "10.00");
assert.equal(r.fetched.length, 1);
assert.deepEqual(r.storedUrl.map((i) => i.id), ["b1"]);
assert.equal(r.failed.length, 0);
diff --git a/common/ytdlp/fetchWindowManaged.ts b/common/ytdlp/fetchWindowManaged.ts
@@ -188,6 +188,36 @@ export const CORRUPT_WINDOW_ATTEMPTS = 2;
class MalformedWindowError extends Error {}
+// ffmpeg's argv for a window cut from a stored media URL (see fetchWindowOnce): the player's
+// headers, an input seek so only the window's bytes are fetched, a frame-accurate re-encode
+// (as --force-keyframes-at-cuts) capped at the clip height, faststart mp4.
+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";
+
+export function storedMediaFfmpegArgs(
+ stored: Pick<StoredMediaUrl, "url" | "referer">,
+ from: number,
+ to: number,
+ maxHeight: number,
+ out: string,
+): string[] {
+ const origin = new URL(stored.referer).origin;
+ return [
+ "-nostdin", "-hide_banner", "-v", "error", "-y",
+ "-user_agent", STORED_MEDIA_USER_AGENT,
+ "-headers", `Referer: ${stored.referer}\r\nOrigin: ${origin}\r\n`,
+ "-ss", from.toFixed(2),
+ "-i", stored.url,
+ "-t", (to - from).toFixed(2),
+ "-map", "0:v:0?", "-map", "0:a:0?",
+ "-vf", `scale=-2:'min(${maxHeight},ih)'`,
+ "-c:v", "libx264", "-preset", "veryfast", "-crf", "20",
+ "-c:a", "aac", "-b:a", "160k",
+ "-movflags", "+faststart",
+ out,
+ ];
+}
+
export async function fetchWindowManaged(
opts: FetchWindowOpts,
): Promise<FetchWindowResult> {
@@ -326,79 +356,110 @@ async function fetchWindowOnce(opts: FetchWindowOpts, attempt: number): Promise<
stored ? stored.url : opts.videoUrl,
];
- const run = async (cookies: string | undefined, retryArgs: string[] = []) =>
- runOneYtdlp(
- {
- ytdlpBin: opts.paths.ytdlpBin,
- onLog: opts.onLog,
- signal: opts.signal,
- },
+ let args: string[] = [];
+ if (stored) {
+ // A STORED MEDIA URL IS READ THE WAY THE SITE'S OWN PLAYER READS IT (release 32): ranged GETs
+ // with the page's Referer and Origin and a browser's user agent — ffmpeg's input seek (-ss
+ // before -i) asks only for the bytes around the window. yt-dlp's generic extractor opens the
+ // URL with one unranged GET first, which the CDN answers like a bulk download (429 on Odysee,
+ // 2026-10-16) while it serves the player's ranged requests (206). No yt-dlp, no cookies.
+ args = storedMediaFfmpegArgs(stored, from, to, maxHeight, part);
+ const outcome = await runOneYtdlp(
+ { ytdlpBin: opts.paths.ffmpegBin, onLog: opts.onLog, signal: opts.signal },
opts.cwd ?? videoDir,
- argsWith(cookies, retryArgs),
+ args,
);
+ if (outcome.exitCode !== 0) {
+ await rm(part, { force: true });
+ const tail = outcome.stderrTail.trim().split("\n").slice(-4).join(" / ");
+ const failureClass: DownloadFailureClass = /\b429\b|Too Many Requests/i.test(outcome.stderrTail)
+ ? "rate_limit"
+ : /\b(403|404|410)\b|Forbidden|Not Found/i.test(outcome.stderrTail)
+ ? "per_video"
+ : "network";
+ if (failureClass === "rate_limit") await opts.onPlatformBackoff?.("rate_limit");
+ throw new FetchWindowError(
+ `ffmpeg failed cutting ${from.toFixed(2)}–${to.toFixed(2)} of ${opts.videoId} from the stored ` +
+ `media URL (exit ${outcome.exitCode ?? "null"}): ${tail}`,
+ failureClass,
+ "public",
+ );
+ }
+ } else {
+ const run = async (cookies: string | undefined, retryArgs: string[] = []) =>
+ runOneYtdlp(
+ {
+ ytdlpBin: opts.paths.ytdlpBin,
+ onLog: opts.onLog,
+ signal: opts.signal,
+ },
+ opts.cwd ?? videoDir,
+ argsWith(cookies, retryArgs),
+ );
- let cookiesUsed = alwaysCookies(policy);
- let picky = detectPlatform(opts.videoUrl) === "rumble" ? HLS_PICKY_RETRY_ARGS : [];
- let args = argsWith(cookiesUsed, picky);
- let outcome = await run(cookiesUsed, picky);
- let backedOff = false;
+ let cookiesUsed = alwaysCookies(policy);
+ let picky = detectPlatform(opts.videoUrl) === "rumble" ? HLS_PICKY_RETRY_ARGS : [];
+ args = argsWith(cookiesUsed, picky);
+ let outcome = await run(cookiesUsed, picky);
+ let backedOff = false;
- if (outcome.exitCode !== 0) {
- const availability = parseUnavailableFromStderr(outcome.stderrTail);
- const failure = classifyDownloadFailure(outcome.stderrTail, availability);
- if (failure === "rate_limit") {
- // The 429 / bot-check cooldown the auto-download runner and a clicked
- // Sync both honour. Recorded before the throw so the NEXT request is
- // refused at the door rather than re-storming the source.
- await opts.onPlatformBackoff?.("rate_limit");
- backedOff = true;
- } else if (AUTH_RETRY_CLASSES.has(availability)) {
- const retryCookies = authRetryCookies(policy);
- if (retryCookies) {
- opts.onLog(
- `Window fetch failed with ${availability}; retrying once with cookies.\n`,
- );
- cookiesUsed = retryCookies;
- args = argsWith(retryCookies, picky);
- outcome = await run(retryCookies, picky);
+ if (outcome.exitCode !== 0) {
+ const availability = parseUnavailableFromStderr(outcome.stderrTail);
+ const failure = classifyDownloadFailure(outcome.stderrTail, availability);
+ if (failure === "rate_limit") {
+ // The 429 / bot-check cooldown the auto-download runner and a clicked
+ // Sync both honour. Recorded before the throw so the NEXT request is
+ // refused at the door rather than re-storming the source.
+ await opts.onPlatformBackoff?.("rate_limit");
+ backedOff = true;
+ } else if (AUTH_RETRY_CLASSES.has(availability)) {
+ const retryCookies = authRetryCookies(policy);
+ if (retryCookies) {
+ opts.onLog(
+ `Window fetch failed with ${availability}; retrying once with cookies.\n`,
+ );
+ cookiesUsed = retryCookies;
+ args = argsWith(retryCookies, picky);
+ outcome = await run(retryCookies, picky);
+ }
}
}
- }
- if (outcome.exitCode !== 0 && !picky.length && HLS_EXTENSION_REFUSED.test(outcome.stderrTail)) {
- opts.onLog(
- `Window fetch: ffmpeg refused the HLS segment extension; retrying once with -extension_picky 0.\n`,
- );
- await rm(part, { force: true });
- picky = HLS_PICKY_RETRY_ARGS;
- args = argsWith(cookiesUsed, picky);
- outcome = await run(cookiesUsed, picky);
- } else if (outcome.exitCode !== 0 && picky.length && HLS_PICKY_REFUSED.test(outcome.stderrTail)) {
- opts.onLog(
- `Window fetch: the source is not HLS after all; retrying once without -extension_picky.\n`,
- );
- await rm(part, { force: true });
- picky = [];
- args = argsWith(cookiesUsed, picky);
- outcome = await run(cookiesUsed, picky);
- }
+ if (outcome.exitCode !== 0 && !picky.length && HLS_EXTENSION_REFUSED.test(outcome.stderrTail)) {
+ opts.onLog(
+ `Window fetch: ffmpeg refused the HLS segment extension; retrying once with -extension_picky 0.\n`,
+ );
+ await rm(part, { force: true });
+ picky = HLS_PICKY_RETRY_ARGS;
+ args = argsWith(cookiesUsed, picky);
+ outcome = await run(cookiesUsed, picky);
+ } else if (outcome.exitCode !== 0 && picky.length && HLS_PICKY_REFUSED.test(outcome.stderrTail)) {
+ opts.onLog(
+ `Window fetch: the source is not HLS after all; retrying once without -extension_picky.\n`,
+ );
+ await rm(part, { force: true });
+ picky = [];
+ args = argsWith(cookiesUsed, picky);
+ outcome = await run(cookiesUsed, picky);
+ }
- if (outcome.exitCode !== 0) {
- await rm(part, { force: true });
- const tail = outcome.stderrTail.trim().split("\n").slice(-4).join(" / ");
- // Classified from the LAST attempt, which is the one that decided.
- const availability = parseUnavailableFromStderr(outcome.stderrTail);
- const failureClass = classifyDownloadFailure(outcome.stderrTail, availability);
- // A cookie retry that ran into a 429 is a 429 like any other.
- if (failureClass === "rate_limit" && !backedOff) {
- await opts.onPlatformBackoff?.("rate_limit");
+ if (outcome.exitCode !== 0) {
+ await rm(part, { force: true });
+ const tail = outcome.stderrTail.trim().split("\n").slice(-4).join(" / ");
+ // Classified from the LAST attempt, which is the one that decided.
+ const availability = parseUnavailableFromStderr(outcome.stderrTail);
+ const failureClass = classifyDownloadFailure(outcome.stderrTail, availability);
+ // A cookie retry that ran into a 429 is a 429 like any other.
+ if (failureClass === "rate_limit" && !backedOff) {
+ await opts.onPlatformBackoff?.("rate_limit");
+ }
+ throw new FetchWindowError(
+ `yt-dlp failed fetching ${from.toFixed(2)}–${to.toFixed(2)} of ` +
+ `${opts.videoId} (exit ${outcome.exitCode ?? "null"}): ${tail}`,
+ failureClass,
+ availability,
+ );
}
- throw new FetchWindowError(
- `yt-dlp failed fetching ${from.toFixed(2)}–${to.toFixed(2)} of ` +
- `${opts.videoId} (exit ${outcome.exitCode ?? "null"}): ${tail}`,
- failureClass,
- availability,
- );
}
// A fallback branch of the selector can still force another container, in