guessit-js 4.5.0 → 4.5.1

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_(1333%2F1333)-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 (1333/1333 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 104 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 (1333/1333 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
 
@@ -3681,13 +3681,13 @@ function episodes(config) {
3681
3681
  rebulk.chain({
3682
3682
  tags: ["weak-episode"],
3683
3683
  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})`, {
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})`, {
3685
3685
  abbreviations: null
3686
3686
  }).repeater("*");
3687
3687
  rebulk.chain({
3688
3688
  tags: ["weak-episode"],
3689
3689
  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})`, {
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})`, {
3691
3691
  abbreviations: null
3692
3692
  }).repeater("*");
3693
3693
  rebulk.chain({
@@ -3698,13 +3698,13 @@ function episodes(config) {
3698
3698
  validator: null,
3699
3699
  tags: ["weak-episode"],
3700
3700
  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})`, {
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})`, {
3702
3702
  abbreviations: null
3703
3703
  }).repeater("*");
3704
3704
  rebulk.chain({
3705
3705
  tags: ["weak-episode"],
3706
3706
  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})`, {
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})`, {
3708
3708
  abbreviations: null
3709
3709
  }).repeater("*");
3710
3710
  rebulk.chain({
@@ -3733,7 +3733,7 @@ function episodes(config) {
3733
3733
  name: "weak_duplicate",
3734
3734
  validator: null,
3735
3735
  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})`, {
3736
+ }).regex(`(?<![^\\W_])(?<season>\\d{1,2})(?<episode>\\d{2})(?!%)(?!(?![vV]\\d)[^\\W_])`).regex(`v(?<version>\\d+)`).repeater("?").regex(`(?<episodeSeparator>x|-)(?<episode>\\d{2})`, {
3737
3737
  abbreviations: null
3738
3738
  }).repeater("*");
3739
3739
  rebulk.regex(`v(?<version>\\d+)`, {
@@ -3761,6 +3761,7 @@ function episodes(config) {
3761
3761
  disabled: (context) => isDisabled(context, "episode_format")
3762
3762
  });
3763
3763
  rebulk.rules(
3764
+ EventNumberAsTitleRule,
3764
3765
  EpisodeWordBeforeYearAsTitle,
3765
3766
  RemoveGroupSuffixSeason,
3766
3767
  AnimeTrailingEpisodeRule,
@@ -3818,6 +3819,45 @@ const _RemoveGroupSuffixSeason = class _RemoveGroupSuffixSeason extends Rule {
3818
3819
  };
3819
3820
  _RemoveGroupSuffixSeason.priority = 72;
3820
3821
  let RemoveGroupSuffixSeason = _RemoveGroupSuffixSeason;
3822
+ const _EventNumberAsTitleRule = class _EventNumberAsTitleRule extends Rule {
3823
+ constructor() {
3824
+ super(...arguments);
3825
+ this.priority = 60;
3826
+ this.consequence = RemoveMatch;
3827
+ }
3828
+ when(matches, _context) {
3829
+ const input = matches.inputString ?? "";
3830
+ const toRemove = [];
3831
+ const isWeak = (m) => !!(m.tags?.includes("weak-episode") || ["weak_episode", "weak_duplicate"].includes(m.initiator?.name));
3832
+ for (const filepart of matches.markers.named("path") ?? []) {
3833
+ const weaks = matches.range(
3834
+ filepart.start,
3835
+ filepart.end,
3836
+ (m) => m.name === "episode" && !m.private && isWeak(m)
3837
+ ) ?? [];
3838
+ if (!weaks.length) continue;
3839
+ 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);
3840
+ for (const w of weaks) {
3841
+ const init = w.initiator ?? w;
3842
+ const after = input.slice(init.end, init.end + 5);
3843
+ if (/^[\s._-]?PPV/i.test(after)) {
3844
+ for (const c of [init, ...init.children ?? []]) if (!toRemove.includes(c)) toRemove.push(c);
3845
+ continue;
3846
+ }
3847
+ if (!strong && init.start === filepart.start && /^[1-9]\d$/.test(String(init.raw ?? ""))) {
3848
+ const rest = input.slice(init.end, filepart.end);
3849
+ const words = rest.match(/[A-Za-z][a-z]+/g) ?? [];
3850
+ if (words.length >= 2) {
3851
+ for (const c of [init, ...init.children ?? []]) if (!toRemove.includes(c)) toRemove.push(c);
3852
+ }
3853
+ }
3854
+ }
3855
+ }
3856
+ return toRemove.length ? toRemove : false;
3857
+ }
3858
+ };
3859
+ _EventNumberAsTitleRule.priority = 60;
3860
+ let EventNumberAsTitleRule = _EventNumberAsTitleRule;
3821
3861
  const _EpisodeWordBeforeYearAsTitle = class _EpisodeWordBeforeYearAsTitle extends Rule {
3822
3862
  constructor() {
3823
3863
  super(...arguments);
@@ -7061,8 +7101,10 @@ const _BracketedTitleFallback = class _BracketedTitleFallback extends Rule {
7061
7101
  const toRemove = [];
7062
7102
  const toAppend = [];
7063
7103
  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;
7104
+ const titlesHere = matches.range(filepart.start, filepart.end, (m) => m.name === "title") ?? [];
7105
+ const realTitle = titlesHere.find((t) => /[\p{L}\p{N}]/u.test(String(t.value ?? "")));
7106
+ if (realTitle) continue;
7107
+ toRemove.push(...titlesHere);
7066
7108
  const groups2 = matches.markers.range(filepart.start, filepart.end, (m) => m.name === "group") ?? [];
7067
7109
  if (!groups2.length) continue;
7068
7110
  const rg = matches.range(filepart.start, filepart.end, (m) => m.name === "release_group", 0);
@@ -7071,6 +7113,25 @@ const _BracketedTitleFallback = class _BracketedTitleFallback extends Rule {
7071
7113
  if (rg && g.start <= rg.start && g.end >= rg.end) continue;
7072
7114
  const core = input.slice(g.start + 1, g.end - 1);
7073
7115
  if (!/[a-zA-Z]{2,}/.test(core)) continue;
7116
+ const softInner = matches.range(
7117
+ g.start,
7118
+ g.end,
7119
+ (m) => !m.private && ["episode_title", "alternative_title"].includes(m.name ?? "")
7120
+ ) ?? [];
7121
+ const hardInner = matches.range(
7122
+ g.start,
7123
+ g.end,
7124
+ (m) => !m.private && !["episode_title", "alternative_title"].includes(m.name ?? "")
7125
+ ) ?? [];
7126
+ if (softInner.length && !hardInner.length) {
7127
+ toRemove.push(...softInner);
7128
+ candidate = new Match(g.start + 1, g.end - 1, {
7129
+ name: "title",
7130
+ value: cleanup(input.slice(g.start + 1, g.end - 1)),
7131
+ inputString: input
7132
+ });
7133
+ break;
7134
+ }
7074
7135
  const hole = matches.holes(g.start + 1, g.end - 1, {
7075
7136
  formatter: cleanup,
7076
7137
  predicate: (h) => !!h.value,
@@ -7173,6 +7234,41 @@ const _BonusAtTitlePositionRule = class _BonusAtTitlePositionRule extends Rule {
7173
7234
  };
7174
7235
  _BonusAtTitlePositionRule.priority = 64;
7175
7236
  let BonusAtTitlePositionRule = _BonusAtTitlePositionRule;
7237
+ const _LanguageWordInAnimeTitle = class _LanguageWordInAnimeTitle extends Rule {
7238
+ constructor() {
7239
+ super(...arguments);
7240
+ this.priority = 64;
7241
+ this.consequence = RemoveMatch;
7242
+ }
7243
+ when(matches, context) {
7244
+ if (isDisabled(context, "language")) return false;
7245
+ const toRemove = [];
7246
+ for (const lang of matches.named("language") ?? []) {
7247
+ const raw = String(lang.raw ?? "");
7248
+ if (raw.length > 3 || !/^[A-Z][a-z]{0,2}$/.test(raw)) continue;
7249
+ const filepart = matches.markers.atMatch(lang, (m) => m.name === "path", 0);
7250
+ if (!filepart) continue;
7251
+ const leadingBracket = matches.markers.range(
7252
+ filepart.start,
7253
+ filepart.end,
7254
+ (m) => m.name === "group" && m.start === filepart.start,
7255
+ 0
7256
+ );
7257
+ if (!leadingBracket) continue;
7258
+ const anchor = matches.range(
7259
+ lang.end,
7260
+ filepart.end,
7261
+ (m) => !m.private && ["episode", "season", "year", "date"].includes(m.name ?? ""),
7262
+ 0
7263
+ );
7264
+ if (!anchor) continue;
7265
+ toRemove.push(lang);
7266
+ }
7267
+ return toRemove.length ? toRemove : false;
7268
+ }
7269
+ };
7270
+ _LanguageWordInAnimeTitle.priority = 64;
7271
+ let LanguageWordInAnimeTitle = _LanguageWordInAnimeTitle;
7176
7272
  const _PropertyAtTitlePositionAsTitle = class _PropertyAtTitlePositionAsTitle extends Rule {
7177
7273
  constructor() {
7178
7274
  super(...arguments);
@@ -7333,7 +7429,7 @@ function title(config) {
7333
7429
  const rebulk = new Rebulk({
7334
7430
  disabled: (context) => isDisabled(context, "title")
7335
7431
  });
7336
- rebulk.rules(CountryAtTitlePosition, TitleWordAtTitlePosition, WordNumeralPartAtTitlePosition, BonusAtTitlePositionRule, SplitOriginalScriptTitle, TitleFromPosition, PreferTitleWithYear, ExtendLoneArticleTitle, PropertyAtTitlePositionAsTitle, RemoveNumericAlternativeTitle, RemoveTailAlternativeTitle, RemoveTailTitle, BracketedTitleFallback, PreBracketJunkTitle, TrimSeasonWordFromTitle);
7432
+ rebulk.rules(CountryAtTitlePosition, TitleWordAtTitlePosition, WordNumeralPartAtTitlePosition, BonusAtTitlePositionRule, LanguageWordInAnimeTitle, SplitOriginalScriptTitle, TitleFromPosition, PreferTitleWithYear, ExtendLoneArticleTitle, PropertyAtTitlePositionAsTitle, RemoveNumericAlternativeTitle, RemoveTailAlternativeTitle, RemoveTailTitle, BracketedTitleFallback, PreBracketJunkTitle, TrimSeasonWordFromTitle);
7337
7433
  const expectedTitle = buildExpectedFunction("expected_title");
7338
7434
  rebulk.functional(expectedTitle, {
7339
7435
  name: "title",
@@ -11542,8 +11638,8 @@ const advanced_config = {
11542
11638
  "sub"
11543
11639
  ],
11544
11640
  groups: {
11545
- starting: "([{",
11546
- ending: ")]}"
11641
+ starting: "([{【「(",
11642
+ ending: ")]}】」)"
11547
11643
  },
11548
11644
  audio_codec: {
11549
11645
  audio_codec: {
@@ -12695,7 +12791,8 @@ const advanced_config = {
12695
12791
  string: [
12696
12792
  "Ova",
12697
12793
  "Oav"
12698
- ]
12794
+ ],
12795
+ tags: "title-word"
12699
12796
  },
12700
12797
  "Original Net Animation": "Ona",
12701
12798
  "Original Animation DVD": "Oad",