commit 49721fb3b62aecd3548700c9b07c42b313ca39d8
parent b8b9fd72db416c88b2e6e884e126ed50500a8417
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Sat, 17 Oct 2026 00:49:22 -0400
common: find-copy's Wayback found check — a video the index lists is a copy only when a format's stream answers a ranged GET (/web/2id_/<format url>, yt-dlp's URL, through the paced client: ArchiveOrgClient.probe, WaybackClient.youtubeVideoStream, at most 3 formats); else 'page captured, no video', none found and recorded none-found in copy-attempts.json (the article mode now records none-found as the scope mode does); the fake Wayback serves streams
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Diffstat:
9 files changed, 312 insertions(+), 19 deletions(-)
diff --git a/common/lib/archiveOrgClient.ts b/common/lib/archiveOrgClient.ts
@@ -86,6 +86,9 @@ export type DownloadFileOpts = {
const RETRYABLE = new Set([429, 502, 503, 504]);
+// How much of a file `probe` asks for.
+export const PROBE_BYTES = 1024;
+
function defaultSleep(ms: number, signal?: AbortSignal): Promise<void> {
return new Promise((resolve, reject) => {
if (signal?.aborted) return reject(signal.reason ?? new Error("aborted"));
@@ -153,7 +156,7 @@ export class ArchiveOrgClient {
}
// One GET, with the gap before it and the retry policy around it.
- private async getOnce(url: string, accept: string, signal?: AbortSignal): Promise<Response> {
+ private async getOnce(url: string, accept: string, signal?: AbortSignal, extraHeaders: Record<string, string> = {}): Promise<Response> {
let lastError = "";
for (let attempt = 1; attempt <= this.opts.maxAttempts; attempt++) {
const wait = this.lastDoneAt + this.opts.minGapMs - this.deps.now();
@@ -165,7 +168,7 @@ export class ArchiveOrgClient {
res = await this.deps.fetch(url, {
signal: signal ? AbortSignal.any([signal, timeout]) : timeout,
redirect: "follow",
- headers: { accept, "user-agent": ARCHIVE_ORG_USER_AGENT },
+ headers: { accept, "user-agent": ARCHIVE_ORG_USER_AGENT, ...extraHeaders },
});
} catch (err) {
if (signal?.aborted) throw err;
@@ -203,6 +206,26 @@ export class ArchiveOrgClient {
});
}
+ // Whether `url` serves bytes: ONE ranged GET of its first `PROBE_BYTES`
+ // (release 32 R8, the Wayback "found" check), through the same chain, gap
+ // and back-off; the body is never read past those bytes. Answers the status
+ // (200 or 206 when it serves, with its content type), or the refusal's status
+ // when it answered an error that is not retried (404, 410, 403 …). Throws
+ // ArchiveOrgRequestError `rateLimited` when it kept refusing (429/503).
+ probe(url: string, signal?: AbortSignal): Promise<{ ok: boolean; status: number; contentType: string | null }> {
+ return this.serial(async () => {
+ try {
+ const res = await this.getOnce(url, "*/*", signal, { range: `bytes=0-${PROBE_BYTES - 1}` });
+ const contentType = res.headers.get("content-type");
+ await res.body?.cancel().catch(() => {});
+ return { ok: true, status: res.status, contentType };
+ } catch (e) {
+ if (e instanceof ArchiveOrgRequestError && e.status !== null) return { ok: false, status: e.status, contentType: null };
+ throw e;
+ }
+ });
+ }
+
getJson(url: string, signal?: AbortSignal): Promise<unknown> {
return this.serial(async () => {
const res = await this.getOnce(url, "application/json", signal);
diff --git a/common/lib/waybackClient.test.ts b/common/lib/waybackClient.test.ts
@@ -7,7 +7,7 @@
import { test } from "node:test";
import assert from "node:assert/strict";
import { startFakeWayback } from "../testing/web/fakeWayback.mjs";
-import { parseCdxJson, waybackCdxUrl, WaybackClient, waybackReplayUrl, waybackYoutubeUrl } from "./waybackClient";
+import { parseCdxJson, videoInfoFormatUrls, waybackCdxUrl, WaybackClient, waybackReplayUrl, waybackStreamUrl, waybackYoutubeUrl, WAYBACK_STREAM_PROBES_MAX } from "./waybackClient";
import { ArchiveOrgRequestError } from "./archiveOrgClient";
const BREAD = "https://video.example/watch?v=bread-day-01";
@@ -95,3 +95,60 @@ test("youtubeVideoArchived: yt-dlp's check — the video index's formats, not a
await wb.close();
}
});
+
+test("youtubeVideoStream (R8): listed AND its stream answers a ranged GET — else page only, each probe's status kept", async () => {
+ const wb = await startFakeWayback({ videos: ["waybackVid1", "pageOnly001"], streams: ["waybackVid1"] });
+ try {
+ const c = new WaybackClient({ fetch: wb.fetch }, { minGapMs: 0 });
+ const fmt = "https://rr1---sn-fake.googlevideo.com/videoplayback?itag=18&id=waybackVid1";
+ assert.deepEqual(await c.youtubeVideoStream("waybackVid1"), {
+ formats: 1,
+ stream: waybackStreamUrl(fmt),
+ probes: [{ url: `https://web.archive.org/web/2id_/${fmt}`, status: 206 }],
+ });
+ const page = await c.youtubeVideoStream("pageOnly001");
+ assert.equal(page.formats, 1);
+ assert.equal(page.stream, null);
+ assert.deepEqual(page.probes.map((p) => p.status), [404]);
+ const none = await c.youtubeVideoStream("neverArch01");
+ assert.deepEqual(none, { formats: 0, stream: null, probes: [] });
+ // Each probe asked for its first bytes only.
+ assert.equal(wb.requests.filter((r) => r.path.startsWith("/web/2id_/")).length, 2);
+ } finally {
+ await wb.close();
+ }
+});
+
+test("videoInfoFormatUrls: audio first for a dmux answer, repeats once, non-URLs skipped; at most WAYBACK_STREAM_PROBES_MAX probed", async () => {
+ assert.deepEqual(videoInfoFormatUrls({ formats: [{ url: "https://a.example/1" }, { url: "https://a.example/1" }, { url: 5 }, { url: "ftp://x" }] }), ["https://a.example/1"]);
+ assert.deepEqual(videoInfoFormatUrls({ dmux: true, formats: { video: [{ url: "https://v.example/v" }], audio: [{ url: "https://v.example/a" }] } }), ["https://v.example/a", "https://v.example/v"]);
+ assert.deepEqual(videoInfoFormatUrls({}), []);
+ assert.deepEqual(videoInfoFormatUrls(null), []);
+ const statuses: string[] = [];
+ const many = { formats: Array.from({ length: 6 }, (_, i) => ({ url: `https://rr1---sn-fake.googlevideo.com/videoplayback?itag=${i}&id=x` })) };
+ const c = new WaybackClient(
+ {
+ fetch: async (url) => {
+ if (url.includes("/__wb/videoinfo")) return new Response(JSON.stringify(many), { status: 200 });
+ statuses.push(url);
+ return new Response("<p>nope</p>", { status: 404, headers: { "content-type": "text/html" } });
+ },
+ },
+ { minGapMs: 0 },
+ );
+ const got = await c.youtubeVideoStream("x");
+ assert.equal(got.formats, 6);
+ assert.equal(got.stream, null);
+ assert.equal(statuses.length, WAYBACK_STREAM_PROBES_MAX);
+ // A 200 that is an HTML page is not a stream.
+ const html = new WaybackClient(
+ {
+ fetch: async (url) =>
+ url.includes("/__wb/videoinfo")
+ ? new Response(JSON.stringify({ formats: [{ url: "https://rr1---sn-fake.googlevideo.com/videoplayback?itag=18&id=x" }] }), { status: 200 })
+ : new Response("<html>Wayback Machine</html>", { status: 200, headers: { "content-type": "text/html; charset=utf-8" } }),
+ },
+ { minGapMs: 0 },
+ );
+ assert.equal((await html.youtubeVideoStream("x")).stream, null);
+});
diff --git a/common/lib/waybackClient.ts b/common/lib/waybackClient.ts
@@ -102,6 +102,45 @@ export function waybackYoutubeUrl(youtubeId: string, timestamp?: string): string
return `${WAYBACK_ORIGIN}/web/${timestamp ?? ""}${timestamp ? "/" : ""}https://www.youtube.com/watch?v=${youtubeId}`;
}
+// THE STREAM of an archived YouTube format, as yt-dlp's extractor fetches it
+// (archiveorg.py `_parse_fmt`): `https://web.archive.org/web/2id_/<format url>`
+// — the raw bytes Wayback holds for that googlevideo URL, if any.
+export function waybackStreamUrl(formatUrl: string): string {
+ return `${WAYBACK_ORIGIN}/web/2id_/${formatUrl}`;
+}
+
+// The format URLs of the video index's answer, audio first (fetch-copies asks
+// yt-dlp for `ba/b`): a dmux answer's `formats.audio` then `formats.video`,
+// else `formats` in its order. Repeats once; anything not an http(s) URL is
+// skipped.
+export function videoInfoFormatUrls(raw: unknown): string[] {
+ const formats = (raw as { formats?: unknown } | null)?.formats;
+ const urlsOf = (list: unknown): string[] =>
+ Array.isArray(list)
+ ? list.map((f) => (f as { url?: unknown } | null)?.url).filter((u): u is string => typeof u === "string" && /^https?:\/\//.test(u))
+ : [];
+ const all = Array.isArray(formats)
+ ? urlsOf(formats)
+ : formats && typeof formats === "object"
+ ? [...urlsOf((formats as Record<string, unknown>).audio), ...urlsOf((formats as Record<string, unknown>).video), ...Object.entries(formats as Record<string, unknown>).filter(([k]) => k !== "audio" && k !== "video").flatMap(([, v]) => urlsOf(v))]
+ : [];
+ return [...new Set(all)];
+}
+
+// At most this many of a video's formats are probed for a stream (one ranged
+// request each, paced): a video whose first three formats all 404 is taken as
+// its page alone.
+export const WAYBACK_STREAM_PROBES_MAX = 3;
+
+// What the "found" check saw (release 32 R8): the formats the video index
+// lists, the stream that answered (null: none did — the page was captured,
+// the video was not), and each probe's status.
+export type WaybackVideoStream = {
+ formats: number;
+ stream: string | null;
+ probes: { url: string; status: number }[];
+};
+
export class WaybackClient {
private readonly http: ArchiveOrgClient;
@@ -117,6 +156,11 @@ export class WaybackClient {
// Whether the Wayback Machine holds the YouTube VIDEO itself (formats in
// its videoinfo index — what yt-dlp asks), not only captures of its page.
async youtubeVideoArchived(youtubeId: string, o: { signal?: AbortSignal } = {}): Promise<boolean> {
+ return (await this.youtubeVideoFormats(youtubeId, o)).length > 0;
+ }
+
+ // The video index's format URLs for a YouTube id (videoInfoFormatUrls).
+ async youtubeVideoFormats(youtubeId: string, o: { signal?: AbortSignal } = {}): Promise<string[]> {
const body = await this.http.getText(waybackVideoInfoUrl(youtubeId), "application/json", o.signal);
let raw: unknown;
try {
@@ -124,10 +168,29 @@ export class WaybackClient {
} catch {
throw new ArchiveOrgRequestError(`the Wayback video index did not answer JSON for ${youtubeId}`, null, false);
}
- const formats = (raw as { formats?: unknown } | null)?.formats;
- if (Array.isArray(formats)) return formats.length > 0;
- // A dmux answer keeps its formats by kind.
- return !!formats && typeof formats === "object" && Object.values(formats as Record<string, unknown>).some((v) => Array.isArray(v) && v.length > 0);
+ return videoInfoFormatUrls(raw);
+ }
+
+ // THE "FOUND" CHECK (release 32 R8): the video index lists formats AND one
+ // of their streams answers. The index can list a video whose bytes Wayback
+ // does not hold (the live case: formats listed, 404 at the format URL), so
+ // each of the first WAYBACK_STREAM_PROBES_MAX formats is probed with one
+ // ranged GET through the paced client; the first that serves (200/206, not
+ // an HTML page) is the stream. Throws ArchiveOrgRequestError when the index
+ // or a probe kept refusing.
+ async youtubeVideoStream(youtubeId: string, o: { signal?: AbortSignal } = {}): Promise<WaybackVideoStream> {
+ const formats = await this.youtubeVideoFormats(youtubeId, o);
+ const out: WaybackVideoStream = { formats: formats.length, stream: null, probes: [] };
+ for (const f of formats.slice(0, WAYBACK_STREAM_PROBES_MAX)) {
+ const url = waybackStreamUrl(f);
+ const p = await this.http.probe(url, o.signal);
+ out.probes.push({ url, status: p.status });
+ if (p.ok && !/^text\/html\b/i.test(p.contentType ?? "")) {
+ out.stream = url;
+ break;
+ }
+ }
+ return out;
}
// The captures of `url`, oldest first: every capture, or (`okOnly`) only the
diff --git a/common/publish/findCopy.test.ts b/common/publish/findCopy.test.ts
@@ -15,7 +15,7 @@ import { startFakeWayback } from "../testing/web/fakeWayback.mjs";
import { startFakeArchiveOrg, type FakeArchiveOrgItem } from "../testing/archiveOrg/fakeArchiveOrg.mjs";
import { ArchiveOrgClient } from "../lib/archiveOrgClient";
import { WaybackClient } from "../lib/waybackClient";
-import type { FailedCopy } from "../lib/copyAttempts-server";
+import type { CopyAttempt, FailedCopy } from "../lib/copyAttempts-server";
import type { MissingEvidenceWindows, UnfetchableEvidenceWindow } from "./reportMedia";
import type { ReportHost } from "./reportHost";
import type { Paths } from "../lib/paths";
@@ -26,6 +26,7 @@ import {
mirrorNamesId,
pickMirrorFile,
runFindCopy,
+ WAYBACK_PAGE_ONLY,
youtubeIdOf,
youtubeIdQuery,
type RecordFacts,
@@ -89,17 +90,27 @@ const FACTS: Record<string, RecordFacts> = {
v5abcde: { webpageUrl: "https://rumble.com/v5abcde-a-stream.html", duration: 100, videoDir: "/x/v5abcde" },
};
-async function fakes(o: { waybackBusy?: number; failed?: Record<string, FailedCopy[]>; need?: MissingEvidenceWindows } = {}) {
- const wb = await startFakeWayback({ busyTimes: o.waybackBusy ?? 0, videos: [WB] });
- const ia = await startFakeArchiveOrg({ items: ITEMS });
+async function fakes(
+ o: { waybackBusy?: number; failed?: Record<string, FailedCopy[]>; need?: MissingEvidenceWindows; videos?: string[]; streams?: string[]; streamBusy?: number; items?: FakeArchiveOrgItem[] } = {},
+) {
+ const wb = await startFakeWayback({
+ busyTimes: o.waybackBusy ?? 0,
+ videos: o.videos ?? [WB],
+ ...(o.streams ? { streams: o.streams } : {}),
+ streamBusyTimes: o.streamBusy ?? 0,
+ });
+ const ia = await startFakeArchiveOrg({ items: o.items ?? ITEMS });
+ const recorded: { dir: string; attempt: CopyAttempt }[] = [];
const deps = {
wayback: new WaybackClient({ fetch: wb.fetch, sleep: async () => {} }, { minGapMs: 0, maxAttempts: 2 }),
archive: new ArchiveOrgClient({ fetch: ia.fetch }, { minGapMs: 0 }),
missing: async () => o.need ?? NEED,
facts: async (_p: Paths, _slug: string, id: string) => FACTS[id]!,
failedCopies: async (dir: string) => o.failed?.[dir] ?? [],
+ recordAttempt: async (dir: string, attempt: CopyAttempt) => void recorded.push({ dir, attempt }),
+ now: () => new Date("2026-10-17T00:00:00Z"),
};
- return { wb, ia, deps, close: async () => Promise.all([wb.close(), ia.close()]) };
+ return { wb, ia, deps, recorded, close: async () => Promise.all([wb.close(), ia.close()]) };
}
const opts = (deps: unknown) => ({ paths: {} as Paths, host: { id: "articles" } as ReportHost, deps: deps as never });
@@ -157,7 +168,7 @@ test("archive-search by YouTube id: the mirror's direct file URL; a compilation
});
test("find-copy: the Wayback video, else an archive.org mirror, else words only; a non-YouTube record is not looked for", async () => {
- const { wb, ia, deps, close } = await fakes();
+ const { wb, ia, deps, recorded, close } = await fakes();
try {
const lines: string[] = [];
const r = await findCopies({ ...opts(deps), onLog: (l) => lines.push(l) });
@@ -196,9 +207,63 @@ test("find-copy: the Wayback video, else an archive.org mirror, else words only;
],
);
assert.ok(lines.some((l) => l.includes(COMP) && l.includes("its words only")));
+ // The found check asked for WB's stream once (a ranged GET at yt-dlp's URL).
+ const probes = wb.requests.filter((q) => q.path.startsWith("/web/2id_/"));
+ assert.deepEqual(probes.map((q) => q.path), [`/web/2id_/https://rr1---sn-fake.googlevideo.com/videoplayback?itag=18&id=${WB}`]);
+ // (R8) The YouTube recordings neither source holds are recorded none-found; the Rumble one is not.
+ assert.deepEqual(recorded.map((x) => [x.dir, x.attempt.outcome]), [
+ [`/x/${COMP}`, "none-found"],
+ [`/x/${NONE}`, "none-found"],
+ ]);
+ } finally {
+ await close();
+ }
+});
+
+test("the Wayback found check: a video the index lists whose stream 404s is 'page captured, no video' — none found, recorded, never a copy", async () => {
+ // WB is in the video index, but Wayback holds no bytes for its format (the live case).
+ const { wb, deps, recorded, close } = await fakes({ streams: [], items: [], need: { ...NEED, unfetchable: NEED.unfetchable.slice(0, 1) } });
+ try {
+ const lines: string[] = [];
+ const r = await findCopies({ ...opts(deps), onLog: (l) => lines.push(l) });
+ assert.equal(r.recordings[0]!.outcome, "text-only");
+ assert.deepEqual(r.items, [], "nothing goes to fetch-windows");
+ const t = r.recordings[0]!.tried[0]!;
+ assert.deepEqual([t.from, t.found], ["wayback", false]);
+ assert.equal(t.error, undefined, "not a lookup error");
+ assert.match(t.detail ?? "", new RegExp(`^${WAYBACK_PAGE_ONLY} \\(the video index lists 1 format\\(s\\); 1 probed, HTTP 404\\)$`));
+ assert.equal(wb.requests.filter((q) => q.path.startsWith("/web/2id_/")).length, 1);
+ assert.equal(recorded.length, 1);
+ assert.equal(recorded[0]!.attempt.outcome, "none-found");
+ assert.match(recorded[0]!.attempt.detail ?? "", /wayback none — page captured, no video/);
+ assert.ok(lines.some((l) => l.includes("page captured, no video") && l.includes("its words only")));
+ // A dry run records nothing.
+ const dry = await runFindCopy({ ...opts(deps), dryRun: true, startFetch: async () => null });
+ assert.equal(dry.recordings[0]!.outcome, "text-only");
+ assert.equal(recorded.length, 1);
} finally {
await close();
}
+ // Page only on Wayback, a mirror on archive.org: the mirror is the copy.
+ const both = await fakes({ streams: [], need: { ...NEED, unfetchable: NEED.unfetchable.slice(0, 1) } });
+ try {
+ const r = await findCopies(opts(both.deps));
+ assert.equal(r.recordings[0]!.copy?.from, "archive.org");
+ assert.match(r.recordings[0]!.tried[0]!.detail ?? "", /^page captured, no video/);
+ assert.equal(both.recorded.length, 0);
+ } finally {
+ await both.close();
+ }
+ // A probe Wayback keeps refusing is a lookup error (tried again later), never none-found.
+ const busy = await fakes({ streamBusy: 50, need: { ...NEED, unfetchable: NEED.unfetchable.slice(0, 1) } });
+ try {
+ const r = await findCopies(opts(busy.deps));
+ assert.equal(r.recordings[0]!.outcome, "error");
+ assert.match(r.stopped ?? "", /kept refusing/);
+ assert.equal(busy.recorded.length, 0);
+ } finally {
+ await busy.close();
+ }
});
test("a copy that failed before is not picked again: Wayback falls through to archive.org, a failed mirror to none", async () => {
diff --git a/common/publish/findCopy.ts b/common/publish/findCopy.ts
@@ -10,7 +10,12 @@
// page captures hold no video). The check is the one yt-dlp's
// YoutubeWebArchive extractor makes before it fetches anything
// (yt_dlp/extractor/archiveorg.py `_real_extract`: web.archive.org's
-// `__wb/videoinfo?vtype=youtube&vid=<id>` has formats); the copy's URL is
+// `__wb/videoinfo?vtype=youtube&vid=<id>` has formats) AND (release 32
+// R8) a format's stream answers a ranged GET (`/web/2id_/<format url>`,
+// lib/waybackClient.ts youtubeVideoStream): the index lists videos whose
+// bytes Wayback does not hold (the live case, 404 at the format URL), and
+// such a video is "page captured, no video" — none found, never a copy
+// that fails at its source; the copy's URL is
// `https://web.archive.org/web/<ts>/https://www.youtube.com/watch?v=<id>`,
// the form that extractor takes (the newest 200 capture's timestamp, when
// the CDX names one);
@@ -314,6 +319,10 @@ export async function waybackLookup(
// ─── find-copy ───
+// The Wayback finding for a video the index lists but whose stream does not
+// answer (release 32 R8): none found, recorded as such.
+export const WAYBACK_PAGE_ONLY = "page captured, no video";
+
export type FindCopyAttempt = {
from: ClipCopy["from"];
found: boolean;
@@ -352,11 +361,15 @@ export type FindCopyResult = {
};
export type FindCopyDeps = {
- wayback: Pick<typeof waybackClient, "captures" | "youtubeVideoArchived">;
+ wayback: Pick<typeof waybackClient, "captures" | "youtubeVideoStream">;
archive: ArchiveOrgClient;
missing: (paths: Paths, host: ReportHost) => Promise<MissingEvidenceWindows>;
facts: (paths: Paths, slug: string, id: string) => Promise<RecordFacts>;
failedCopies: (videoDir: string) => Promise<FailedCopy[]>;
+ // (release 32 R8) a YouTube recording neither source holds is recorded
+ // `none-found` in its copy-attempts.json, as the scope mode records one.
+ recordAttempt: (videoDir: string, attempt: CopyAttempt) => Promise<void>;
+ now: () => Date;
};
const DEFAULT_DEPS: FindCopyDeps = {
@@ -365,6 +378,8 @@ const DEFAULT_DEPS: FindCopyDeps = {
missing: (paths, host) => missingEvidenceWindows(paths, host),
facts: recordFacts,
failedCopies: readFailedCopies,
+ recordAttempt: recordCopyAttempt,
+ now: () => new Date(),
};
const describeAttempt = (t: FindCopyAttempt) =>
@@ -411,7 +426,8 @@ export async function lookForCopy(o: {
out.tried.push({ from: "wayback", found: false, detail: "a fetch from its Wayback copy failed before" });
} else {
try {
- if (await deps.wayback.youtubeVideoArchived(youtubeId, sig)) {
+ const video = await deps.wayback.youtubeVideoStream(youtubeId, sig);
+ if (video.stream) {
// The newest capture of the page that recorded a 200 dates the copy.
const { captures } = await waybackLookup(`https://www.youtube.com/watch?v=${youtubeId}`, {
client: deps.wayback,
@@ -422,7 +438,14 @@ export async function lookForCopy(o: {
const url = waybackYoutubeUrl(youtubeId, newest?.timestamp);
out.copy = { from: "wayback", url };
if (newest) out.captureTs = newest.timestamp;
- out.tried.push({ from: "wayback", found: true, url, detail: `the video is archived${newest ? `; its page captured ${newest.timestamp}` : ""}` });
+ out.tried.push({ from: "wayback", found: true, url, detail: `the video is archived and its stream answers${newest ? `; its page captured ${newest.timestamp}` : ""}` });
+ } else if (video.formats > 0) {
+ const statuses = [...new Set(video.probes.map((p) => p.status))].join(", ");
+ out.tried.push({
+ from: "wayback",
+ found: false,
+ detail: `${WAYBACK_PAGE_ONLY} (the video index lists ${video.formats} format(s); ${video.probes.length} probed, HTTP ${statuses})`,
+ });
} else {
out.tried.push({ from: "wayback", found: false, detail: "the video is not archived (its page may be)" });
}
@@ -473,6 +496,8 @@ export async function findCopies(opts: {
// Try copies recorded as failed again (they are still listed, as
// `failedBefore`): for a failure later found to be ours, not the copy's.
retryFailed?: boolean;
+ // Nothing recorded (runFindCopy's dry run).
+ dryRun?: boolean;
signal?: AbortSignal;
onLog?: (line: string) => void;
deps?: Partial<FindCopyDeps>;
@@ -521,6 +546,10 @@ export async function findCopies(opts: {
}
} else if (rec.tried.some((t) => t.error)) {
rec.outcome = "error";
+ } else if (youtubeId && !opts.dryRun) {
+ await deps
+ .recordAttempt(facts.videoDir, { at: deps.now().toISOString(), outcome: "none-found", detail: rec.tried.map(describeAttempt).join("; ") })
+ .catch((e: unknown) => log(` ${r.slug}/${r.id}: copy-attempts.json not written (${(e as Error).message}).`));
}
log(
` ${r.slug}/${r.id} (${r.gone}, ${r.windows.length} window(s)): ` +
diff --git a/common/publish/findCopyScope.test.ts b/common/publish/findCopyScope.test.ts
@@ -181,6 +181,32 @@ test("a run: none-found recorded (and then left out), ONE fetch of every copy fo
}
});
+test("(R8) a Wayback video whose stream does not answer is none-found, recorded 'page captured, no video' — not a copy, not failed at its source", async () => {
+ const c = await corpus();
+ const wb = await startFakeWayback({ videos: [WB], streams: [] });
+ const ia = await startFakeArchiveOrg({ items: [] });
+ try {
+ const deps = {
+ wayback: new WaybackClient({ fetch: wb.fetch, sleep: async () => {} }, { minGapMs: 0, maxAttempts: 2 }),
+ archive: new ArchiveOrgClient({ fetch: ia.fetch }, { minGapMs: 0 }),
+ now: () => NOW,
+ };
+ let started = 0;
+ const r = await runFindWholeCopies({ paths: c.paths, scope: { slug: "alpha" }, gone: "no-transcript", deps, startFetch: async () => void started++ });
+ const rec = r.looked.find((x) => x.id === WB);
+ assert.equal(rec?.outcome, "none-found");
+ assert.equal(started, 0, "nothing found: no fetch-copies");
+ const got = await loadCopyAttempts(path.join(c.alpha, "data", WB));
+ assert.deepEqual(got?.failed, []);
+ assert.equal(got?.attempts?.[0]?.outcome, "none-found");
+ assert.match(got?.attempts?.[0]?.detail ?? "", /wayback none — page captured, no video/);
+ } finally {
+ await wb.close();
+ await ia.close();
+ await c.close();
+ }
+});
+
test("archive.org refusing stops the run there; a cancelled run starts no fetch", async () => {
const c = await corpus();
const wb = await startFakeWayback({ videos: [] });
diff --git a/common/testing/README.md b/common/testing/README.md
@@ -23,7 +23,7 @@ transcript, channel or person goes in these fixtures, ever.
| `draft/manifests/full`, `flips` | Release 28: every media field a draft task writes, as the build accepts it today — per-entry `onscreen`, a narrated card, a teaser, `claim` verdicts, `render.chrome.threads` with a `thread` per clip (`full`), or `render.chrome.flips` (`flips`: one THEN/NOW pair over clips of different dates). Hand-written, not derived; `umtool/report-to-video/fixtures-r28.test.mjs` keeps them lint-clean. |
| `draft/reports/ruled.report.json` | Release 28: a synthetic fact-check whose claims carry verdicts standing for operator rulings — every verdict at least once, each cited quote a cue of the corpus. The verdict bench's tests read it. |
| `social/fakeBluesky.mjs` | Release 29: a fake Bluesky on loopback — the public AppView (`resolveHandle`, `getPosts` answering only live posts, images as `embed.images[].fullsize`), a bsky.app-shaped post page (`pageUrl(handle, rkey)`: the post in `[data-testid="postThreadItem-by-<handle>"]` inside page chrome, "Post not found" for a deleted one) for a headless screenshot, and PNG images. `bsky.fetch` sends `https://public.api.bsky.app`, `https://bsky.app` and `https://cdn.bsky.app` to it; `busyTimes` answers 429 first. |
-| `web/fakeWayback.mjs` | Release 29: a fake Wayback Machine — the CDX API (`/cdx/search/cdx`, `output=json` with its header row, `[]` for none, `filter=statuscode:`, `limit`, `matchType=prefix`) and capture pages (`/web/<ts>[id_]/<url>`). `wb.fetch` sends `https://web.archive.org` to it; `busyTimes` 429s, `downTimes` 503s. |
+| `web/fakeWayback.mjs` | Release 29: a fake Wayback Machine — the CDX API (`/cdx/search/cdx`, `output=json` with its header row, `[]` for none, `filter=statuscode:`, `limit`, `matchType=prefix`) and capture pages (`/web/<ts>[id_]/<url>`). `wb.fetch` sends `https://web.archive.org` to it; `busyTimes` 429s, `downTimes` 503s. Release 32 R8: a format's stream at `/web/<ts>id_/<googlevideo url>` (yt-dlp's `2id_` form) serves bytes (206 for a Range) for an id in `streams` (default `videos`), else 404 — `videos` without `streams` is the live "page captured, no video" case; `streamBusyTimes` 429s. |
| `draft/corpus.mjs` `GONE_RECORD`, `GONE_AVAILABILITY` | Release 29: a recording deleted on its platform (`state: "deleted"`, cues kept; add it with `withRecords`) and the `availability.json` it carries on disk. The fake Wayback has one capture of its watch page. |
| `audio/corruptAudio.mjs` | Release 30 lane Q: damaged audio for the salvage and refetch tests — `makeToneFile` (an AAC-in-MP4 tone-burst recording: a 0.3 s burst every 4 s, the bursts being the clock), `corruptBytes` (the same with a seeded run of its bytes overwritten: the frames there fail to decode, their timestamps survive), `readWavMono16`, `toneOnsets` (burst onsets in decoded samples), `burstTimes`, `hasFfmpeg`. Needs ffmpeg; the tests that use it skip without. |
| `mirrors/mirrorCorpus.mjs` | Release 31 lane D: a synthetic creator (`synth-streamer`, "youtube": a public, a deleted and a private stream, removed shorts in and out of the window), its Rumble twin (`synth-streamer-rumble`: data dirs are URL slugs, ids embed ids) and a VOD mirror (`synth-vod-archive`, "odysee", titles `[VOD] SynthStreamer - MM/DD/YYYY - <topic>`, config `recordedDate` + `mirror.of`). `MIRROR_RECORDS` / `CREATOR_RECORDS` / `RUMBLE_RECORDS` are the matcher's input; `writeMirrorCorpus(channelsDir)` writes the three channels to disk (config, metadata, availability); `EXPECTED` is what a mirror scan finds (each status once or more, the removed uploads the mirror holds). |
diff --git a/common/testing/web/fakeWayback.d.mts b/common/testing/web/fakeWayback.d.mts
@@ -10,4 +10,12 @@ export type FakeWayback = {
close(): Promise<void>;
};
-export function startFakeWayback(opts?: { captures?: FakeWaybackCapture[]; videos?: string[]; busyTimes?: number; downTimes?: number }): Promise<FakeWayback>;
+export function startFakeWayback(opts?: {
+ captures?: FakeWaybackCapture[];
+ videos?: string[];
+ // (release 32 R8) ids whose format stream answers (default: videos).
+ streams?: string[];
+ busyTimes?: number;
+ downTimes?: number;
+ streamBusyTimes?: number;
+}): Promise<FakeWayback>;
diff --git a/common/testing/web/fakeWayback.mjs b/common/testing/web/fakeWayback.mjs
@@ -18,7 +18,12 @@
// YoutubeWebArchive extractor asks: `{formats: [...]}` for an id in
// opts.videos (default VIDEOS), `{}` for any other — the video itself
// archived, not only its watch page
+// GET /web/<ts>id_/<format url> (release 32 R8) a format's STREAM, as yt-dlp fetches it
+// (`/web/2id_/<url>`): fake bytes (a Range is answered 206) when the format's `id`
+// is in opts.streams (default: opts.videos), 404 otherwise — an id in `videos` but
+// not in `streams` is the live case, the index listing a video Wayback does not hold
// opts.busyTimes: the first N CDX requests answer 429 (Retry-After: 1); opts.downTimes: then 503s.
+// opts.streamBusyTimes: the first N stream requests answer 429 (Retry-After: 1).
import http from "node:http";
@@ -47,6 +52,8 @@ export const VIDEOS = ["gone-video-05"];
export async function startFakeWayback(opts = {}) {
const captures = opts.captures ?? CAPTURES;
const videos = opts.videos ?? VIDEOS;
+ const streams = opts.streams ?? videos;
+ let streamBusy = opts.streamBusyTimes ?? 0;
const requests = [];
let busy = opts.busyTimes ?? 0;
let down = opts.downTimes ?? 0;
@@ -86,6 +93,21 @@ export async function startFakeWayback(opts = {}) {
: {};
return send(200, "application/json", JSON.stringify(body));
}
+ const st = /^\/web\/\d{1,14}id_\/(https?:\/\/[^/]*googlevideo\.com\/.+)$/.exec(u.pathname + u.search);
+ if (st) {
+ if (streamBusy > 0) {
+ streamBusy--;
+ return send(429, "text/plain", "Too Many Requests", { "retry-after": "1" });
+ }
+ const id = new URL(st[1]).searchParams.get("id") ?? "";
+ if (!streams.includes(id)) return send(404, "text/html", "<p>Wayback Machine has not archived that URL.</p>");
+ const body = Buffer.alloc(4096, 7);
+ const range = /^bytes=(\d+)-(\d*)$/.exec(String(req.headers.range ?? ""));
+ if (!range) return send(200, "video/mp4", body);
+ const from = Number(range[1]);
+ const to = Math.min(body.length - 1, range[2] ? Number(range[2]) : body.length - 1);
+ return send(206, "video/mp4", body.subarray(from, to + 1), { "content-range": `bytes ${from}-${to}/${body.length}` });
+ }
const m = /^\/web\/(\d{14})(?:id_|if_)?\/(.+)$/.exec(u.pathname + u.search);
if (m) {
const c = captures.find((x) => x.timestamp === m[1] && x.original === m[2]);