Files
iptvnator/libs
4grayandClaude Fable 5 402382421c feat(matching): strip appended language/quality tags in title normalization (#1211)
* feat(matching): strip appended language/quality tags in title normalization

Real-world portal catalogs duplicate one show under dozens of tagged
variants ("|ALB| Fallout", "4K-DE - The Pitt (2025) (US)",
"Breaking Bad-eng", "Fallout_esp", "The Last of Us (2023) AF"). A third
of them normalized to polluted keys, silently skipping TMDB enrichment
and staying invisible to cross-portal title matching.

normalizeTitleKeys() now handles, conservatively:
- wrapped pipe tags:      "|ALB| X", "|MULTI| X"
- longer/compound leads:  "EXYU| X", "4K-DE - X", "AR-SUBS - X",
                          "4K-OSN+ - X" (dash/pipe only; colon stays
                          2-3 chars so "NCIS: LA" is untouched)
- underscore suffixes:    "X_eng", "(US)_msub" (single-underscore only,
                          "The_Last_of_Us" stays intact)
- double-dash suffixes:   "X--esp"
- joined dash tags:       "X-DE", "X-eng" (vocabulary-gated and
                          case-uniform only; "Spider-Man", "Kick-It",
                          "Peut-être" are untouched)
- bare trailing tags:     "X (2025) DE", "Breaking Bad ES" (UPPERCASE
                          vocabulary only, skipped for ALL-CAPS titles;
                          "Rocky II", "Made in USA", "Making It" are
                          untouched)

Every leading-tag segment must contain a letter, so numeric titles
("1917 - ...") are never treated as tags. The display-side
stripCountryPrefix() learns the same compound/plus-sign prefixes and the
numeric guard.

buildSearchLookupKey() gets a |v2 suffix so cached negative TMDB match
resolutions keyed on old polluted titles are invalidated.

Measured on 248 real catalog names from four shows (The Pitt, Fallout,
The Last of Us, Breaking Bad): clean matching keys 65% -> 99%, display
strip 91% -> 100%. The corpora are committed as spec fixtures.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* fix(matching): use ES2015-safe trailing trim in title normalization

String.prototype.trimEnd is ES2019; the shared-interfaces lib compiles
against an older lib target (TS2550 in typecheck:web). Replace with a
regex-based trimRight helper. Jest uses its own tsconfig, so this only
surfaced in the CI typecheck, not local unit runs.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* fix(matching): guard tag stripping against real-title false positives

Address code-review findings on the tag-stripping rules:

- underscore suffix is now vocabulary-gated, so "Mr_Robot",
  "Cowboy_Bebop", "Mrs_Davis" keep their second word
- leading single-segment tags before a spaced dash stay 2-3 chars
  (only hyphen-compounds like "4K-DE" and pipe-tags like "EXYU|" may be
  wider), so "DUNE - Part Two" and "ALIEN - Covenant" are left intact
- "IN" is excluded from the weak joined-dash/underscore paths so
  "drive-in" and "Plug-in" are not truncated (India still strips via
  the strong "IN| " / "IN - " forms)

The display-side stripCountryPrefix() mirrors the narrowed dash rule.
Corpus coverage is unchanged at 99% (245/248); new counter-example
tests lock in the guards.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-07-19 19:42:20 +02:00
..