commit d67b0260342bfda425cda30fe61ee3f88ed8bfe4
parent 3b7caec64ba92249993f96be3e7d717edc1ef68c
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Thu, 19 Nov 2026 13:38:18 -0500
availability: a one-video fetch the platform refused is an observation
The chat replay pass (fetch-chat, the chat backlog, find-clips) and the
metadata refresh classified a refusal such as "Join this channel to get
access to members-only content" and then threw, recording nothing: a stream
backfilled "public" while it was live kept reading public after it went
members-only. Both now record what they were told as source "fetch"
(members-only, private, removed; never a rate limit, the soft block, the bot
check or an age gate), and a refresh records its own metadata field when it
changes the reading. Written only on change. A "fetch" is first-hand but is
not a "check": platformPresence still trusts only a check to say a video is
on its platform.
Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat:
8 files changed, 423 insertions(+), 1 deletion(-)
diff --git a/common/controller/fetchLiveChat.test.ts b/common/controller/fetchLiveChat.test.ts
@@ -189,6 +189,69 @@ test("a rate-limited pass records the cooldown and fails; an auth gate retries o
assert.ok(calls[1].includes("--cookies-from-browser"));
});
+test("a members-only refusal is recorded as the video's availability, and the job still fails", async () => {
+ const dir = await video("ym1", { webpage_url: "https://www.youtube.com/watch?v=ym1", was_live: true });
+ // What the backfill wrote while the stream was live and public.
+ await writeFile(
+ path.join(dir, "availability.json"),
+ JSON.stringify({
+ checkedAt: "2026-01-02T03:00:00.000Z",
+ checkedBy: "backfill",
+ availability: "public",
+ history: [{ availability: "public", observedAt: "2026-01-02T03:00:00.000Z", source: "backfill" }],
+ }),
+ );
+ const stderr =
+ "ERROR: [youtube] ym1: Join this channel to get access to members-only content like this video, and other exclusive perks.";
+ const { run } = stubRunner({ exitCode: 1, stderr, writes: null });
+ const l = log();
+ await assert.rejects(
+ fetchLiveChat({
+ paths, slug: SLUG, videoId: "ym1", videoUrl: "https://www.youtube.com/watch?v=ym1",
+ channelConfig: CONFIG, cookiePolicy: { cookies: undefined, mode: "defer" },
+ onLog: l.onLog, signal: new AbortController().signal, run, paceSeconds: 0,
+ }),
+ /could not fetch the chat of ym1/,
+ );
+ const rec = JSON.parse(await readFile(path.join(dir, "availability.json"), "utf8"));
+ assert.equal(rec.availability, "members_only");
+ assert.equal(rec.checkedBy, "fetch");
+ assert.deepEqual(rec.history.map((h: { availability: string; source: string }) => [h.availability, h.source]), [
+ ["public", "backfill"],
+ ["members_only", "fetch"],
+ ]);
+ // The same refusal again rewrites nothing.
+ const before = await readFile(path.join(dir, "availability.json"), "utf8");
+ await assert.rejects(
+ fetchLiveChat({
+ paths, slug: SLUG, videoId: "ym1", videoUrl: "https://www.youtube.com/watch?v=ym1",
+ channelConfig: CONFIG, cookiePolicy: { cookies: undefined, mode: "defer" },
+ onLog: l.onLog, signal: new AbortController().signal, run, paceSeconds: 0,
+ }),
+ );
+ assert.equal(await readFile(path.join(dir, "availability.json"), "utf8"), before);
+});
+
+test("a rate-limited or soft-blocked chat pass records no availability", async () => {
+ const dir = await video("yr1", { webpage_url: "https://www.youtube.com/watch?v=yr1", was_live: true });
+ for (const stderr of [
+ "ERROR: [youtube] yr1: HTTP Error 429: Too Many Requests",
+ "ERROR: [youtube] yr1: This content isn't available, try again later.",
+ "ERROR: [youtube] yr1: Sign in to confirm you're not a bot",
+ ]) {
+ const { run } = stubRunner({ exitCode: 1, stderr, writes: null });
+ await assert.rejects(
+ fetchLiveChat({
+ paths, slug: SLUG, videoId: "yr1", videoUrl: "https://www.youtube.com/watch?v=yr1",
+ channelConfig: CONFIG, cookiePolicy: { cookies: undefined, mode: "defer" },
+ onLog: () => {}, signal: new AbortController().signal, run, paceSeconds: 0,
+ onPlatformBackoff: () => {},
+ }),
+ );
+ }
+ await assert.rejects(readFile(path.join(dir, "availability.json"), "utf8"));
+});
+
test("the job: refusals before any job (info for a skip), a fetch job, a normalize-only job", async () => {
await writeFile(path.join(CORPUS, "channels", SLUG, "config.json"), JSON.stringify(CONFIG));
const tw = await runFetchChatJob({ paths, slug: SLUG, videoId: "tw1", channelConfig: CONFIG, cookiePolicy: NO_COOKIES });
diff --git a/common/controller/fetchLiveChat.ts b/common/controller/fetchLiveChat.ts
@@ -37,7 +37,9 @@ import {
AUTH_RETRY_CLASSES,
classifyDownloadFailure,
parseUnavailableFromStderr,
+ refusalAvailability,
} from "../lib/availability";
+import { recordFetchObservation } from "../lib/availability-server";
import type { ChannelConfig } from "../lib/channelConfig";
import { assertChannelTextReadable } from "../lib/channelMedia";
import {
@@ -190,6 +192,10 @@ export async function fetchLiveChat(opts: FetchLiveChatOpts): Promise<FetchLiveC
opts.onLog(`Fetching the live chat replay of ${opts.videoId} from ${opts.videoUrl} (no media)\n`);
const firstCookies = alwaysCookies(policy);
let outcome = await pass(firstCookies);
+ // A pass the platform refused for THIS video ("Join this channel …") is an
+ // observation, recorded even when the cookie retry below then succeeds: a
+ // members' cookie reading it is exactly what members-only means.
+ if (!succeeded(outcome.exitCode)) await noteRefusal(videoDir, outcome.stderrTail, opts.onLog);
if (!succeeded(outcome.exitCode) && !opts.signal.aborted) {
const cls = parseUnavailableFromStderr(outcome.stderrTail);
const retryCookies = authRetryCookies(policy);
@@ -201,6 +207,7 @@ export async function fetchLiveChat(opts: FetchLiveChatOpts): Promise<FetchLiveC
) {
opts.onLog(`The chat fetch needs a login (${cls}); retrying with --cookies-from-browser ${retryCookies}\n`);
outcome = await pass(retryCookies);
+ if (!succeeded(outcome.exitCode)) await noteRefusal(videoDir, outcome.stderrTail, opts.onLog);
}
}
if (opts.signal.aborted) throw new Error("Cancelled");
@@ -229,6 +236,19 @@ export async function fetchLiveChat(opts: FetchLiveChatOpts): Promise<FetchLiveC
return normalizeChat(opts, videoDir);
}
+// Best-effort: a failed write is logged, never the job's failure.
+async function noteRefusal(videoDir: string, stderrTail: string, onLog: (s: string) => void): Promise<void> {
+ const seen = refusalAvailability(stderrTail);
+ if (!seen) return;
+ try {
+ if (await recordFetchObservation(videoDir, seen, new Date().toISOString())) {
+ onLog(`Recorded the source's answer for this video: ${seen} (availability.json)\n`);
+ }
+ } catch (err) {
+ onLog(`Could not record the availability (${seen}): ${(err as Error).message}\n`);
+ }
+}
+
async function normalizeChat(
opts: Pick<FetchLiveChatOpts, "slug" | "videoId" | "channelConfig" | "onLog">,
videoDir: string,
diff --git a/common/controller/refreshVideoMetadata.test.ts b/common/controller/refreshVideoMetadata.test.ts
@@ -289,6 +289,68 @@ test("an auth-gated refresh retries once with cookies in when-required mode, nev
}
});
+test("a members-only refusal is recorded, once, even when the members' cookie retry then reads the video", async () => {
+ const f = await fixture({ meta: BEFORE });
+ try {
+ await writeFile(
+ path.join(f.videoDir, "availability.json"),
+ JSON.stringify({
+ checkedAt: "2026-01-02T03:00:00.000Z",
+ checkedBy: "backfill",
+ availability: "public",
+ history: [{ availability: "public", observedAt: "2026-01-02T03:00:00.000Z", source: "backfill" }],
+ }),
+ );
+ const { run } = stubRunner([
+ { exitCode: 1, stderr: `ERROR: [youtube] ${ID}: Join this channel to get access to members-only content like this video.` },
+ { exitCode: 0, write: { ...AFTER, availability: "subscriber_only" } },
+ ]);
+ const lines: string[] = [];
+ await refreshVideoMetadata({
+ paths: f.paths, slug: SLUG, videoId: ID, videoUrl: URL, channelConfig: CONFIG,
+ cookiePolicy: { cookies: "firefox", mode: "when-required" },
+ onLog: (s) => lines.push(s), signal: new AbortController().signal, run, paceSeconds: 1,
+ });
+ const rec = JSON.parse(await readFile(path.join(f.videoDir, "availability.json"), "utf8"));
+ assert.equal(rec.availability, "members_only");
+ assert.equal(rec.checkedBy, "fetch");
+ assert.equal(rec.history.length, 2, "the refusal and the refreshed field agree: one entry");
+ assert.match(lines.join(""), /Recorded the source's answer for this video: members_only/);
+ } finally {
+ await rm(f.root, { recursive: true, force: true });
+ }
+});
+
+test("a refresh writes availability only when the video's own field changes it", async () => {
+ const f = await fixture({ meta: BEFORE });
+ try {
+ const checked = JSON.stringify({
+ checkedAt: "2026-01-02T03:00:00.000Z",
+ checkedBy: "check",
+ availability: "public",
+ history: [{ availability: "public", observedAt: "2026-01-02T03:00:00.000Z", source: "check" }],
+ });
+ await writeFile(path.join(f.videoDir, "availability.json"), checked);
+ const opts = {
+ paths: f.paths, slug: SLUG, videoId: ID, videoUrl: URL, channelConfig: CONFIG,
+ cookiePolicy: { cookies: undefined, mode: "when-required" } as ResolvedCookiePolicy,
+ onLog: () => {}, signal: new AbortController().signal, paceSeconds: 1,
+ };
+ // Public again, and a record with no field at all: nothing written, the
+ // check stays a check.
+ await refreshVideoMetadata({ ...opts, run: stubRunner([{ exitCode: 0, write: { ...AFTER, availability: "public" } }]).run });
+ await refreshVideoMetadata({ ...opts, run: stubRunner([{ exitCode: 0, write: AFTER }]).run });
+ assert.equal(await readFile(path.join(f.videoDir, "availability.json"), "utf8"), checked);
+ // Made private: recorded as a fetch.
+ await refreshVideoMetadata({ ...opts, run: stubRunner([{ exitCode: 0, write: { ...AFTER, availability: "private" } }]).run });
+ const rec = JSON.parse(await readFile(path.join(f.videoDir, "availability.json"), "utf8"));
+ assert.equal(rec.availability, "private");
+ assert.equal(rec.checkedBy, "fetch");
+ } finally {
+ await rm(f.root, { recursive: true, force: true });
+ }
+});
+
test("a rate-limited refresh records the platform cooldown, rewrites nothing and fails", async () => {
const f = await fixture({ meta: BEFORE });
try {
diff --git a/common/controller/refreshVideoMetadata.ts b/common/controller/refreshVideoMetadata.ts
@@ -48,9 +48,13 @@ import path from "node:path";
import { readFile, stat } from "node:fs/promises";
import {
AUTH_RETRY_CLASSES,
+ availabilityFromJsonField,
classifyDownloadFailure,
parseUnavailableFromStderr,
+ refusalAvailability,
+ type Availability,
} from "../lib/availability";
+import { recordFetchObservation } from "../lib/availability-server";
import type { ChannelConfig } from "../lib/channelConfig";
import {
DEFAULT_COOKIE_MODE,
@@ -445,6 +449,11 @@ export async function refreshVideoMetadata(
const firstCookies = alwaysCookies(policy);
let usedCookies = Boolean(firstCookies);
let outcome = await pass(firstCookies);
+ // A pass the platform refused for THIS video is an observation (lane
+ // missing-source), recorded even when the cookie retry below succeeds.
+ if (!succeeded(outcome.exitCode)) {
+ await noteAvailability(videoDir, refusalAvailability(outcome.stderrTail), opts.onLog);
+ }
// The prefetch's auth retry, verbatim in effect: once, with cookies, when
// the failure is an auth/age gate, the mode allows it, and the failed pass
@@ -464,6 +473,9 @@ export async function refreshVideoMetadata(
);
usedCookies = true;
outcome = await pass(retryCookies);
+ if (!succeeded(outcome.exitCode)) {
+ await noteAvailability(videoDir, refusalAvailability(outcome.stderrTail), opts.onLog);
+ }
}
}
@@ -504,6 +516,13 @@ export async function refreshVideoMetadata(
if (!isObject(meta)) {
throw new Error(`${path.relative(channelDir, infoPath)} is not a JSON object`);
}
+ // What the refreshed metadata itself says (a members' cookie reads
+ // `subscriber_only`), recorded only when the video's own field is there and
+ // differs from what the archive holds.
+ const field = (meta as { availability?: unknown }).availability;
+ if (typeof field === "string") {
+ await noteAvailability(videoDir, availabilityFromJsonField(field), opts.onLog);
+ }
const summary = refreshSummaryLines({
videoId: opts.videoId,
meta,
@@ -513,3 +532,19 @@ export async function refreshVideoMetadata(
opts.onLog(`${summary.join("\n")}\n`);
return { meta, entries, usedCookies, summary };
}
+
+// Best-effort: a failed write is logged, never the job's failure.
+async function noteAvailability(
+ videoDir: string,
+ seen: Availability | null,
+ onLog: (s: string) => void,
+): Promise<void> {
+ if (!seen) return;
+ try {
+ if (await recordFetchObservation(videoDir, seen, new Date().toISOString())) {
+ onLog(`Recorded the source's answer for this video: ${seen} (availability.json)\n`);
+ }
+ } catch (err) {
+ onLog(`Could not record the availability (${seen}): ${(err as Error).message}\n`);
+ }
+}
diff --git a/common/lib/availability-server.test.ts b/common/lib/availability-server.test.ts
@@ -0,0 +1,108 @@
+import { test } from "node:test";
+import assert from "node:assert/strict";
+import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
+import { tmpdir } from "node:os";
+import path from "node:path";
+import {
+ platformPresence,
+ recordFetchObservation,
+ resolveEffectiveAvailabilityObserved,
+} from "./availability-server";
+
+// Run with:
+// pnpm --filter yt-dlp-transcript-common exec tsx --test lib/availability-server.test.ts
+//
+// The fetch observation (lane missing-source) and the day a state was first
+// seen. Every case is a temp video dir.
+
+async function dir(): Promise<string> {
+ return mkdtemp(path.join(tmpdir(), "avail-"));
+}
+
+const PUBLIC_BACKFILL = {
+ checkedAt: "2026-01-02T03:00:00.000Z",
+ checkedBy: "backfill",
+ availability: "public",
+ history: [{ availability: "public", observedAt: "2026-01-02T03:00:00.000Z", source: "backfill" }],
+ webpageUrl: "https://www.youtube.com/watch?v=synthvid001",
+};
+
+test("a fetch observation over a backfilled 'public' moves the top level and keeps the page URL", async () => {
+ const d = await dir();
+ try {
+ await writeFile(path.join(d, "availability.json"), JSON.stringify(PUBLIC_BACKFILL));
+ assert.equal(await recordFetchObservation(d, "members_only", "2026-01-03T10:00:00.000Z"), true);
+ const rec = JSON.parse(await readFile(path.join(d, "availability.json"), "utf8"));
+ assert.equal(rec.availability, "members_only");
+ assert.equal(rec.checkedBy, "fetch");
+ assert.equal(rec.checkedAt, "2026-01-03T10:00:00.000Z");
+ assert.equal(rec.webpageUrl, PUBLIC_BACKFILL.webpageUrl);
+ assert.equal(rec.history.length, 2);
+ // The same reading again writes nothing.
+ assert.equal(await recordFetchObservation(d, "members_only", "2026-01-04T10:00:00.000Z"), false);
+ assert.equal(JSON.parse(await readFile(path.join(d, "availability.json"), "utf8")).checkedAt, "2026-01-03T10:00:00.000Z");
+ // A fetch never says a video is ON its platform.
+ const presence = await platformPresence(d, { maxAgeDays: 30, now: new Date("2026-01-03T12:00:00Z") });
+ assert.equal(presence.onPlatform, false);
+ } finally {
+ await rm(d, { recursive: true, force: true });
+ }
+});
+
+test("a fetch that reads 'public' with no record writes nothing", async () => {
+ const d = await dir();
+ try {
+ assert.equal(await recordFetchObservation(d, "public", "2026-01-03T10:00:00.000Z"), false);
+ await assert.rejects(readFile(path.join(d, "availability.json"), "utf8"));
+ } finally {
+ await rm(d, { recursive: true, force: true });
+ }
+});
+
+test("observed: the first entry of the trailing run, else checkedAt, else the outcome's time", async () => {
+ const d = await dir();
+ try {
+ assert.equal(await resolveEffectiveAvailabilityObserved(d), null);
+ await writeFile(
+ path.join(d, "availability.json"),
+ JSON.stringify({
+ checkedAt: "2026-01-09T00:00:00.000Z",
+ checkedBy: "check",
+ availability: "members_only",
+ history: [
+ { availability: "public", observedAt: "2026-01-01T00:00:00.000Z", source: "backfill" },
+ { availability: "members_only", observedAt: "2026-01-05T00:00:00.000Z", source: "fetch" },
+ ],
+ }),
+ );
+ assert.deepEqual(await resolveEffectiveAvailabilityObserved(d), {
+ availability: "members_only",
+ observedAt: "2026-01-05T00:00:00.000Z",
+ });
+ await writeFile(
+ path.join(d, "availability.json"),
+ JSON.stringify({ checkedAt: "2026-01-09T00:00:00.000Z", availability: "private" }),
+ );
+ assert.deepEqual(await resolveEffectiveAvailabilityObserved(d), {
+ availability: "private",
+ observedAt: "2026-01-09T00:00:00.000Z",
+ });
+ // A newer download outcome that found it removed wins, dated by its finish.
+ await writeFile(
+ path.join(d, "download-outcome.json"),
+ JSON.stringify({
+ videoId: "synthvid001",
+ webpageUrl: "https://www.youtube.com/watch?v=synthvid001",
+ status: "failed",
+ startedAt: "2026-01-10T00:00:00.000Z",
+ finishedAt: "2026-01-10T00:01:00.000Z",
+ attempts: [{ n: 0, kind: "download", handling: "youtube", usedCookies: false, ytdlpExitCode: 1, availabilityClass: "deleted" }],
+ }),
+ );
+ const got = await resolveEffectiveAvailabilityObserved(d);
+ assert.equal(got?.availability, "deleted");
+ assert.equal(got?.observedAt, "2026-01-10T00:01:00.000Z");
+ } finally {
+ await rm(d, { recursive: true, force: true });
+ }
+});
diff --git a/common/lib/availability-server.ts b/common/lib/availability-server.ts
@@ -127,6 +127,73 @@ export async function resolveEffectiveAvailability(
return outcome?.availability ?? null;
}
+// The effective availability (as resolveEffectiveAvailability) AND the instant
+// the archive first observed it — the start of the trailing run of history
+// entries that agree with it, else the record's checkedAt, else the outcome's
+// finishedAt. The published `stateSince` is this instant's day (buildIndex).
+export async function resolveEffectiveAvailabilityObserved(
+ videoDir: string,
+): Promise<{ availability: Availability; observedAt: string | null } | null> {
+ const [explicit, outcome] = await Promise.all([
+ loadAvailability(videoDir),
+ loadDownloadOutcomeAvailability(videoDir),
+ ]);
+ const fromOutcome =
+ outcome &&
+ (!explicit ||
+ (outcome.finishedAt !== null &&
+ new Date(outcome.finishedAt) > new Date(explicit.checkedAt)));
+ if (fromOutcome && outcome) {
+ // A download's class also appends a history entry (downloadOneManaged), so
+ // the history can date it when it agrees; else the outcome's own time.
+ const since = explicit ? firstOfTrailingRun(explicit, outcome.availability) : null;
+ return { availability: outcome.availability, observedAt: since ?? outcome.finishedAt };
+ }
+ if (!explicit) return null;
+ return {
+ availability: explicit.availability,
+ observedAt: firstOfTrailingRun(explicit, explicit.availability) ?? explicit.checkedAt,
+ };
+}
+
+function firstOfTrailingRun(record: AvailabilityRecord, availability: Availability): string | null {
+ const history = record.history ?? [];
+ let since: string | null = null;
+ for (let i = history.length - 1; i >= 0; i--) {
+ if (history[i].availability !== availability) break;
+ since = history[i].observedAt;
+ }
+ return since;
+}
+
+// RECORD WHAT A FETCH OF ONE VIDEO WAS TOLD (lane missing-source): the chat
+// replay pass and the metadata refresh hear the platform answer for this one
+// video — "Join this channel to get access to members-only content", or a
+// refreshed metadata.info.json whose own field says subscriber_only — and that
+// is an observation. Written, as source "fetch" over the top-level fields, ONLY
+// when it differs from the effective availability, so a repeated refusal or an
+// unchanged refresh rewrites nothing (and never turns a fresh "check" into a
+// "fetch"). Returns whether it wrote.
+export async function recordFetchObservation(
+ videoDir: string,
+ availability: Availability,
+ observedAt: string,
+): Promise<boolean> {
+ const effective = await resolveEffectiveAvailability(videoDir).catch(() => null);
+ if (effective === availability) return false;
+ // A fetch that read "public" over NO record says nothing worth writing: the
+ // backfill or a check owns a first record.
+ if (effective === null && availability === "public") return false;
+ const existing = await loadAvailability(videoDir);
+ await recordAvailability(videoDir, {
+ availability,
+ observedAt,
+ source: "fetch",
+ ...(existing?.webpageUrl ? { webpageUrl: existing.webpageUrl } : {}),
+ });
+ return true;
+}
+
// Decide the VideoState for one video that the last quick availability check
// found absent from its channel's fresh playlist listing. `scannedAtMs` is that
// check's `checkedAt`. Three outcomes, and both of the non-obvious ones earn
diff --git a/common/lib/availability.test.ts b/common/lib/availability.test.ts
@@ -215,3 +215,32 @@ test("a subtitle 429 beside another subtitle failure classes as the OTHER failur
"rate_limit",
);
});
+
+test("refusalAvailability: only a per-video 'not public there' reason counts", async () => {
+ const { refusalAvailability } = await import("./availability");
+ assert.equal(
+ refusalAvailability("ERROR: [youtube] abc: Join this channel to get access to members-only content like this video."),
+ "members_only",
+ );
+ assert.equal(refusalAvailability("ERROR: [youtube] abc: Private video. Sign in if you've been granted access"), "private");
+ assert.equal(refusalAvailability("ERROR: [youtube] abc: Video unavailable. This video has been removed by the uploader"), "deleted");
+ for (const nothing of [
+ "ERROR: [youtube] abc: HTTP Error 429: Too Many Requests",
+ "ERROR: [youtube] abc: This content isn't available, try again later. The current session has been rate-limited",
+ "ERROR: [youtube] abc: Sign in to confirm you're not a bot",
+ "ERROR: [youtube] abc: Sign in to confirm your age",
+ "ERROR: unable to download webpage: <urlopen error [Errno 111] ECONNREFUSED>",
+ "ERROR: something nobody has seen before",
+ ]) {
+ assert.equal(refusalAvailability(nothing), null, nothing);
+ }
+});
+
+test("isNotPublicState: members-only, private and deleted; never unlisted or a suspicion", async () => {
+ const { isNotPublicState } = await import("./availability");
+ assert.deepEqual(
+ (["available", "maybe_missing", "unlisted", "private", "members_only", "deleted"] as const).filter((s) => isNotPublicState(s)),
+ ["private", "members_only", "deleted"],
+ );
+ assert.equal(isNotPublicState(undefined), false);
+});
diff --git a/common/lib/availability.ts b/common/lib/availability.ts
@@ -68,6 +68,22 @@ export type VideoState =
| "members_only"
| "deleted";
+// NO LONGER PUBLIC AT ITS PLATFORM (lane missing-source): the states in which a
+// visitor cannot watch the source there, so the export site mounts no player
+// for it and says so. Unlisted still plays by direct link and "maybe missing" is
+// a suspicion, so neither is here. NOT the same reading as lib/sourceGone.ts's
+// goneState (deleted / private), which reports use and which by its own ruling
+// does not count members-only as gone: a member's cookies fetch it.
+export const NOT_PUBLIC_STATES: ReadonlyArray<VideoState> = [
+ "members_only",
+ "private",
+ "deleted",
+];
+
+export function isNotPublicState(s: VideoState | null | undefined): boolean {
+ return s != null && NOT_PUBLIC_STATES.includes(s);
+}
+
// Ordered for UI: the umbrella's leaves in the order they're offered.
export const MISSING_STATES: ReadonlyArray<VideoState> = [
"maybe_missing",
@@ -136,7 +152,17 @@ export const VIDEO_STATE_LABELS: Record<VideoState, string> = {
unlisted: "Unlisted",
};
-export type AvailabilityHistorySource = "check" | "backfill" | "download";
+// WHO OBSERVED IT. "check" is a real probe of the platform (the channel page's
+// Diagnostics → Check availability); "backfill" an assumption copied from a
+// video's metadata.info.json when it first lands; "download" a download
+// attempt's class (history only — the class itself is in download-outcome.json).
+// "fetch" (lane missing-source) is a one-video fetch — the chat replay pass, a
+// metadata refresh — that the platform answered with a per-video reason
+// ("Join this channel …"), or a refresh that read the video's own field. It is
+// first-hand, but it is NOT a "check": platformPresence trusts only a check to
+// say a video is still ON its platform, so a fetch can never make compaction
+// treat a source as present.
+export type AvailabilityHistorySource = "check" | "backfill" | "download" | "fetch";
export type AvailabilityHistoryEntry = {
availability: Availability;
@@ -371,6 +397,18 @@ export function classifyDownloadFailure(
return "unknown";
}
+// WHAT A REFUSED FETCH OF ONE VIDEO SAYS ABOUT IT, or null when it says
+// nothing (lane missing-source). Only the per-video classes that mean "not
+// public there" count: members-only, private, removed. A rate limit, the soft
+// block, the bot check, a network failure or an unclassified error never saw
+// the video; an age gate (needs_auth) is the video answering, and a login
+// retry may still read it.
+export function refusalAvailability(stderrTail: string): Availability | null {
+ const cls = parseUnavailableFromStderr(stderrTail);
+ if (classifyDownloadFailure(stderrTail, cls) !== "per_video") return null;
+ return cls === "members_only" || cls === "private" || cls === "deleted" ? cls : null;
+}
+
// Map the `availability` field that yt-dlp puts in --dump-json output to our
// enum. yt-dlp uses: public, unlisted, needs_auth, premium_only, subscriber_only,
// public_unlisted (rare), private, etc.