Archilyzer · Source

archilyzer

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

commit 14e3e298d739855dc671a2bd682c28691e71a728
parent b48bbb85043d49de9a3131e6a6b63a9d5753bac8
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Wed, 11 Nov 2026 08:05:20 -0500

windows: the single window too -- fetch-window takes `archive`, the MCP's fetch_clip names its remote source (demo epic D1 item 5)

AGENTS.md noted that an MCP pointed at a public site with a fresh editor
gets a 404 `Channel not found` on every clip. /api/media/fetch-window now
takes `archive` (a connected archive's origin) and `allowWholeRecording`:
a channel the editor does not hold is registered remote-only of it, as
fetch-windows does; a remote-only channel's page URL is the ask's, else its
archive's record; its whole recording (`full`, or a window on a
whole-recording platform) is a 409 with the recording's size unless allowed.
The MCP's fetch_clip sends its source's origin when the source is a
published archive (remote:). Tests: registration and the Rumble refusal
through the route, against a fake archive.

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

Diffstat:
Aeditor/app/api/media/fetch-window/route.remote.test.ts | 57+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Meditor/app/api/media/fetch-window/route.ts | 60+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
Mmcp/src/fetchClip.ts | 5+++++
Mmcp/src/server.ts | 5++++-
4 files changed, 125 insertions(+), 2 deletions(-)

