guessit-js 4.4.0 → 4.4.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.
@@ -3519,7 +3519,7 @@ function episodes(config) {
3519
3519
  chainBreaker: (matches) => episodesSeasonChainBreaker(matches, config),
3520
3520
  disabled: isSeasonEpisodeDisabled
3521
3521
  }).defaults({ tags: ["SxxExx"] }).regex(
3522
- seasonMarkerPattern + `(?<season>\\d+)@?` + episodeMarkerPattern + `@?(?<episode>\\d+)`
3522
+ seasonMarkerPattern + `(?<season>\\d+)@?` + episodeMarkerPattern + `@?(?<episode>\\d+)(?:[a-d](?![a-z0-9]))?`
3523
3523
  ).repeater("+").regex(
3524
3524
  allSeparatorsPattern + `@?(?<episode>\\d+)`
3525
3525
  ).repeater("*");
@@ -3561,6 +3561,10 @@ function episodes(config) {
3561
3561
  `(?<season>\\d{1,2})(?:st|nd|rd|th)@?(?:season)(?![^\\W_])`,
3562
3562
  { tags: ["SxxExx", "numfirst"], disabled: isSeasonEpisodeDisabled }
3563
3563
  );
3564
+ rebulk.regex(
3565
+ `(?<!\\d)(?<season>\\d{1,2})(?<episodeMarker>x)(?<episode>\\d{2})(?!\\d)`,
3566
+ { tags: ["SxxExx"], disabled: isSeasonEpisodeDisabled }
3567
+ );
3564
3568
  const seasonOnlySepPattern = buildOrPattern(
3565
3569
  [...config.season_markers, ...discreteSeparators, ...config.range_separators],
3566
3570
  "seasonSeparator",
@@ -3603,7 +3607,8 @@ function episodes(config) {
3603
3607
  validator: { season: seasonWordNotYear, season_count: validateRoman },
3604
3608
  conflictSolver: seasonEpisodeConflictSolver
3605
3609
  }).regex(seasonWordPattern + `@?(?P<season>${numeralWithWords})`).regex(ofWordPattern + `@?(?P<season_count>${numeral})`).repeater("?").regex(
3606
- `@?` + buildOrPattern(
3610
+ // an optional comma before the separator covers list forms like ", & 6"
3611
+ `(?:,@?)?@?` + buildOrPattern(
3607
3612
  [...config.range_separators, ...discreteSeparators, "@"],
3608
3613
  "seasonSeparator",
3609
3614
  true
@@ -3631,6 +3636,24 @@ function episodes(config) {
3631
3636
  );
3632
3637
  }
3633
3638
  const episodeWordPattern = buildOrPattern(episodeWords, "episodeMarker");
3639
+ rebulk.regex(
3640
+ buildOrPattern(episodeWords, "episodeMarker") + `@?(?<season>\\d{1,2})\\.(?<episode>\\d{2,3})(?!\\d)`,
3641
+ { tags: ["SxxExx"], disabled: isSeasonEpisodeDisabled }
3642
+ );
3643
+ rebulk.regex(
3644
+ `(?<=[\\s([_-][\\s._-]?)(?<season>\\d{1,2})\\.(?<episode>\\d{2,3})(?=[\\s)\\]._-]|$)(?!\\.\\d)`,
3645
+ {
3646
+ tags: ["SxxExx", "decimal-episode"],
3647
+ validator: {
3648
+ __parent__: (m) => {
3649
+ const inp = m.inputString ?? "";
3650
+ const before = inp.slice(Math.max(0, m.start - 3), m.start);
3651
+ return /[-([]\s?$|^\s*$|\s-\s$/.test(before) || /[([]/.test(before);
3652
+ }
3653
+ },
3654
+ disabled: isSeasonEpisodeDisabled
3655
+ }
3656
+ );
3634
3657
  rebulk.regex(
3635
3658
  `(?<![a-zA-Z\\d])` + episodeWordPattern + `@?(?<episode>\\d+)(?:v(?<version>\\d+))?(?:@?` + ofWordPattern + `@?(?<count>\\d+))?`,
3636
3659
  {
@@ -3736,6 +3759,7 @@ function episodes(config) {
3736
3759
  disabled: (context) => isDisabled(context, "episode_format")
3737
3760
  });
3738
3761
  rebulk.rules(
3762
+ RemoveGroupSuffixSeason,
3739
3763
  AnimeTrailingEpisodeRule,
3740
3764
  PreferAnchoredWeakEpisodeRule,
3741
3765
  SeasonWordDashedEpisodeRule,
@@ -3754,6 +3778,43 @@ function episodes(config) {
3754
3778
  );
3755
3779
  return rebulk;
3756
3780
  }
3781
+ const _RemoveGroupSuffixSeason = class _RemoveGroupSuffixSeason extends Rule {
3782
+ constructor() {
3783
+ super(...arguments);
3784
+ this.priority = 72;
3785
+ this.consequence = RemoveMatch;
3786
+ }
3787
+ when(matches, _context) {
3788
+ const input = matches.inputString ?? "";
3789
+ const toRemove = [];
3790
+ const TOKENS = /* @__PURE__ */ new Set(["audio_codec", "audio_channels", "video_codec", "audio_profile", "other"]);
3791
+ for (const season of matches.named("season") ?? []) {
3792
+ const init = season.initiator ?? season;
3793
+ if (!/^s\d{1,3}$/i.test(String(init.raw ?? ""))) continue;
3794
+ const hasEpisode = [...init.children ?? []].some((c) => c.name === "episode");
3795
+ if (hasEpisode) continue;
3796
+ if (input[init.start - 1] !== "-") continue;
3797
+ const prev = matches.range(
3798
+ Math.max(0, init.start - 12),
3799
+ init.start - 1,
3800
+ (m) => !m.private && TOKENS.has(m.name ?? ""),
3801
+ -1
3802
+ ) ?? matches.range(
3803
+ Math.max(0, init.start - 12),
3804
+ init.start - 1,
3805
+ (m) => !m.private && TOKENS.has(m.name ?? ""),
3806
+ 0
3807
+ );
3808
+ const inGroup = matches.markers.atMatch(init, (m) => m.name === "group", 0);
3809
+ if (!prev && !inGroup) continue;
3810
+ toRemove.push(season);
3811
+ for (const c of init.children ?? []) if (!toRemove.includes(c)) toRemove.push(c);
3812
+ }
3813
+ return toRemove.length ? toRemove : false;
3814
+ }
3815
+ };
3816
+ _RemoveGroupSuffixSeason.priority = 72;
3817
+ let RemoveGroupSuffixSeason = _RemoveGroupSuffixSeason;
3757
3818
  const _AnimeTrailingEpisodeRule = class _AnimeTrailingEpisodeRule extends Rule {
3758
3819
  constructor() {
3759
3820
  super(...arguments);
@@ -4131,7 +4192,8 @@ class RangeExpansionRule extends Rule {
4131
4192
  const betweenClean = between.replace(/[\s.]/g, "").toLowerCase();
4132
4193
  const betweenStripMarkers = betweenClean.replace(/[sexp]/gi, "");
4133
4194
  const hasRangeChar = /[-~_]/.test(between);
4134
- const isRange = hasRangeChar || rangeSeps.has(betweenClean) || rangeSeps.has(betweenStripMarkers);
4195
+ const seasonColon = name === "season" && betweenClean === ":";
4196
+ const isRange = hasRangeChar || seasonColon || rangeSeps.has(betweenClean) || rangeSeps.has(betweenStripMarkers);
4135
4197
  if (isRange) {
4136
4198
  for (let v = curVal + 1; v < nextVal; v++) {
4137
4199
  const m = new Match(current.start, next.end, {
@@ -7009,6 +7071,36 @@ const _BracketedTitleFallback = class _BracketedTitleFallback extends Rule {
7009
7071
  };
7010
7072
  _BracketedTitleFallback.priority = POST_PROCESS;
7011
7073
  let BracketedTitleFallback = _BracketedTitleFallback;
7074
+ const _WordNumeralPartAtTitlePosition = class _WordNumeralPartAtTitlePosition extends Rule {
7075
+ constructor() {
7076
+ super(...arguments);
7077
+ this.priority = 64;
7078
+ this.consequence = RemoveMatch;
7079
+ }
7080
+ when(matches, context) {
7081
+ if (isDisabled(context, "part")) return false;
7082
+ const toRemove = [];
7083
+ for (const part2 of matches.named("part") ?? []) {
7084
+ const target = part2.initiator ?? part2;
7085
+ if (/\d/.test(String(target.raw ?? ""))) continue;
7086
+ const filepart = matches.markers.atMatch(part2, (m) => m.name === "path", 0);
7087
+ if (!filepart) continue;
7088
+ const anchor = matches.range(
7089
+ part2.end,
7090
+ filepart.end,
7091
+ (m) => !m.private && ["year", "season", "episode", "date"].includes(m.name ?? ""),
7092
+ 0
7093
+ );
7094
+ if (!anchor) continue;
7095
+ toRemove.push(part2);
7096
+ for (const c of [...target.children ?? []]) if (!toRemove.includes(c)) toRemove.push(c);
7097
+ if (target !== part2 && !toRemove.includes(target)) toRemove.push(target);
7098
+ }
7099
+ return toRemove.length ? toRemove : false;
7100
+ }
7101
+ };
7102
+ _WordNumeralPartAtTitlePosition.priority = 64;
7103
+ let WordNumeralPartAtTitlePosition = _WordNumeralPartAtTitlePosition;
7012
7104
  const _PropertyAtTitlePositionAsTitle = class _PropertyAtTitlePositionAsTitle extends Rule {
7013
7105
  constructor() {
7014
7106
  super(...arguments);
@@ -7018,18 +7110,22 @@ const _PropertyAtTitlePositionAsTitle = class _PropertyAtTitlePositionAsTitle ex
7018
7110
  const inp = matches.inputString || "";
7019
7111
  const out = [];
7020
7112
  for (const filepart of matches.markers.named("path")) {
7021
- if (matches.range(filepart.start, filepart.end, (m) => m.name === "title", 0)) continue;
7113
+ const lead = matches.range(filepart.start, filepart.end, (m) => !m.private && !!m.value, 0);
7114
+ if (!lead) continue;
7022
7115
  const anchor = matches.range(
7023
- filepart.start,
7116
+ lead.end,
7024
7117
  filepart.end,
7025
7118
  (m) => !m.private && ["year", "season", "episode", "date"].includes(m.name ?? ""),
7026
7119
  0
7027
7120
  );
7028
7121
  if (!anchor) continue;
7029
- const lead = matches.range(filepart.start, filepart.end, (m) => !m.private && !!m.value, 0);
7030
- if (!lead || !["other", "country", "edition"].includes(lead.name ?? "")) continue;
7031
- if (lead.start >= anchor.start) continue;
7032
- if ((lead.raw ?? "") === String(lead.value ?? "")) continue;
7122
+ const yearTitled = lead.name === "year" && ["season", "episode"].includes(anchor.name ?? "") && !anchor.tags?.includes("weak-episode") && !anchor.tags?.includes("weak-duplicate");
7123
+ if (!yearTitled && !["other", "country", "edition"].includes(lead.name ?? "")) continue;
7124
+ const titles = matches.range(filepart.start, filepart.end, (m) => m.name === "title") ?? [];
7125
+ if (titles.some((t) => t.start < anchor.end)) continue;
7126
+ if (titles.length && !yearTitled) continue;
7127
+ out.push(...titles);
7128
+ if (lead.name !== "year" && (lead.raw ?? "") === String(lead.value ?? "")) continue;
7033
7129
  if (![...inp.slice(filepart.start, lead.start)].every((c) => seps.includes(c))) continue;
7034
7130
  out.push(lead);
7035
7131
  }
@@ -7156,7 +7252,7 @@ function title(config) {
7156
7252
  const rebulk = new Rebulk({
7157
7253
  disabled: (context) => isDisabled(context, "title")
7158
7254
  });
7159
- rebulk.rules(CountryAtTitlePosition, TitleWordAtTitlePosition, SplitOriginalScriptTitle, TitleFromPosition, PreferTitleWithYear, ExtendLoneArticleTitle, PropertyAtTitlePositionAsTitle, RemoveNumericAlternativeTitle, RemoveTailAlternativeTitle, RemoveTailTitle, BracketedTitleFallback, PreBracketJunkTitle, TrimSeasonWordFromTitle);
7255
+ rebulk.rules(CountryAtTitlePosition, TitleWordAtTitlePosition, WordNumeralPartAtTitlePosition, SplitOriginalScriptTitle, TitleFromPosition, PreferTitleWithYear, ExtendLoneArticleTitle, PropertyAtTitlePositionAsTitle, RemoveNumericAlternativeTitle, RemoveTailAlternativeTitle, RemoveTailTitle, BracketedTitleFallback, PreBracketJunkTitle, TrimSeasonWordFromTitle);
7160
7256
  const expectedTitle = buildExpectedFunction("expected_title");
7161
7257
  rebulk.functional(expectedTitle, {
7162
7258
  name: "title",
@@ -11353,7 +11449,8 @@ const advanced_config = {
11353
11449
  regex: [
11354
11450
  "Dolby-Digital",
11355
11451
  "DD",
11356
- "AC-?3D?"
11452
+ "AC-?3D?",
11453
+ "DolbyD"
11357
11454
  ]
11358
11455
  },
11359
11456
  "Dolby Atmos": {
@@ -11866,7 +11963,8 @@ const advanced_config = {
11866
11963
  episode_max_range: 100,
11867
11964
  max_range_gap: 1,
11868
11965
  season_markers: [
11869
- "s"
11966
+ "s",
11967
+ "sn"
11870
11968
  ],
11871
11969
  season_ep_markers: [
11872
11970
  "x",