guessit-js 4.3.1 → 4.4.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.
@@ -3776,7 +3776,12 @@ const _AnimeTrailingEpisodeRule = class _AnimeTrailingEpisodeRule extends Rule {
3776
3776
  (m2) => m2.name === "release_group" && m2.tags?.includes("anime"),
3777
3777
  0
3778
3778
  );
3779
- if (!crc2 && !animeRg) continue;
3779
+ const groupCount = (matches.markers.range(
3780
+ filepart.start,
3781
+ filepart.end,
3782
+ (m2) => m2.name === "group"
3783
+ ) ?? []).length;
3784
+ if (!crc2 && !animeRg && groupCount < 3) continue;
3780
3785
  let done = false;
3781
3786
  for (const group of matches.markers.range(filepart.start, filepart.end, (m2) => m2.name === "group") ?? []) {
3782
3787
  const core = input.slice(group.start + 1, group.end - 1).trim();
@@ -3932,10 +3937,11 @@ const _RemoveNumfirstMarkerCollision = class _RemoveNumfirstMarkerCollision exte
3932
3937
  constructor() {
3933
3938
  super(...arguments);
3934
3939
  this.priority = 70;
3935
- this.consequence = RemoveMatch;
3940
+ this.consequence = [RemoveMatch, AppendMatch];
3936
3941
  }
3937
3942
  when(matches, _context) {
3938
3943
  const toRemove = [];
3944
+ const toAppend = [];
3939
3945
  const isWeak = (m) => !!(m.tags?.includes("weak-episode") || ["weak_episode", "weak_duplicate"].includes(m.initiator?.name));
3940
3946
  const removeWithParent = (m) => {
3941
3947
  const init = m.initiator ?? m;
@@ -3958,10 +3964,18 @@ const _RemoveNumfirstMarkerCollision = class _RemoveNumfirstMarkerCollision exte
3958
3964
  if (!wordFirst) continue;
3959
3965
  const claimed = all.some((m) => !m.private && (m.name === "screen_size" || m.name === "year") && m.start < wordFirst.end && wordFirst.start < m.end);
3960
3966
  const gluedOrdinal = /^(?:st|nd|rd|th|ª|º|°)/i.test(String(matches.inputString ?? "").slice(nf.end, nf.end + 2));
3961
- if (claimed || gluedOrdinal) removeWithParent(wordFirst);
3962
- else removeWithParent(nf);
3967
+ if (claimed || gluedOrdinal) {
3968
+ removeWithParent(wordFirst);
3969
+ if (!claimed) {
3970
+ toAppend.push(new Match(wordFirst.start, wordFirst.end, {
3971
+ name: "episode",
3972
+ value: wordFirst.value,
3973
+ inputString: matches.inputString
3974
+ }));
3975
+ }
3976
+ } else removeWithParent(nf);
3963
3977
  }
3964
- return toRemove.length ? toRemove : false;
3978
+ return toRemove.length || toAppend.length ? [toRemove, toAppend] : false;
3965
3979
  }
3966
3980
  };
3967
3981
  _RemoveNumfirstMarkerCollision.priority = 70;
@@ -4553,6 +4567,14 @@ function source(config) {
4553
4567
  ...buildSourcePattern(["HD-?CAM"], "", optional(ripSuffix)),
4554
4568
  { value: { source: "HD Camera", other: "Rip" } }
4555
4569
  );
