guessit-js 4.2.0 → 4.3.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_(1036%2F1036)-brightgreen)](https://github.com/guessit-io/guessit)
8
+ [![Python guessit compat](https://img.shields.io/badge/guessit_compat-100%25_(1289%2F1289)-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 (1036/1036 fixtures passing) — and **more correct** in places: ships fixes for 32 upstream guessit bugs that Python still has (see [Differences from Python](#differences-from-python-guessit))
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))
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 (1036/1036 fixtures match Python 3.8.0), but it is
125
+ guessit-js is a faithful port (1289/1289 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
 
@@ -3289,6 +3289,8 @@ function episodesSeasonChainBreaker(matches, config) {
3289
3289
  return false;
3290
3290
  }
3291
3291
  function seasonEpisodeConflictSolver(match, other2) {
3292
+ const weakFamily = (m) => !!(m?.tags?.includes("weak-episode") || ["weak_episode", "weak_duplicate"].includes(m?.initiator?.name) || ["weak_episode", "weak_duplicate"].includes(m?.name));
3293
+ if (weakFamily(match) && weakFamily(other2)) return null;
3292
3294
  const famChild = (p) => {
3293
3295
  if (p?.name) return null;
3294
3296
  const ch = [...p?.children ?? []];
@@ -3312,6 +3314,10 @@ function seasonEpisodeConflictSolver(match, other2) {
3312
3314
  "container",
3313
3315
  "date"
3314
3316
  ].includes(other2.name)) {
3317
+ if (other2.name === "video_codec" && /^[hx][\W_]\d/i.test(String(other2.raw ?? ""))) {
3318
+ const before = (other2.inputString ?? "")[other2.start - 1] ?? "";
3319
+ if (/[a-z]/i.test(before)) return other2;
3320
+ }
3315
3321
  return match;
3316
3322
  }
3317
3323
  if (other2.name === "audio_channels" && !other2.tags?.includes("weak-audio_channels") && !match.initiator?.children?.named(match.name + "Marker")?.length || other2.name === "screen_size" && !intCoercable(other2.raw)) {
@@ -3355,7 +3361,7 @@ function seasonEpisodeConflictSolver(match, other2) {
3355
3361
  const matchIsWeak = !!(match.tags?.includes("weak-episode") || ["weak_episode", "weak_duplicate"].includes(match.initiator?.name));
3356
3362
  const otherIsWeak = !!(other2.tags?.includes("weak-episode") || ["weak_episode", "weak_duplicate"].includes(other2.initiator?.name));
3357
3363
  if (matchIsWeak && otherIsWeak) {
3358
- return "__default__";
3364
+ return null;
3359
3365
  }
3360
3366
  if (matchIsWeak) return match;
3361
3367
  if (otherIsWeak) return other2;
@@ -3371,7 +3377,8 @@ function seasonEpisodeConflictSolver(match, other2) {
3371
3377
  return "__default__";
3372
3378
  }
3373
3379
  function orderingValidator(match) {
3374
- const values = match.children?.to_dict?.() || {};
3380
+ const dict = match.children?.toDict?.() ?? match.children?.to_dict?.();
3381
+ const values = dict instanceof Map ? Object.fromEntries(dict) : dict || {};
3375
3382
  if (values.season && Array.isArray(values.season)) {
3376
3383
  const sorted = [...values.season].sort((a, b) => a - b);
3377
3384
  if (JSON.stringify(sorted) !== JSON.stringify(values.season)) {
@@ -3528,7 +3535,7 @@ function episodes(config) {
3528
3535
  },
3529
3536
  disabled: isSeasonEpisodeDisabled
3530
3537
  }).defaults({ tags: ["SxxExx"] }).regex(
3531
- `(?<season>\\d+)` + asymmetricSeasonEpMarker + `@?` + seasonEpMarkerPattern + `@?(?<episode>\\d+)`
3538
+ `(?!0x[0-9a-fA-F])(?<season>\\d+)` + asymmetricSeasonEpMarker + `@?` + seasonEpMarkerPattern + `@?(?<episode>\\d+)`
3532
3539
  ).repeater("+");
3533
3540
  rebulk.chain({
3534
3541
  tags: ["SxxExx"],
@@ -3537,7 +3544,7 @@ function episodes(config) {
3537
3544
  __parent__: and_(sepsSurround, orderingValidator)
3538
3545
  },
3539
3546
  disabled: isSeasonEpisodeDisabled
3540
- }).defaults({ tags: ["SxxExx"] }).regex(`(?<season>\\d+)` + asymmetricSeasonEpMarker + `@?` + seasonEpMarkerPattern + `@?(?<episode>\\d+)`).regex(
3547
+ }).defaults({ tags: ["SxxExx"] }).regex(`(?!0x[0-9a-fA-F])(?<season>\\d+)` + asymmetricSeasonEpMarker + `@?` + seasonEpMarkerPattern + `@?(?<episode>\\d+)`).regex(
3541
3548
  buildOrPattern(
3542
3549
  [...config.season_ep_markers, ...discreteSeparators, ...config.range_separators],
3543
3550
  "episodeSeparator",
@@ -3548,6 +3555,14 @@ function episodes(config) {
3548
3555
  `t(?<season>\\d{1,2})@?` + buildOrPattern(config.episode_markers, "episodeMarker") + `@?(?<episode>\\d{1,4})`,
3549
3556
  { tags: ["SxxExx"], disabled: isSeasonEpisodeDisabled }
3550
3557
  );
3558
+ rebulk.regex(
3559
+ `(?<![^\\W_])(?:SP|EX|OVA|OAV)-?(?<episode>\\d{1,3})(?![^\\W_])`,
3560
+ { tags: ["SxxExx", "special-episode"], disabled: (context) => isDisabled(context, "episode") }
3561
+ );
3562
+ rebulk.regex(
3563
+ `(?<season>\\d{1,2})(?:st|nd|rd|th)@?(?:season)(?![^\\W_])`,
3564
+ { tags: ["SxxExx", "numfirst"], disabled: isSeasonEpisodeDisabled }
3565
+ );
3551
3566
  const seasonOnlySepPattern = buildOrPattern(
3552
3567
  [...config.season_markers, ...discreteSeparators, ...config.range_separators],
3553
3568
  "seasonSeparator",
@@ -3723,6 +3738,9 @@ function episodes(config) {
3723
3738
  disabled: (context) => isDisabled(context, "episode_format")
3724
3739
  });
3725
3740
  rebulk.rules(
3741
+ AnimeTrailingEpisodeRule,
3742
+ PreferAnchoredWeakEpisodeRule,
3743
+ SeasonWordDashedEpisodeRule,
3726
3744
  RemoveNumfirstMarkerCollision,
3727
3745
  CountValidator,
3728
3746
  new DiscMarkerRule(config),
@@ -3738,6 +3756,178 @@ function episodes(config) {
3738
3756
  );
3739
3757
  return rebulk;
3740
3758
  }
3759
+ const _AnimeTrailingEpisodeRule = class _AnimeTrailingEpisodeRule extends Rule {
3760
+ constructor() {
3761
+ super(...arguments);
3762
+ this.priority = -64;
3763
+ this.consequence = [RemoveMatch, AppendMatch];
3764
+ }
3765
+ when(matches, _context) {
3766
+ const input = matches.inputString ?? "";
3767
+ const toRemove = [];
3768
+ const toAppend = [];
3769
+ const episodes2 = matches.named("episode") ?? [];
3770
+ if (episodes2.length) return false;
3771
+ for (const filepart of matches.markers.named("path") ?? []) {
3772
+ const crc2 = matches.range(filepart.start, filepart.end, (m2) => m2.name === "crc32", 0);
3773
+ const animeRg = matches.range(
3774
+ filepart.start,
3775
+ filepart.end,
3776
+ (m2) => m2.name === "release_group" && m2.tags?.includes("anime"),
3777
+ 0
3778
+ );
3779
+ if (!crc2 && !animeRg) continue;
3780
+ let done = false;
3781
+ for (const group of matches.markers.range(filepart.start, filepart.end, (m2) => m2.name === "group") ?? []) {
3782
+ const core = input.slice(group.start + 1, group.end - 1).trim();
3783
+ if (!/^\d{1,3}$/.test(core)) continue;
3784
+ const inner = matches.range(group.start, group.end, (m2) => !m2.private) ?? [];
3785
+ if (inner.some((m2) => !["alternative_title", "episode_title"].includes(m2.name ?? "") && !m2.tags?.includes("weak-episode"))) continue;
3786
+ toRemove.push(...inner);
3787
+ toAppend.push(new Match(group.start + 1, group.end - 1, {
3788
+ name: "episode",
3789
+ value: parseInt(core, 10),
3790
+ inputString: input,
3791
+ tags: ["anime"]
3792
+ }));
3793
+ done = true;
3794
+ break;
3795
+ }
3796
+ if (done) continue;
3797
+ const title2 = matches.range(filepart.start, filepart.end, (m2) => m2.name === "title", 0);
3798
+ if (!title2) continue;
3799
+ const m = /^(.*[^\W\d_])[\s._-]+(\d{1,3})$/.exec(input.slice(title2.start, title2.end));
3800
+ if (!m) continue;
3801
+ const numStart = title2.start + m[1].length + (m[0].length - m[1].length - m[2].length);
3802
+ toRemove.push(title2);
3803
+ const newTitle = new Match(title2.start, title2.start + m[1].length, {
3804
+ name: "title",
3805
+ value: cleanup(m[1]),
3806
+ inputString: input
3807
+ });
3808
+ toAppend.push(newTitle);
3809
+ toAppend.push(new Match(numStart, title2.end, {
3810
+ name: "episode",
3811
+ value: parseInt(m[2], 10),
3812
+ inputString: input,
3813
+ tags: ["anime"]
3814
+ }));
3815
+ }
3816
+ return toRemove.length || toAppend.length ? [toRemove, toAppend] : false;
3817
+ }
3818
+ };
3819
+ _AnimeTrailingEpisodeRule.priority = -64;
3820
+ let AnimeTrailingEpisodeRule = _AnimeTrailingEpisodeRule;
3821
+ const _PreferAnchoredWeakEpisodeRule = class _PreferAnchoredWeakEpisodeRule extends Rule {
3822
+ constructor() {
3823
+ super(...arguments);
3824
+ this.priority = 40;
3825
+ this.consequence = RemoveMatch;
3826
+ }
3827
+ when(matches, _context) {
3828
+ const input = matches.inputString ?? "";
3829
+ const toRemove = [];
3830
+ const isWeakEp = (m) => m.name === "episode" && !m.private && (m.tags?.includes("weak-episode") || ["weak_episode", "weak_duplicate"].includes(m.initiator?.name));
3831
+ const removeGroup = (init) => {
3832
+ for (const c of [...init.children ?? [], init]) {
3833
+ if (!toRemove.includes(c)) toRemove.push(c);
3834
+ }
3835
+ if (!init.children?.length && !toRemove.includes(init)) toRemove.push(init);
3836
+ };
3837
+ for (const filepart of matches.markers.named("path") ?? []) {
3838
+ const weaks = matches.range(filepart.start, filepart.end, isWeakEp) ?? [];
3839
+ if (!weaks.length) continue;
3840
+ const strong = matches.range(filepart.start, filepart.end, (m) => m.name === "episode" && !m.private && !isWeakEp(m) && !!m.initiator?.children?.named?.("episodeMarker")?.length, 0);
3841
+ const byInit = /* @__PURE__ */ new Map();
3842
+ for (const w of weaks) {
3843
+ const init = w.initiator ?? w;
3844
+ byInit.set(init, [...byInit.get(init) ?? [], w]);
3845
+ }
3846
+ if (strong) {
3847
+ for (const init of byInit.keys()) removeGroup(init);
3848
+ continue;
3849
+ }
3850
+ if (byInit.size < 2) continue;
3851
+ const score = (init) => {
3852
+ let sc = 0;
3853
+ const raw = String(init.raw ?? "");
3854
+ if (/^0\d/.test(raw)) sc += 4;
3855
+ let i = init.start - 1;
3856
+ while (i >= 0 && (input[i] === " " || input[i] === "." || input[i] === "_")) i--;
3857
+ if (input[i] === "-") sc += 1;
3858
+ if (matches.markers.atMatch(init, (m) => m.name === "group", 0)) sc -= 2;
3859
+ return sc;
3860
+ };
3861
+ const scored = [...byInit.keys()].map((init) => [init, score(init)]);
3862
+ const top = Math.max(...scored.map(([, sc]) => sc));
3863
+ const winners = scored.filter(([, sc]) => sc === top);
3864
+ if (winners.length === scored.length) continue;
3865
+ const winnerValues = new Set(winners.flatMap(([init]) => (byInit.get(init) ?? []).map((w) => Number(w.value))));
3866
+ for (const [init, sc] of scored) {
3867
+ if (sc >= top) continue;
3868
+ const eps = byInit.get(init) ?? [];
3869
+ if (eps.length > 1) continue;
3870
+ if (eps.some((w) => winnerValues.has(Number(w.value)))) continue;
3871
+ removeGroup(init);
3872
+ }
3873
+ }
3874
+ return toRemove.length ? toRemove : false;
3875
+ }
3876
+ };
3877
+ _PreferAnchoredWeakEpisodeRule.priority = 40;
3878
+ let PreferAnchoredWeakEpisodeRule = _PreferAnchoredWeakEpisodeRule;
3879
+ const _SeasonWordDashedEpisodeRule = class _SeasonWordDashedEpisodeRule extends Rule {
3880
+ constructor() {
3881
+ super(...arguments);
3882
+ this.priority = 32;
3883
+ this.consequence = [RemoveMatch, AppendMatch];
3884
+ }
3885
+ when(matches, _context) {
3886
+ const input = matches.inputString ?? "";
3887
+ const toRemove = [];
3888
+ const toAppend = [];
3889
+ const seasons = matches.named("season") ?? [];
3890
+ const seen = /* @__PURE__ */ new Set();
3891
+ for (const season of seasons) {
3892
+ const init = season.initiator ?? season;
3893
+ if (seen.has(init)) continue;
3894
+ seen.add(init);
3895
+ const children = [...init.children ?? []];
3896
+ const marker = children.find((c) => c.name === "seasonMarker");
3897
+ if (!marker) continue;
3898
+ const markerRaw = String(marker.raw ?? "");
3899
+ const isWordMarker = /^[a-zà-ÿа-я]{3,}$/i.test(markerRaw);
3900
+ const inBracket = !!matches.markers.atMatch(season, (m) => m.name === "group", 0);
3901
+ if (!isWordMarker && !(markerRaw.toLowerCase() === "s" && inBracket)) continue;
3902
+ if (isWordMarker && /s$/i.test(markerRaw)) continue;
3903
+ const nums = children.filter((c) => c.name === "season");
3904
+ if (nums.length !== 2) continue;
3905
+ const sep = children.find((c) => c.name === "seasonSeparator");
3906
+ if (!sep || String(sep.raw ?? "").trim() !== "-") continue;
3907
+ if (isWordMarker && (input[sep.start - 1] !== " " || input[sep.end] !== " ")) continue;
3908
+ const filepart = matches.markers.atMatch(season, (m) => m.name === "path", 0);
3909
+ if (filepart) {
3910
+ const complete = matches.range(
3911
+ filepart.start,
3912
+ filepart.end,
3913
+ (m) => m.name === "other" && m.value === "Complete",
3914
+ 0
3915
+ );
3916
+ if (complete) continue;
3917
+ }
3918
+ const episodeMatch = new Match(nums[1].start, nums[1].end, {
3919
+ name: "episode",
3920
+ value: nums[1].value,
3921
+ inputString: input
3922
+ });
3923
+ toRemove.push(nums[1]);
3924
+ toAppend.push(episodeMatch);
3925
+ }
3926
+ return toRemove.length || toAppend.length ? [toRemove, toAppend] : false;
3927
+ }
3928
+ };
3929
+ _SeasonWordDashedEpisodeRule.priority = 32;
3930
+ let SeasonWordDashedEpisodeRule = _SeasonWordDashedEpisodeRule;
3741
3931
  const _RemoveNumfirstMarkerCollision = class _RemoveNumfirstMarkerCollision extends Rule {
3742
3932
  constructor() {
3743
3933
  super(...arguments);
@@ -3767,7 +3957,8 @@ const _RemoveNumfirstMarkerCollision = class _RemoveNumfirstMarkerCollision exte
3767
3957
  });
3768
3958
  if (!wordFirst) continue;
3769
3959
  const claimed = all.some((m) => !m.private && (m.name === "screen_size" || m.name === "year") && m.start < wordFirst.end && wordFirst.start < m.end);
3770
- if (claimed) removeWithParent(wordFirst);
3960
+ const gluedOrdinal = /^(?:st|nd|rd|th|ª|º|°)/i.test(String(matches.inputString ?? "").slice(nf.end, nf.end + 2));
3961
+ if (claimed || gluedOrdinal) removeWithParent(wordFirst);
3771
3962
  else removeWithParent(nf);
3772
3963
  }
3773
3964
  return toRemove.length ? toRemove : false;
@@ -4717,12 +4908,13 @@ const _ValidateVideoCodec = class _ValidateVideoCodec extends Rule {
4717
4908
  when(matches, _context) {
4718
4909
  const ret = [];
4719
4910
  const codecs = matches.named("video_codec");
4911
+ const hasAny = (v) => Array.isArray(v) ? v.length > 0 : !!v;
4720
4912
  for (const codec of codecs) {
4721
- if (!sepsBefore(codec) && !matches.atIndex(codec.start - 1, (m) => m.tags?.includes("video-codec-prefix"))) {
4913
+ if (!sepsBefore(codec) && !hasAny(matches.atIndex(codec.start - 1, (m) => m.tags?.includes("video-codec-prefix")))) {
4722
4914
  ret.push(codec);
4723
4915
  continue;
4724
4916
  }
4725
- if (!sepsAfter(codec) && !matches.atIndex(codec.end + 1, (m) => m.tags?.includes("video-codec-suffix"))) {
4917
+ if (!sepsAfter(codec) && !hasAny(matches.atIndex(codec.end + 1, (m) => m.tags?.includes("video-codec-suffix")))) {
4726
4918
  ret.push(codec);
4727
4919
  continue;
4728
4920
  }
@@ -6652,6 +6844,97 @@ const _SplitOriginalScriptTitle = class _SplitOriginalScriptTitle extends Rule {
6652
6844
  };
6653
6845
  _SplitOriginalScriptTitle.priority = POST_PROCESS;
6654
6846
  let SplitOriginalScriptTitle = _SplitOriginalScriptTitle;
6847
+ const _PreBracketJunkTitle = class _PreBracketJunkTitle extends Rule {
6848
+ constructor() {
6849
+ super(...arguments);
6850
+ this.priority = POST_PROCESS;
6851
+ this.consequence = RemoveMatch;
6852
+ }
6853
+ when(matches, context) {
6854
+ if (isDisabled(context, "title")) return false;
6855
+ const input = matches.inputString ?? "";
6856
+ const toRemove = [];
6857
+ for (const filepart of matches.markers.named("path")) {
6858
+ const titles = (matches.range(filepart.start, filepart.end, (m) => m.name === "title") ?? []).sort((a, b) => a.start - b.start);
6859
+ if (titles.length < 2) continue;
6860
+ const first = titles[0];
6861
+ if (first.start !== filepart.start) continue;
6862
+ if (/[\s._-]/.test(String(first.value ?? "").trim())) continue;
6863
+ const group = matches.markers.range(first.end, filepart.end, (m) => m.name === "group", 0);
6864
+ if (!group || group.start >= titles[1].start) continue;
6865
+ if (![...input.slice(first.end, group.start)].every((c) => seps.includes(c))) continue;
6866
+ const rg = matches.range(
6867
+ group.start,
6868
+ group.end,
6869
+ (m) => m.name === "release_group" && !!m.tags?.includes("anime"),
6870
+ 0
6871
+ );
6872
+ if (!rg) continue;
6873
+ toRemove.push(first);
6874
+ }
6875
+ return toRemove.length ? toRemove : false;
6876
+ }
6877
+ };
6878
+ _PreBracketJunkTitle.priority = POST_PROCESS;
6879
+ let PreBracketJunkTitle = _PreBracketJunkTitle;
6880
+ const _BracketedTitleFallback = class _BracketedTitleFallback extends Rule {
6881
+ constructor() {
6882
+ super(...arguments);
6883
+ this.priority = POST_PROCESS;
6884
+ this.consequence = [RemoveMatch, AppendMatch];
6885
+ }
6886
+ when(matches, context) {
6887
+ if (isDisabled(context, "title")) return false;
6888
+ const input = matches.inputString ?? "";
6889
+ const toRemove = [];
6890
+ const toAppend = [];
6891
+ for (const filepart of matches.markers.named("path")) {
6892
+ const hasTitle = matches.range(filepart.start, filepart.end, (m) => m.name === "title", 0);
6893
+ if (hasTitle) continue;
6894
+ const groups2 = matches.markers.range(filepart.start, filepart.end, (m) => m.name === "group") ?? [];
6895
+ if (!groups2.length) continue;
6896
+ const rg = matches.range(filepart.start, filepart.end, (m) => m.name === "release_group", 0);
6897
+ let candidate;
6898
+ for (const g of groups2) {
6899
+ if (rg && g.start <= rg.start && g.end >= rg.end) continue;
6900
+ const core = input.slice(g.start + 1, g.end - 1);
6901
+ if (!/[a-zA-Z]{2,}/.test(core)) continue;
6902
+ const inner = matches.range(g.start, g.end, (m) => !m.private) ?? [];
6903
+ if (inner.length) continue;
6904
+ candidate = g;
6905
+ break;
6906
+ }
6907
+ if (candidate) {
6908
+ toAppend.push(new Match(candidate.start + 1, candidate.end - 1, {
6909
+ name: "title",
6910
+ value: cleanup(input.slice(candidate.start + 1, candidate.end - 1)),
6911
+ inputString: input
6912
+ }));
6913
+ continue;
6914
+ }
6915
+ if (rg && rg.tags?.includes("anime")) {
6916
+ const outside = input.slice(filepart.start, filepart.end).replace(input.slice(rg.start - 1 >= filepart.start ? rg.start - 1 : rg.start, Math.min(rg.end + 1, filepart.end)), "");
6917
+ const outsideMatches = matches.range(
6918
+ filepart.start,
6919
+ filepart.end,
6920
+ (m) => !m.private && m.name !== "release_group" && m.start >= filepart.start
6921
+ ) ?? [];
6922
+ const wordyOutside = /[a-zA-Z]{2,}/.test(outside.replace(/\b(mkv|avi|mp4)\b/gi, "")) && outsideMatches.some((m) => ["title", "episode_title", "alternative_title"].includes(m.name ?? ""));
6923
+ if (!wordyOutside) {
6924
+ toRemove.push(rg);
6925
+ toAppend.push(new Match(rg.start, rg.end, {
6926
+ name: "title",
6927
+ value: cleanup(input.slice(rg.start, rg.end)),
6928
+ inputString: input
6929
+ }));
6930
+ }
6931
+ }
6932
+ }
6933
+ return toRemove.length || toAppend.length ? [toRemove, toAppend] : false;
6934
+ }
6935
+ };
6936
+ _BracketedTitleFallback.priority = POST_PROCESS;
6937
+ let BracketedTitleFallback = _BracketedTitleFallback;
6655
6938
  const _PropertyAtTitlePositionAsTitle = class _PropertyAtTitlePositionAsTitle extends Rule {
6656
6939
  constructor() {
6657
6940
  super(...arguments);
@@ -6799,7 +7082,7 @@ function title(config) {
6799
7082
  const rebulk = new Rebulk({
6800
7083
  disabled: (context) => isDisabled(context, "title")
6801
7084
  });
6802
- rebulk.rules(CountryAtTitlePosition, TitleWordAtTitlePosition, SplitOriginalScriptTitle, TitleFromPosition, PreferTitleWithYear, ExtendLoneArticleTitle, PropertyAtTitlePositionAsTitle, RemoveNumericAlternativeTitle, RemoveTailAlternativeTitle, RemoveTailTitle);
7085
+ rebulk.rules(CountryAtTitlePosition, TitleWordAtTitlePosition, SplitOriginalScriptTitle, TitleFromPosition, PreferTitleWithYear, ExtendLoneArticleTitle, PropertyAtTitlePositionAsTitle, RemoveNumericAlternativeTitle, RemoveTailAlternativeTitle, RemoveTailTitle, BracketedTitleFallback, PreBracketJunkTitle);
6803
7086
  const expectedTitle = buildExpectedFunction("expected_title");
6804
7087
  rebulk.functional(expectedTitle, {
6805
7088
  name: "title",
@@ -6820,6 +7103,39 @@ const LEADING_ARTICLES_RE = /^(the|a|an|le|la|les|l'|el|los|las|der|die|das)\s+/
6820
7103
  function normalizeTitle(s) {
6821
7104
  return s.toLowerCase().replace(LEADING_ARTICLES_RE, "").trim();
6822
7105
  }
7106
+ const _FormationRunEpisodeTitle = class _FormationRunEpisodeTitle extends Rule {
7107
+ constructor() {
7108
+ super(...arguments);
7109
+ this.priority = POST_PROCESS;
7110
+ this.consequence = [RemoveMatch, AppendMatch];
7111
+ }
7112
+ when(matches, _context) {
7113
+ const input = matches.inputString ?? "";
7114
+ const toRemove = [];
7115
+ const toAppend = [];
7116
+ const ets = matches.named("episode_title") ?? [];
7117
+ for (const et of ets) {
7118
+ if (!/^\d{1,2}$/.test(String(et.value ?? ""))) continue;
7119
+ const eps = (matches.named("episode") ?? []).filter((e) => e.end <= et.start && !e.private).sort((a, b) => a.start - b.start);
7120
+ if (eps.length < 3) continue;
7121
+ const run = eps.slice(1);
7122
+ const runStart = run[0].start;
7123
+ const span = input.slice(runStart, et.end);
7124
+ if (!/^\d{1,3}(-\d{1,3})+$/.test(span)) continue;
7125
+ const between = input.slice(eps[0].end, runStart);
7126
+ if (!/^[\s._]+$/.test(between)) continue;
7127
+ toRemove.push(...run, et);
7128
+ toAppend.push(new Match(runStart, et.end, {
7129
+ name: "episode_title",
7130
+ value: span,
7131
+ inputString: input
7132
+ }));
7133
+ }
7134
+ return toRemove.length || toAppend.length ? [toRemove, toAppend] : false;
7135
+ }
7136
+ };
7137
+ _FormationRunEpisodeTitle.priority = POST_PROCESS;
7138
+ let FormationRunEpisodeTitle = _FormationRunEpisodeTitle;
6823
7139
  function episodeTitle(config) {
6824
7140
  const rebulk = new Rebulk({ disabled: (context) => isDisabled(context, "episode_title") });
6825
7141
  rebulk.rules(
@@ -6839,6 +7155,7 @@ function episodeTitle(config) {
6839
7155
  RemoveSubtitleDescriptorEpisodeTitle,
6840
7156
  RemoveHashFilepartJunk,
6841
7157
  RemoveTailEpisodeTitle,
7158
+ FormationRunEpisodeTitle,
6842
7159
  RenameEpisodeTitleWhenMovieType
6843
7160
  );
6844
7161
  return rebulk;