Archilyzer · Source

archilyzer

Archilyzer
git clone https://archilyzer.pages.dev/source/archilyzer.git
Log | Files | Refs | README | LICENSE

commit 102c3e62d376c1a9a241a515e886c162d1761886
parent 8a899cb0e912dbbf5b03b01d728e69875b5c4ce8
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Thu, 19 Nov 2026 13:54:00 -0500

common: the sentence for a source no longer public, and the own-copy clock

lib/sourceMissing.ts says a members-only, private or deleted source in one
sentence with the state and the day, and nothing about who saw it or how:
"This stream is no longer public on YouTube (members-only since 19 Nov 2026).
The transcript is kept here." It also gives the marked platform link and the
badge tooltip's day. lib/localFileClock.ts keeps a visitor's own copy on the
cue clock through one offset, and the offset is the only thing it stores.
Search cards carry `stateSince` to their badge's tooltip. The IndexedDB
transcript store goes to v5 so cached records pick up the new keys.

Co-Authored-By: Claude <noreply@anthropic.com>

Diffstat:
Mcommon/components/SearchResults.tsx | 2+-
Mcommon/components/SearchSessionContext.tsx | 4++++
Mcommon/components/badges.tsx | 8++++++--
Mcommon/components/transcriptStore.ts | 7++++++-
Acommon/lib/localFileClock.test.ts | 72++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Acommon/lib/localFileClock.ts | 76++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Acommon/lib/sourceMissing.test.ts | 47+++++++++++++++++++++++++++++++++++++++++++++++
Acommon/lib/sourceMissing.ts | 80+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
8 files changed, 292 insertions(+), 4 deletions(-)

