commit 26c697752efb6d779faff5483339fc99f33b7c6b
parent 8f9574521541ce1620d0066afcb198fd8c0c7eec
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Sat, 17 Oct 2026 01:19:38 -0400
common: the download lane takes a cooling or held platform's stored-URL videos — a channel with storedUrlDownloads only/fallback (transcribe, Odysee) keeps its pending videos whose record stores a trusted media URL, when the platform is not busy and its stored-URL rest has elapsed (controller/laneStoredUrl.ts: the filter, a per-video memo read at most 40 a tick); the unit downloads as `only` (`storedUrlHeld` on a held platform) and settles nothing; a failed one moves no backoff (a CDN refusal defers the video 6 h)
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Diffstat:
4 files changed, 329 insertions(+), 9 deletions(-)
diff --git a/common/controller/autoRunner.ts b/common/controller/autoRunner.ts
@@ -123,6 +123,8 @@ import {
import { transcribeOneFromQueue } from "./transcribeOneFromQueue";
import { findVideoSourceUrl } from "./undownloadedVideos";
import { downloadOneManaged } from "../ytdlp/downloadOneManaged";
+import { makeStoredUrlLaneMemo, storedUrlLaneMode, storedUrlRescue } from "./laneStoredUrl";
+import { storedUrlGapRemainingMs } from "../jobs/storedUrlPace";
import { resolveDownloadFormatPreset } from "../ytdlp/downloadFormat";
// The automatic priority-queue runners. Each kind (auto-transcribe /
@@ -1170,6 +1172,10 @@ type Picked = {
// `pick.path` is empty, so no node's active count moves for it. `run()`
// branches on this and nothing else.
scan?: { slug: string; targets: number };
+ // THE STORED-URL UNIT (release 32 R9, controller/laneStoredUrl.ts): picked
+ // past a cooling or held platform because its record stores a media URL; it
+ // downloads as `only`, `held` on a held platform.
+ storedOnly?: { held: boolean };
};
async function runLoop(
@@ -1290,6 +1296,11 @@ async function runLoop(
const platformSkip = new Set<string>();
const platformKey = (slug: string, slugToPlatform: Map<string, string>) =>
slugToPlatform.get(slug) ?? "unknown";
+ // Which pending videos store a media URL (release 32 R9), remembered for
+ // the runner's life, and this tick's videos offered past a cooling or held
+ // platform because they do.
+ const storedLane = makeStoredUrlLaneMemo();
+ let storedPickIds = new Set<string>();
// videoId -> child download job id, for the units the runner currently has on
// the registry's platform queues. Used to hard-cancel them (kill yt-dlp or
@@ -1677,6 +1688,7 @@ async function runLoop(
let anyHeld = false;
let anyPaced = false;
platformSkip.clear();
+ storedPickIds = new Set<string>();
if (kind === "download") {
// Merge in any cooldown a manual sync/import wrote to the shared state
// (read-modify-write from outside the runner) since our last persist.
@@ -1698,8 +1710,12 @@ async function runLoop(
for (const [pf, n] of platformInFlight) {
if (n >= PER_PLATFORM_CAP) platformSkip.add(pf);
}
+ // Skipped for a cooldown or a hold, and not busy: a platform whose
+ // stored-URL videos may still be taken (release 32 R9).
+ const backedOff = new Set<string>();
for (const pf of Object.keys(kindState.platformBackoff)) {
if (isCoolingDown(kindState.platformBackoff, pf, now)) {
+ if (!platformSkip.has(pf)) backedOff.add(pf);
platformSkip.add(pf);
// A platform skipped for a cooldown is a different answer to "why is
// it idle?" than one skipped for being busy, so the two are tracked
@@ -1716,12 +1732,31 @@ async function runLoop(
}
}
if (platformSkip.size > 0) {
- for (const leafId of Object.keys(pending)) {
- pending[leafId] = pending[leafId].filter((id) => {
- const slug = owner.get(id);
- return !(slug && platformSkip.has(platformKey(slug, slugToPlatform)));
- });
- }
+ // THE STORED-URL RESCUE (release 32 R9, controller/laneStoredUrl.ts):
+ // an opted-in channel's video on a cooling or held platform stays
+ // pending when its record stores a media URL and the platform's
+ // stored-URL rest has elapsed — one new file per rest. Everything else
+ // on a skipped platform is dropped, as before.
+ const rescuable = new Set(
+ [...backedOff].filter((pf) => storedUrlGapRemainingMs(pf, {}, now) === 0),
+ );
+ const metaBySlug = new Map(metaCache.map((m) => [m.slug, m]));
+ const rescue = storedUrlRescue({
+ pending,
+ owner,
+ platformSkip,
+ rescuable,
+ platformOf: (slug) => platformKey(slug, slugToPlatform),
+ optedIn: (slug) => {
+ const m = metaBySlug.get(slug);
+ return m ? storedUrlLaneMode(m.config, platformKey(slug, slugToPlatform)) !== null : false;
+ },
+ known: storedLane.known,
+ });
+ for (const leafId of Object.keys(pending)) pending[leafId] = rescue.pending[leafId] ?? [];
+ storedPickIds = rescue.storedIds;
+ // Read on this tick, offered from the next.
+ if (rescue.unknown.length > 0) await storedLane.probe(paths.channelsDir, rescue.unknown);
}
// A video rate-limited recently is skipped until its deferral lapses, so
// after a cooldown the runner moves on rather than re-picking it.
@@ -1842,6 +1877,10 @@ async function runLoop(
const unitPlatform =
kind === "download" ? platformKey(channelSlug, slugToPlatform) : null;
+ const storedOnly =
+ unitPlatform && storedPickIds.has(pick.videoId) && platformSkip.has(unitPlatform)
+ ? { held: isPlatformHeld(kindState.platformHolds, unitPlatform) }
+ : undefined;
// Reserve the slot and account active counts up the path BEFORE returning,
// so the next selection sees the reservation (and ancestor caps reflect it).
live.inFlight.set(pick.videoId, {
@@ -1864,8 +1903,13 @@ async function runLoop(
channelSlug,
});
persist();
- onLog(`Auto-${kind}: ${channelSlug}/${pick.videoId} (leaf ${pick.leafId})`);
- return { pick, channelSlug, unitPlatform };
+ onLog(
+ `Auto-${kind}: ${channelSlug}/${pick.videoId} (leaf ${pick.leafId})` +
+ (storedOnly
+ ? ` from its stored media URL — ${unitPlatform} is ${storedOnly.held ? "held" : "cooling down"}`
+ : ""),
+ );
+ return { pick, channelSlug, unitPlatform, ...(storedOnly ? { storedOnly } : {}) };
};
// ONE UNIT ON AN OPERATION LANE.
@@ -2002,6 +2046,7 @@ async function runLoop(
onLog,
signal: runSignal,
drainSignal: ctx.drainSignal,
+ ...(picked.storedOnly ? { storedOnly: picked.storedOnly } : {}),
onChildJob: (jid) => { childJobIds.set(pick.videoId, jid); const u = live.inFlight.get(pick.videoId); if (u) u.jobId = jid; },
});
} catch (err) {
@@ -2164,6 +2209,9 @@ type LaunchArgs = {
// Download only: called with the child download job's id once enqueued, so the
// runner can hard-cancel it when stopped. No-op for transcription units.
onChildJob?: (jobId: string) => void;
+ // Download only: picked past a cooling or held platform (release 32 R9) —
+ // the download is `only` from the record's stored media URL.
+ storedOnly?: { held: boolean };
};
// The outcome of one unit. `failureClass` is set only for download failures
@@ -2317,6 +2365,10 @@ async function launchUnit(args: LaunchArgs): Promise<UnitResult> {
global: settings.downloadFormat,
}),
appendArchive: true,
+ // Past a cooling or held platform: the stored URL only, no lookup.
+ ...(args.storedOnly
+ ? { storedUrl: "only" as const, ...(args.storedOnly.held ? { storedUrlHeld: true } : {}) }
+ : {}),
});
unitStatus = record.status;
unitFailureClass = record.failureClass;
@@ -2377,6 +2429,11 @@ async function launchUnit(args: LaunchArgs): Promise<UnitResult> {
? { outcome: "transcribed", failureClass: "subs_rate_limit" }
: { outcome: "transcribed" };
}
+ // A stored-URL unit asked the platform nothing: its failure (the CDN's, or
+ // no trusted URL after all) is not the platform's (jobs/unitOutcome.ts).
+ if (args.storedOnly) {
+ return { outcome: "failed", viaStoredUrl: true, ...(unitFailureClass ? { failureClass: unitFailureClass } : {}) };
+ }
// failureClass drives the runner's per-platform backoff (rate_limit/network).
return { outcome: "failed", failureClass: unitFailureClass };
}
diff --git a/common/controller/laneStoredUrl.test.ts b/common/controller/laneStoredUrl.test.ts
@@ -0,0 +1,135 @@
+// The download lane takes a cooling or held platform's stored-URL videos
+// (release 32 R9): the channel's opt-in, the filter, the per-video memo, and
+// what a failed stored-URL unit does to the platform (nothing).
+//
+// Run with: pnpm --filter yt-dlp-transcript-common exec tsx --test controller/laneStoredUrl.test.ts
+
+import { test } from "node:test";
+import assert from "node:assert/strict";
+import { mkdir, mkdtemp, writeFile } from "node:fs/promises";
+import os from "node:os";
+import path from "node:path";
+import { makeStoredUrlLaneMemo, storedUrlLaneMode, storedUrlRescue } from "./laneStoredUrl";
+import { applyUnitOutcome, type UnitOutcomeState } from "../jobs/unitOutcome";
+import { isVideoDeferred } from "../jobs/platformBackoff";
+import type { ChannelConfig } from "../lib/channelConfig";
+
+const cfg = (over: Partial<ChannelConfig>) => ({ handling: "transcribe", ...over }) as ChannelConfig;
+
+test("the opt-in: only/fallback, transcribe handling, a stored-URL platform", () => {
+ assert.equal(storedUrlLaneMode(cfg({ storedUrlDownloads: "only" }), "odysee"), "only");
+ assert.equal(storedUrlLaneMode(cfg({ storedUrlDownloads: "fallback" }), "odysee"), "fallback");
+ assert.equal(storedUrlLaneMode(cfg({ storedUrlDownloads: "never" }), "odysee"), null);
+ assert.equal(storedUrlLaneMode(cfg({}), "odysee"), null, "absent = never");
+ assert.equal(storedUrlLaneMode(cfg({ storedUrlDownloads: "only", handling: "youtube" }), "odysee"), null);
+ assert.equal(storedUrlLaneMode(cfg({ storedUrlDownloads: "only" }), "youtube"), null);
+});
+
+test("the filter keeps a skipped platform's opted-in videos that store a URL, and lists the unread", () => {
+ const owner = new Map([
+ ["o1", "ody"],
+ ["o2", "ody"],
+ ["o3", "ody"],
+ ["n1", "ody-plain"],
+ ["y1", "yt"],
+ ]);
+ const platforms: Record<string, string> = { ody: "odysee", "ody-plain": "odysee", yt: "youtube" };
+ const known: Record<string, boolean | undefined> = { o1: true, o2: false };
+ const r = storedUrlRescue({
+ pending: { leaf: ["o1", "o2", "o3", "n1", "y1"], other: ["o3"] },
+ owner,
+ platformSkip: new Set(["odysee"]),
+ rescuable: new Set(["odysee"]),
+ platformOf: (slug) => platforms[slug],
+ optedIn: (slug) => slug === "ody",
+ known: (_slug, id) => known[id],
+ });
+ assert.deepEqual(r.pending, { leaf: ["o1", "y1"], other: [] });
+ assert.deepEqual([...r.storedIds], ["o1"]);
+ assert.deepEqual(r.unknown, [{ slug: "ody", id: "o3" }], "once, though it is in two leaves");
+});
+
+test("a skipped platform that is not rescuable (busy, or its stored-URL rest not over) keeps nothing", () => {
+ const r = storedUrlRescue({
+ pending: { leaf: ["o1", "y1"] },
+ owner: new Map([
+ ["o1", "ody"],
+ ["y1", "yt"],
+ ]),
+ platformSkip: new Set(["odysee"]),
+ rescuable: new Set(),
+ platformOf: (slug) => (slug === "ody" ? "odysee" : "youtube"),
+ optedIn: () => true,
+ known: () => true,
+ });
+ assert.deepEqual(r.pending, { leaf: ["y1"] });
+ assert.equal(r.storedIds.size, 0);
+ assert.deepEqual(r.unknown, []);
+});
+
+test("the memo reads a record once, at most the limit per call, and a trusted URL reads true", async () => {
+ const root = await mkdtemp(path.join(os.tmpdir(), "lanestored-"));
+ const dir = (id: string) => path.join(root, "ody", "data", id);
+ await mkdir(dir("a"), { recursive: true });
+ await writeFile(
+ path.join(dir("a"), "metadata.info.json"),
+ JSON.stringify({
+ id: "a",
+ webpage_url: "https://odysee.com/@x:1/a:1",
+ formats: [{ format_id: "original", url: "https://player.odycdn.com/v6/streams/a/sd.mp4", protocol: "https" }],
+ }),
+ );
+ await mkdir(dir("b"), { recursive: true });
+ let reads = 0;
+ const memo = makeStoredUrlLaneMemo(async (d) => {
+ reads++;
+ const { storedMediaUrl } = await import("../lib/storedMediaUrl-server");
+ return storedMediaUrl(d);
+ });
+ const ids = [
+ { slug: "ody", id: "a" },
+ { slug: "ody", id: "b" },
+ { slug: "ody", id: "c" },
+ ];
+ assert.equal(await memo.probe(root, ids, 2), 2);
+ assert.equal(memo.known("ody", "a"), true);
+ assert.equal(memo.known("ody", "b"), false);
+ assert.equal(memo.known("ody", "c"), undefined, "past the limit: next tick");
+ assert.equal(await memo.probe(root, ids, 2), 1);
+ assert.equal(reads, 3, "each record read once");
+});
+
+const empty = (): UnitOutcomeState => ({
+ platformBackoff: {},
+ videoDeferrals: {},
+ platformPace: {},
+ platformHolds: {},
+ subtitleDeferrals: {},
+});
+
+test("a failed stored-URL unit: a CDN refusal defers the video and backs nothing off", () => {
+ const s = empty();
+ const now = 1_000_000;
+ const r = applyUnitOutcome(
+ s,
+ { platform: "odysee", videoId: "v1", channelSlug: "ody", outcome: "failed", failureClass: "rate_limit", viaStoredUrl: true },
+ now,
+ );
+ assert.equal(r.markCompleted, false);
+ assert.ok(isVideoDeferred(s.videoDeferrals, "v1", now + 1));
+ assert.deepEqual(s.platformBackoff, {}, "the platform is not backed off");
+ assert.deepEqual(s.platformPace, {});
+ assert.match(r.line ?? "", /stored media URL refused it \(rate_limit\).*odysee is not backed off/);
+});
+
+test("a failed stored-URL unit for any other reason retires the video, touching nothing", () => {
+ const s = empty();
+ const r = applyUnitOutcome(
+ s,
+ { platform: "odysee", videoId: "v2", channelSlug: "ody", outcome: "failed", failureClass: "per_video", viaStoredUrl: true },
+ 1_000_000,
+ );
+ assert.equal(r.markCompleted, true);
+ assert.deepEqual(s.platformBackoff, {});
+ assert.deepEqual(s.videoDeferrals, {});
+});
diff --git a/common/controller/laneStoredUrl.ts b/common/controller/laneStoredUrl.ts
@@ -0,0 +1,108 @@
+// THE DOWNLOAD LANE PICKS HELD-PLATFORM WORK FROM STORED URLS (release 32 R9).
+//
+// The lane drops every pending video of a platform that is cooling down or
+// held (autoRunner's platformSkip): asking the platform again would only earn
+// another 429. Release 32 R7 gave a download a way round the LOOKUP — the media
+// URL the record's metadata.info.json already stores, read the way the player
+// reads it — but the lane never offered such a video, so the held Odysee
+// backlog waited for the hold to lift.
+//
+// Now a channel that opted in (`storedUrlDownloads: "only" | "fallback"`,
+// transcribe handling, a STORED_URL_PLATFORMS platform) keeps the pending
+// videos of a cooling or held platform whose record stores a trusted URL —
+// and only when the platform is not busy and the platform's stored-URL rest
+// (jobs/storedUrlPace.ts, the gap shared with clip cuts) has elapsed, so the
+// lane takes one new file per rest. Such a unit downloads as `only` (no page
+// or API request: the lookup is the limited thing), `storedUrlHeld` on a held
+// platform, and settles nothing (viaStoredUrl, jobs/unitOutcome.ts).
+//
+// "Does the record store a URL" is a file read, so it is remembered per video
+// for the runner's life (a record's stored format does not change without a
+// new lookup, which is exactly what is not happening) and at most
+// STORED_URL_LANE_PROBES_PER_TICK unknown videos are read per tick; a video is
+// offered from the tick after its read.
+
+import path from "node:path";
+import type { ChannelConfig } from "../lib/channelConfig";
+import { isStoredUrlPlatform, type StoredMediaUrl } from "../lib/storedMediaUrl";
+import { storedMediaUrl } from "../lib/storedMediaUrl-server";
+
+export const STORED_URL_LANE_PROBES_PER_TICK = 40;
+
+// The channel's stored-URL mode when the lane may take its videos past a
+// cooling or held platform, else null.
+export function storedUrlLaneMode(
+ config: Pick<ChannelConfig, "storedUrlDownloads" | "handling">,
+ platform: string | null | undefined,
+): "only" | "fallback" | null {
+ const mode = config.storedUrlDownloads;
+ if (mode !== "only" && mode !== "fallback") return null;
+ if (config.handling !== "transcribe") return null;
+ if (!isStoredUrlPlatform(platform)) return null;
+ return mode;
+}
+
+export type StoredUrlLaneMemo = {
+ // true / false once read; undefined = not read yet.
+ known(slug: string, id: string): boolean | undefined;
+ // Read up to `limit` of `ids` (unknown ones), remembering each answer.
+ probe(channelsDir: string, ids: ReadonlyArray<{ slug: string; id: string }>, limit?: number): Promise<number>;
+};
+
+export function makeStoredUrlLaneMemo(
+ read: (videoDir: string) => Promise<StoredMediaUrl | null> = storedMediaUrl,
+): StoredUrlLaneMemo {
+ const memo = new Map<string, boolean>();
+ const key = (slug: string, id: string) => `${slug}\0${id}`;
+ return {
+ known: (slug, id) => memo.get(key(slug, id)),
+ async probe(channelsDir, ids, limit = STORED_URL_LANE_PROBES_PER_TICK) {
+ const todo = ids.filter((x) => !memo.has(key(x.slug, x.id))).slice(0, limit);
+ await Promise.all(
+ todo.map(async ({ slug, id }) => {
+ const s = await read(path.join(channelsDir, slug, "data", id)).catch(() => null);
+ memo.set(key(slug, id), s !== null);
+ }),
+ );
+ return todo.length;
+ },
+ };
+}
+
+// THE FILTER (pure): which skipped videos stay pending because they can be
+// downloaded from their stored URL. `rescuable` = the platforms skipped ONLY
+// for a cooldown or a hold (not busy) whose stored-URL rest has elapsed.
+export function storedUrlRescue(args: {
+ pending: Record<string, string[]>;
+ owner: ReadonlyMap<string, string>;
+ platformSkip: ReadonlySet<string>;
+ rescuable: ReadonlySet<string>;
+ platformOf: (slug: string) => string;
+ optedIn: (slug: string) => boolean;
+ known: (slug: string, id: string) => boolean | undefined;
+}): { pending: Record<string, string[]>; storedIds: Set<string>; unknown: { slug: string; id: string }[] } {
+ const storedIds = new Set<string>();
+ const unknown: { slug: string; id: string }[] = [];
+ const seenUnknown = new Set<string>();
+ const out: Record<string, string[]> = {};
+ for (const [leafId, ids] of Object.entries(args.pending)) {
+ out[leafId] = ids.filter((id) => {
+ const slug = args.owner.get(id);
+ if (!slug) return true;
+ const pf = args.platformOf(slug);
+ if (!args.platformSkip.has(pf)) return true;
+ if (!args.rescuable.has(pf) || !args.optedIn(slug)) return false;
+ const k = args.known(slug, id);
+ if (k === true) {
+ storedIds.add(id);
+ return true;
+ }
+ if (k === undefined && !seenUnknown.has(id)) {
+ seenUnknown.add(id);
+ unknown.push({ slug, id });
+ }
+ return false;
+ });
+ }
+ return { pending: out, storedIds, unknown };
+}
diff --git a/common/jobs/unitOutcome.ts b/common/jobs/unitOutcome.ts
@@ -20,7 +20,9 @@
// - a success through the record's stored media URL (release 32 R7,
// `viaStoredUrl`) retires the video and settles nothing: the platform was
// not asked. One whose page lookup was rate-limited first comes in as a
-// `rate_limit` and backs the platform off like any other.
+// `rate_limit` and backs the platform off like any other. A stored-URL unit
+// that FAILED (release 32 R9, picked past a cooling or held platform) moves
+// nothing either: a CDN refusal defers the video, anything else retires it.
//
// Release 17, slice RL (see platformBackoff.ts, "The adaptive pace"):
// - `rate_limit` also doubles the platform's pace, and a backoff that has
@@ -94,6 +96,24 @@ export function applyUnitOutcome(
pruneSubtitleDeferrals(state.subtitleDeferrals, now);
decayPaceByTime(state.platformPace, now);
const pf = unit.platform;
+ if (pf !== null && unit.viaStoredUrl && unit.outcome === "failed") {
+ // A STORED-URL UNIT THAT FAILED (release 32 R9: the lane picked it past a
+ // cooling or held platform, `only`). The platform was not asked, so its
+ // backoff, hold and pace stay as they are. A refusal from the CDN defers
+ // the video (the stored-URL rest spaces the next file anyway); anything
+ // else retires it for the session.
+ if (unit.failureClass === "rate_limit" || unit.failureClass === "network") {
+ deferVideo(state.videoDeferrals, unit.videoId, unit.channelSlug, now);
+ return {
+ markCompleted: false,
+ line: `Auto-download: ${unit.videoId}'s stored media URL refused it (${unit.failureClass}) — deferred 6h; ${pf} is not backed off by it.`,
+ };
+ }
+ return {
+ markCompleted: true,
+ line: `Auto-download: ${unit.videoId} from its stored media URL failed (${unit.failureClass ?? "unknown"}); ${pf} is not touched.`,
+ };
+ }
if (
pf !== null &&
(unit.failureClass === "rate_limit" || unit.failureClass === "network")