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