diff --git a/common/components/SearchResults.tsx b/common/components/SearchResults.tsx @@ -681,7 +681,7 @@ const ResultCard = memo(function ResultCard({ </span> {group.isLivestream && <LivestreamBadge />} {group.ageRestricted && <AgeRestrictedBadge />} - <VideoStateBadge state={group.state} /> + <VideoStateBadge state={group.state} since={group.stateSince} /> {siblings.length > 0 && ( <DuplicateBadge count={siblings.length} /> )} diff --git a/common/components/SearchSessionContext.tsx b/common/components/SearchSessionContext.tsx @@ -151,6 +151,8 @@ export type ResultGroup = { // Presence on the source platform, for the card's state badge. Posts are // always "available" — a post has no channel listing to fall out of. state: VideoState; + // The day the archive first saw `state` (YYYYMMDD), for the badge's tooltip. + stateSince?: string; // Carried through so the card can flag likely-expired stream VODs (Kick, // Twitch) via vodExpiry(platform, uploadDate). platform: Platform; @@ -1022,6 +1024,7 @@ function useSearchSessionState() { isLivestream: t.isLivestream, ageRestricted: t.ageRestricted, state: summaryState(t), + ...(t.stateSince ? { stateSince: t.stateSince } : {}), platform: t.platform, uploadDate: t.uploadDate, hits: [], @@ -1050,6 +1053,7 @@ function useSearchSessionState() { isLivestream: t.isLivestream, ageRestricted: t.ageRestricted, state: summaryState(t), + ...(t.stateSince ? { stateSince: t.stateSince } : {}), platform: t.platform, uploadDate: t.uploadDate, hits: hitsBySlug.get(t.slug) ?? [], diff --git a/common/components/badges.tsx b/common/components/badges.tsx @@ -1,4 +1,5 @@ import { VIDEO_STATE_LABELS, type VideoState } from "../lib/availability"; +import { stateSinceTitle } from "../lib/sourceMissing"; const badgeBase = "shrink-0 text-[10px] font-semibold uppercase tracking-wide px-1.5 py-0.5 rounded"; @@ -49,12 +50,15 @@ const STATE_STYLES: Record< }, }; -export function VideoStateBadge({ state }: { state: VideoState }) { +// `since` (YYYYMMDD, lane missing-source): the day the archive first saw the +// state, added to the tooltip ("… since 19 Nov 2026"). The label and test id +// are unchanged. +export function VideoStateBadge({ state, since }: { state: VideoState; since?: string }) { if (state === "available") return null; const style = STATE_STYLES[state]; return ( <span - title={style.title} + title={stateSinceTitle(style.title, since)} data-testid={`state-badge-${state}`} data-state={state} aria-label={VIDEO_STATE_LABELS[state]} diff --git a/common/components/transcriptStore.ts b/common/components/transcriptStore.ts @@ -12,7 +12,12 @@ const DB_NAME = "yt-dlp-transcript-browser"; // the bare slug, so behavior is unchanged after the one-time wipe. // v4 adds the optional `hlsUrl` field to cached TranscriptDetail (Kick VOD // playback); wipe so stale entries re-fetch the authoritative page JSON. -const DB_VERSION = 4; +// v5 (lane missing-source) adds `state` / `stateSince` to a record whose +// source is no longer public at its platform; wipe so a record cached before +// re-fetches. (A cached record is never refreshed after that — the modal reads +// a video's state from the fresh summaries first, PlayerProvider +// useFreshSummaryState.) +const DB_VERSION = 5; const STORE = "transcripts"; type Mode = "pending" | "ok" | "unavailable"; diff --git a/common/lib/localFileClock.test.ts b/common/lib/localFileClock.test.ts @@ -0,0 +1,72 @@ +import { test } from "node:test"; +import assert from "node:assert/strict"; +import { + OFFSET_LIMIT_SECONDS, + formatOffset, + nudgeOffset, + offsetFromSync, + offsetKey, + readOffset, + toCueTime, + toFileTime, + writeOffset, +} from "./localFileClock"; + +// Run with: +// pnpm --filter yt-dlp-transcript-common exec tsx --test lib/localFileClock.test.ts + +function memoryStore() { + const m = new Map<string, string>(); + return { + m, + getItem: (k: string) => m.get(k) ?? null, + setItem: (k: string, v: string) => void m.set(k, v), + removeItem: (k: string) => void m.delete(k), + }; +} + +test("the two clocks round-trip through the offset, and never go below 0", () => { + assert.equal(toFileTime(10, 2.5), 12.5); + assert.equal(toCueTime(12.5, 2.5), 10); + assert.equal(toFileTime(1, -3), 0); + assert.equal(toCueTime(1, 3), 0); + for (const off of [-7.25, 0, 0.1, 42]) assert.equal(toCueTime(toFileTime(100, off), off), 100); +}); + +test("nudge and sync round to centiseconds and stay in range", () => { + assert.equal(nudgeOffset(0, 0.1), 0.1); + assert.equal(nudgeOffset(0.1, 0.1), 0.2); + assert.equal(nudgeOffset(0.2, -1), -0.8); + assert.equal(nudgeOffset(OFFSET_LIMIT_SECONDS, 1), OFFSET_LIMIT_SECONDS); + // The line that starts at 30 s is what the file plays at 32.346 s. + assert.equal(offsetFromSync(32.346, 30), 2.35); + assert.equal(offsetFromSync(5, 30), -25); +}); + +test("the offset display", () => { + assert.equal(formatOffset(0), "0.00 s"); + assert.equal(formatOffset(1.5), "+1.50 s"); + assert.equal(formatOffset(-0.1), "−0.10 s"); +}); + +test("storage holds only a number under the video's key; junk and refusals read as 0", () => { + const s = memoryStore(); + assert.equal(readOffset(s, "chan/vid"), 0); + writeOffset(s, "chan/vid", 2.345); + assert.deepEqual([...s.m.entries()], [[offsetKey("chan/vid"), "2.35"]]); + assert.equal(readOffset(s, "chan/vid"), 2.35); + writeOffset(s, "chan/vid", 0); + assert.equal(s.m.size, 0, "0 removes the key"); + s.m.set(offsetKey("chan/vid"), "not a number"); + assert.equal(readOffset(s, "chan/vid"), 0); + s.m.set(offsetKey("chan/vid"), String(OFFSET_LIMIT_SECONDS * 2)); + assert.equal(readOffset(s, "chan/vid"), 0); + const refusing = { + getItem: () => { throw new Error("SecurityError"); }, + setItem: () => { throw new Error("QuotaExceededError"); }, + removeItem: () => { throw new Error("SecurityError"); }, + }; + assert.equal(readOffset(refusing, "chan/vid"), 0); + writeOffset(refusing, "chan/vid", 1); + assert.equal(readOffset(null, "chan/vid"), 0); +}); diff --git a/common/lib/localFileClock.ts b/common/lib/localFileClock.ts @@ -0,0 +1,76 @@ +// A VISITOR'S OWN COPY ON THE TRANSCRIPT'S CLOCK (lane missing-source, slice 2). +// +// The export site can play a local file the visitor picks — from an object URL, +// in the page, never uploaded — with the transcript following it. Their copy +// may start earlier or later than the cues' clock, so everything the page does +// (follow, click-to-seek, clip marks, Share's t=) stays on the CUE clock and the +// file is reached through one offset: +// +// fileTime = cueTime + offset cueTime = fileTime - offset +// +// A positive offset: the transcript's 0:00 is that far into the file (the copy +// has a lead-in). The offset is the ONLY thing ever stored, per video, in +// localStorage — never the file's name, size or anything else about it. +// +// Pure: client-safe, no node: imports, no I/O but the Storage handed in. + +export const OFFSET_LIMIT_SECONDS = 24 * 3600; +export const OFFSET_KEY_PREFIX = "archilyzer:local-offset:"; + +const round = (v: number) => Math.round(v * 100) / 100; +const clampOffset = (v: number) => Math.max(-OFFSET_LIMIT_SECONDS, Math.min(OFFSET_LIMIT_SECONDS, round(v))); + +export function toFileTime(cueTime: number, offset: number): number { + return Math.max(0, cueTime + offset); +} + +export function toCueTime(fileTime: number, offset: number): number { + return Math.max(0, fileTime - offset); +} + +export function nudgeOffset(offset: number, delta: number): number { + return clampOffset(offset + delta); +} + +// "This line is playing now": the line that starts at `cueStart` is what the +// file plays at `fileTime`. +export function offsetFromSync(fileTime: number, cueStart: number): number { + return clampOffset(fileTime - cueStart); +} + +export function formatOffset(offset: number): string { + const v = round(offset); + if (v === 0) return "0.00 s"; + return `${v > 0 ? "+" : "−"}${Math.abs(v).toFixed(2)} s`; +} + +export function offsetKey(slug: string): string { + return `${OFFSET_KEY_PREFIX}${slug}`; +} + +type OffsetStore = Pick<Storage, "getItem" | "setItem" | "removeItem">; + +// A stored offset, or 0 when there is none, it is not a finite number in range, +// or storage is unavailable (a private window, blocked site data). +export function readOffset(store: OffsetStore | null | undefined, slug: string): number { + try { + const raw = store?.getItem(offsetKey(slug)); + if (raw == null) return 0; + const v = Number(raw); + if (!Number.isFinite(v) || Math.abs(v) > OFFSET_LIMIT_SECONDS) return 0; + return round(v); + } catch { + return 0; + } +} + +// 0 removes the key: nothing is kept for a copy that needs no offset. +export function writeOffset(store: OffsetStore | null | undefined, slug: string, offset: number): void { + try { + const v = clampOffset(offset); + if (v === 0) store?.removeItem(offsetKey(slug)); + else store?.setItem(offsetKey(slug), String(v)); + } catch { + /* storage refused: the offset lives for this page only */ + } +} diff --git a/common/lib/sourceMissing.test.ts b/common/lib/sourceMissing.test.ts @@ -0,0 +1,47 @@ +import { test } from "node:test"; +import assert from "node:assert/strict"; +import { + formatStateDay, + sourceLinkLabel, + sourceMissingSentence, + stateSinceTitle, +} from "./sourceMissing"; + +// Run with: +// pnpm --filter yt-dlp-transcript-common exec tsx --test lib/sourceMissing.test.ts + +test("the sentence names the state and the day, and nothing else", () => { + assert.equal( + sourceMissingSentence({ state: "members_only", stateSince: "20261119", platform: "youtube", isLivestream: true }), + "This stream is no longer public on YouTube (members-only since 19 Nov 2026). The transcript is kept here.", + ); + assert.equal( + sourceMissingSentence({ state: "private", stateSince: "20260301", platform: "rumble" }), + "This video is no longer public on Rumble (private since 1 Mar 2026). The transcript is kept here.", + ); + assert.equal( + sourceMissingSentence({ state: "deleted", stateSince: "20251231", platform: "youtube" }), + "This video is no longer public on YouTube (removed since 31 Dec 2025). The transcript is kept here.", + ); + // No day: the state alone. + assert.equal( + sourceMissingSentence({ state: "deleted", platform: "odysee" }), + "This video is no longer public on Odysee (removed). The transcript is kept here.", + ); +}); + +test("states that keep their player get no sentence", () => { + for (const state of ["available", "unlisted", "maybe_missing", undefined] as const) { + assert.equal(sourceMissingSentence({ state, platform: "youtube" }), null, String(state)); + } +}); + +test("the marked link, the badge title, the day format", () => { + assert.equal(sourceLinkLabel("youtube", "members_only"), "Open on YouTube (members-only)"); + assert.equal(sourceLinkLabel("twitch", "deleted"), "Open on Twitch (removed)"); + assert.equal(sourceLinkLabel(undefined, "private"), "Open on its platform (private)"); + assert.equal(stateSinceTitle("Members-only on the source platform", "20261119"), "Members-only on the source platform since 19 Nov 2026"); + assert.equal(stateSinceTitle("Deleted", undefined), "Deleted"); + assert.equal(formatStateDay("2026-11-19"), null); + assert.equal(formatStateDay("20261319"), null); +}); diff --git a/common/lib/sourceMissing.ts b/common/lib/sourceMissing.ts @@ -0,0 +1,80 @@ +// WHAT THE SITE SAYS WHEN A SOURCE IS NO LONGER PUBLIC (lane missing-source). +// +// A video whose state is members-only, private or deleted at its platform +// (availability.ts NOT_PUBLIC_STATES) gets no player on the export site: a +// sentence in its place, the platform link kept but marked, and the transcript +// as for any video. The sentence names the state and the day the archive first +// saw it (`stateSince`) and nothing else — never who observed it or how. +// +// Pure: client-safe, no node: imports. + +import { isNotPublicState, type VideoState } from "./availability"; + +// A platform's name as a person writes it. Kept here rather than imported from +// the report modules so the client bundle does not pull them in. +const PLATFORM_NAMES: Readonly<Record<string, string>> = { + youtube: "YouTube", + rumble: "Rumble", + odysee: "Odysee", + twitch: "Twitch", + kick: "Kick", + archiveorg: "archive.org", + bitchute: "BitChute", +}; + +export function sourcePlatformName(platform: string | null | undefined): string { + return (platform && PLATFORM_NAMES[platform]) || "its platform"; +} + +// The state as the sentence says it. +const STATE_WORDS: Readonly<Record<string, string>> = { + members_only: "members-only", + private: "private", + deleted: "removed", +}; + +const MONTHS = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]; + +// "20261119" -> "19 Nov 2026"; anything else -> null. +export function formatStateDay(yyyymmdd: string | null | undefined): string | null { + if (!yyyymmdd || !/^\d{8}$/.test(yyyymmdd)) return null; + const m = Number(yyyymmdd.slice(4, 6)); + const d = Number(yyyymmdd.slice(6, 8)); + if (m < 1 || m > 12 || d < 1 || d > 31) return null; + return `${d} ${MONTHS[m - 1]} ${yyyymmdd.slice(0, 4)}`; +} + +export type SourceGone = { + state: VideoState; + stateSince?: string; +}; + +// The one sentence: "This stream is no longer public on YouTube (members-only +// since 19 Nov 2026). The transcript is kept here." With no day, the +// parenthesis is the state alone. Null for a state that keeps its player. +export function sourceMissingSentence(o: { + state: VideoState | null | undefined; + stateSince?: string | null; + platform: string | null | undefined; + isLivestream?: boolean; +}): string | null { + if (!isNotPublicState(o.state)) return null; + const what = o.isLivestream ? "stream" : "video"; + const word = STATE_WORDS[o.state as string]; + const day = formatStateDay(o.stateSince); + const paren = day ? `${word} since ${day}` : word; + return `This ${what} is no longer public on ${sourcePlatformName(o.platform)} (${paren}). The transcript is kept here.`; +} + +// The platform link, kept but marked: "Open on YouTube (members-only)". +export function sourceLinkLabel(platform: string | null | undefined, state: VideoState): string { + const word = STATE_WORDS[state]; + const name = sourcePlatformName(platform); + return word ? `Open on ${name} (${word})` : `Open on ${name}`; +} + +// The badge tooltip's day: "Members-only on YouTube since 19 Nov 2026". +export function stateSinceTitle(base: string, stateSince: string | null | undefined): string { + const day = formatStateDay(stateSince); + return day ? `${base} since ${day}` : base; +}