guessit-js 4.4.2 → 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+)(?:[a-d](?![a-z0-9]))?`
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("*");
@@ -3679,13 +3679,13 @@ function episodes(config) {
3679
3679
  rebulk.chain({
3680
3680
  tags: ["weak-episode"],
3681
3681
  disabled: (context) => context?.type === "movie" || isDisabled(context, "episode")
3682
- }).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})`, {
3683
3683
  abbreviations: null
3684
3684
  }).repeater("*");
3685
3685
  rebulk.chain({
3686
3686
  tags: ["weak-episode"],
3687
3687
  disabled: (context) => context?.type === "movie" || isDisabled(context, "episode")
3688
- }).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})`, {
3689
3689
  abbreviations: null
3690
3690
  }).repeater("*");
3691
3691
  rebulk.chain({
@@ -3696,7 +3696,7 @@ function episodes(config) {
3696
3696
  validator: null,
3697
3697
  tags: ["weak-episode"],
3698
3698
  name: "weak_episode"
3699
- }).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})`, {
3700
3700
  abbreviations: null
3701
3701
  }).repeater("*");
3702
3702
  rebulk.chain({
@@ -3759,6 +3759,7 @@ function episodes(config) {
3759
3759
  disabled: (context) => isDisabled(context, "episode_format")
3760
3760
  });
3761
3761
  rebulk.rules(
3762
+ EpisodeWordBeforeYearAsTitle,
3762
3763
  RemoveGroupSuffixSeason,
3763
3764
  AnimeTrailingEpisodeRule,
3764
3765
  PreferAnchoredWeakEpisodeRule,
@@ -3815,6 +3816,40 @@ const _RemoveGroupSuffixSeason = class _RemoveGroupSuffixSeason extends Rule {
3815
3816
  };
3816
3817
  _RemoveGroupSuffixSeason.priority = 72;
3817
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;
3818
3853
  const _AnimeTrailingEpisodeRule = class _AnimeTrailingEpisodeRule extends Rule {
3819
3854
  constructor() {
3820
3855
  super(...arguments);
@@ -7101,6 +7136,41 @@ const _WordNumeralPartAtTitlePosition = class _WordNumeralPartAtTitlePosition ex
7101
7136
  };
7102
7137
  _WordNumeralPartAtTitlePosition.priority = 64;
7103
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;
7104
7174
  const _PropertyAtTitlePositionAsTitle = class _PropertyAtTitlePositionAsTitle extends Rule {
7105
7175
  constructor() {
7106
7176
  super(...arguments);
@@ -7118,7 +7188,16 @@ const _PropertyAtTitlePositionAsTitle = class _PropertyAtTitlePositionAsTitle ex
7118
7188
  (m) => !m.private && ["year", "season", "episode", "date"].includes(m.name ?? ""),
7119
7189
  0
7120
7190
  );
7121
- 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
+ }
7122
7201
  const yearTitled = lead.name === "year" && ["season", "episode"].includes(anchor.name ?? "") && !anchor.tags?.includes("weak-episode") && !anchor.tags?.includes("weak-duplicate");
7123
7202
  if (!yearTitled && !["other", "country", "edition"].includes(lead.name ?? "")) continue;
7124
7203
  const titles = matches.range(filepart.start, filepart.end, (m) => m.name === "title") ?? [];
@@ -7252,7 +7331,7 @@ function title(config) {
7252
7331
  const rebulk = new Rebulk({
7253
7332
  disabled: (context) => isDisabled(context, "title")
7254
7333
  });
7255
- 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);
7256
7335
  const expectedTitle = buildExpectedFunction("expected_title");
7257
7336
  rebulk.functional(expectedTitle, {
7258
7337
  name: "title",
@@ -9244,6 +9323,7 @@ function releaseGroup(config) {
9244
9323
  new SceneReleaseGroup(cleanGroupname),
9245
9324
  AnimeReleaseGroup,
9246
9325
  new TrailingTokenAfterEpisodeAsReleaseGroup(cleanGroupname),
9326
+ NumericPrefixedGroupRule,
9247
9327
  RemoveSeasonPackReleaseGroup
9248
9328
  );
9249
9329
  }
@@ -9589,6 +9669,39 @@ _AnimeReleaseGroup.dependency = ["SceneReleaseGroup", "TitleFromPosition"];
9589
9669
  _AnimeReleaseGroup.consequence = [RemoveMatch, AppendMatch];
9590
9670
  _AnimeReleaseGroup.properties = { release_group: [null] };
9591
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;
9592
9705
  const _TrailingTokenAfterEpisodeAsReleaseGroup = class _TrailingTokenAfterEpisodeAsReleaseGroup extends Rule {
9593
9706
  constructor(valueFormatter) {
9594
9707
  super();
@@ -10798,10 +10911,11 @@ function imdb(_config) {
10798
10911
  function volume(_config) {
10799
10912
  const rebulk = new Rebulk({ disabled: (context) => isDisabled(context, "volume") });
10800
10913
  rebulk.regexDefaults({ flags: "i" });
10801
- 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})?", {
10802
10915
  name: "volume",
10803
10916
  validator: sepsSurround,
10804
- 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__"
10805
10919
  });
10806
10920
  return rebulk;
10807
10921
  }