// A video's COPIES as the mirror scans see them (release 31, lane D): // `transcripts/mirrors/.json` (lib/mirrors/scanFile.ts), written by the // editor's mirror scan. Mirror data is PRIVATE — no published site carries it — // so only a LOCAL source reads it (the archive's own `transcripts/`, i.e. // TRANSCRIPTS_DIR or the checkout's); a remote or hub source answers "not // available" rather than guessing. import { getPaths } from "yt-dlp-transcript-common/lib/paths"; import { listMirrorScans } from "yt-dlp-transcript-common/lib/mirrors/scanFile-server"; import { copiesIndex, type MirrorScanFile, type VideoCopies } from "yt-dlp-transcript-common/lib/mirrors/scanFile"; import { MIRROR_STATUS_LABELS } from "yt-dlp-transcript-common/lib/mirrors/match"; import { LocalSource, type ShardSource } from "./source"; export const COPIES_NOT_AVAILABLE = "not available: mirror scans are local-only (no published site carries them) — ask a local archive's MCP (--local)"; // The scans, or null when this source cannot have them (not local). export async function loadMirrorScans( source: ShardSource, transcriptsDir: string = getPaths().transcriptsDir, ): Promise { if (!(source instanceof LocalSource)) return null; return listMirrorScans(transcriptsDir).catch(() => []); } // The `copies` line of get_video_metadata, or "" when the scans say nothing of // this video. export function describeCopies(scans: MirrorScanFile[] | null, channel: string, id: string): string { if (scans === null) return `- copies: ${COPIES_NOT_AVAILABLE}`; const c: VideoCopies | undefined = copiesIndex(scans).get(`${channel}/${id}`); if (!c) return ""; if (c.role === "mirror") { const theirs = c.matches.length ? c.matches.map((m) => `${m.id} (${m.channel}${m.gone ? `, ${m.gone}` : ""})`).join(", ") : "none found"; return `- copies: a MIRROR copy — ${MIRROR_STATUS_LABELS[c.status].toLowerCase()}; the creator's copies: ${theirs}`; } const held = c.copies.map((x) => `${x.id} (${x.mirror})`).join(", "); return c.gone ? `- copies: this video is ${c.gone} on its platform; a mirror holds it: ${held}` : `- copies: a mirror holds a copy: ${held}`; } // The record ids of mirror videos that are the only copy (status only-copy), // with the mirror channels they are on. export function onlyHereIds(scans: MirrorScanFile[]): { ids: string[]; channels: string[] } { const ids: string[] = []; const channels = new Set(); for (const f of scans) { for (const v of f.videos) { if (v.status !== "only-copy") continue; ids.push(v.id); channels.add(f.mirror); } } return { ids, channels: [...channels].sort() }; }