guessit-js 4.5.0 → 4.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -5,13 +5,13 @@ Extract metadata (title, year, season, episode, codec, language, etc.) from medi
5
5
  [![npm version](https://img.shields.io/npm/v/guessit-js.svg)](https://www.npmjs.com/package/guessit-js)
6
6
  [![Tests](https://github.com/opensubtitles/guessit-js/actions/workflows/ci.yml/badge.svg)](https://github.com/opensubtitles/guessit-js/actions/workflows/ci.yml)
7
7
  [![License: LGPL-3.0](https://img.shields.io/badge/License-LGPL--3.0-blue.svg)](https://www.gnu.org/licenses/lgpl-3.0)
8
- [![Python guessit compat](https://img.shields.io/badge/guessit_compat-100%25_(1289%2F1289)-brightgreen)](https://github.com/guessit-io/guessit)
8
+ [![Python guessit compat](https://img.shields.io/badge/guessit_compat-100%25_(1342%2F1342)-brightgreen)](https://github.com/guessit-io/guessit)
9
9
 
10
10
  **[Live Demo](https://opensubtitles.github.io/guessit-js)** · **[API Docs](https://opensubtitles.github.io/guessit-js/docs)** · **[npm](https://www.npmjs.com/package/guessit-js)**
11
11
 
12
12
  ## Features
13
13
 
14
- - **100% compatibility** with Python guessit 4.4.0 (1289/1289 fixtures passing, including Python's own grown 4.x corpus) — and **more correct**: ships fixes for 32 historical upstream bugs plus Python's still-open #875 and #877 (see [Differences from Python](#differences-from-python-guessit))
14
+ - **100% compatibility** with Python guessit 4.4.0 (1342/1342 fixtures passing, including Python's own grown 4.x corpus) — and **more correct**: ships fixes for 32 historical upstream bugs, Python's still-open #875 and #877, and 112 of the 276 cross-parser cases Python admits failing (see [Differences from Python](#differences-from-python-guessit))
15
15
  - **3.5x faster** than Python (6.87ms vs 23.86ms per parse)
16
16
  - **50 properties** detected: title, year, season, episode, resolution, codec, language, and more — with a [machine-readable schema](#output-schema)
17
17
  - **Single dependency** ([rebulk-js](https://www.npmjs.com/package/rebulk-js))
@@ -122,7 +122,7 @@ The WASM build is **bit-identical to the JS build** across the entire test corpu
122
122
 
123
123
  ## Differences from Python guessit
124
124
 
125
- guessit-js is a faithful port (1289/1289 fixtures, tracking Python 4.4.0), but it is
125
+ guessit-js is a faithful port (1342/1342 fixtures, tracking Python 4.4.0), but it is
126
126
  **not bug-for-bug identical** — where Python has a genuine parsing bug, guessit-js
127
127
  is corrected. Highlights:
128
128
 
@@ -372,6 +372,11 @@ class _BaseMatches {
372
372
  toArray() {
373
373
  return [...this._delegate];
374
374
  }
375
+ /** All matches as an array. Ported Python code reads `matches.matches` — without
376
+ * this getter that silently evaluated to undefined and turned rules into no-ops. */
377
+ get matches() {
378
+ return [...this._delegate];
379
+ }
375
380
  // ── Cache accessors ──────────────────────────────────────────────────────
376
381
  get nameDict() {
377
382
  if (!this._nameDict) {
@@ -1621,12 +1626,10 @@ function executeRule(rule, matches, context) {
1621
1626
  }
1622
1627
  function toposortRules(rules) {
1623
1628
  const graph = /* @__PURE__ */ new Map();
1624
- const classToDep = /* @__PURE__ */ new Map();
1629
+ const classToDeps = /* @__PURE__ */ new Map();
1625
1630
  for (const rule of rules) {
1626
- if (classToDep.has(rule.constructor)) {
1627
- throw new Error(`Duplicate class rules are not allowed: ${rule.constructor.name}`);
1628
- }
1629
- classToDep.set(rule.constructor, rule);
1631
+ const cls = rule.constructor;
1632
+ classToDeps.set(cls, [...classToDeps.get(cls) ?? [], rule]);
1630
1633
  }
1631
1634
  for (const rule of rules) {
1632
1635
  const deps = /* @__PURE__ */ new Set();
@@ -1634,18 +1637,20 @@ function toposortRules(rules) {
1634
1637
  if (rawDeps) {
1635
1638
  const depArr = Array.isArray(rawDeps) ? rawDeps : [rawDeps];
1636
1639
  for (const dep of depArr) {
1637
- let resolved;
1640
+ let resolved = [];
1638
1641
  if (typeof dep === "string") {
1639
- for (const [cls, inst] of classToDep) {
1642
+ for (const [cls, insts] of classToDeps) {
1640
1643
  if (cls.name === dep) {
1641
- resolved = inst;
1644
+ resolved = insts;
1642
1645
  break;
1643
1646
  }
1644
1647
  }
1645
1648
  } else {
1646
- resolved = classToDep.get(dep);
1649
+ resolved = classToDeps.get(dep) ?? [];
1650
+ }
1651
+ for (const inst of resolved) {
1652
+ if (inst !== rule) deps.add(inst);
1647
1653
  }
1648
- if (resolved) deps.add(resolved);
1649
1654
  }
1650
1655
  }
1651
1656
  graph.set(rule, deps);
@@ -3681,13 +3686,13 @@ function episodes(config) {
3681
3686
  rebulk.chain({
3682
3687
  tags: ["weak-episode"],
3683
3688
  disabled: (context) => context?.type === "movie" || isDisabled(context, "episode")
3684
- }).defaults({ validator: null, tags: ["weak-episode"] }).regex(`(?<![^\\W_])(?<episode>\\d{2})(?!(?:st|nd|rd|th)\\b)(?:[a-d](?![a-z0-9]))?(?!(?![vV]\\d)[^\\W_])`).regex(`v(?<version>\\d+)`).repeater("?").regex(`(?<episodeSeparator>[x-])(?<episode>\\d{2})`, {
3689
+ }).defaults({ validator: null, tags: ["weak-episode"] }).regex(`(?<![^\\W_])(?<episode>\\d{2})(?!(?:st|nd|rd|th)\\b)(?!%)(?:[a-d](?![a-z0-9]))?(?!(?![vV]\\d)[^\\W_])`).regex(`v(?<version>\\d+)`).repeater("?").regex(`(?<episodeSeparator>[x-])(?<episode>\\d{2})`, {
3685
3690
  abbreviations: null
3686
3691
  }).repeater("*");
3687
3692
  rebulk.chain({
3688
3693
  tags: ["weak-episode"],
3689
3694
  disabled: (context) => context?.type === "movie" || isDisabled(context, "episode")
3690
- }).defaults({ validator: null, tags: ["weak-episode"] }).regex(`(?<![^\\W_])0(?<episode>\\d{1,2})(?:[a-d](?![a-z0-9]))?(?!(?![vV]\\d)[^\\W_])`).regex(`v(?<version>\\d+)`).repeater("?").regex(`(?<episodeSeparator>[x-])0(?<episode>\\d{1,2})`, {
3695
+ }).defaults({ validator: null, tags: ["weak-episode"] }).regex(`(?<![^\\W_])0(?<episode>\\d{1,2})(?!%)(?:[a-d](?![a-z0-9]))?(?!(?![vV]\\d)[^\\W_])`).regex(`v(?<version>\\d+)`).repeater("?").regex(`(?<episodeSeparator>[x-])0(?<episode>\\d{1,2})`, {
3691
3696
  abbreviations: null
3692
3697
  }).repeater("*");
3693
3698
  rebulk.chain({
@@ -3698,13 +3703,13 @@ function episodes(config) {
3698
3703
  validator: null,
3699
3704
  tags: ["weak-episode"],
3700
3705
  name: "weak_episode"
3701
- }).regex(`(?<![^\\W_])(?<episode>\\d{3,4})(?:[a-d](?![a-z0-9]))?(?!(?![vV]\\d)[^\\W_])`).regex(`v(?<version>\\d+)`).repeater("?").regex(`(?<episodeSeparator>[x-])(?<episode>\\d{3,4})`, {
3706
+ }).regex(`(?<![^\\W_])(?<episode>\\d{3,4})(?!%)(?:[a-d](?![a-z0-9]))?(?!(?![vV]\\d)[^\\W_])`).regex(`v(?<version>\\d+)`).repeater("?").regex(`(?<episodeSeparator>[x-])(?<episode>\\d{3,4})`, {
3702
3707
  abbreviations: null
3703
3708
  }).repeater("*");
3704
3709
  rebulk.chain({
3705
3710
  tags: ["weak-episode"],
3706
3711
  disabled: (context) => context?.type !== "episode" || isDisabled(context, "episode")
3707
- }).defaults({ validator: null, tags: ["weak-episode"] }).regex(`(?<![^\\W_])(?<episode>\\d)(?!-[a-z])(?!(?![vV]\\d)[^\\W_])`).regex(`v(?<version>\\d+)`).repeater("?").regex(`(?<episodeSeparator>[x-])(?<episode>\\d{1,2})`, {
3712
+ }).defaults({ validator: null, tags: ["weak-episode"] }).regex(`(?<![^\\W_])(?<episode>\\d)(?!-[a-z])(?!%)(?!(?![vV]\\d)[^\\W_])`).regex(`v(?<version>\\d+)`).repeater("?").regex(`(?<episodeSeparator>[x-])(?<episode>\\d{1,2})`, {
3708
3713
  abbreviations: null
3709
3714
  }).repeater("*");
3710
3715
  rebulk.chain({
@@ -3733,7 +3738,7 @@ function episodes(config) {
3733
3738
  name: "weak_duplicate",
3734
3739
  validator: null,
3735
3740
  conflictSolver: seasonEpisodeConflictSolver
3736
- }).regex(`(?<![^\\W_])(?<season>\\d{1,2})(?<episode>\\d{2})(?!(?![vV]\\d)[^\\W_])`).regex(`v(?<version>\\d+)`).repeater("?").regex(`(?<episodeSeparator>x|-)(?<episode>\\d{2})`, {
3741
+ }).regex(`(?<![^\\W_])(?<season>\\d{1,2})(?<episode>\\d{2})(?!%)(?!(?![vV]\\d)[^\\W_])`).regex(`v(?<version>\\d+)`).repeater("?").regex(`(?<episodeSeparator>x|-)(?<episode>\\d{2})`, {
3737
3742
  abbreviations: null
3738
3743
  }).repeater("*");
3739
3744
  rebulk.regex(`v(?<version>\\d+)`, {
@@ -3761,6 +3766,7 @@ function episodes(config) {
3761
3766
  disabled: (context) => isDisabled(context, "episode_format")
3762
3767
  });
3763
3768
  rebulk.rules(
3769
+ EventNumberAsTitleRule,
3764
3770
  EpisodeWordBeforeYearAsTitle,
3765
3771
  RemoveGroupSuffixSeason,
3766
3772
  AnimeTrailingEpisodeRule,
@@ -3818,6 +3824,45 @@ const _RemoveGroupSuffixSeason = class _RemoveGroupSuffixSeason extends Rule {
3818
3824
  };
3819
3825
  _RemoveGroupSuffixSeason.priority = 72;
3820
3826
  let RemoveGroupSuffixSeason = _RemoveGroupSuffixSeason;
3827
+ const _EventNumberAsTitleRule = class _EventNumberAsTitleRule extends Rule {
3828
+ constructor() {
3829
+ super(...arguments);
3830
+ this.priority = 60;
3831
+ this.consequence = RemoveMatch;
3832
+ }
3833
+ when(matches, _context) {
3834
+ const input = matches.inputString ?? "";
3835
+ const toRemove = [];
3836
+ const isWeak = (m) => !!(m.tags?.includes("weak-episode") || ["weak_episode", "weak_duplicate"].includes(m.initiator?.name));
3837
+ for (const filepart of matches.markers.named("path") ?? []) {
3838
+ const weaks = matches.range(
3839
+ filepart.start,
3840
+ filepart.end,
3841
+ (m) => m.name === "episode" && !m.private && isWeak(m)
3842
+ ) ?? [];
3843
+ if (!weaks.length) continue;
3844
+ const strong = matches.range(filepart.start, filepart.end, (m) => !m.private && (m.name === "season" || m.name === "year" || m.name === "date" || m.name === "episode" && m.tags?.includes("SxxExx")), 0);
3845
+ for (const w of weaks) {
3846
+ const init = w.initiator ?? w;
3847
+ const after = input.slice(init.end, init.end + 5);
3848
+ if (/^[\s._-]?PPV/i.test(after)) {
3849
+ for (const c of [init, ...init.children ?? []]) if (!toRemove.includes(c)) toRemove.push(c);
3850
+ continue;
3851
+ }
3852
+ if (!strong && init.start === filepart.start && /^[1-9]\d$/.test(String(init.raw ?? ""))) {
3853
+ const rest = input.slice(init.end, filepart.end);
3854
+ const words = rest.match(/[A-Za-z][a-z]+/g) ?? [];
3855
+ if (words.length >= 2) {
3856
+ for (const c of [init, ...init.children ?? []]) if (!toRemove.includes(c)) toRemove.push(c);
3857
+ }
3858
+ }
3859
+ }
3860
+ }
3861
+ return toRemove.length ? toRemove : false;
3862
+ }
3863
+ };
3864
+ _EventNumberAsTitleRule.priority = 60;
3865
+ let EventNumberAsTitleRule = _EventNumberAsTitleRule;
3821
3866
  const _EpisodeWordBeforeYearAsTitle = class _EpisodeWordBeforeYearAsTitle extends Rule {
3822
3867
  constructor() {
3823
3868
  super(...arguments);
@@ -7061,8 +7106,10 @@ const _BracketedTitleFallback = class _BracketedTitleFallback extends Rule {
7061
7106
  const toRemove = [];
7062
7107
  const toAppend = [];
7063
7108
  for (const filepart of matches.markers.named("path")) {
7064
- const hasTitle = matches.range(filepart.start, filepart.end, (m) => m.name === "title", 0);
7065
- if (hasTitle) continue;
7109
+ const titlesHere = matches.range(filepart.start, filepart.end, (m) => m.name === "title") ?? [];
7110
+ const realTitle = titlesHere.find((t) => /[\p{L}\p{N}]/u.test(String(t.value ?? "")));
7111
+ if (realTitle) continue;
7112
+ toRemove.push(...titlesHere);
7066
7113
  const groups2 = matches.markers.range(filepart.start, filepart.end, (m) => m.name === "group") ?? [];
7067
7114
  if (!groups2.length) continue;
7068
7115
  const rg = matches.range(filepart.start, filepart.end, (m) => m.name === "release_group", 0);
@@ -7071,6 +7118,25 @@ const _BracketedTitleFallback = class _BracketedTitleFallback extends Rule {
7071
7118
  if (rg && g.start <= rg.start && g.end >= rg.end) continue;
7072
7119
  const core = input.slice(g.start + 1, g.end - 1);
7073
7120
  if (!/[a-zA-Z]{2,}/.test(core)) continue;
7121
+ const softInner = matches.range(
7122
+ g.start,
7123
+ g.end,
7124
+ (m) => !m.private && ["episode_title", "alternative_title"].includes(m.name ?? "")
7125
+ ) ?? [];
7126
+ const hardInner = matches.range(
7127
+ g.start,
7128
+ g.end,
7129
+ (m) => !m.private && !["episode_title", "alternative_title"].includes(m.name ?? "")
7130
+ ) ?? [];
7131
+ if (softInner.length && !hardInner.length) {
7132
+ toRemove.push(...softInner);
7133
+ candidate = new Match(g.start + 1, g.end - 1, {
7134
+ name: "title",
7135
+ value: cleanup(input.slice(g.start + 1, g.end - 1)),
7136
+ inputString: input
7137
+ });
7138
+ break;
7139
+ }
7074
7140
  const hole = matches.holes(g.start + 1, g.end - 1, {
7075
7141
  formatter: cleanup,
7076
7142
  predicate: (h) => !!h.value,
@@ -7173,6 +7239,41 @@ const _BonusAtTitlePositionRule = class _BonusAtTitlePositionRule extends Rule {
7173
7239
  };
7174
7240
  _BonusAtTitlePositionRule.priority = 64;
7175
7241
  let BonusAtTitlePositionRule = _BonusAtTitlePositionRule;
7242
+ const _LanguageWordInAnimeTitle = class _LanguageWordInAnimeTitle extends Rule {
7243
+ constructor() {
7244
+ super(...arguments);
7245
+ this.priority = 64;
7246
+ this.consequence = RemoveMatch;
7247
+ }
7248
+ when(matches, context) {
7249
+ if (isDisabled(context, "language")) return false;
7250
+ const toRemove = [];
7251
+ for (const lang of matches.named("language") ?? []) {
7252
+ const raw = String(lang.raw ?? "");
7253
+ if (raw.length > 3 || !/^[A-Z][a-z]{0,2}$/.test(raw)) continue;
7254
+ const filepart = matches.markers.atMatch(lang, (m) => m.name === "path", 0);
7255
+ if (!filepart) continue;
7256
+ const leadingBracket = matches.markers.range(
7257
+ filepart.start,
7258
+ filepart.end,
7259
+ (m) => m.name === "group" && m.start === filepart.start,
7260
+ 0
7261
+ );
7262
+ if (!leadingBracket) continue;
7263
+ const anchor = matches.range(
7264
+ lang.end,
7265
+ filepart.end,
7266
+ (m) => !m.private && ["episode", "season", "year", "date"].includes(m.name ?? ""),
7267
+ 0
7268
+ );
7269
+ if (!anchor) continue;
7270
+ toRemove.push(lang);
7271
+ }
7272
+ return toRemove.length ? toRemove : false;
7273
+ }
7274
+ };
7275
+ _LanguageWordInAnimeTitle.priority = 64;
7276
+ let LanguageWordInAnimeTitle = _LanguageWordInAnimeTitle;
7176
7277
  const _PropertyAtTitlePositionAsTitle = class _PropertyAtTitlePositionAsTitle extends Rule {
7177
7278
  constructor() {
7178
7279
  super(...arguments);
@@ -7333,7 +7434,7 @@ function title(config) {
7333
7434
  const rebulk = new Rebulk({
7334
7435
  disabled: (context) => isDisabled(context, "title")
7335
7436
  });
7336
- rebulk.rules(CountryAtTitlePosition, TitleWordAtTitlePosition, WordNumeralPartAtTitlePosition, BonusAtTitlePositionRule, SplitOriginalScriptTitle, TitleFromPosition, PreferTitleWithYear, ExtendLoneArticleTitle, PropertyAtTitlePositionAsTitle, RemoveNumericAlternativeTitle, RemoveTailAlternativeTitle, RemoveTailTitle, BracketedTitleFallback, PreBracketJunkTitle, TrimSeasonWordFromTitle);
7437
+ rebulk.rules(CountryAtTitlePosition, TitleWordAtTitlePosition, WordNumeralPartAtTitlePosition, BonusAtTitlePositionRule, LanguageWordInAnimeTitle, SplitOriginalScriptTitle, TitleFromPosition, PreferTitleWithYear, ExtendLoneArticleTitle, PropertyAtTitlePositionAsTitle, RemoveNumericAlternativeTitle, RemoveTailAlternativeTitle, RemoveTailTitle, BracketedTitleFallback, PreBracketJunkTitle, TrimSeasonWordFromTitle);
7337
7438
  const expectedTitle = buildExpectedFunction("expected_title");
7338
7439
  rebulk.functional(expectedTitle, {
7339
7440
  name: "title",
@@ -11542,8 +11643,8 @@ const advanced_config = {
11542
11643
  "sub"
11543
11644
  ],
11544
11645
  groups: {
11545
- starting: "([{",
11546
- ending: ")]}"
11646
+ starting: "([{【「(",
11647
+ ending: ")]}】」)"
11547
11648
  },
11548
11649
  audio_codec: {
11549
11650
  audio_codec: {
@@ -12695,7 +12796,8 @@ const advanced_config = {
12695
12796
  string: [
12696
12797
  "Ova",
12697
12798
  "Oav"
12698
- ]
12799
+ ],
12800
+ tags: "title-word"
12699
12801
  },
12700
12802
  "Original Net Animation": "Ona",
12701
12803
  "Original Animation DVD": "Oad",