Archilyzer · Source

archilyzer

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

commit d6d29d60bad863aa276363d49c37dc6ed79e4f41
parent 49c7c02ccd62715d532f6d7023415e8921594c50
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Fri, 16 Oct 2026 01:36:24 -0400

common, editor: a channel's `mirror: {of}` config key and the mirror matcher (release 31 D)

A channel that copies another creator's streams names the creator's channels
in `mirror.of` (slugs; trimmed, de-duplicated, invalid ones dropped, an empty
list drops the key). The Configure form's "Mirror of (channel slugs)" field
and `ops channel-config` (`mirrorOf`) set it; CHANNEL.md regenerated.

lib/mirrors/match.ts pairs a mirror's videos with the creator's, pure: a
creator video dated one day before to two after the mirror video's recorded
(else upload) date matches by title Jaccard >= 0.25, >= 0.12 with durations
within 25 %, or durations alone for a >3000 s stream; strong = >= 0.5, or
>= 0.25 with durations. Per mirror video: the matches, presence per creator
platform and a status (only-copy, creator-deleted, never-uploaded,
creator-public). The other direction: the creator's gone uploads inside the
mirror's window and which strong matches hold them. Every threshold a named
constant. The synthetic mirror corpus joins the test kit
(common/testing/mirrors/).

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

Diffstat:
MCHANNEL.md | 7+++++++
Mcommon/lib/channelConfig.ts | 7++++++-
Mcommon/lib/channelConfigSchema.test.ts | 2+-
Mcommon/lib/channelConfigSchema.ts | 1+
Mcommon/lib/fileSchemaDocs.ts | 8++++++++
Acommon/lib/mirrors/config.test.ts | 27+++++++++++++++++++++++++++
Acommon/lib/mirrors/config.ts | 35+++++++++++++++++++++++++++++++++++
Acommon/lib/mirrors/match.test.ts | 185+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Acommon/lib/mirrors/match.ts | 406+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Acommon/testing/mirrors/mirrorCorpus.d.mts | 32++++++++++++++++++++++++++++++++
Acommon/testing/mirrors/mirrorCorpus.mjs | 164+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Meditor/app/channels/components/ChannelForm.tsx | 8++++++++
Meditor/app/channels/components/channelConfigToForm.ts | 2++
Meditor/app/channels/components/parseChannelForm.test.ts | 24++++++++++++++++++++++++
Meditor/app/channels/components/parseChannelForm.ts | 13+++++++++++++
15 files changed, 919 insertions(+), 2 deletions(-)

