commit 5ad64ba2e3311b53191d2f544331a495c3e08956
parent 3deb510156fc2af3334287b2c1e91b11ef93ec5f
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Sun, 25 Oct 2026 22:17:04 -0400
A download filter's ^ and $ anchor to the title: include/exclude match when the pattern matches the title alone or title + description as before (a $-anchored pattern could never match a title)
The pattern was only tested against title + "\n" + description with flags
"i", so `$` was the end of the description and `^ROOSTER(123|456)$` selected
nothing on h3-podcast-audio-feed for two days. downloadFilterPatternMatches is
the one matcher classifyAgainstFilter and titleFilterReason call, so the
settled set, the snapshot, the downloader, the Playlist stage and keep-videos
agree. An empty title is not tested alone. Field docs (CHANNEL.md) and the
Configure form's hints say ^/$ anchor to the title.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Diffstat:
6 files changed, 94 insertions(+), 15 deletions(-)
diff --git a/CHANNEL.md b/CHANNEL.md
@@ -57,8 +57,8 @@ Regenerate this file with `pnpm --filter yt-dlp-transcript-common exec tsx bin/f
| Key | Default | Description |
|---|---|---|
-| `include` | absent | Case-insensitive regex SOURCE (no delimiters, no flags) a video's `title + "\n" + description` must match to be downloaded. Trimmed; blank = no include rule. |
-| `exclude` | absent | Case-insensitive regex source that rejects a matching video. Wins over `include`. Trimmed; blank = no exclude rule. |
+| `include` | absent | Case-insensitive regex SOURCE (no delimiters, no flags) a video must match to be downloaded. It is tested against the title alone AND against `title + "\n" + description`, and either match counts — so `^` and `$` anchor to the title (`^EPISODE (12\|13)$` matches that exact title). Trimmed; blank = no include rule. |
+| `exclude` | absent | Case-insensitive regex source that rejects a matching video, tested the same way as `include` (title alone, or title + description; `^`/`$` anchor to the title). Wins over `include`. Trimmed; blank = no exclude rule. |
| `includeLivestreams` | absent | Opt every livestream VOD in, whatever it is called. A SECOND positive selector beside `include`, not a modifier of it — so `{ includeLivestreams: true }` alone rejects plain uploads and passes livestreams. Stored only when `true`. |
| `rejectedLivestreams` | absent | What to do with a livestream the filter REJECTED: `"skip"` (default, and what every channel predating the field did) or `"chat-only"` — the video is not downloaded, its live chat is, and it joins the corpus as a chat track with no captions. Stored only when not `"skip"`, and only beside a real filter: with nothing to reject it names a decision that can never be taken. |
diff --git a/common/controller/keepVideosMatching.ts b/common/controller/keepVideosMatching.ts
@@ -26,9 +26,10 @@ import { loadRoster } from "./rosterStore";
//
// "MATCHES" MEANS WHAT THE DOWNLOAD FILTER MEANS BY IT. The pattern is compiled
// by `compileDownloadFilter` (case-insensitive, the same source a channel's
-// `downloadFilter.include` holds) and tested by `classifyAgainstFilter` over
-// `downloadFilterText` — title + "\n" + description, the description capped
-// exactly as the filter caps it. So a pattern that keeps the right videos here
+// `downloadFilter.include` holds) and tested by `classifyAgainstFilter`
+// against the title alone and `downloadFilterText` — title + "\n" +
+// description, the description capped exactly as the filter caps it (so `^`
+// and `$` anchor to the title). So a pattern that keeps the right videos here
// is one that would download the right ones there, and vice versa. There is no
// second matcher. `fields` narrows the SUBJECT, not the matcher: a field left
// out is passed as empty.
diff --git a/common/lib/channelConfig.ts b/common/lib/channelConfig.ts
@@ -87,9 +87,9 @@ export type DownloadFilterConfig = {
export const DOWNLOAD_FILTER_FIELD_DOCS: FieldDocs<DownloadFilterConfig> = {
include:
- "Case-insensitive regex SOURCE (no delimiters, no flags) a video's `title + \"\\n\" + description` must match to be downloaded. Trimmed; blank = no include rule.",
+ "Case-insensitive regex SOURCE (no delimiters, no flags) a video must match to be downloaded. It is tested against the title alone AND against `title + \"\\n\" + description`, and either match counts — so `^` and `$` anchor to the title (`^EPISODE (12|13)$` matches that exact title). Trimmed; blank = no include rule.",
exclude:
- "Case-insensitive regex source that rejects a matching video. Wins over `include`. Trimmed; blank = no exclude rule.",
+ "Case-insensitive regex source that rejects a matching video, tested the same way as `include` (title alone, or title + description; `^`/`$` anchor to the title). Wins over `include`. Trimmed; blank = no exclude rule.",
includeLivestreams:
"Opt every livestream VOD in, whatever it is called. A SECOND positive selector beside `include`, not a modifier of it — so `{ includeLivestreams: true }` alone rejects plain uploads and passes livestreams. Stored only when `true`.",
rejectedLivestreams:
diff --git a/common/lib/downloadFilters.test.ts b/common/lib/downloadFilters.test.ts
@@ -8,6 +8,7 @@ import {
downloadFilterPatternProblem,
downloadFilterText,
evaluateDownloadFilters,
+ titleFilterReason,
titleFilterRejects,
titleFilterWantsChat,
type DownloadFilterContext,
@@ -498,3 +499,55 @@ test("evaluateDownloadFilters marks the decision, and it is still a skip", () =>
assert.match(decision.reason, /live chat only/);
});
+
+// `^` and `$` anchor to the TITLE (downloadFilterPatternMatches). Before, the
+// pattern only saw title + "\n" + description, where `$` is the end of the
+// description, so an exact-title include selected nothing
+// (h3-podcast-audio-feed, 2026-10-25).
+test("a $-anchored include matches the exact title", () => {
+ const f = compiled("^ROOSTER(123|456)$");
+ const hit = meta({ title: "Rooster456", description: "An episode." });
+ assert.equal(classifyAgainstFilter(f, hit), "text");
+ assert.equal(titleFilterRejects(f, hit), false);
+ // Still anchored: a longer title does not match.
+ assert.equal(
+ titleFilterRejects(f, meta({ title: "Rooster456 part 2", description: "" })),
+ true,
+ );
+});
+
+test("an exclude ending in $ rejects a title ending that way", () => {
+ const f = compiled(undefined, "\\(rerun\\)$");
+ const rerun = meta({ title: "Big show (rerun)", description: "A long description." });
+ assert.equal(titleFilterRejects(f, rerun), true);
+ assert.match(titleFilterReason(f, rerun), /matches exclude/);
+ assert.equal(
+ titleFilterRejects(f, meta({ title: "Big show", description: "not a (rerun) here" })),
+ false,
+ );
+});
+
+test("description-only matches behave exactly as before", () => {
+ const f = compiled("special guest");
+ const inDesc = meta({ title: "Episode 9", description: "With a special guest." });
+ assert.equal(classifyAgainstFilter(f, inDesc), "text");
+ assert.equal(
+ titleFilterRejects(f, meta({ title: "Episode 9", description: "Solo." })),
+ true,
+ );
+ // A $ at the end of the description still matches the joined text.
+ const end = compiled("guest\\.$");
+ assert.equal(classifyAgainstFilter(end, inDesc), "text");
+ // An exclude matching only the description still wins.
+ const ex = compiled("episode", "sponsor");
+ assert.equal(
+ titleFilterRejects(ex, meta({ title: "Episode 9", description: "Our sponsor today" })),
+ true,
+ );
+});
+
+test("an empty title is not tested alone (a pattern matching the empty string)", () => {
+ const f = compiled("^$");
+ assert.equal(titleFilterRejects(f, meta({ title: "", description: "words" })), true);
+ assert.equal(titleFilterRejects(f, meta({ title: "Episode", description: "" })), true);
+});
diff --git a/common/lib/downloadFilters.ts b/common/lib/downloadFilters.ts
@@ -180,6 +180,30 @@ export function downloadFilterText(
return `${meta?.title ?? ""}\n${description}`;
}
+// Does one of a filter's patterns match this video? It matches when it
+// matches the TITLE ALONE or the title + "\n" + description text, so `^` and
+// `$` anchor to the title. Before this, the pattern only ever saw the joined
+// text (flags "i", no "m"), where `$` is the end of the DESCRIPTION — so
+// `^ROOSTER(123|456)$` could never match a title, and the
+// h3-podcast-audio-feed channel's filter selected nothing for two days.
+// Every pattern that does not anchor to the end behaves exactly as before: a
+// match inside the title is also a match inside the joined text, so the
+// title-alone test only ever ADDS the matches an end anchor (or a lookahead
+// past the title's end) used to miss.
+export function downloadFilterPatternMatches(
+ pattern: RegExp,
+ meta: FilterableVideo | null | undefined,
+): boolean {
+ // An empty title is not tested alone: a pattern that matches the empty
+ // string (`^$`, `^(?!…)`) would otherwise pass every untitled video — and
+ // every video of a keep-videos run narrowed to the description.
+ const title = meta?.title ?? "";
+ return (
+ (title !== "" && pattern.test(title)) ||
+ pattern.test(downloadFilterText(meta))
+ );
+}
+
// Is this pattern safe to hand to the matcher? The operator's regex runs over
// every stored title+description on every snapshot, every sync page and every
// render of the Configure stage, on the server's single thread — so a
@@ -233,7 +257,8 @@ export type DownloadFilterVerdict =
// 2. With NO positive selector (an exclude-only filter), everything else
// passes.
// 3. Otherwise a video must satisfy at least one positive selector: the
-// `include` pattern over title + "\n" + description, or — when
+// `include` pattern over the title alone or title + "\n" + description
+// (downloadFilterPatternMatches), or — when
// `includeLivestreams` is on — being a livestream.
//
// THE CORNER WORTH STATING: `{ includeLivestreams: true }` with no `include`
@@ -245,13 +270,14 @@ export function classifyAgainstFilter(
compiled: CompiledDownloadFilter,
meta: FilterableVideo,
): DownloadFilterVerdict {
- const text = downloadFilterText(meta);
- if (compiled.exclude && compiled.exclude.test(text)) {
+ if (compiled.exclude && downloadFilterPatternMatches(compiled.exclude, meta)) {
return rejection(compiled, meta);
}
const hasPositive = Boolean(compiled.include || compiled.includeLivestreams);
if (!hasPositive) return "text";
- if (compiled.include && compiled.include.test(text)) return "text";
+ if (compiled.include && downloadFilterPatternMatches(compiled.include, meta)) {
+ return "text";
+ }
if (compiled.includeLivestreams && isLivestream(meta)) return "livestream";
return rejection(compiled, meta);
}
@@ -297,8 +323,7 @@ export function titleFilterReason(
compiled: CompiledDownloadFilter,
meta: FilterableVideo,
): string {
- const text = downloadFilterText(meta);
- if (compiled.exclude && compiled.exclude.test(text)) {
+ if (compiled.exclude && downloadFilterPatternMatches(compiled.exclude, meta)) {
return `title/description matches exclude /${compiled.exclude.source}/i`;
}
const wants: string[] = [];
diff --git a/editor/app/channels/components/ChannelForm.tsx b/editor/app/channels/components/ChannelForm.tsx
@@ -923,7 +923,7 @@ export function ChannelForm({
value={filterInclude}
onChange={setFilterInclude}
placeholder="(download everything)"
- hint="Case-insensitive regex. Only videos whose title + description match are downloaded. Run Metadata scan on the Playlist stage to read the titles first — non-matching videos are then settled (never downloaded, never retried) until you change this. The listing and the roster stay complete either way."
+ hint="Case-insensitive regex. Only videos whose title, or title + description, match are downloaded; ^ and $ anchor to the title. Run Metadata scan on the Playlist stage to read the titles first — non-matching videos are then settled (never downloaded, never retried) until you change this. The listing and the roster stay complete either way."
/>
<Field
label="Download filter: exclude (regex)"
@@ -931,7 +931,7 @@ export function ChannelForm({
value={filterExclude}
onChange={setFilterExclude}
placeholder="(exclude nothing)"
- hint="Case-insensitive regex, applied to title + description and winning over include. Matching videos are settled until you change this. Patterns are capped at 200 characters and must not nest quantifiers — this runs on the server for every stored title."
+ hint="Case-insensitive regex, applied like include (^ and $ anchor to the title) and winning over include. Matching videos are settled until you change this. Patterns are capped at 200 characters and must not nest quantifiers — this runs on the server for every stored title."
/>
<label className="flex items-start gap-2 text-sm">
<input