4570
+ rebulk.regex(
4571
+ ...buildSourcePattern(["HQ-?CAM"], "", optional(ripSuffix)),
4572
+ { value: { source: "Camera", other: "Rip" } }
4573
+ );
4574
+ rebulk.regex(
4575
+ ...buildSourcePattern(["S-?Print"], "", optional(ripSuffix)),
4576
+ { value: { source: "Camera" } }
4577
+ );
4556
4578
  rebulk.regex(
4557
4579
  ...buildSourcePattern(["TELESYNC", "TS"], "", optional(ripSuffix)),
4558
4580
  { value: { source: "Telesync", other: "Rip" }, tags: ["video-codec-prefix"], overrides: ["tags"] }
@@ -4601,6 +4623,10 @@ function source(config) {
4601
4623
  ...buildSourcePattern(["DVD"], "", optional(ripSuffix)),
4602
4624
  { value: { source: "DVD", other: "Rip" } }
4603
4625
  );
4626
+ rebulk.regex(
4627
+ ...buildSourcePattern(["DVD-?R[59]"], "", ""),
4628
+ { value: { source: "DVD" } }
4629
+ );
4604
4630
  rebulk.regex(
4605
4631
  ...buildSourcePattern(["LD"], "", ripSuffix),
4606
4632
  { value: { source: "Laserdisc", other: "Rip" } }
@@ -4909,12 +4935,15 @@ const _ValidateVideoCodec = class _ValidateVideoCodec extends Rule {
4909
4935
  const ret = [];
4910
4936
  const codecs = matches.named("video_codec");
4911
4937
  const hasAny = (v) => Array.isArray(v) ? v.length > 0 : !!v;
4938
+ const inp = matches.inputString ?? "";
4912
4939
  for (const codec of codecs) {
4913
- if (!sepsBefore(codec) && !hasAny(matches.atIndex(codec.start - 1, (m) => m.tags?.includes("video-codec-prefix")))) {
4940
+ const bracketBefore = inp[codec.start] === "[" || inp[codec.start - 1] === "[";
4941
+ const bracketAfter = inp[codec.end - 1] === "]" || inp[codec.end] === "]";
4942
+ if (!bracketBefore && !sepsBefore(codec) && !hasAny(matches.atIndex(codec.start - 1, (m) => m.tags?.includes("video-codec-prefix")))) {
4914
4943
  ret.push(codec);
4915
4944
  continue;
4916
4945
  }
4917
- if (!sepsAfter(codec) && !hasAny(matches.atIndex(codec.end + 1, (m) => m.tags?.includes("video-codec-suffix")))) {
4946
+ if (!bracketAfter && !sepsAfter(codec) && !hasAny(matches.atIndex(codec.end + 1, (m) => m.tags?.includes("video-codec-suffix")))) {
4918
4947
  ret.push(codec);
4919
4948
  continue;
4920
4949
  }
@@ -6226,6 +6255,7 @@ const _TitleBaseRule = class _TitleBaseRule extends Rule {
6226
6255
  const lastSeg = createMatch(prevEnd, hole.end);
6227
6256
  if (lastSeg) segments.push(lastSeg);
6228
6257
  if (segments.length < 2) return null;
6258
+ if (/^\d+$/.test(String(segments[0].value ?? "").trim())) return null;
6229
6259
  return { title: segments[0], alternatives: segments.slice(1) };
6230
6260
  }
6231
6261
  /**
@@ -6418,7 +6448,20 @@ const _TitleBaseRule = class _TitleBaseRule extends Rule {
6418
6448
  console.log(` result: hole=[${trimmedHole.start},${trimmedHole.end}) length=${trimmedHole.length} value="${trimmedHole.value}"`);
6419
6449
  }
6420
6450
  if (trimmedHole.length > 0 && !this.shouldRemove(trimmedHole) && trimmedHole.value) {
6421
- const splitResult = this.alternativePropertyName && !isDisabled(context, this.alternativePropertyName) ? this.splitTitleAlternative(trimmedHole, inp) : null;
6451
+ matches.inputString ?? "";
6452
+ const animeStyle = matches.markers.range(
6453
+ filepart.start,
6454
+ filepart.end,
6455
+ (m) => m.name === "group" && m.start === filepart.start,
6456
+ 0
6457
+ ) !== void 0 || matches.range(filepart.start, filepart.end, (m) => m.name === "crc32", 0) !== void 0;
6458
+ let splitResult = this.alternativePropertyName && !isDisabled(context, this.alternativePropertyName) ? this.splitTitleAlternative(trimmedHole, inp) : null;
6459
+ if (splitResult && animeStyle && splitResult.alternatives.every((a) => {
6460
+ const v = String(a.value ?? "").trim();
6461
+ return v.length >= 4 || /\s/.test(v);
6462
+ })) {
6463
+ splitResult = null;
6464
+ }
6422
6465
  if (splitResult) {
6423
6466
  splitResult.title.name = this.matchName;
6424
6467
  toAppend.push(splitResult.title);
@@ -6844,6 +6887,38 @@ const _SplitOriginalScriptTitle = class _SplitOriginalScriptTitle extends Rule {
6844
6887
  };
6845
6888
  _SplitOriginalScriptTitle.priority = POST_PROCESS;
6846
6889
  let SplitOriginalScriptTitle = _SplitOriginalScriptTitle;
6890
+ const _TrimSeasonWordFromTitle = class _TrimSeasonWordFromTitle extends Rule {
6891
+ constructor() {
6892
+ super(...arguments);
6893
+ this.priority = POST_PROCESS;
6894
+ this.consequence = [RemoveMatch, AppendMatch];
6895
+ }
6896
+ when(matches, context) {
6897
+ if (isDisabled(context, "title")) return false;
6898
+ const input = matches.inputString ?? "";
6899
+ const toRemove = [];
6900
+ const toAppend = [];
6901
+ for (const title2 of matches.named("title") ?? []) {
6902
+ const m = /^(.*\S)[\s._-]+(seasons?|saison)$/i.exec(String(title2.value ?? ""));
6903
+ if (!m) continue;
6904
+ const next = matches.range(title2.end, input.length, (mm) => !mm.private && !!mm.value, 0);
6905
+ if (!next || next.name !== "season") continue;
6906
+ toRemove.push(title2);
6907
+ input.slice(title2.start, title2.end).slice(0, m[1].length + (String(title2.value).length === title2.end - title2.start ? 0 : 0));
6908
+ let newEnd = title2.end;
6909
+ while (newEnd > title2.start && cleanup(input.slice(title2.start, newEnd)).toLowerCase() !== m[1].toLowerCase()) newEnd--;
6910
+ if (newEnd <= title2.start) continue;
6911
+ toAppend.push(new Match(title2.start, newEnd, {
6912
+ name: "title",
6913
+ value: cleanup(input.slice(title2.start, newEnd)),
6914
+ inputString: input
6915
+ }));
6916
+ }
6917
+ return toRemove.length || toAppend.length ? [toRemove, toAppend] : false;
6918
+ }
6919
+ };
6920
+ _TrimSeasonWordFromTitle.priority = POST_PROCESS;
6921
+ let TrimSeasonWordFromTitle = _TrimSeasonWordFromTitle;
6847
6922
  const _PreBracketJunkTitle = class _PreBracketJunkTitle extends Rule {
6848
6923
  constructor() {
6849
6924
  super(...arguments);
@@ -6899,17 +6974,18 @@ const _BracketedTitleFallback = class _BracketedTitleFallback extends Rule {
6899
6974
  if (rg && g.start <= rg.start && g.end >= rg.end) continue;
6900
6975
  const core = input.slice(g.start + 1, g.end - 1);
6901
6976
  if (!/[a-zA-Z]{2,}/.test(core)) continue;
6902
- const inner = matches.range(g.start, g.end, (m) => !m.private) ?? [];
6903
- if (inner.length) continue;
6904
- candidate = g;
6977
+ const hole = matches.holes(g.start + 1, g.end - 1, {
6978
+ formatter: cleanup,
6979
+ predicate: (h) => !!h.value,
6980
+ index: 0
6981
+ });
6982
+ if (!hole || !/[a-zA-Z]{3,}/.test(String(hole.value ?? ""))) continue;
6983
+ candidate = hole;
6905
6984
  break;
6906
6985
  }
6907
6986
  if (candidate) {
6908
- toAppend.push(new Match(candidate.start + 1, candidate.end - 1, {
6909
- name: "title",
6910
- value: cleanup(input.slice(candidate.start + 1, candidate.end - 1)),
6911
- inputString: input
6912
- }));
6987
+ candidate.name = "title";
6988
+ toAppend.push(candidate);
6913
6989
  continue;
6914
6990
  }
6915
6991
  if (rg && rg.tags?.includes("anime")) {
@@ -7082,7 +7158,7 @@ function title(config) {
7082
7158
  const rebulk = new Rebulk({
7083
7159
  disabled: (context) => isDisabled(context, "title")
7084
7160
  });
7085
- rebulk.rules(CountryAtTitlePosition, TitleWordAtTitlePosition, SplitOriginalScriptTitle, TitleFromPosition, PreferTitleWithYear, ExtendLoneArticleTitle, PropertyAtTitlePositionAsTitle, RemoveNumericAlternativeTitle, RemoveTailAlternativeTitle, RemoveTailTitle, BracketedTitleFallback, PreBracketJunkTitle);
7161
+ rebulk.rules(CountryAtTitlePosition, TitleWordAtTitlePosition, SplitOriginalScriptTitle, TitleFromPosition, PreferTitleWithYear, ExtendLoneArticleTitle, PropertyAtTitlePositionAsTitle, RemoveNumericAlternativeTitle, RemoveTailAlternativeTitle, RemoveTailTitle, BracketedTitleFallback, PreBracketJunkTitle, TrimSeasonWordFromTitle);
7086
7162
  const expectedTitle = buildExpectedFunction("expected_title");
7087
7163
  rebulk.functional(expectedTitle, {
7088
7164
  name: "title",
@@ -12250,7 +12326,10 @@ const advanced_config = {
12250
12326
  },
12251
12327
  "High Resolution": "HR",
12252
12328
  "Line Dubbed": "LD",
12253
- "Mic Dubbed": "MD",
12329
+ "Mic Dubbed": {
12330
+ string: "MD",
12331
+ tags: "title-word"
12332
+ },
12254
12333
  "Micro HD": {
12255
12334
  string: [
12256
12335
  "mHD",