diff --git a/CHANNEL.md b/CHANNEL.md @@ -47,6 +47,7 @@ Regenerate this file with `pnpm --filter yt-dlp-transcript-common exec tsx bin/f | `sleepBetweenDownloadsSeconds` | config | Per-channel override for the global pause between downloads. Absent = inherit; 0 = no sleep; floored and capped at 600. | | `audioCheck` | config | Opt-in audio-integrity checking for sources that intermittently serve corrupt audio mid-download (e.g. Odysee "original"): the managed downloader periodically validates the in-progress `.part` file and rolls back to the last known-good snapshot on corruption. transcribe-handling only. See [`audioCheck`](#audiocheck). | | `recordedDate` | config | For a channel that MIRRORS another's streams (a VOD archive): how to read the date a video was RECORDED from its title, since its `upload_date` is the date of the copy. The index stores the result as the record's `recordedDate` (`YYYYMMDD`), which coverage reads before the upload date. A title it does not match, a date that is not a real day, or one after the upload date gives none. Changing the rule re-derives the channel's records on the next index build. An object without a usable `titlePattern` is dropped. See [`recordedDate`](#recordeddate). | +| `mirror` | config | For a channel that MIRRORS another creator's streams: the creator's channels it copies (`of`, their slugs). The mirror scan (`pnpm ops mirror-scan`) pairs each of this channel's videos with the creator's by date and title and writes `transcripts/mirrors/<slug>.json`: which videos the creator still has public, removed or never uploaded, and which of the creator's removed videos this channel holds. Private: never published. An object without a usable `of` is dropped. See [`mirror`](#mirror). | #### `downloadFilter` @@ -72,3 +73,9 @@ Regenerate this file with `pnpm --filter yt-dlp-transcript-common exec tsx bin/f | Key | Default | Description | |---|---|---| | `titlePattern` | required | Case-insensitive regex SOURCE (no delimiters, no flags) matched against each video's title, with three named groups: `year` (four digits, or two read as 20YY), `month` (1–12, or an English month name, whole or cut to three or more letters) and `day`. Trimmed; at most 200 characters, no nested quantifier (the download filter's rules). A pattern that breaks any of this drops the whole rule. | + +#### `mirror` + +| Key | Default | Description | +|---|---|---| +| `of` | required | The slugs of the creator's channels in this corpus that this channel copies (every platform the creator uploads to), e.g. `["creator-youtube", "creator-rumble"]`. Trimmed and de-duplicated; a value that is not a channel slug is dropped, and a list left empty drops the whole key. | diff --git a/common/lib/channelConfig.ts b/common/lib/channelConfig.ts @@ -8,6 +8,7 @@ import { import { isCookieMode, type CookieMode } from "./cookiePolicy"; import type { FieldDocs } from "./fieldDocs"; import { coerceRecordedDateRule, type RecordedDateRule } from "./recordedDate"; +import { coerceMirrorConfig, type MirrorConfig } from "./mirrors/config"; export type ChannelHandling = "youtube" | "transcribe"; @@ -148,6 +149,7 @@ export type ChannelConfig = { sleepBetweenDownloadsSeconds?: number; audioCheck?: AudioCheckConfig; recordedDate?: RecordedDateRule; + mirror?: MirrorConfig; }; // In the order parseChannelConfig emits (and CHANNEL.md lists) them. @@ -207,7 +209,9 @@ export const CHANNEL_CONFIG_FIELD_DOCS: FieldDocs<ChannelConfig> = { audioCheck: "Opt-in audio-integrity checking for sources that intermittently serve corrupt audio mid-download (e.g. Odysee \"original\"): the managed downloader periodically validates the in-progress `.part` file and rolls back to the last known-good snapshot on corruption. transcribe-handling only.", recordedDate: - "For a channel that MIRRORS another's streams (a VOD archive): how to read the date a video was RECORDED from its title, since its `upload_date` is the date of the copy. The index stores the result as the record's `recordedDate` (`YYYYMMDD`), which coverage reads before the upload date. A title it does not match, a date that is not a real day, or one after the upload date gives none. Changing the rule re-derives the channel's records on the next index build. An object without a usable `titlePattern` is dropped." + "For a channel that MIRRORS another's streams (a VOD archive): how to read the date a video was RECORDED from its title, since its `upload_date` is the date of the copy. The index stores the result as the record's `recordedDate` (`YYYYMMDD`), which coverage reads before the upload date. A title it does not match, a date that is not a real day, or one after the upload date gives none. Changing the rule re-derives the channel's records on the next index build. An object without a usable `titlePattern` is dropped.", + mirror: + "For a channel that MIRRORS another creator's streams: the creator's channels it copies (`of`, their slugs). The mirror scan (`pnpm ops mirror-scan`) pairs each of this channel's videos with the creator's by date and title and writes `transcripts/mirrors/<slug>.json`: which videos the creator still has public, removed or never uploaded, and which of the creator's removed videos this channel holds. Private: never published. An object without a usable `of` is dropped." }; // Every key a config.json may carry, in emission order. The unknown-key oracle: @@ -412,6 +416,7 @@ export const CHANNEL_CONFIG_COERCIONS: { : undefined, audioCheck: coerceAudioCheck, recordedDate: coerceRecordedDateRule, + mirror: coerceMirrorConfig, }; // A channel's config.json as a ChannelConfig, or null when it is not a channel diff --git a/common/lib/channelConfigSchema.test.ts b/common/lib/channelConfigSchema.test.ts @@ -39,7 +39,7 @@ test("one key list: docs = coercions = schema shape, sync-state keys inside it", assert.deepEqual(Object.keys(CHANNEL_CONFIG_COERCIONS), [...CHANNEL_CONFIG_KEYS]); assert.deepEqual(Object.keys(channelConfigObjectSchema.shape), [...CHANNEL_CONFIG_KEYS]); assert.deepEqual(Object.keys(CHANNEL_CONFIG_FIELD_DOCS), [...CHANNEL_CONFIG_KEYS]); - assert.equal(CHANNEL_CONFIG_KEYS.length, 33); + assert.equal(CHANNEL_CONFIG_KEYS.length, 34); assert.equal(sameKeys, true); assert.equal(fits, true); for (const k of CHANNEL_SYNC_STATE_KEYS) assert.ok(CHANNEL_CONFIG_KEYS.includes(k), k); diff --git a/common/lib/channelConfigSchema.ts b/common/lib/channelConfigSchema.ts @@ -76,6 +76,7 @@ export const channelConfigObjectSchema = z.object({ sleepBetweenDownloadsSeconds: field("sleepBetweenDownloadsSeconds"), audioCheck: field("audioCheck"), recordedDate: field("recordedDate"), + mirror: field("mirror"), }); // Drop every own key whose value is `undefined` (the OMIT rule, above). diff --git a/common/lib/fileSchemaDocs.ts b/common/lib/fileSchemaDocs.ts @@ -23,6 +23,7 @@ import { DOWNLOAD_FILTER_FIELD_DOCS, } from "./channelConfig"; import { RECORDED_DATE_RULE_FIELD_DOCS } from "./recordedDate"; +import { MIRROR_CONFIG_FIELD_DOCS } from "./mirrors/config"; import { SOCIAL_LINK_FIELD_DOCS } from "./settingsSchema"; import { RELATED_SITE_GROUP_FIELD_DOCS, @@ -141,6 +142,13 @@ const CHANNEL_NESTED: Partial<Record<string, KeyTable[]>> = { defaults: () => "required", }, ], + mirror: [ + { + path: "mirror", + docs: MIRROR_CONFIG_FIELD_DOCS, + defaults: () => "required", + }, + ], }; function channelKind(key: string): string { diff --git a/common/lib/mirrors/config.test.ts b/common/lib/mirrors/config.test.ts @@ -0,0 +1,27 @@ +// The `mirror` config key (release 31, lane D): `of` kept as valid slugs, +// trimmed and de-duplicated; nothing usable drops the key, as its siblings do. +// +// Run with: pnpm --filter yt-dlp-transcript-common exec tsx --test lib/mirrors/config.test.ts + +import { test } from "node:test"; +import assert from "node:assert/strict"; +import { coerceMirrorConfig, mirrorSlugs } from "./config"; +import { parseChannelConfig } from "../channelConfig"; +import { channelConfigSchema } from "../channelConfigSchema"; + +test("coerceMirrorConfig keeps valid slugs and drops the rest", () => { + assert.deepEqual(coerceMirrorConfig({ of: [" a-b ", "c_d", "a-b", "../x", 3, ""] }), { of: ["a-b", "c_d"] }); + assert.equal(coerceMirrorConfig({ of: [] }), undefined); + assert.equal(coerceMirrorConfig({ of: ["../x"] }), undefined); + assert.equal(coerceMirrorConfig({}), undefined); + assert.equal(coerceMirrorConfig(["a"]), undefined); + assert.equal(coerceMirrorConfig("a"), undefined); + assert.deepEqual(mirrorSlugs("a, b c,,a"), ["a", "b", "c"]); +}); + +test("a config.json's mirror reads through both compositions", () => { + const raw = { handling: "transcribe", mirror: { of: ["creator-yt", "bad/slug"] } }; + assert.deepEqual(parseChannelConfig(raw)?.mirror, { of: ["creator-yt"] }); + assert.deepEqual(channelConfigSchema.parse(raw)?.mirror, { of: ["creator-yt"] }); + assert.equal("mirror" in (channelConfigSchema.parse({ handling: "transcribe", mirror: { of: [] } }) ?? {}), false); +}); diff --git a/common/lib/mirrors/config.ts b/common/lib/mirrors/config.ts @@ -0,0 +1,35 @@ +// A channel's `mirror` config key (release 31, lane D): the channel MIRRORS +// another creator's streams, and `of` names the creator's channels in this +// corpus (their slugs). The mirror scan (controller/mirrorScan.ts) pairs the +// two (lib/mirrors/match.ts). +// +// Pure, client-safe (channelConfig.ts imports the coercion). + +import { isSafeChannelSegment } from "../citations/moments"; + +export type MirrorConfig = { + of: string[]; +}; + +export const MIRROR_CONFIG_FIELD_DOCS: Record<keyof MirrorConfig, string> = { + of: "The slugs of the creator's channels in this corpus that this channel copies (every platform the creator uploads to), e.g. `[\"creator-youtube\", \"creator-rumble\"]`. Trimmed and de-duplicated; a value that is not a channel slug is dropped, and a list left empty drops the whole key.", +}; + +// The slugs of a list (an array, or text separated by commas or whitespace), +// trimmed, valid and de-duplicated, in order. +export function mirrorSlugs(v: unknown): string[] { + const raw = Array.isArray(v) ? v : typeof v === "string" ? v.split(/[\s,]+/) : []; + const out: string[] = []; + for (const x of raw) { + if (typeof x !== "string") continue; + const s = x.trim(); + if (s && isSafeChannelSegment(s) && !out.includes(s)) out.push(s); + } + return out; +} + +export function coerceMirrorConfig(v: unknown): MirrorConfig | undefined { + if (!v || typeof v !== "object" || Array.isArray(v)) return undefined; + const of = mirrorSlugs((v as Record<string, unknown>).of); + return of.length > 0 ? { of } : undefined; +} diff --git a/common/lib/mirrors/match.test.ts b/common/lib/mirrors/match.test.ts @@ -0,0 +1,185 @@ +// The mirror matcher (release 31, lane D): match.py's rules on hand-built +// cases (each rule branch, the day window's edges, stop words, the topic), +// status.py's strong cut and the four statuses, then the synthetic mirror +// corpus both ways. +// +// Run with: pnpm --filter yt-dlp-transcript-common exec tsx --test lib/mirrors/match.test.ts + +import { test } from "node:test"; +import assert from "node:assert/strict"; +import { + addDays, + contentDate, + durationsAgree, + isStrong, + matchMirror, + matchRule, + mirrorTopic, + statusOf, + titleJaccard, + titleWords, + MIRROR_DURATION_TOLERANCE, + MIRROR_LIVE_MIN_SECONDS, + type MirrorRecord, +} from "./match"; +import { + CREATOR_RECORDS, + CREATOR_SLUG, + EXPECTED, + MIRROR_RECORDS, + MIRROR_SLUG, + RECORDED_DATE_PATTERN, + RUMBLE_RECORDS, + RUMBLE_SLUG, +} from "../../testing/mirrors/mirrorCorpus.mjs"; + +const RULE = new RegExp(RECORDED_DATE_PATTERN, "i"); + +function rec(id: string, title: string, date: string, extra: Partial<MirrorRecord> = {}): MirrorRecord { + return { id, title, uploadDate: date, duration: 0, wasLive: false, gone: null, ...extra }; +} + +function one(mirror: MirrorRecord, creators: MirrorRecord[], platform = "youtube") { + return matchMirror({ + mirror: { slug: "m", platform: "odysee", records: [mirror], titleRule: RULE }, + creators: [{ slug: "c", platform, records: creators }], + }).videos[0]; +} + +test("words: lowercase [a-z0-9'] runs, one-letter words and stop words dropped", () => { + assert.deepEqual([...titleWords("The Oven's BIG Day & More w/ a Guest: 2023!")].sort(), ["2023", "big", "day", "guest", "oven's"]); + assert.deepEqual([...titleWords("This is what he gets, and got")], ["what", "he"]); + assert.equal(titleJaccard(new Set(["a", "b"]), new Set(["b", "c"])), 1 / 3); + assert.equal(titleJaccard(new Set(), new Set()), 0); +}); + +test("topic: the title after the date the rule reads, before it when nothing follows, whole otherwise", () => { + assert.equal(mirrorTopic("[VOD] Name - 03/01/2023 - Big News Day", RULE), "Big News Day"); + assert.equal(mirrorTopic("Big News Day | 03/01/2023", RULE), "Big News Day"); + assert.equal(mirrorTopic("[VOD] Name - Bonus Stream", RULE), "[VOD] Name - Bonus Stream"); + assert.equal(mirrorTopic("Anything", null), "Anything"); +}); + +test("dates: recorded first, else upload; whole calendar days", () => { + assert.equal(contentDate({ uploadDate: "20230304", recordedDate: "20230301" }), "20230301"); + assert.equal(contentDate({ uploadDate: "20230304" }), "20230304"); + assert.equal(contentDate({ uploadDate: "" }), null); + assert.equal(addDays("20230228", 1), "20230301"); + assert.equal(addDays("20240101", -1), "20231231"); +}); + +test("durations agree under 25% of the mirror's, both known", () => { + assert.equal(MIRROR_DURATION_TOLERANCE, 0.25); + assert.equal(durationsAgree(1000, 1249), true); + assert.equal(durationsAgree(1000, 1250), false, "strictly less"); + assert.equal(durationsAgree(1000, 751), true); + assert.equal(durationsAgree(0, 1000), false); + assert.equal(durationsAgree(1000, 0), false); +}); + +test("rules in order: title ≥ 0.25; ≥ 0.12 with durations; a long stream with durations", () => { + const stream = { duration: 4000, wasLive: true }; + assert.equal(matchRule(0.25, false, stream), "title"); + assert.equal(matchRule(0.24, false, stream), null); + assert.equal(matchRule(0.12, true, { duration: 100, wasLive: false }), "title-duration"); + assert.equal(matchRule(0.11, true, { duration: 100, wasLive: false }), null); + assert.equal(matchRule(0, true, stream), "live-duration"); + assert.equal(matchRule(0, true, { duration: MIRROR_LIVE_MIN_SECONDS, wasLive: true }), null, "longer than 3000 s"); + assert.equal(matchRule(0, true, { duration: 4000, wasLive: false }), null, "a stream"); + assert.equal(matchRule(0, false, stream), null, "durations must agree"); +}); + +test("strong: score ≥ 0.5, or ≥ 0.25 with durations (the score is the Jaccard to two decimals)", () => { + assert.equal(isStrong(0.5, false), true); + assert.equal(isStrong(0.49, false), false); + assert.equal(isStrong(0.25, true), true); + assert.equal(isStrong(0.24, true), false); +}); + +test("each rule branch on hand-built videos", () => { + const m = rec("m1", "[VOD] X - 03/01/2023 - alpha beta gamma delta", "20230305", { recordedDate: "20230301", duration: 4000 }); + // title: 2 of 6 words = 0.33 — a match, strong only with durations. + let v = one(m, [rec("c1", "alpha beta zeta eta", "20230301")]); + assert.equal(v.matches[0].rule, "title"); + assert.equal(v.matches[0].score, 0.33); + assert.equal(v.matches[0].strong, false); + v = one(m, [rec("c1", "alpha beta zeta eta", "20230301", { duration: 4100 })]); + assert.equal(v.matches[0].strong, true); + // under 0.25 with no durations: nothing. + assert.equal(one(m, [rec("c1", "alpha zeta", "20230301")]).matches.length, 0, "1 of 5 = 0.2"); + v = one(m, [rec("c1", "alpha beta gamma", "20230301")]); + assert.equal(v.matches[0].score, 0.75); + assert.equal(v.matches[0].strong, true); + // title-duration: 1/7 ≈ 0.14 with durations. + v = one(m, [rec("c2", "alpha one two three", "20230301", { duration: 4100 })]); + assert.equal(v.matches[0].rule, "title-duration"); + assert.equal(v.matches[0].strong, false); + // live-duration: nothing shared, a 4100 s stream. + v = one(m, [rec("c3", "unrelated words", "20230301", { duration: 4100, wasLive: true })]); + assert.equal(v.matches[0].rule, "live-duration"); + assert.equal(v.matches[0].strong, false); + assert.equal(v.status, "only-copy", "a weak match decides nothing"); + // none. + v = one(m, [rec("c4", "unrelated words", "20230301", { duration: 9000, wasLive: true })]); + assert.equal(v.matches.length, 0); +}); + +test("the day window: one day before to two after the recorded date", () => { + const m = rec("m1", "[VOD] X - 03/10/2023 - alpha beta", "20230320", { recordedDate: "20230310" }); + const at = (d: string) => one(m, [rec("c", "alpha beta", d)]).matches.length; + assert.equal(at("20230308"), 0); + assert.equal(at("20230309"), 1); + assert.equal(at("20230310"), 1); + assert.equal(at("20230312"), 1); + assert.equal(at("20230313"), 0); + // No recorded date: the upload date. + const u = rec("m2", "alpha beta", "20230320"); + assert.equal(one(u, [rec("c", "alpha beta", "20230321")]).matches.length, 1); + assert.equal(one(u, [rec("c", "alpha beta", "20230310")]).matches.length, 0); +}); + +test("stop words do not make a match", () => { + const m = rec("m1", "[VOD] X - 03/10/2023 - the more of this", "20230320", { recordedDate: "20230310" }); + assert.equal(one(m, [rec("c", "The More Of This", "20230310")]).matches.length, 0); +}); + +test("statuses from presence", () => { + assert.equal(statusOf({ youtube: "none", rumble: "none" }), "only-copy"); + assert.equal(statusOf({ youtube: "gone", rumble: "none" }), "only-copy"); + assert.equal(statusOf({ youtube: "gone", rumble: "public" }), "creator-deleted"); + assert.equal(statusOf({ youtube: "none", rumble: "public" }), "never-uploaded"); + assert.equal(statusOf({ youtube: "public", rumble: "public" }), "creator-public"); + assert.equal(statusOf({ youtube: "public" }), "creator-public"); +}); + +test("the synthetic mirror corpus, both directions", () => { + const r = matchMirror({ + mirror: { slug: MIRROR_SLUG, platform: "odysee", records: MIRROR_RECORDS, titleRule: RULE }, + creators: [ + { slug: CREATOR_SLUG, platform: "youtube", records: CREATOR_RECORDS }, + { slug: RUMBLE_SLUG, platform: "rumble", records: RUMBLE_RECORDS }, + ], + }); + assert.deepEqual(r.window, EXPECTED.window); + assert.deepEqual(Object.fromEntries(r.videos.map((v) => [v.id, v.status])), EXPECTED.status); + assert.deepEqual(r.totals.byStatus, EXPECTED.byStatus); + assert.deepEqual(r.totals.byPlatform, EXPECTED.byPlatform); + assert.equal(r.totals.creatorRemoved.inWindow, EXPECTED.creatorRemoved.inWindow); + assert.equal(r.totals.creatorRemoved.held, EXPECTED.creatorRemoved.held); + assert.deepEqual(Object.fromEntries(r.removed.map((x) => [x.id, x.heldBy])), EXPECTED.held); + assert.deepEqual(r.totals.creatorRemoved.byChannel, { + [CREATOR_SLUG]: { inWindow: 3, held: 2 }, + [RUMBLE_SLUG]: { inWindow: 0, held: 0 }, + }); + const m2 = r.videos.find((v) => v.id === "vod-m2")!; + assert.deepEqual( + m2.matches.map((x) => [x.channel, x.id, x.gone ?? null, x.strong]), + [ + [CREATOR_SLUG, "yt-s2", "deleted", true], + [RUMBLE_SLUG, "v4embed2", null, true], + ], + ); + assert.equal(m2.matches[1].dir, "v1abd-oven-lawsuit", "a Rumble match names its dir"); + assert.equal(r.totals.matched, 4); + assert.equal(r.totals.dated, 6); +}); diff --git a/common/lib/mirrors/match.ts b/common/lib/mirrors/match.ts @@ -0,0 +1,406 @@ +// A MIRROR CHANNEL AND THE CREATOR IT COPIES (release 31, lane D). +// +// A channel that mirrors another creator's streams (a VOD archive on another +// platform: config `mirror.of` names the creator's channels) holds copies whose +// originals the creator may have deleted, made private, or never uploaded at +// all. The duplicate finder (lib/duplicates.ts) clusters only short videos, so +// a 1–5 h stream never folds with its original; this module is the one place +// that pairs a mirror's videos with the creator's, in BOTH directions, from the +// same matches — so "the mirror holds N of the creator's removed videos" and +// "M of the mirror's videos are the only copy" are counted off one set. +// +// PURE: no fs, no clock. The records come from controller/mirrorScan.ts (the +// index, else metadata on disk) with their gone state already read through the +// one gone reading (lib/sourceGone-server.ts, `sourceGoneState`). +// +// ── A MATCH ── +// +// Each mirror video is dated by its RECORDED date (`recordedDate`, the +// channel's title rule — lib/recordedDate.ts), else its upload date; a creator +// video the same way (`contentDate`). A creator video is a CANDIDATE when its +// date is within MIRROR_DAYS_BEFORE days before to MIRROR_DAYS_AFTER days +// after the mirror video's (an upload lands the day of the stream or a day or +// two later; a mirror's title date is sometimes the day after a late stream). +// A candidate MATCHES by the first rule that holds: +// +// "title" title Jaccard ≥ MIRROR_TITLE_JACCARD +// "title-duration" title Jaccard ≥ MIRROR_WEAK_TITLE_JACCARD and the +// durations agree +// "live-duration" the durations agree, the creator video is a stream +// (`wasLive`) and longer than MIRROR_LIVE_MIN_SECONDS +// +// The title Jaccard is over word sets (lowercase `[a-z0-9']+`, words of one +// character and MIRROR_STOP_WORDS dropped). The mirror's side is its TOPIC: the +// title after the recorded date its rule reads (the creator's name and the +// date are not the topic), or before it when nothing follows; the whole title +// when the rule does not match. Durations AGREE when both are known and differ +// by less than MIRROR_DURATION_TOLERANCE of the mirror's. +// +// A match is STRONG when its score (the Jaccard to two decimals) is ≥ +// MIRROR_STRONG_TITLE_JACCARD, or ≥ MIRROR_STRONG_DURATION_TITLE_JACCARD with +// the durations agreeing. Every match is kept in the file; only STRONG ones +// decide a status or hold a removed upload. (The research scripts this +// generalises: ~/reports/quartering-cornbreadman match.py = the rules, +// status.py = strong; the thresholds are theirs.) +// +// ── A MIRROR VIDEO'S STATUS ── +// +// `presence` per creator PLATFORM (the platforms of the `mirror.of` channels): +// "public" when a strong match on that platform is not gone, else "gone" when a +// strong match there is gone (deleted or private), else "none". Then the +// status, the first that holds: +// +// only-copy no platform is "public": the mirror holds the only public +// copy (the creator removed it, or never uploaded it, or both) +// creator-deleted a platform is "gone" (the creator removed a copy) and +// another is "public" +// never-uploaded a platform is "none" (never uploaded there) and the rest +// are "public" +// creator-public every creator platform has it public +// +// A mirror video with no date has no candidates: only-copy. +// +// ── THE CREATOR'S REMOVED UPLOADS ── +// +// The other direction: every creator video that is gone and whose date lies in +// the mirror's WINDOW (the first to the last date of the mirror's dated +// videos). One is HELD by the mirror when it is a strong match of a mirror +// video; `heldBy` names them. + +import type { GoneState } from "../sourceGone"; + +export const MIRROR_DAYS_BEFORE = 1; +export const MIRROR_DAYS_AFTER = 2; +export const MIRROR_TITLE_JACCARD = 0.25; +export const MIRROR_WEAK_TITLE_JACCARD = 0.12; +export const MIRROR_DURATION_TOLERANCE = 0.25; +export const MIRROR_LIVE_MIN_SECONDS = 3000; +export const MIRROR_STRONG_TITLE_JACCARD = 0.5; +export const MIRROR_STRONG_DURATION_TITLE_JACCARD = 0.25; +export const MIRROR_MIN_WORD_LENGTH = 2; +export const MIRROR_STOP_WORDS: ReadonlySet<string> = new Set( + "the a an and of to in is on for w with & more much by it at as be are his her i my me you we our this that gets got".split(" "), +); + +export const MIRROR_STATUSES = ["only-copy", "creator-deleted", "never-uploaded", "creator-public"] as const; +export type MirrorStatus = (typeof MIRROR_STATUSES)[number]; + +export const MIRROR_STATUS_LABELS: Readonly<Record<MirrorStatus, string>> = Object.freeze({ + "only-copy": "Only copy", + "creator-deleted": "Creator deleted", + "never-uploaded": "Never uploaded", + "creator-public": "Creator public", +}); + +export type MirrorRule = "title" | "title-duration" | "live-duration"; +export type Presence = "public" | "gone" | "none"; + +// One video, as the matcher reads it. +export type MirrorRecord = { + id: string; + // The data/<dir>/ it lives in, when that is not `id` (a Rumble embed id). + dir?: string; + title: string; + // Seconds; 0 = unknown. + duration: number; + // YYYYMMDD, or "" when unknown. + uploadDate: string; + recordedDate?: string; + wasLive: boolean; + // The gone reading (sourceGone.ts); null = not gone (or never checked). + gone: GoneState | null; +}; + +export type MirrorChannelInput = { + slug: string; + platform: string; + records: MirrorRecord[]; +}; + +export type MirrorMatchInput = { + mirror: MirrorChannelInput & { + // The mirror's recorded-date title rule, for the topic; null = none. + titleRule?: RegExp | null; + }; + creators: MirrorChannelInput[]; +}; + +export type MirrorMatch = { + channel: string; + id: string; + dir?: string; + title: string; + date: string; + duration: number; + wasLive: boolean; + rule: MirrorRule; + // The title Jaccard, to two decimals. + score: number; + durationAgrees: boolean; + strong: boolean; + gone?: GoneState; +}; + +export type MirrorVideo = { + id: string; + dir?: string; + title: string; + // The date it was matched by (recorded, else upload); null = undated. + date: string | null; + recordedDate?: string; + duration: number; + status: MirrorStatus; + presence: Record<string, Presence>; + // Strongest first. + matches: MirrorMatch[]; +}; + +export type RemovedUpload = { + channel: string; + id: string; + dir?: string; + title: string; + date: string; + duration: number; + gone: GoneState; + // Mirror video ids holding it (strong matches); empty = not held. + heldBy: string[]; +}; + +export type MirrorTotals = { + videos: number; + dated: number; + // Mirror videos with at least one strong match. + matched: number; + byStatus: Record<MirrorStatus, number>; + byPlatform: Record<string, Record<Presence, number>>; + creatorRemoved: { + inWindow: number; + held: number; + byChannel: Record<string, { inWindow: number; held: number }>; + }; +}; + +export type MirrorMatchResult = { + window: { from: string; to: string } | null; + platforms: Record<string, string>; + videos: MirrorVideo[]; + removed: RemovedUpload[]; + totals: MirrorTotals; +}; + +const YMD = /^\d{8}$/; + +// The date a record is matched by: recorded, else upload; null when neither is +// a YYYYMMDD. +export function contentDate(r: { uploadDate: string; recordedDate?: string }): string | null { + if (r.recordedDate && YMD.test(r.recordedDate)) return r.recordedDate; + return YMD.test(r.uploadDate) ? r.uploadDate : null; +} + +// A YYYYMMDD moved by `days` (UTC calendar days). +export function addDays(ymd: string, days: number): string { + const d = new Date(Date.UTC(Number(ymd.slice(0, 4)), Number(ymd.slice(4, 6)) - 1, Number(ymd.slice(6, 8)) + days)); + return `${d.getUTCFullYear()}${String(d.getUTCMonth() + 1).padStart(2, "0")}${String(d.getUTCDate()).padStart(2, "0")}`; +} + +// The words a title is compared on. +export function titleWords(s: string): Set<string> { + const out = new Set<string>(); + for (const w of (s ?? "").toLowerCase().match(/[a-z0-9']+/g) ?? []) { + if (w.length >= MIRROR_MIN_WORD_LENGTH && !MIRROR_STOP_WORDS.has(w)) out.add(w); + } + return out; +} + +export function titleJaccard(a: ReadonlySet<string>, b: ReadonlySet<string>): number { + let inter = 0; + for (const w of a) if (b.has(w)) inter++; + const union = a.size + b.size - inter; + return inter / Math.max(1, union); +} + +const SEPARATORS = /^[\s\-–—|:•·,.]+|[\s\-–—|:•·,.]+$/g; + +// A mirror title's topic: what follows the date its rule reads (else what +// precedes it), or the whole title when the rule reads none. +export function mirrorTopic(title: string, rule: RegExp | null | undefined): string { + if (!rule) return title; + const m = new RegExp(rule.source, rule.flags.replace("g", "")).exec(title); + if (!m) return title; + const after = title.slice(m.index + m[0].length).replace(SEPARATORS, ""); + if (titleWords(after).size > 0) return after; + return title.slice(0, m.index).replace(SEPARATORS, ""); +} + +export function durationsAgree(mirrorSeconds: number, creatorSeconds: number): boolean { + return mirrorSeconds > 0 && creatorSeconds > 0 && Math.abs(creatorSeconds - mirrorSeconds) < MIRROR_DURATION_TOLERANCE * mirrorSeconds; +} + +// The rule a candidate matches by, or null. +export function matchRule(j: number, durationAgrees: boolean, creator: { duration: number; wasLive: boolean }): MirrorRule | null { + if (j >= MIRROR_TITLE_JACCARD) return "title"; + if (j >= MIRROR_WEAK_TITLE_JACCARD && durationAgrees) return "title-duration"; + if (durationAgrees && creator.duration > MIRROR_LIVE_MIN_SECONDS && creator.wasLive) return "live-duration"; + return null; +} + +export const roundScore = (j: number): number => Math.round(j * 100) / 100; + +export function isStrong(score: number, durationAgrees: boolean): boolean { + return score >= MIRROR_STRONG_TITLE_JACCARD || (durationAgrees && score >= MIRROR_STRONG_DURATION_TITLE_JACCARD); +} + +export function statusOf(presence: Record<string, Presence>): MirrorStatus { + const p = Object.values(presence); + if (!p.includes("public")) return "only-copy"; + if (p.includes("gone")) return "creator-deleted"; + if (p.includes("none")) return "never-uploaded"; + return "creator-public"; +} + +type Candidate = { channel: string; platform: string; rec: MirrorRecord; date: string; words: Set<string> }; + +const byIdThenChannel = (a: { id: string; channel?: string }, b: { id: string; channel?: string }) => + (a.channel ?? "").localeCompare(b.channel ?? "") || a.id.localeCompare(b.id); + +export function matchMirror(input: MirrorMatchInput): MirrorMatchResult { + const platforms: Record<string, string> = {}; + for (const c of input.creators) platforms[c.slug] = c.platform; + const platformList = [...new Set(input.creators.map((c) => c.platform))].sort(); + + // The creator's videos by date. + const byDate = new Map<string, Candidate[]>(); + for (const c of input.creators) { + for (const rec of c.records) { + const date = contentDate(rec); + if (!date) continue; + const list = byDate.get(date) ?? []; + list.push({ channel: c.slug, platform: c.platform, rec, date, words: titleWords(rec.title) }); + byDate.set(date, list); + } + } + + const rule = input.mirror.titleRule ?? null; + const videos: MirrorVideo[] = []; + // creator channel + id → mirror ids holding it (strong). + const held = new Map<string, string[]>(); + let dated = 0; + let from: string | null = null; + let to: string | null = null; + for (const m of input.mirror.records) { + const date = contentDate(m); + const matches: (MirrorMatch & { platform: string })[] = []; + if (date) { + dated++; + if (!from || date < from) from = date; + if (!to || date > to) to = date; + const words = titleWords(mirrorTopic(m.title, rule)); + for (let k = -MIRROR_DAYS_BEFORE; k <= MIRROR_DAYS_AFTER; k++) { + for (const cand of byDate.get(addDays(date, k)) ?? []) { + const j = titleJaccard(words, cand.words); + const agrees = durationsAgree(m.duration, cand.rec.duration); + const how = matchRule(j, agrees, cand.rec); + if (!how) continue; + const score = roundScore(j); + const strong = isStrong(score, agrees); + matches.push({ + channel: cand.channel, + platform: cand.platform, + id: cand.rec.id, + ...(cand.rec.dir && cand.rec.dir !== cand.rec.id ? { dir: cand.rec.dir } : {}), + title: cand.rec.title, + date: cand.date, + duration: cand.rec.duration, + wasLive: cand.rec.wasLive, + rule: how, + score, + durationAgrees: agrees, + strong, + ...(cand.rec.gone ? { gone: cand.rec.gone } : {}), + }); + if (strong) { + const key = `${cand.channel}\x00${cand.rec.id}`; + const list = held.get(key) ?? []; + if (!list.includes(m.id)) list.push(m.id); + held.set(key, list); + } + } + } + } + matches.sort((a, b) => b.score - a.score || Number(b.strong) - Number(a.strong) || byIdThenChannel(a, b)); + const presence: Record<string, Presence> = {}; + for (const p of platformList) { + const strong = matches.filter((x) => x.strong && x.platform === p); + presence[p] = strong.some((x) => !x.gone) ? "public" : strong.length > 0 ? "gone" : "none"; + } + videos.push({ + id: m.id, + ...(m.dir && m.dir !== m.id ? { dir: m.dir } : {}), + title: m.title, + date, + ...(m.recordedDate ? { recordedDate: m.recordedDate } : {}), + duration: m.duration, + status: statusOf(presence), + presence, + matches: matches.map(({ platform: _p, ...rest }) => rest), + }); + } + videos.sort((a, b) => (a.date ?? "").localeCompare(b.date ?? "") || a.id.localeCompare(b.id)); + + const removed: RemovedUpload[] = []; + if (from && to) { + for (const c of input.creators) { + for (const rec of c.records) { + const date = contentDate(rec); + if (!rec.gone || !date || date < from || date > to) continue; + removed.push({ + channel: c.slug, + id: rec.id, + ...(rec.dir && rec.dir !== rec.id ? { dir: rec.dir } : {}), + title: rec.title, + date, + duration: rec.duration, + gone: rec.gone, + heldBy: [...(held.get(`${c.slug}\x00${rec.id}`) ?? [])].sort(), + }); + } + } + } + removed.sort((a, b) => a.date.localeCompare(b.date) || byIdThenChannel(a, b)); + + const byStatus = Object.fromEntries(MIRROR_STATUSES.map((s) => [s, 0])) as Record<MirrorStatus, number>; + const byPlatform: Record<string, Record<Presence, number>> = {}; + for (const p of platformList) byPlatform[p] = { public: 0, gone: 0, none: 0 }; + let matched = 0; + for (const v of videos) { + byStatus[v.status]++; + if (v.matches.some((x) => x.strong)) matched++; + for (const [p, pr] of Object.entries(v.presence)) byPlatform[p][pr]++; + } + const byChannel: Record<string, { inWindow: number; held: number }> = {}; + for (const c of input.creators) byChannel[c.slug] = { inWindow: 0, held: 0 }; + for (const r of removed) { + byChannel[r.channel].inWindow++; + if (r.heldBy.length > 0) byChannel[r.channel].held++; + } + + return { + window: from && to ? { from, to } : null, + platforms, + videos, + removed, + totals: { + videos: videos.length, + dated, + matched, + byStatus, + byPlatform, + creatorRemoved: { + inWindow: removed.length, + held: removed.filter((r) => r.heldBy.length > 0).length, + byChannel, + }, + }, + }; +} diff --git a/common/testing/mirrors/mirrorCorpus.d.mts b/common/testing/mirrors/mirrorCorpus.d.mts @@ -0,0 +1,32 @@ +export type SynthMirrorRecord = { + id: string; + dir?: string; + title: string; + uploadDate: string; + recordedDate?: string; + duration: number; + wasLive: boolean; + gone: "deleted" | "private" | null; +}; + +export const MIRROR_SLUG: string; +export const CREATOR_SLUG: string; +export const RUMBLE_SLUG: string; +export const RECORDED_DATE_PATTERN: string; +export const MIRROR_RECORDS: SynthMirrorRecord[]; +export const CREATOR_RECORDS: SynthMirrorRecord[]; +export const RUMBLE_RECORDS: SynthMirrorRecord[]; +export const CHANNELS: { + slug: string; + platform: string; + config: Record<string, unknown>; +}[]; +export function writeMirrorCorpus(channelsDir: string, opts?: { noMirrorOf?: boolean }): Promise<void>; +export const EXPECTED: { + window: { from: string; to: string }; + status: Record<string, string>; + byStatus: Record<string, number>; + byPlatform: Record<string, { public: number; gone: number; none: number }>; + creatorRemoved: { inWindow: number; held: number }; + held: Record<string, string[]>; +}; diff --git a/common/testing/mirrors/mirrorCorpus.mjs b/common/testing/mirrors/mirrorCorpus.mjs @@ -0,0 +1,164 @@ +// A SYNTHETIC MIRROR CORPUS (release 31, lane D) — a creator who streams on +// two platforms and a channel that archives the streams on a third. Invented +// names, titles and ids; nothing from a real channel. +// +// synth-streamer the creator on "youtube": three streams (one public, +// one deleted, one private), a removed short outside +// the mirror's window, a removed short inside it that +// the mirror does not hold, a public video nothing +// matches. +// synth-streamer-rumble the creator's "rumble" twin: copies of the public and +// the deleted stream, and a stream never on YouTube. +// Rumble's data dirs are URL slugs, its ids embed ids. +// synth-vod-archive the MIRROR ("odysee"): titles +// "[VOD] SynthStreamer - MM/DD/YYYY - <topic>", uploaded +// days after the stream; one title with no date (dated +// by its upload). config `recordedDate` + `mirror.of`. +// +// `MIRROR_RECORDS` / `CREATOR_RECORDS` are the records as the matcher reads them +// (lib/mirrors/match.ts MirrorRecord, recorded dates filled in); +// `writeMirrorCorpus(channelsDir)` writes the same three channels to disk +// (config.json, data/<dir>/metadata.info.json, availability.json) for the +// controller and the editor's e2e; `EXPECTED` is what a scan finds. + +import { mkdir, writeFile } from "node:fs/promises"; +import path from "node:path"; + +export const MIRROR_SLUG = "synth-vod-archive"; +export const CREATOR_SLUG = "synth-streamer"; +export const RUMBLE_SLUG = "synth-streamer-rumble"; +export const RECORDED_DATE_PATTERN = "(?<month>\\d{1,2})/(?<day>\\d{1,2})/(?<year>\\d{4})"; + +const vod = (date, topic) => `[VOD] SynthStreamer - ${date} - ${topic}`; + +// [id, dir?, title, uploadDate, recordedDate?, duration, live, availability?] +const MIRROR = [ + ["vod-m1", null, vod("03/01/2023", "Big News Day, Kitchen Fire & More"), "20230304", "20230301", 10790, false], + ["vod-m2", null, vod("03/05/2023", "Oven Lawsuit Explained And Toaster Recall"), "20230308", "20230305", 8950, false], + ["vod-m3", null, vod("03/09/2023", "Spatula Drama Gets Worse"), "20230311", "20230309", 7180, false], + ["vod-m4", null, vod("03/11/2023", "Garden Hose Investigation"), "20230314", "20230311", 5000, false], + ["vod-m5", null, vod("03/12/2023", "Pan Review Marathon"), "20230316", "20230312", 14350, false], + ["vod-m7", null, "[VOD] SynthStreamer - Bonus Stream", "20230320", undefined, 3600, false], +]; + +const CREATOR = [ + ["yt-s1", null, "Big News Day, Kitchen Fire & More", "20230301", undefined, 10800, true, "public"], + ["yt-s2", null, "Oven Lawsuit Explained And Toaster Recall", "20230306", undefined, 9000, true, "deleted"], + ["yt-s3", null, "Spatula Drama Gets Worse", "20230309", undefined, 7200, true, "private"], + ["yt-x1", null, "Old Pantry Tour", "20220110", undefined, 400, false, "deleted"], + ["yt-x2", null, "Short Clip About Forks", "20230307", undefined, 300, false, "deleted"], + ["yt-n1", null, "Weekly Mailbag", "20230312", undefined, 600, false, undefined], +]; + +const RUMBLE = [ + ["v4embed1", "v1abc-big-news-day", "Big News Day, Kitchen Fire & More", "20230301", undefined, 10805, true, "public"], + ["v4embed2", "v1abd-oven-lawsuit", "Oven Lawsuit Explained And Toaster Recall", "20230306", undefined, 9010, true, undefined], + ["v4embed5", "v1abe-pan-review", "Pan Review Marathon", "20230313", undefined, 14400, true, "public"], +]; + +function record(row) { + const [id, dir, title, uploadDate, recordedDate, duration, wasLive, availability] = row; + const gone = availability === "deleted" || availability === "private" ? availability : null; + return { + id, + ...(dir ? { dir } : {}), + title, + uploadDate, + ...(recordedDate ? { recordedDate } : {}), + duration, + wasLive, + gone, + }; +} + +export const MIRROR_RECORDS = MIRROR.map(record); +export const CREATOR_RECORDS = CREATOR.map(record); +export const RUMBLE_RECORDS = RUMBLE.map(record); + +export const CHANNELS = [ + { + slug: MIRROR_SLUG, + platform: "odysee", + rows: MIRROR, + config: { + handling: "transcribe", + platform: "odysee", + name: "Synth VOD Archive", + url: "https://odysee.com/@SynthVodArchive:0", + recordedDate: { titlePattern: RECORDED_DATE_PATTERN }, + mirror: { of: [CREATOR_SLUG, RUMBLE_SLUG] }, + }, + page: (id) => `https://odysee.com/@SynthVodArchive:0/${id}:1`, + }, + { + slug: CREATOR_SLUG, + platform: "youtube", + rows: CREATOR, + config: { handling: "youtube", platform: "youtube", name: "SynthStreamer", url: "https://www.youtube.com/@SynthStreamer/videos" }, + page: (id) => `https://www.youtube.com/watch?v=${id}`, + }, + { + slug: RUMBLE_SLUG, + platform: "rumble", + rows: RUMBLE, + config: { handling: "transcribe", platform: "rumble", name: "SynthStreamer (Rumble)", url: "https://rumble.com/c/SynthStreamer" }, + page: (_id, dir) => `https://rumble.com/${dir}.html`, + }, +]; + +// The three channels on disk under `channelsDir`. No index: a scan reads them +// off disk (the controller's fallback for videos the index has not seen). +export async function writeMirrorCorpus(channelsDir, opts = {}) { + for (const ch of CHANNELS) { + const dir = path.join(channelsDir, ch.slug); + await mkdir(path.join(dir, "data"), { recursive: true }); + const config = opts.noMirrorOf && ch.slug === MIRROR_SLUG ? { ...ch.config, mirror: undefined } : ch.config; + await writeFile(path.join(dir, "config.json"), JSON.stringify(config, null, 2)); + for (const [id, vdir, title, uploadDate, , duration, live, availability] of ch.rows) { + const videoDir = path.join(dir, "data", vdir ?? id); + await mkdir(videoDir, { recursive: true }); + const webpageUrl = ch.page(id, vdir ?? id); + await writeFile( + path.join(videoDir, "metadata.info.json"), + JSON.stringify({ + id, + title, + upload_date: uploadDate, + duration, + webpage_url: webpageUrl, + ...(ch.platform === "odysee" ? { webpage_url_basename: id, extractor_key: "LBRY" } : {}), + ...(ch.platform === "rumble" ? { extractor_key: "Rumble" } : {}), + ...(ch.platform === "youtube" ? { extractor_key: "Youtube" } : {}), + live_status: live ? "was_live" : "not_live", + }), + ); + if (availability) { + await writeFile( + path.join(videoDir, "availability.json"), + JSON.stringify({ checkedAt: "2026-10-01T00:00:00.000Z", availability, webpageUrl }), + ); + } + } + } +} + +// What a scan of the corpus finds (lib/mirrors/match.ts's rules). +export const EXPECTED = { + window: { from: "20230301", to: "20230320" }, + status: { + "vod-m1": "creator-public", + "vod-m2": "creator-deleted", + "vod-m3": "only-copy", + "vod-m4": "only-copy", + "vod-m5": "never-uploaded", + "vod-m7": "only-copy", + }, + byStatus: { "only-copy": 3, "creator-deleted": 1, "never-uploaded": 1, "creator-public": 1 }, + byPlatform: { + rumble: { public: 3, gone: 0, none: 3 }, + youtube: { public: 1, gone: 2, none: 3 }, + }, + // yt-s2 (vod-m2), yt-s3 (vod-m3) held; yt-x2 not; yt-x1 outside the window. + creatorRemoved: { inWindow: 3, held: 2 }, + held: { "yt-s2": ["vod-m2"], "yt-s3": ["vod-m3"], "yt-x2": [] }, +}; diff --git a/editor/app/channels/components/ChannelForm.tsx b/editor/app/channels/components/ChannelForm.tsx @@ -878,6 +878,14 @@ export function ChannelForm({ hint="For a channel that mirrors another's streams, whose upload dates are the copies'. Case-insensitive regex naming three groups — year, month (a number or an English month name) and day — e.g. (?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2}). The index reads each video's recorded date from its title, and coverage uses it before the upload date. A title it does not match keeps the upload date." /> <Field + label="Mirror of (channel slugs)" + name="mirrorOf" + state={state} + defaultValue={c?.mirror?.of.join(", ") ?? ""} + placeholder="(not a mirror)" + hint="For a channel that copies another creator's streams: the creator's channels here, by slug, separated by commas. The channel page then has a Mirror stage, where a scan pairs each video with the creator's and says which are the only copy left." + /> + <Field label="Cookies from browser" name="cookiesFromBrowser" state={state} diff --git a/editor/app/channels/components/channelConfigToForm.ts b/editor/app/channels/components/channelConfigToForm.ts @@ -51,6 +51,7 @@ export const CHANNEL_FORM_VALUES = [ "downloadFilterExclude", "downloadFilterRejectedLivestreams", "recordedDateTitlePattern", + "mirrorOf", "audioCheckIntervalSeconds", "audioCheckMaxRollbacks", "audioCheckCopyTimeoutSeconds", @@ -116,6 +117,7 @@ export function channelConfigToFormData(config: ChannelConfig): FormData { config.downloadFilter?.rejectedLivestreams, ); put(fd, "recordedDateTitlePattern", config.recordedDate?.titlePattern); + put(fd, "mirrorOf", config.mirror?.of.join(", ")); if (config.audioCheck?.enabled) { fd.set("audioCheckEnabled", "on"); putNum(fd, "audioCheckIntervalSeconds", config.audioCheck.intervalSeconds); diff --git a/editor/app/channels/components/parseChannelForm.test.ts b/editor/app/channels/components/parseChannelForm.test.ts @@ -61,3 +61,27 @@ test("the ops patch sets and clears it over the channel's current form", () => { applyChannelFormPatch(back, { recordedDateTitlePattern: "" }); assert.equal("recordedDate" in parseChannelForm(back).config, false); }); + +// The Configure form's mirror field (release 31, lane D): slugs separated by +// commas or spaces into `mirror.of`, a value that is not a slug refused, the +// ops patch round trip, an empty value clearing it. + +test("the form writes mirror.of from slugs, de-duplicated", () => { + const { config } = parseChannelForm(form({ mirrorOf: " creator-yt, creator-rumble creator-yt " })); + assert.deepEqual(config.mirror, { of: ["creator-yt", "creator-rumble"] }); + assert.equal("mirror" in parseChannelForm(form({})).config, false); + assert.ok((CHANNEL_FORM_FIELDS as readonly string[]).includes("mirror")); + assert.throws(() => parseChannelForm(form({ mirrorOf: "creator-yt, ../etc" })), /Mirror of: "\.\.\/etc" is not a channel slug/); +}); + +test("the ops patch sets and clears mirrorOf over the channel's current form", () => { + validateChannelFormPatch({ mirrorOf: "creator-yt,creator-rumble" }); + const fd = channelConfigToFormData({ handling: "transcribe", name: "Example VODs" }); + applyChannelFormPatch(fd, { mirrorOf: "creator-yt,creator-rumble" }); + const set = parseChannelForm(fd).config; + assert.deepEqual(set.mirror, { of: ["creator-yt", "creator-rumble"] }); + const back = channelConfigToFormData(set); + assert.equal(back.get("mirrorOf"), "creator-yt, creator-rumble"); + applyChannelFormPatch(back, { mirrorOf: "" }); + assert.equal("mirror" in parseChannelForm(back).config, false); +}); diff --git a/editor/app/channels/components/parseChannelForm.ts b/editor/app/channels/components/parseChannelForm.ts @@ -26,6 +26,7 @@ import { } from "yt-dlp-transcript-common/ytdlp/downloadFormat"; import { downloadFilterPatternProblem } from "yt-dlp-transcript-common/lib/downloadFilters"; import { recordedDatePatternProblem } from "yt-dlp-transcript-common/lib/recordedDate"; +import { mirrorSlugs } from "yt-dlp-transcript-common/lib/mirrors/config"; import { isRejectedLivestreamMode } from "yt-dlp-transcript-common/lib/channelConfig"; export type ParsedChannelForm = { @@ -60,6 +61,7 @@ export const CHANNEL_FORM_FIELDS = [ "audioCheck", "downloadFilter", "recordedDate", + "mirror", ] as const satisfies ReadonlyArray<keyof ChannelConfig>; // Maps FormData -> ChannelConfig. Throws on invalid input so the server @@ -291,6 +293,16 @@ export function parseChannelForm(formData: FormData): ParsedChannelForm { if (problem) throw new Error(`Recorded-date pattern ${problem}`); } + // A mirror's creator channels (release 31, lib/mirrors/config.ts): slugs + // separated by commas or spaces; one that is not a slug is refused here + // rather than silently dropped by the config reader. + const mirrorOfRaw = stringOrUndef(formData, "mirrorOf"); + const mirrorOf = mirrorOfRaw ? mirrorSlugs(mirrorOfRaw) : []; + if (mirrorOfRaw) { + const bad = mirrorOfRaw.split(/[\s,]+/).filter((x) => x && !mirrorSlugs([x]).length); + if (bad.length > 0) throw new Error(`Mirror of: ${bad.map((b) => `"${b}"`).join(", ")} is not a channel slug`); + } + const audioCheckEnabled = formData.get("audioCheckEnabled") != null; let audioCheck: AudioCheckConfig | undefined; if (audioCheckEnabled) { @@ -383,6 +395,7 @@ export function parseChannelForm(formData: FormData): ParsedChannelForm { if (recordedDateTitlePattern) { config.recordedDate = { titlePattern: recordedDateTitlePattern }; } + if (mirrorOf.length > 0) config.mirror = { of: mirrorOf }; return { name, slug, config }; }