guessit-js 4.4.1 → 4.5.0

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]))?(?:v(?<version>\\d+))?`
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
  {
@@ -3656,13 +3679,13 @@ function episodes(config) {
3656
3679
  rebulk.chain({
3657
3680
  tags: ["weak-episode"],
3658
3681
  disabled: (context) => context?.type === "movie" || isDisabled(context, "episode")
3659
- }).defaults({ validator: null, tags: ["weak-episode"] }).regex(`(?<![^\\W_])(?<episode>\\d{2})(?!(?:st|nd|rd|th)\\b)(?!(?![vV]\\d)[^\\W_])`).regex(`v(?<version>\\d+)`).repeater("?").regex(`(?<episodeSeparator>[x-])(?<episode>\\d{2})`, {
3682
+ }).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})`, {
3660
3683
  abbreviations: null
3661
3684
  }).repeater("*");
3662
3685
  rebulk.chain({
3663
3686
  tags: ["weak-episode"],
3664
3687
  disabled: (context) => context?.type === "movie" || isDisabled(context, "episode")
3665
- }).defaults({ validator: null, tags: ["weak-episode"] }).regex(`(?<![^\\W_])0(?<episode>\\d{1,2})(?!(?![vV]\\d)[^\\W_])`).regex(`v(?<version>\\d+)`).repeater("?").regex(`(?<episodeSeparator>[x-])0(?<episode>\\d{1,2})`, {
3688
+ }).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})`, {
3666
3689
  abbreviations: null
3667
3690
  }).repeater("*");
3668
3691
  rebulk.chain({
@@ -3673,7 +3696,7 @@ function episodes(config) {
3673
3696
  validator: null,
3674
3697
  tags: ["weak-episode"],
3675
3698
  name: "weak_episode"
3676
- }).regex(`(?<![^\\W_])(?<episode>\\d{3,4})(?!(?![vV]\\d)[^\\W_])`).regex(`v(?<version>\\d+)`).repeater("?").regex(`(?<episodeSeparator>[x-])(?<episode>\\d{3,4})`, {
3699
+ }).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})`, {
3677
3700
  abbreviations: null
3678
3701
  }).repeater("*");
