Archilyzer · Source

archilyzer

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

commit 719c7fe9448862847717e9b7217f13358a59e6b6
parent 8240f10440058a7f10f30f199af026a26f7e06a8
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Fri, 16 Oct 2026 02:40:58 -0400

common, editor: the channel page's Mirror stage (release 31 D)

A channel with `mirror` in its config gets a Mirror stage (`?stage=mirror`,
listed only for it): the last scan's totals both ways (how many videos are
the only copy, how many of the creator's removed videos in the window the
mirror holds, presence per platform), a filter per status, each row linking
the mirror video and the creator's copies (removed ones marked), the
creator's removed videos with what holds them, and Scan / Scan again (a
mirror-scan job). With no scan yet it says so beside the button. The stage
summary reads the scan's numbers (computeStageStatuses' `mirrorScan`);
mirror-scan maps to the stage for its running dot. e2e/mirror-panel.spec.ts
drives it over the kit's synthetic mirror corpus.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

Diffstat:
Mcommon/views/pipeline/stageStatus.ts | 27+++++++++++++++++++++++++++
Aeditor/app/channels/[slug]/components/stages/MirrorStage.tsx | 207+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Meditor/app/channels/[slug]/page.tsx | 27+++++++++++++++++++++++++++
Aeditor/e2e/mirror-panel.spec.ts | 64++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 325 insertions(+), 0 deletions(-)