diff --git a/editor/app/api/media/fetch-window/route.remote.test.ts b/editor/app/api/media/fetch-window/route.remote.test.ts @@ -0,0 +1,57 @@ +import test from "node:test"; +import assert from "node:assert/strict"; +import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises"; +import os from "node:os"; +import path from "node:path"; + +// Run with: +// pnpm -C editor exec tsx --test "app/api/media/fetch-window/route.remote.test.ts" +// +// demo epic D1: the single window (the MCP's fetch_clip over a remote source) +// of a channel this editor does not hold, named with its connected archive — +// registered remote-only; its Rumble whole recording refused with the size +// (409, no job). The archive is a fake fetch. + +const ROOT = await mkdtemp(path.join(os.tmpdir(), "fetch-window-remote-")); +process.env.WORKER_TOKEN = "test-token"; +process.env.TRANSCRIPTS_DIR = ROOT; +process.env.SETTINGS_FILE = path.join(ROOT, "settings.json"); +delete process.env.TRANSCRIPT_SITE_URL; +const ORIGIN = "https://stub.test"; +await writeFile(process.env.SETTINGS_FILE, JSON.stringify({ remoteArchives: [{ id: "stub", origin: ORIGIN, title: "Stub", addedAt: "2026-11-11T00:00:00Z" }] })); +const DOCS: Record<string, unknown> = { + [`${ORIGIN}/corpus.json`]: { spec: 6, channels: [{ slug: "rb-remote", name: "RB Remote", platform: "rumble", manifests: { transcripts: `${ORIGIN}/transcripts/rb-remote/manifest.json` } }] }, + [`${ORIGIN}/transcripts/rb-remote/manifest.json`]: { slugToPage: { rb9: 0 } }, + [`${ORIGIN}/transcripts/rb-remote/page-0000.json`]: [{ id: "rb9", duration: 600, webpageUrl: "https://rumble.com/vrb9-x.html" }], +}; +globalThis.fetch = (async (input: RequestInfo | URL) => { + const url = String(input); + return url in DOCS ? new Response(JSON.stringify(DOCS[url]), { status: 200 }) : new Response("nope", { status: 404 }); +}) as typeof fetch; +const { POST } = await import("./route"); +test.after(() => rm(ROOT, { recursive: true, force: true })); + +const post = async (body: Record<string, unknown>) => { + const res = await POST( + new Request("http://localhost/api/media/fetch-window", { + method: "POST", + headers: { authorization: "Bearer test-token", "content-type": "application/json" }, + body: JSON.stringify(body), + }), + ); + return { status: res.status, json: (await res.json()) as { error?: string } }; +}; + +test("a single window of an archive's channel registers it remote-only, and its Rumble whole recording is refused with the size", async () => { + const r = await post({ channelSlug: "rb-remote", videoId: "rb9", from: 10, to: 20, requestedBy: "test", reason: "a test", archive: ORIGIN }); + assert.equal(r.status, 409, r.json.error); + assert.match(r.json.error ?? "", /^whole recording refused: Rumble windows are cut from the WHOLE recording, and rb-remote is a remote-only channel: rb-remote\/rb9 is 10:00 long/); + const config = JSON.parse(await readFile(path.join(ROOT, "channels", "rb-remote", "config.json"), "utf8")); + assert.equal(config.remoteOnly, true); + assert.equal(config.remoteArchive, ORIGIN); +}); + +test("without its archive named, a channel not held is a 404 as before", async () => { + const r = await post({ channelSlug: "nope-remote", videoId: "x1", from: 10, to: 20, requestedBy: "test", reason: "a test" }); + assert.equal(r.status, 404); +}); diff --git a/editor/app/api/media/fetch-window/route.ts b/editor/app/api/media/fetch-window/route.ts @@ -18,6 +18,20 @@ import { type FetchMediaOutcome, } from "../../../channels/[slug]/videos/[id]/videoActions"; +import { getPaths } from "yt-dlp-transcript-common/lib/paths"; +import { getSettings } from "yt-dlp-transcript-common/lib/settings"; +import { detectPlatform } from "yt-dlp-transcript-common/lib/platform"; +import { isRemoteOnlyChannel } from "yt-dlp-transcript-common/lib/channelConfig"; +import { connectedArchives, findConnectedArchive } from "yt-dlp-transcript-common/lib/remoteArchives"; +import { cachedArchiveGetJson } from "yt-dlp-transcript-common/lib/archiveCache-server"; +import { readChannelConfig } from "yt-dlp-transcript-common/controller/channels"; +import { wholeRecordingFor } from "yt-dlp-transcript-common/controller/fetchWindows"; +import { + archiveRecordOf, + ensureRemoteOnlyChannel, + wholeRecordingRefusal, +} from "yt-dlp-transcript-common/controller/remoteOnlyChannel"; + export const dynamic = "force-dynamic"; // SOURCE MEDIA FOR ANOTHER TOOL, fetched through the editor's managed download @@ -186,6 +200,50 @@ export async function POST(request: Request) { ); } + // A CONNECTED ARCHIVE'S CLIP (demo epic D1; `archive`, the MCP's fetch_clip + // over a remote source): a channel this editor does not hold is registered + // remote-only of it (controller/remoteOnlyChannel.ts), as fetch-windows does. + // A remote-only channel's page URL is the ask's, else its archive's record; + // its whole recording — `full`, or a window on a whole-recording platform — + // is refused with the recording's size (409) unless `allowWholeRecording`. + let webpageUrl = str(body.webpageUrl); + { + const paths = getPaths(); + const getJson = cachedArchiveGetJson(); + const named = str(body.archive); + let config = await readChannelConfig(paths, channelSlug); + if (!config && named) { + const archive = findConnectedArchive(connectedArchives(getSettings().remoteArchives), named); + if (archive) { + try { + config = (await ensureRemoteOnlyChannel(paths, channelSlug, archive, { getJson })).config; + } catch (e) { + return NextResponse.json({ error: `Channel "${channelSlug}" not found, and it could not be registered from ${archive.origin}: ${(e as Error).message}` }, { status: 404 }); + } + } + } + if (config && isRemoteOnlyChannel(config)) { + const record = config.remoteArchive ? await archiveRecordOf(config.remoteArchive, channelSlug, videoId, { getJson }).catch(() => null) : null; + webpageUrl ||= record?.webpageUrl; + const platform = detectPlatform(webpageUrl) ?? config.platform ?? "unknown"; + const whole = body.full === true || wholeRecordingFor(getSettings(), platform, { slug: channelSlug, id: videoId, from: 0, to: 1 }, undefined); + if (whole && body.allowWholeRecording !== true) { + return NextResponse.json( + { + error: wholeRecordingRefusal({ + platform, + slug: channelSlug, + id: videoId, + ...(record?.duration !== undefined ? { duration: record.duration } : {}), + ...(typeof body.maxHeight === "number" ? { maxHeight: body.maxHeight } : {}), + }), + }, + { status: 409 }, + ); + } + } + } + if (body.full === true) { // A cap at or under 720 asks for "video_720"; one above it asks for // "original" in so many words. No cap: the channel's, else the global, @@ -233,7 +291,7 @@ export async function POST(request: Request) { await fetchWindowAction({ slug: channelSlug, videoId, - webpageUrl: str(body.webpageUrl), + webpageUrl, from, to, provenance, diff --git a/mcp/src/fetchClip.ts b/mcp/src/fetchClip.ts @@ -178,6 +178,10 @@ export type FetchClipRequest = reason: string; report?: string; waitSeconds: number; + // The published archive the clip is cited from (demo epic D1): the + // editor registers a channel it does not hold as remote-only of it, when + // it is a connected archive. Set by the server from a remote source. + archive?: string; }; const trimmed = (v: unknown): string => @@ -549,6 +553,7 @@ export async function fetchClip( pad: target.pad, ...capped, ...(target.storedUrl ? { storedUrl: target.storedUrl } : {}), + ...(request.archive ? { archive: request.archive } : {}), ...provenance, }; const res = await call(`${editor.url}/api/media/fetch-window`, { diff --git a/mcp/src/server.ts b/mcp/src/server.ts @@ -1203,7 +1203,10 @@ async function handleFetchClip( const { note, ctx } = await resolveClipTarget(source, resolved.handle, request); - const outcome = await fetchClip(request, deps, { onPoll }); + // A clip cited from a published archive names it (demo epic D1): the editor + // registers its channel remote-only when the archive is connected there. + const archived = "target" in request && resolved.spec.kind === "remote" ? { ...request, archive: resolved.spec.url } : request; + const outcome = await fetchClip(archived, deps, { onPoll }); const rendered = renderFetchClip(outcome, ctx); const body = `${note}${rendered.text}`; return rendered.isError ? errorText(body) : text(body);