3679
3702
  rebulk.chain({
@@ -3736,6 +3759,7 @@ function episodes(config) {
3736
3759
  disabled: (context) => isDisabled(context, "episode_format")
3737
3760
  });
3738
3761
  rebulk.rules(
3762
+ EpisodeWordBeforeYearAsTitle,
3739
3763
  RemoveGroupSuffixSeason,
3740
3764
  AnimeTrailingEpisodeRule,
3741
3765
  PreferAnchoredWeakEpisodeRule,
@@ -3792,6 +3816,40 @@ const _RemoveGroupSuffixSeason = class _RemoveGroupSuffixSeason extends Rule {
3792
3816
  };
3793
3817
  _RemoveGroupSuffixSeason.priority = 72;
3794
3818
  let RemoveGroupSuffixSeason = _RemoveGroupSuffixSeason;
3819
+ const _EpisodeWordBeforeYearAsTitle = class _EpisodeWordBeforeYearAsTitle extends Rule {
3820
+ constructor() {
3821
+ super(...arguments);
3822
+ this.priority = 60;
3823
+ this.consequence = RemoveMatch;
3824
+ }
3825
+ when(matches, _context) {
3826
+ const toRemove = [];
3827
+ for (const episode of matches.named("episode") ?? []) {
3828
+ const init = episode.initiator ?? episode;
3829
+ const marker = [...init.children ?? []].find((c) => c.name === "episodeMarker");
3830
+ if (!marker || String(marker.raw ?? "").length < 3) continue;
3831
+ const filepart = matches.markers.atMatch(episode, (m) => m.name === "path", 0);
3832
+ if (!filepart) continue;
3833
+ const year = matches.range(episode.end, filepart.end, (m) => !m.private && m.name === "year", 0);
3834
+ if (!year) continue;
3835
+ const seasonish = matches.range(
3836
+ filepart.start,
3837
+ filepart.end,
3838
+ (m) => !m.private && (m.name === "season" || m.name === "episode" && m.tags?.includes("SxxExx")),
3839
+ 0
3840
+ );
3841
+ if (seasonish) continue;
3842
+ const between = String(matches.inputString ?? "").slice(episode.end, year.start);
3843
+ if (!/[a-zA-Z]{2,}/.test(between)) continue;
3844
+ toRemove.push(episode);
3845
+ if (!toRemove.includes(init)) toRemove.push(init);
3846
+ for (const c of init.children ?? []) if (!toRemove.includes(c)) toRemove.push(c);
3847
+ }
3848
+ return toRemove.length ? toRemove : false;
3849
+ }
3850
+ };
3851
+ _EpisodeWordBeforeYearAsTitle.priority = 60;
3852
+ let EpisodeWordBeforeYearAsTitle = _EpisodeWordBeforeYearAsTitle;
3795
3853
  const _AnimeTrailingEpisodeRule = class _AnimeTrailingEpisodeRule extends Rule {
3796
3854
  constructor() {
3797
3855
  super(...arguments);
@@ -4169,7 +4227,8 @@ class RangeExpansionRule extends Rule {
4169
4227
  const betweenClean = between.replace(/[\s.]/g, "").toLowerCase();
4170
4228
  const betweenStripMarkers = betweenClean.replace(/[sexp]/gi, "");
4171
4229
  const hasRangeChar = /[-~_]/.test(between);
4172
- const isRange = hasRangeChar || rangeSeps.has(betweenClean) || rangeSeps.has(betweenStripMarkers);
4230
+ const seasonColon = name === "season" && betweenClean === ":";
4231
+ const isRange = hasRangeChar || seasonColon || rangeSeps.has(betweenClean) || rangeSeps.has(betweenStripMarkers);
4173
4232
  if (isRange) {
4174
4233
  for (let v = curVal + 1; v < nextVal; v++) {
4175
4234
  const m = new Match(current.start, next.end, {
@@ -7077,6 +7136,41 @@ const _WordNumeralPartAtTitlePosition = class _WordNumeralPartAtTitlePosition ex
7077
7136
  };
7078
7137
  _WordNumeralPartAtTitlePosition.priority = 64;
7079
7138
  let WordNumeralPartAtTitlePosition = _WordNumeralPartAtTitlePosition;
7139
+ const _BonusAtTitlePositionRule = class _BonusAtTitlePositionRule extends Rule {
7140
+ constructor() {
7141
+ super(...arguments);
7142
+ this.priority = 64;
7143
+ this.consequence = RemoveMatch;
7144
+ }
7145
+ when(matches, context) {
7146
+ if (isDisabled(context, "bonus")) return false;
7147
+ const toRemove = [];
7148
+ for (const bonus2 of matches.named("bonus") ?? []) {
7149
+ const filepart = matches.markers.atMatch(bonus2, (m) => m.name === "path", 0);
7150
+ if (!filepart) continue;
7151
+ const anime = matches.range(filepart.start, filepart.end, (m) => m.name === "crc32", 0) || matches.markers.range(
7152
+ filepart.start,
7153
+ filepart.end,
7154
+ (m) => m.name === "group" && m.start === filepart.start,
7155
+ 0
7156
+ );
7157
+ if (!anime) continue;
7158
+ const anchor = matches.range(
7159
+ bonus2.end,
7160
+ filepart.end,
7161
+ (m) => !m.private && ["episode", "season", "year", "date"].includes(m.name ?? ""),
7162
+ 0
7163
+ );
7164
+ const bonusTitles = matches.named("bonus_title") ?? [];
7165
+ if (!anchor && !bonusTitles.length) continue;
7166
+ toRemove.push(bonus2);
7167
+ toRemove.push(...bonusTitles.filter((bt) => bt.start >= filepart.start && bt.end <= filepart.end));
7168
+ }
7169
+ return toRemove.length ? toRemove : false;
7170
+ }
7171
+ };
7172
+ _BonusAtTitlePositionRule.priority = 64;
7173
+ let BonusAtTitlePositionRule = _BonusAtTitlePositionRule;
7080
7174
  const _PropertyAtTitlePositionAsTitle = class _PropertyAtTitlePositionAsTitle extends Rule {
7081
7175
  constructor() {
7082
7176
  super(...arguments);
@@ -7094,7 +7188,16 @@ const _PropertyAtTitlePositionAsTitle = class _PropertyAtTitlePositionAsTitle ex
7094
7188
  (m) => !m.private && ["year", "season", "episode", "date"].includes(m.name ?? ""),
7095
7189
  0
7096
7190
  );
7097
- if (!anchor) continue;
7191
+ if (!anchor) {
7192
+ const anyTitle = matches.range(filepart.start, filepart.end, (m) => m.name === "title", 0);
7193
+ if (lead.name === "year" && lead.start === filepart.start && !anyTitle) {
7194
+ lead.name = "title";
7195
+ lead.value = String(matches.inputString ?? "").slice(lead.start, lead.end);
7196
+ out.push(lead);
7197
+ continue;
7198
+ }
7199
+ continue;
7200
+ }
7098
7201
  const yearTitled = lead.name === "year" && ["season", "episode"].includes(anchor.name ?? "") && !anchor.tags?.includes("weak-episode") && !anchor.tags?.includes("weak-duplicate");
7099
7202
  if (!yearTitled && !["other", "country", "edition"].includes(lead.name ?? "")) continue;
7100
7203
  const titles = matches.range(filepart.start, filepart.end, (m) => m.name === "title") ?? [];
@@ -7228,7 +7331,7 @@ function title(config) {
7228
7331
  const rebulk = new Rebulk({
7229
7332
  disabled: (context) => isDisabled(context, "title")
7230
7333
  });
7231
- rebulk.rules(CountryAtTitlePosition, TitleWordAtTitlePosition, WordNumeralPartAtTitlePosition, SplitOriginalScriptTitle, TitleFromPosition, PreferTitleWithYear, ExtendLoneArticleTitle, PropertyAtTitlePositionAsTitle, RemoveNumericAlternativeTitle, RemoveTailAlternativeTitle, RemoveTailTitle, BracketedTitleFallback, PreBracketJunkTitle, TrimSeasonWordFromTitle);
7334
+ rebulk.rules(CountryAtTitlePosition, TitleWordAtTitlePosition, WordNumeralPartAtTitlePosition, BonusAtTitlePositionRule, SplitOriginalScriptTitle, TitleFromPosition, PreferTitleWithYear, ExtendLoneArticleTitle, PropertyAtTitlePositionAsTitle, RemoveNumericAlternativeTitle, RemoveTailAlternativeTitle, RemoveTailTitle, BracketedTitleFallback, PreBracketJunkTitle, TrimSeasonWordFromTitle);
7232
7335
  const expectedTitle = buildExpectedFunction("expected_title");
7233
7336
  rebulk.functional(expectedTitle, {
7234
7337
  name: "title",
@@ -9220,6 +9323,7 @@ function releaseGroup(config) {
9220
9323
  new SceneReleaseGroup(cleanGroupname),
9221
9324
  AnimeReleaseGroup,
9222
9325
  new TrailingTokenAfterEpisodeAsReleaseGroup(cleanGroupname),
9326
+ NumericPrefixedGroupRule,
9223
9327
  RemoveSeasonPackReleaseGroup
9224
9328
  );
9225
9329
  }
@@ -9565,6 +9669,39 @@ _AnimeReleaseGroup.dependency = ["SceneReleaseGroup", "TitleFromPosition"];
9565
9669
  _AnimeReleaseGroup.consequence = [RemoveMatch, AppendMatch];
9566
9670
  _AnimeReleaseGroup.properties = { release_group: [null] };
9567
9671
  let AnimeReleaseGroup = _AnimeReleaseGroup;
9672
+ const _NumericPrefixedGroupRule = class _NumericPrefixedGroupRule extends Rule {
9673
+ constructor() {
9674
+ super(...arguments);
9675
+ this.priority = -32;
9676
+ this.consequence = [RemoveMatch, AppendMatch];
9677
+ }
9678
+ when(matches, _context) {
9679
+ const input = matches.inputString ?? "";
9680
+ const toRemove = [];
9681
+ const toAppend = [];
9682
+ for (const rg of matches.named("release_group") ?? []) {
9683
+ const m = /^(\d{1,3})\s*\[([^\]]+)\]$/.exec(String(rg.value ?? ""));
9684
+ if (!m) continue;
9685
+ const raw = input.slice(rg.start, rg.end);
9686
+ const numLen = m[1].length;
9687
+ toRemove.push(rg);
9688
+ toAppend.push(new Match(rg.start, rg.start + numLen, {
9689
+ name: "episode",
9690
+ value: parseInt(m[1], 10),
9691
+ inputString: input
9692
+ }));
9693
+ const inner = raw.indexOf("[");
9694
+ toAppend.push(new Match(rg.start + inner + 1, rg.end - 1, {
9695
+ name: "release_group",
9696
+ value: m[2],
9697
+ inputString: input
9698
+ }));
9699
+ }
9700
+ return toRemove.length || toAppend.length ? [toRemove, toAppend] : false;
9701
+ }
9702
+ };
9703
+ _NumericPrefixedGroupRule.priority = -32;
9704
+ let NumericPrefixedGroupRule = _NumericPrefixedGroupRule;
9568
9705
  const _TrailingTokenAfterEpisodeAsReleaseGroup = class _TrailingTokenAfterEpisodeAsReleaseGroup extends Rule {
9569
9706
  constructor(valueFormatter) {
9570
9707
  super();
@@ -10774,10 +10911,11 @@ function imdb(_config) {
10774
10911
  function volume(_config) {
10775
10912
  const rebulk = new Rebulk({ disabled: (context) => isDisabled(context, "volume") });
10776
10913
  rebulk.regexDefaults({ flags: "i" });
10777
- rebulk.regex("vol(?:\\d{1,3}|(?:ume)?[-. ]\\d{1,3})", {
10914
+ rebulk.regex("vol(?:\\d{1,3}|(?:ume)?[-. ]{1,2}\\d{1,3})(?:v\\d)?(?:[&+]\\d{1,3})?", {
10778
10915
  name: "volume",
10779
10916
  validator: sepsSurround,
10780
- formatter: (value) => parseInt(value.replace(/\D/g, ""), 10)
10917
+ formatter: (value) => parseInt(String(value).replace(/^vol(?:ume)?[-. ]*/i, "").replace(/[v&+].*$/i, ""), 10),
10918
+ conflictSolver: (match, other2) => other2.name === "episode" || other2.name === "season" ? other2 : "__default__"
10781
10919
  });
10782
10920
  return rebulk;
10783
10921
  }
@@ -11939,7 +12077,8 @@ const advanced_config = {
11939
12077
  episode_max_range: 100,
11940
12078
  max_range_gap: 1,
11941
12079
  season_markers: [
11942
- "s"
12080
+ "s",
12081
+ "sn"
11943
12082
  ],
11944
12083
  season_ep_markers: [
11945
12084
  "x",