diff --git a/common/views/pipeline/stageStatus.ts b/common/views/pipeline/stageStatus.ts @@ -72,6 +72,10 @@ export type StageId = // and no group owns it — so it is hand-listed at the call site alongside them // and is deliberately absent from GROUP_STAGES below. | "storage" + // A MIRROR CHANNEL'S PAIRING WITH THE CREATOR IT COPIES (release 31, lane D; + // controller/mirrorScan.ts). A channel chore, hand-listed at the call site + // and only for a channel whose config has `mirror`. + | "mirror" | "danger"; // THE STAGES EACH OPERATION GROUP OWNS, in the group's own order. @@ -142,6 +146,7 @@ const JOB_KIND_TO_STAGE: Record<string, StageId> = { "clean-extra-audio-formats": "cleanup", "remove-wrong-format-audio": "cleanup", "check-availability": "diagnostics", + "mirror-scan": "mirror", }; function pluralize(n: number, singular: string, plural?: string): string { @@ -188,6 +193,10 @@ export type ComputeStageStatusesInput = { // have to do I/O to get them — an omitted location reads as "in place", which // is what every channel was before relocation existed. media?: ChannelMediaLocation | null; + // The channel's last mirror scan, in numbers (lib/mirrors/scanFile.ts), or + // null when it has none. Read only by the `mirror` stage, which the page + // lists only for a channel with `mirror` in its config; omitted = no scan. + mirrorScan?: { videos: number; onlyCopy: number; removedInWindow: number; held: number } | null; }; export function computeStageStatuses( @@ -201,6 +210,7 @@ export function computeStageStatuses( backfillEnabled = true, backfillKindIds, media, + mirrorScan, } = input; const buckets = normalizeBuckets(snapshot.buckets); @@ -608,6 +618,22 @@ export function computeStageStatuses( : "neutral", }; + const mirrorRunning = runningByStage.has("mirror"); + const mirror: StageStatus = { + id: "mirror", + title: "Mirror", + pending: 0, + failed: 0, + running: mirrorRunning, + defaultOpen: true, + summary: mirrorRunning + ? "Scanning…" + : mirrorScan + ? `${mirrorScan.onlyCopy} of ${pluralize(mirrorScan.videos, "video")} the only copy; the mirror holds ${mirrorScan.held} of ${mirrorScan.removedInWindow} the creator removed.` + : "Not scanned.", + tone: mirrorRunning ? "running" : "neutral", + }; + const danger: StageStatus = { id: "danger", title: "Danger zone", @@ -629,6 +655,7 @@ export function computeStageStatuses( cleanup, diagnostics, storage, + mirror, danger, }; } diff --git a/editor/app/channels/[slug]/components/stages/MirrorStage.tsx b/editor/app/channels/[slug]/components/stages/MirrorStage.tsx @@ -0,0 +1,207 @@ +"use client"; + +import Link from "next/link"; +import { useState } from "react"; +import { StreamActionLog } from "yt-dlp-transcript-common/components/StreamActionLog"; +import { formatDate, formatDuration } from "yt-dlp-transcript-common/lib/format"; +import { + MIRROR_STATUSES, + MIRROR_STATUS_LABELS, + type MirrorStatus, + type Presence, +} from "yt-dlp-transcript-common/lib/mirrors/match"; +import type { MirrorScanFile } from "yt-dlp-transcript-common/lib/mirrors/scanFile"; +import { mirrorScanAction } from "../../mirrorActions"; +import { cancelJobAction } from "../../../../jobs/actions"; + +// THE MIRROR STAGE (release 31, lane D): a mirror channel's last scan +// (transcripts/mirrors/<slug>.json, controller/mirrorScan.ts) — the totals +// both ways, the videos by status with their matches on the creator's +// channels, the creator's removed uploads in the window — and the Scan button. + +type Props = { + slug: string; + of: string[]; + scan: MirrorScanFile | null; +}; + +const PRESENCE_WORDS: Record<Presence, string> = { public: "public", gone: "removed", none: "none" }; + +const chip = (active: boolean) => + `text-xs rounded-full border px-2.5 py-1 ${ + active ? "border-info/30 bg-info-soft text-info" : "border-border bg-card hover:bg-muted" + }`; + +const videoHref = (channel: string, v: { id: string; dir?: string }) => + `/channels/${encodeURIComponent(channel)}/videos/${encodeURIComponent(v.dir ?? v.id)}`; + +const day = (d: string | null) => (d ? formatDate(d) : "undated"); + +export function MirrorStage({ slug, of, scan }: Props) { + const [status, setStatus] = useState<MirrorStatus | null>(null); + const rows = scan ? scan.videos.filter((v) => status === null || v.status === status) : []; + const t = scan?.totals; + return ( + <div className="flex flex-col gap-5"> + <div className="flex flex-col gap-2"> + <p className="text-sm text-muted-foreground" aria-label="mirror status line"> + Mirror of {of.join(", ")} + {scan ? ` · scanned ${scan.generatedAt.slice(0, 16).replace("T", " ")} UTC` : " · not scanned yet"} + {scan?.missing?.length ? ` · not in this corpus: ${scan.missing.join(", ")}` : ""} + </p> + <StreamActionLog + trigger={() => mirrorScanAction(slug)} + cancelAction={cancelJobAction} + buttonLabel={scan ? "Scan again" : "Scan"} + runningLabel="Scanning…" + label="Mirror scan" + /> + </div> + + {!scan || !t ? ( + <p className="text-sm" aria-label="mirror scan missing"> + No scan yet: nothing pairs this channel&apos;s videos with the creator&apos;s. + </p> + ) : ( + <> + <section aria-label="mirror totals" className="flex flex-col gap-2 text-sm"> + <p> + <span className="font-medium">{t.byStatus["only-copy"]}</span> of {t.videos} videos are the only copy + {scan.window ? ` (${formatDate(scan.window.from)} – ${formatDate(scan.window.to)})` : ""}. + </p> + <p aria-label="mirror creator removed"> + The creator removed {t.creatorRemoved.inWindow} videos in this window; the mirror holds{" "} + {t.creatorRemoved.held}. + </p> + <ul className="text-muted-foreground" aria-label="mirror presence by platform"> + {Object.entries(t.byPlatform).map(([p, n]) => ( + <li key={p}> + {p}: {n.public} public, {n.gone} removed, {n.none} none + </li> + ))} + </ul> + </section> + + <section aria-label="mirror videos" className="flex flex-col gap-2"> + <div className="flex flex-wrap gap-1.5" aria-label="mirror status filter"> + <button type="button" aria-pressed={status === null} onClick={() => setStatus(null)} className={chip(status === null)}> + All {t.videos} + </button> + {MIRROR_STATUSES.map((s) => ( + <button + key={s} + type="button" + aria-pressed={status === s} + onClick={() => setStatus(status === s ? null : s)} + className={chip(status === s)} + > + {MIRROR_STATUS_LABELS[s]} {t.byStatus[s]} + </button> + ))} + </div> + <table className="text-sm border-collapse"> + <thead> + <tr className="text-left text-muted-foreground"> + <th className="py-1 pr-4 font-medium">Recorded</th> + <th className="py-1 pr-4 font-medium">Video</th> + <th className="py-1 pr-4 font-medium">Status</th> + <th className="py-1 font-medium">On the creator&apos;s channels</th> + </tr> + </thead> + <tbody> + {rows.map((v) => { + const strong = v.matches.filter((m) => m.strong); + return ( + <tr key={v.id} className="border-t border-border align-top" aria-label={`mirror video ${v.id}`} data-status={v.status}> + <td className="py-1 pr-4 whitespace-nowrap tabular-nums">{day(v.date)}</td> + <td className="py-1 pr-4"> + <Link href={videoHref(slug, v)} className="underline hover:no-underline"> + {v.title} + </Link> + {v.duration > 0 ? <span className="text-muted-foreground"> · {formatDuration(v.duration)}</span> : null} + </td> + <td className="py-1 pr-4 whitespace-nowrap"> + {MIRROR_STATUS_LABELS[v.status]} + <div className="text-xs text-muted-foreground"> + {Object.entries(v.presence) + .map(([p, pr]) => `${p} ${PRESENCE_WORDS[pr]}`) + .join(", ")} + </div> + </td> + <td className="py-1"> + {strong.length === 0 ? ( + <span className="text-muted-foreground">no match</span> + ) : ( + <ul> + {strong.map((m) => ( + <li key={`${m.channel}/${m.id}`}> + <Link href={videoHref(m.channel, m)} className="underline hover:no-underline"> + {m.title} + </Link>{" "} + <span className="text-muted-foreground"> + ({m.channel}, {formatDate(m.date)} + {m.gone ? `, ${m.gone === "deleted" ? "deleted" : "private"}` : ""}) + </span> + </li> + ))} + </ul> + )} + </td> + </tr> + ); + })} + </tbody> + </table> + </section> + + <details aria-label="creator removed in window" className="text-sm"> + <summary className="cursor-pointer font-medium"> + The creator&apos;s removed videos in this window ({t.creatorRemoved.inWindow}) + </summary> + <table className="mt-2 border-collapse"> + <thead> + <tr className="text-left text-muted-foreground"> + <th className="py-1 pr-4 font-medium">Uploaded</th> + <th className="py-1 pr-4 font-medium">Video</th> + <th className="py-1 font-medium">Held by the mirror</th> + </tr> + </thead> + <tbody> + {scan.removed.map((r) => ( + <tr key={`${r.channel}/${r.id}`} className="border-t border-border align-top"> + <td className="py-1 pr-4 whitespace-nowrap tabular-nums">{formatDate(r.date)}</td> + <td className="py-1 pr-4"> + <Link href={videoHref(r.channel, r)} className="underline hover:no-underline"> + {r.title} + </Link>{" "} + <span className="text-muted-foreground"> + ({r.channel}, {r.gone}) + </span> + </td> + <td className="py-1"> + {r.heldBy.length === 0 ? ( + <span className="text-muted-foreground">not held</span> + ) : ( + r.heldBy.map((id, i) => { + const v = scan.videos.find((x) => x.id === id); + return ( + <span key={id}> + {i > 0 ? ", " : ""} + <Link href={videoHref(slug, v ?? { id })} className="underline hover:no-underline"> + {id} + </Link> + </span> + ); + }) + )} + </td> + </tr> + ))} + </tbody> + </table> + </details> + </> + )} + </div> + ); +} diff --git a/editor/app/channels/[slug]/page.tsx b/editor/app/channels/[slug]/page.tsx @@ -95,6 +95,8 @@ import { TranscribeStage } from "./components/stages/TranscribeStage"; import { DigestStage } from "./components/stages/DigestStage"; import { SpeakersStage } from "./components/stages/SpeakersStage"; import { StorageStage } from "./components/stages/StorageStage"; +import { MirrorStage } from "./components/stages/MirrorStage"; +import { readMirrorScan } from "yt-dlp-transcript-common/lib/mirrors/scanFile-server"; import { getOperation, backfillLaneOperations, @@ -314,6 +316,12 @@ export default async function ChannelDetailPage({ // now carries an entry for every catalog operation including digest, which has // its own station and its own queue key. const laneOperations = backfillLaneOperations(settings); + // A mirror channel's last scan (release 31, lane D): one small file, read + // only for a channel whose config has `mirror`. + const mirrorOf = config.mirror?.of ?? []; + const mirrorScan = config.mirror + ? await readMirrorScan(paths.transcriptsDir, slug) + : null; const stages = computeStageStatuses({ snapshot, failedVideoIds, @@ -322,6 +330,14 @@ export default async function ChannelDetailPage({ backfillEnabled: laneOperations.length > 0, backfillKindIds: laneOperations.map((k) => k.id), media, + mirrorScan: mirrorScan + ? { + videos: mirrorScan.totals.videos, + onlyCopy: mirrorScan.totals.byStatus["only-copy"], + removedInWindow: mirrorScan.totals.creatorRemoved.inWindow, + held: mirrorScan.totals.creatorRemoved.held, + } + : null, }); // THE MIDDLE COMES FROM THE REGISTRY, in OPERATION_GROUP_ORDER. Same array as @@ -343,6 +359,8 @@ export default async function ChannelDetailPage({ "cleanup", "diagnostics", "storage", + // Only on a channel that mirrors another's streams (config `mirror`). + ...(config.mirror ? (["mirror"] as const) : []), "danger", ]; @@ -654,6 +672,15 @@ export default async function ChannelDetailPage({ downloadDefaultQueueKey={platformDefaultQueueKey} /> ); + case "mirror": { + return ( + <MirrorStage + slug={slug} + of={mirrorOf} + scan={mirrorScan} + /> + ); + } case "storage": { // The free-space figure names the volume the media is on RIGHT NOW — // the platter for a relocated channel, the corpus disk otherwise — so diff --git a/editor/e2e/mirror-panel.spec.ts b/editor/e2e/mirror-panel.spec.ts @@ -0,0 +1,64 @@ +import { test, expect } from "@playwright/test"; +import { join } from "node:path"; +// By relative path, as frame-scan.spec.ts imports the kit: plain .mjs. +import { MIRROR_SLUG, CREATOR_SLUG, writeMirrorCorpus } from "../../common/testing/mirrors/mirrorCorpus.mjs"; +import { resetData, testPaths } from "./helpers"; + +// The Mirror stage (release 31, lane D) on a synthetic mirror channel (the +// kit's VOD archive of a creator on two platforms): no scan yet and the Scan +// button, the mirror-scan job, then the totals both ways, the status filter, +// the rows linking the creator's copies. A channel with no `mirror` has no +// Mirror stage. + +test("Mirror stage: Scan enqueues mirror-scan; the totals, the filter, the rows", async ({ page }) => { + test.setTimeout(120_000); + await resetData("empty"); + await writeMirrorCorpus(join(testPaths().transcriptsDir, "channels")); + + await page.goto(`/channels/${MIRROR_SLUG}?stage=mirror`); + const stage = page.getByRole("region", { name: "Mirror stage" }); + await expect(stage.getByLabel("mirror scan missing")).toBeVisible(); + await expect(page.getByLabel("Mirror stage summary")).toHaveText("Not scanned."); + await stage.getByRole("button", { name: "Scan", exact: true }).click(); + await expect(page.getByLabel("Mirror scan output")).toContainText("@@mirror-scan", { timeout: 60_000 }); + + await page.reload(); + await expect(page.getByLabel("Mirror stage summary")).toHaveText( + "3 of 6 videos the only copy; the mirror holds 2 of 3 the creator removed.", + ); + const totals = stage.getByLabel("mirror totals"); + await expect(totals).toContainText("3 of 6 videos are the only copy (2023-03-01 – 2023-03-20)."); + await expect(stage.getByLabel("mirror creator removed")).toHaveText( + "The creator removed 3 videos in this window; the mirror holds 2.", + ); + await expect(stage.getByLabel("mirror presence by platform")).toContainText("youtube: 1 public, 2 removed, 3 none"); + + const rows = stage.getByLabel("mirror videos").locator("tbody tr"); + await expect(rows).toHaveCount(6); + const filter = stage.getByLabel("mirror status filter"); + await filter.getByRole("button", { name: "Only copy 3" }).click(); + await expect(rows).toHaveCount(3); + await expect(stage.locator('tbody tr[data-status="only-copy"]')).toHaveCount(3); + await filter.getByRole("button", { name: "Never uploaded 1" }).click(); + await expect(rows).toHaveCount(1); + await expect(rows.first()).toHaveAttribute("aria-label", "mirror video vod-m5"); + await filter.getByRole("button", { name: "Creator deleted 1" }).click(); + const m2 = stage.getByLabel("mirror video vod-m2"); + await expect(m2.getByRole("link", { name: "Oven Lawsuit Explained And Toaster Recall", exact: true }).first()).toHaveAttribute( + "href", + `/channels/${CREATOR_SLUG}/videos/yt-s2`, + ); + await expect(m2).toContainText("deleted"); + await expect(m2.getByRole("link", { name: "Oven Lawsuit Explained And Toaster Recall", exact: true }).nth(1)).toHaveAttribute( + "href", + "/channels/synth-streamer-rumble/videos/v1abd-oven-lawsuit", + ); + await filter.getByRole("button", { name: "All 6" }).click(); + await expect(rows).toHaveCount(6); + await expect(stage.getByRole("button", { name: "Scan again", exact: true })).toBeVisible(); + + // A channel that is no mirror has no Mirror stage. + await page.goto(`/channels/${CREATOR_SLUG}`); + await expect(page.getByLabel("pipeline stages")).toBeVisible(); + await expect(page.getByLabel("Mirror stage tab")).toHaveCount(0); +});