guessit-js 4.3.2 → 4.4.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.
@@ -3736,6 +3736,7 @@ function episodes(config) {
3736
3736
  disabled: (context) => isDisabled(context, "episode_format")
3737
3737
  });
3738
3738
  rebulk.rules(
3739
+ RemoveGroupSuffixSeason,
3739
3740
  AnimeTrailingEpisodeRule,
3740
3741
  PreferAnchoredWeakEpisodeRule,
3741
3742
  SeasonWordDashedEpisodeRule,
@@ -3754,6 +3755,43 @@ function episodes(config) {
3754
3755
  );
3755
3756
  return rebulk;
3756
3757
  }
3758
+ const _RemoveGroupSuffixSeason = class _RemoveGroupSuffixSeason extends Rule {
3759
+ constructor() {
3760
+ super(...arguments);
3761
+ this.priority = 72;
3762
+ this.consequence = RemoveMatch;
3763
+ }
3764
+ when(matches, _context) {
3765
+ const input = matches.inputString ?? "";
3766
+ const toRemove = [];
3767
+ const TOKENS = /* @__PURE__ */ new Set(["audio_codec", "audio_channels", "video_codec", "audio_profile", "other"]);
3768
+ for (const season of matches.named("season") ?? []) {
3769
+ const init = season.initiator ?? season;
3770
+ if (!/^s\d{1,3}$/i.test(String(init.raw ?? ""))) continue;
3771
+ const hasEpisode = [...init.children ?? []].some((c) => c.name === "episode");
3772
+ if (hasEpisode) continue;
3773
+ if (input[init.start - 1] !== "-") continue;
3774
+ const prev = matches.range(
3775
+ Math.max(0, init.start - 12),
3776
+ init.start - 1,
3777
+ (m) => !m.private && TOKENS.has(m.name ?? ""),
3778
+ -1
3779
+ ) ?? matches.range(
3780
+ Math.max(0, init.start - 12),
3781
+ init.start - 1,
3782
+ (m) => !m.private && TOKENS.has(m.name ?? ""),
3783
+ 0
3784
+ );
3785
+ const inGroup = matches.markers.atMatch(init, (m) => m.name === "group", 0);
3786
+ if (!prev && !inGroup) continue;
3787
+ toRemove.push(season);
3788
+ for (const c of init.children ?? []) if (!toRemove.includes(c)) toRemove.push(c);
3789
+ }
3790
+ return toRemove.length ? toRemove : false;
3791
+ }
3792
+ };
3793
+ _RemoveGroupSuffixSeason.priority = 72;
3794
+ let RemoveGroupSuffixSeason = _RemoveGroupSuffixSeason;
3757
3795
  const _AnimeTrailingEpisodeRule = class _AnimeTrailingEpisodeRule extends Rule {
3758
3796
  constructor() {
3759
3797
  super(...arguments);
@@ -3774,7 +3812,12 @@ const _AnimeTrailingEpisodeRule = class _AnimeTrailingEpisodeRule extends Rule {
3774
3812
  (m2) => m2.name === "release_group" && m2.tags?.includes("anime"),
3775
3813
  0
3776
3814
  );
3777
- if (!crc2 && !animeRg) continue;
3815
+ const groupCount = (matches.markers.range(
3816
+ filepart.start,
3817
+ filepart.end,
3818
+ (m2) => m2.name === "group"
3819
+ ) ?? []).length;
3820
+ if (!crc2 && !animeRg && groupCount < 3) continue;
3778
3821
  let done = false;
3779
3822
  for (const group of matches.markers.range(filepart.start, filepart.end, (m2) => m2.name === "group") ?? []) {
3780
3823
  const core = input.slice(group.start + 1, group.end - 1).trim();
@@ -3930,10 +3973,11 @@ const _RemoveNumfirstMarkerCollision = class _RemoveNumfirstMarkerCollision exte
3930
3973
  constructor() {
3931
3974
  super(...arguments);
3932
3975
  this.priority = 70;
3933
- this.consequence = RemoveMatch;
3976
+ this.consequence = [RemoveMatch, AppendMatch];
3934
3977
  }
3935
3978
  when(matches, _context) {
3936
3979
  const toRemove = [];
3980
+ const toAppend = [];
3937
3981
  const isWeak = (m) => !!(m.tags?.includes("weak-episode") || ["weak_episode", "weak_duplicate"].includes(m.initiator?.name));
3938
3982
  const removeWithParent = (m) => {
3939
3983
  const init = m.initiator ?? m;
@@ -3956,10 +4000,18 @@ const _RemoveNumfirstMarkerCollision = class _RemoveNumfirstMarkerCollision exte
3956
4000
  if (!wordFirst) continue;
3957
4001
  const claimed = all.some((m) => !m.private && (m.name === "screen_size" || m.name === "year") && m.start < wordFirst.end && wordFirst.start < m.end);
3958
4002
  const gluedOrdinal = /^(?:st|nd|rd|th|ª|º|°)/i.test(String(matches.inputString ?? "").slice(nf.end, nf.end + 2));
3959
- if (claimed || gluedOrdinal) removeWithParent(wordFirst);
3960
- else removeWithParent(nf);
4003
+ if (claimed || gluedOrdinal) {
4004
+ removeWithParent(wordFirst);
4005
+ if (!claimed) {
4006
+ toAppend.push(new Match(wordFirst.start, wordFirst.end, {
4007
+ name: "episode",
4008
+ value: wordFirst.value,
4009
+ inputString: matches.inputString
4010
+ }));
4011
+ }
4012
+ } else removeWithParent(nf);
3961
4013
  }
3962
- return toRemove.length ? toRemove : false;
4014
+ return toRemove.length || toAppend.length ? [toRemove, toAppend] : false;
3963
4015
  }
3964
4016
  };
3965
4017
  _RemoveNumfirstMarkerCollision.priority = 70;
@@ -4919,12 +4971,15 @@ const _ValidateVideoCodec = class _ValidateVideoCodec extends Rule {
4919
4971
  const ret = [];
4920
4972
  const codecs = matches.named("video_codec");
4921
4973
  const hasAny = (v) => Array.isArray(v) ? v.length > 0 : !!v;
4974
+ const inp = matches.inputString ?? "";
4922
4975
  for (const codec of codecs) {
4923
- if (!sepsBefore(codec) && !hasAny(matches.atIndex(codec.start - 1, (m) => m.tags?.includes("video-codec-prefix")))) {
4976
+ const bracketBefore = inp[codec.start] === "[" || inp[codec.start - 1] === "[";
4977
+ const bracketAfter = inp[codec.end - 1] === "]" || inp[codec.end] === "]";
4978
+ if (!bracketBefore && !sepsBefore(codec) && !hasAny(matches.atIndex(codec.start - 1, (m) => m.tags?.includes("video-codec-prefix")))) {
4924
4979
  ret.push(codec);
4925
4980
  continue;
4926
4981
  }
4927
- if (!sepsAfter(codec) && !hasAny(matches.atIndex(codec.end + 1, (m) => m.tags?.includes("video-codec-suffix")))) {
4982
+ if (!bracketAfter && !sepsAfter(codec) && !hasAny(matches.atIndex(codec.end + 1, (m) => m.tags?.includes("video-codec-suffix")))) {
4928
4983
  ret.push(codec);
4929
4984
  continue;
4930
4985
  }
@@ -6429,7 +6484,20 @@ const _TitleBaseRule = class _TitleBaseRule extends Rule {
6429
6484
  console.log(` result: hole=[${trimmedHole.start},${trimmedHole.end}) length=${trimmedHole.length} value="${trimmedHole.value}"`);
6430
6485
  }
6431
6486
  if (trimmedHole.length > 0 && !this.shouldRemove(trimmedHole) && trimmedHole.value) {
6432
- const splitResult = this.alternativePropertyName && !isDisabled(context, this.alternativePropertyName) ? this.splitTitleAlternative(trimmedHole, inp) : null;
6487
+ matches.inputString ?? "";
6488
+ const animeStyle = matches.markers.range(
6489
+ filepart.start,
6490
+ filepart.end,
6491
+ (m) => m.name === "group" && m.start === filepart.start,
6492
+ 0
6493
+ ) !== void 0 || matches.range(filepart.start, filepart.end, (m) => m.name === "crc32", 0) !== void 0;
6494
+ let splitResult = this.alternativePropertyName && !isDisabled(context, this.alternativePropertyName) ? this.splitTitleAlternative(trimmedHole, inp) : null;
6495
+ if (splitResult && animeStyle && splitResult.alternatives.every((a) => {
6496
+ const v = String(a.value ?? "").trim();
6497
+ return v.length >= 4 || /\s/.test(v);
6498
+ })) {
6499
+ splitResult = null;
6500
+ }
6433
6501
  if (splitResult) {
6434
6502
  splitResult.title.name = this.matchName;
6435
6503
  toAppend.push(splitResult.title);
@@ -6942,17 +7010,18 @@ const _BracketedTitleFallback = class _BracketedTitleFallback extends Rule {
6942
7010
  if (rg && g.start <= rg.start && g.end >= rg.end) continue;
6943
7011
  const core = input.slice(g.start + 1, g.end - 1);
6944
7012
  if (!/[a-zA-Z]{2,}/.test(core)) continue;
6945
- const inner = matches.range(g.start, g.end, (m) => !m.private) ?? [];
6946
- if (inner.length) continue;
6947
- candidate = g;
7013
+ const hole = matches.holes(g.start + 1, g.end - 1, {
7014
+ formatter: cleanup,
7015
+ predicate: (h) => !!h.value,
7016
+ index: 0
7017
+ });
7018
+ if (!hole || !/[a-zA-Z]{3,}/.test(String(hole.value ?? ""))) continue;
7019
+ candidate = hole;
6948
7020
  break;
6949
7021
  }
6950
7022
  if (candidate) {
6951
- toAppend.push(new Match(candidate.start + 1, candidate.end - 1, {
6952
- name: "title",
6953
- value: cleanup(input.slice(candidate.start + 1, candidate.end - 1)),
6954
- inputString: input
6955
- }));
7023
+ candidate.name = "title";
7024
+ toAppend.push(candidate);
6956
7025
  continue;
6957
7026
  }
6958
7027
  if (rg && rg.tags?.includes("anime")) {
@@ -6978,6 +7047,36 @@ const _BracketedTitleFallback = class _BracketedTitleFallback extends Rule {
6978
7047
  };
6979
7048
  _BracketedTitleFallback.priority = POST_PROCESS;
6980
7049
  let BracketedTitleFallback = _BracketedTitleFallback;
7050
+ const _WordNumeralPartAtTitlePosition = class _WordNumeralPartAtTitlePosition extends Rule {
7051
+ constructor() {
7052
+ super(...arguments);
7053
+ this.priority = 64;
7054
+ this.consequence = RemoveMatch;
7055
+ }
7056
+ when(matches, context) {
7057
+ if (isDisabled(context, "part")) return false;
7058
+ const toRemove = [];
7059
+ for (const part2 of matches.named("part") ?? []) {
7060
+ const target = part2.initiator ?? part2;
7061
+ if (/\d/.test(String(target.raw ?? ""))) continue;
7062
+ const filepart = matches.markers.atMatch(part2, (m) => m.name === "path", 0);
7063
+ if (!filepart) continue;
7064
+ const anchor = matches.range(
7065
+ part2.end,
7066
+ filepart.end,
7067
+ (m) => !m.private && ["year", "season", "episode", "date"].includes(m.name ?? ""),
7068
+ 0
7069
+ );
7070
+ if (!anchor) continue;
7071
+ toRemove.push(part2);
7072
+ for (const c of [...target.children ?? []]) if (!toRemove.includes(c)) toRemove.push(c);
7073
+ if (target !== part2 && !toRemove.includes(target)) toRemove.push(target);
7074
+ }
7075
+ return toRemove.length ? toRemove : false;
7076
+ }
7077
+ };
7078
+ _WordNumeralPartAtTitlePosition.priority = 64;
7079
+ let WordNumeralPartAtTitlePosition = _WordNumeralPartAtTitlePosition;
6981
7080
  const _PropertyAtTitlePositionAsTitle = class _PropertyAtTitlePositionAsTitle extends Rule {
6982
7081
  constructor() {
6983
7082
  super(...arguments);
@@ -6987,18 +7086,22 @@ const _PropertyAtTitlePositionAsTitle = class _PropertyAtTitlePositionAsTitle ex
6987
7086
  const inp = matches.inputString || "";
6988
7087
  const out = [];
6989
7088
  for (const filepart of matches.markers.named("path")) {
6990
- if (matches.range(filepart.start, filepart.end, (m) => m.name === "title", 0)) continue;
7089
+ const lead = matches.range(filepart.start, filepart.end, (m) => !m.private && !!m.value, 0);
7090
+ if (!lead) continue;
6991
7091
  const anchor = matches.range(
6992
- filepart.start,
7092
+ lead.end,
6993
7093
  filepart.end,
6994
7094
  (m) => !m.private && ["year", "season", "episode", "date"].includes(m.name ?? ""),
6995
7095
  0
6996
7096
  );
6997
7097
  if (!anchor) continue;
6998
- const lead = matches.range(filepart.start, filepart.end, (m) => !m.private && !!m.value, 0);
6999
- if (!lead || !["other", "country", "edition"].includes(lead.name ?? "")) continue;
7000
- if (lead.start >= anchor.start) continue;
7001
- if ((lead.raw ?? "") === String(lead.value ?? "")) continue;
7098
+ const yearTitled = lead.name === "year" && ["season", "episode"].includes(anchor.name ?? "") && !anchor.tags?.includes("weak-episode") && !anchor.tags?.includes("weak-duplicate");
7099
+ if (!yearTitled && !["other", "country", "edition"].includes(lead.name ?? "")) continue;
7100
+ const titles = matches.range(filepart.start, filepart.end, (m) => m.name === "title") ?? [];
7101
+ if (titles.some((t) => t.start < anchor.end)) continue;
7102
+ if (titles.length && !yearTitled) continue;
7103
+ out.push(...titles);
7104
+ if (lead.name !== "year" && (lead.raw ?? "") === String(lead.value ?? "")) continue;
7002
7105
  if (![...inp.slice(filepart.start, lead.start)].every((c) => seps.includes(c))) continue;
7003
7106
  out.push(lead);
7004
7107
  }
@@ -7125,7 +7228,7 @@ function title(config) {
7125
7228
  const rebulk = new Rebulk({
7126
7229
  disabled: (context) => isDisabled(context, "title")
7127
7230
  });
7128
- rebulk.rules(CountryAtTitlePosition, TitleWordAtTitlePosition, SplitOriginalScriptTitle, TitleFromPosition, PreferTitleWithYear, ExtendLoneArticleTitle, PropertyAtTitlePositionAsTitle, RemoveNumericAlternativeTitle, RemoveTailAlternativeTitle, RemoveTailTitle, BracketedTitleFallback, PreBracketJunkTitle, TrimSeasonWordFromTitle);
7231
+ rebulk.rules(CountryAtTitlePosition, TitleWordAtTitlePosition, WordNumeralPartAtTitlePosition, SplitOriginalScriptTitle, TitleFromPosition, PreferTitleWithYear, ExtendLoneArticleTitle, PropertyAtTitlePositionAsTitle, RemoveNumericAlternativeTitle, RemoveTailAlternativeTitle, RemoveTailTitle, BracketedTitleFallback, PreBracketJunkTitle, TrimSeasonWordFromTitle);
7129
7232
  const expectedTitle = buildExpectedFunction("expected_title");
7130
7233
  rebulk.functional(expectedTitle, {
7131
7234
  name: "title",
@@ -11322,7 +11425,8 @@ const advanced_config = {
11322
11425
  regex: [
11323
11426
  "Dolby-Digital",
11324
11427
  "DD",
11325
- "AC-?3D?"
11428
+ "AC-?3D?",
11429
+ "DolbyD"
11326
11430
  ]
11327
11431
  },
11328
11432
  "Dolby Atmos": {