guessit-js 3.8.1 → 3.9.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.
@@ -1,6 +1,7 @@
1
1
  var __defProp = Object.defineProperty;
2
2
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
3
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
+ var _a;
4
5
  function defaultFormatter(value) {
5
6
  return value;
6
7
  }
@@ -2614,13 +2615,13 @@ function episodes(config) {
2614
2615
  ).repeater("*");
2615
2616
  const episodeWordPattern = buildOrPattern(config.episode_words, "episodeMarker");
2616
2617
  rebulk.regex(
2617
- `(?<![a-zA-Z])` + episodeWordPattern + `@?(?<episode>\\d+)(?:v(?<version>\\d+))?(?:@?` + ofWordPattern + `@?(?<count>\\d+))?`,
2618
+ `(?<![a-zA-Z\\d])` + episodeWordPattern + `@?(?<episode>\\d+)(?:v(?<version>\\d+))?(?:@?` + ofWordPattern + `@?(?<count>\\d+))?`,
2618
2619
  {
2619
2620
  disabled: (context) => context?.type === "episode" || isDisabled(context, "episode")
2620
2621
  }
2621
2622
  );
2622
2623
  rebulk.regex(
2623
- `(?<![a-zA-Z])` + episodeWordPattern + `@?(?<episode>${numeral})(?:v(?<version>\\d+))?(?:@?` + ofWordPattern + `@?(?<count>\\d+))?`,
2624
+ `(?<![a-zA-Z\\d])` + episodeWordPattern + `@?(?<episode>${numeral})(?:v(?<version>\\d+))?(?:@?` + ofWordPattern + `@?(?<count>\\d+))?`,
2624
2625
  {
2625
2626
  validator: { episode: validateRoman },
2626
2627
  formatter: { episode: parseNumber },
@@ -2673,7 +2674,7 @@ function episodes(config) {
2673
2674
  }).repeater("*");
2674
2675
  rebulk.chain({
2675
2676
  disabled: (context) => isDisabled(context, "episode")
2676
- }).defaults({ validator: null }).regex(`(?<![a-zA-Z])ep-?(?<episode>\\d{1,4})`).regex(`v(?<version>\\d+)`).repeater("?").regex(`(?<episodeSeparator>ep|e|x|-)(?<episode>\\d{1,4})`, {
2677
+ }).defaults({ validator: null }).regex(`(?<![a-zA-Z\\d])ep-?(?<episode>\\d{1,4})`).regex(`v(?<version>\\d+)`).repeater("?").regex(`(?<episodeSeparator>ep|e|x|-)(?<episode>\\d{1,4})`, {
2677
2678
  abbreviations: null
2678
2679
  }).repeater("*");
2679
2680
  rebulk.chain({
@@ -2720,6 +2721,7 @@ function episodes(config) {
2720
2721
  FixCorruptedGroupBoundaryValues,
2721
2722
  new RangeExpansionRule(config),
2722
2723
  WeakConflictSolverRule,
2724
+ RemoveWeakDuplicateRule,
2723
2725
  RemoveWeakIfSxxExxRule,
2724
2726
  AbsoluteEpisodeInGroupRule,
2725
2727
  RemoveInvalidSeasonRule,
@@ -2728,7 +2730,7 @@ function episodes(config) {
2728
2730
  );
2729
2731
  return rebulk;
2730
2732
  }
2731
- class DiscMarkerRule extends Rule {
2733
+ const _DiscMarkerRule = class _DiscMarkerRule extends Rule {
2732
2734
  constructor(config) {
2733
2735
  super();
2734
2736
  this.priority = 128;
@@ -2755,14 +2757,29 @@ class DiscMarkerRule extends Rule {
2755
2757
  }
2756
2758
  return toRename.length > 0 ? toRename : false;
2757
2759
  }
2758
- then(matches, toRename, _context) {
2760
+ then(matches, toRename, context) {
2761
+ const discExcluded = isDisabled(context, "disc");
2759
2762
  for (const ep of toRename) {
2760
- matches.remove(ep);
2761
- ep.name = "disc";
2762
- matches.append(ep);
2763
+ if (discExcluded) {
2764
+ const initiator = ep.initiator;
2765
+ matches.remove(ep);
2766
+ if (initiator) {
2767
+ const siblings = initiator.children ? typeof initiator.children[Symbol.iterator] === "function" ? [...initiator.children] : [] : [];
2768
+ for (const sib of siblings) {
2769
+ if (matches.includes(sib)) matches.remove(sib);
2770
+ }
2771
+ if (matches.includes(initiator)) matches.remove(initiator);
2772
+ }
2773
+ } else {
2774
+ matches.remove(ep);
2775
+ ep.name = "disc";
2776
+ matches.append(ep);
2777
+ }
2763
2778
  }
2764
2779
  }
2765
- }
2780
+ };
2781
+ _DiscMarkerRule.priority = 128;
2782
+ let DiscMarkerRule = _DiscMarkerRule;
2766
2783
  class FixCorruptedGroupBoundaryValues extends Rule {
2767
2784
  when(matches, _context) {
2768
2785
  const toFix = [];
@@ -2855,7 +2872,7 @@ class RangeExpansionRule extends Rule {
2855
2872
  return toAppend.length > 0 ? toAppend : false;
2856
2873
  }
2857
2874
  }
2858
- class RemoveInvalidSeasonRule extends Rule {
2875
+ const _RemoveInvalidSeasonRule = class _RemoveInvalidSeasonRule extends Rule {
2859
2876
  constructor() {
2860
2877
  super(...arguments);
2861
2878
  this.consequence = RemoveMatch;
@@ -2888,8 +2905,10 @@ class RemoveInvalidSeasonRule extends Rule {
2888
2905
  }
2889
2906
  return toRemove.length > 0 ? toRemove : false;
2890
2907
  }
2891
- }
2892
- class RemoveInvalidEpisodeRule extends Rule {
2908
+ };
2909
+ _RemoveInvalidSeasonRule.priority = 64;
2910
+ let RemoveInvalidSeasonRule = _RemoveInvalidSeasonRule;
2911
+ const _RemoveInvalidEpisodeRule = class _RemoveInvalidEpisodeRule extends Rule {
2893
2912
  constructor() {
2894
2913
  super(...arguments);
2895
2914
  this.consequence = RemoveMatch;
@@ -2939,8 +2958,44 @@ class RemoveInvalidEpisodeRule extends Rule {
2939
2958
  (m) => !m.private && ["episodeMarker", "episodeSeparator"].includes(m.name)
2940
2959
  )?.[0];
2941
2960
  }
2942
- }
2943
- let RemoveUndeterminedLanguagesRule$1 = class RemoveUndeterminedLanguagesRule extends Rule {
2961
+ };
2962
+ _RemoveInvalidEpisodeRule.priority = 64;
2963
+ let RemoveInvalidEpisodeRule = _RemoveInvalidEpisodeRule;
2964
+ const _RemoveWeakDuplicateRule = class _RemoveWeakDuplicateRule extends Rule {
2965
+ constructor() {
2966
+ super(...arguments);
2967
+ this.consequence = RemoveMatch;
2968
+ this.priority = 64;
2969
+ }
2970
+ when(matches, _context) {
2971
+ const toRemove = [];
2972
+ const fileparts = matches.markers?.named("path") || [];
2973
+ const filepartArr = Array.isArray(fileparts) ? fileparts : fileparts ? [fileparts] : [];
2974
+ for (const filepart of filepartArr) {
2975
+ const weakDups = (matches.range?.(
2976
+ filepart.start,
2977
+ filepart.end,
2978
+ (m) => m.tags?.includes("weak-duplicate")
2979
+ ) || []).slice().reverse();
2980
+ const seen = {};
2981
+ for (const match of weakDups) {
2982
+ const name = match.name ?? "";
2983
+ const pattern = match.initiator?.pattern ?? match.pattern ?? null;
2984
+ if (!pattern) continue;
2985
+ if (!seen[name]) seen[name] = /* @__PURE__ */ new Set();
2986
+ if (seen[name].has(pattern)) {
2987
+ toRemove.push(match);
2988
+ } else {
2989
+ seen[name].add(pattern);
2990
+ }
2991
+ }
2992
+ }
2993
+ return toRemove.length > 0 ? toRemove : false;
2994
+ }
2995
+ };
2996
+ _RemoveWeakDuplicateRule.priority = 64;
2997
+ let RemoveWeakDuplicateRule = _RemoveWeakDuplicateRule;
2998
+ let RemoveUndeterminedLanguagesRule$1 = (_a = class extends Rule {
2944
2999
  constructor() {
2945
3000
  super(...arguments);
2946
3001
  this.consequence = RemoveMatch;
@@ -2949,8 +3004,8 @@ let RemoveUndeterminedLanguagesRule$1 = class RemoveUndeterminedLanguagesRule ex
2949
3004
  when(matches, context) {
2950
3005
  return false;
2951
3006
  }
2952
- };
2953
- class WeakConflictSolverRule extends Rule {
3007
+ }, _a.priority = 32, _a);
3008
+ const _WeakConflictSolverRule = class _WeakConflictSolverRule extends Rule {
2954
3009
  constructor() {
2955
3010
  super(...arguments);
2956
3011
  this.consequence = RemoveMatch;
@@ -3029,8 +3084,10 @@ class WeakConflictSolverRule extends Rule {
3029
3084
  }
3030
3085
  return toRemove.length > 0 ? toRemove : false;
3031
3086
  }
3032
- }
3033
- class AbsoluteEpisodeInGroupRule extends Rule {
3087
+ };
3088
+ _WeakConflictSolverRule.priority = 128;
3089
+ let WeakConflictSolverRule = _WeakConflictSolverRule;
3090
+ const _AbsoluteEpisodeInGroupRule = class _AbsoluteEpisodeInGroupRule extends Rule {
3034
3091
  constructor() {
3035
3092
  super(...arguments);
3036
3093
  this.priority = -1;
@@ -3068,8 +3125,10 @@ class AbsoluteEpisodeInGroupRule extends Rule {
3068
3125
  matches.append(match);
3069
3126
  }
3070
3127
  }
3071
- }
3072
- class RemoveWeakIfSxxExxRule extends Rule {
3128
+ };
3129
+ _AbsoluteEpisodeInGroupRule.priority = -1;
3130
+ let AbsoluteEpisodeInGroupRule = _AbsoluteEpisodeInGroupRule;
3131
+ const _RemoveWeakIfSxxExxRule = class _RemoveWeakIfSxxExxRule extends Rule {
3073
3132
  constructor() {
3074
3133
  super(...arguments);
3075
3134
  this.consequence = RemoveMatch;
@@ -3134,7 +3193,9 @@ class RemoveWeakIfSxxExxRule extends Rule {
3134
3193
  matches.append(match);
3135
3194
  }
3136
3195
  }
3137
- }
3196
+ };
3197
+ _RemoveWeakIfSxxExxRule.priority = 64;
3198
+ let RemoveWeakIfSxxExxRule = _RemoveWeakIfSxxExxRule;
3138
3199
  function container(config) {
3139
3200
  const rebulk = new Rebulk({ disabled: (context) => isDisabled(context, "container") });
3140
3201
  rebulk.regexDefaults({ flags: "i" }).stringDefaults({ ignoreCase: true });
@@ -3842,6 +3903,9 @@ const COMPOUND_PROFILES = {
3842
3903
  "Dolby Digital": "EX"
3843
3904
  };
3844
3905
  const _CompoundAudioProfileRule = class _CompoundAudioProfileRule extends Rule {
3906
+ enabled(context) {
3907
+ return !isDisabled(context, "audio_profile");
3908
+ }
3845
3909
  when(matches) {
3846
3910
  const codecs = matches.named("audio_codec");
3847
3911
  for (const codec of codecs) {
@@ -4511,6 +4575,31 @@ const _KeepMarkedYearInFilepart = class _KeepMarkedYearInFilepart extends Rule {
4511
4575
  };
4512
4576
  _KeepMarkedYearInFilepart.priority = 64;
4513
4577
  let KeepMarkedYearInFilepart = _KeepMarkedYearInFilepart;
4578
+ const _RemoveGroupedYearWithSxxExx = class _RemoveGroupedYearWithSxxExx extends Rule {
4579
+ constructor() {
4580
+ super(...arguments);
4581
+ this.consequence = RemoveMatch;
4582
+ }
4583
+ when(matches, _context) {
4584
+ const ret = [];
4585
+ const hasSxxExx = matches.named("episode").some(
4586
+ (m) => m.tags?.includes("SxxExx")
4587
+ );
4588
+ if (!hasSxxExx) return ret;
4589
+ for (const year of matches.named("year")) {
4590
+ const group = matches.markers.atMatch(year, (m) => m.name === "group", 0);
4591
+ if (!group) continue;
4592
+ const groupLen = group.end - group.start;
4593
+ const yearLen = year.end - year.start;
4594
+ if (groupLen - yearLen > 4) {
4595
+ ret.push(year);
4596
+ }
4597
+ }
4598
+ return ret;
4599
+ }
4600
+ };
4601
+ _RemoveGroupedYearWithSxxExx.priority = 64;
4602
+ let RemoveGroupedYearWithSxxExx = _RemoveGroupedYearWithSxxExx;
4514
4603
  function date(config) {
4515
4604
  const rebulk = new Rebulk().defaults({ validator: sepsSurround });
4516
4605
  rebulk.regex("\\d{4}", {
@@ -4550,7 +4639,7 @@ function date(config) {
4550
4639
  disabled: (context) => isDisabled(context, "date"),
4551
4640
  conflictSolver: (match, other2) => other2.name === "episode" || other2.name === "season" || other2.name === "crc32" ? other2 : "__default__"
4552
4641
  });
4553
- rebulk.rules(KeepMarkedYearInFilepart);
4642
+ rebulk.rules(KeepMarkedYearInFilepart, RemoveGroupedYearWithSxxExx);
4554
4643
  return rebulk;
4555
4644
  }
4556
4645
  function markerComparatorPredicate(m) {
@@ -4768,6 +4857,7 @@ const _TitleBaseRule = class _TitleBaseRule extends Rule {
4768
4857
  formatter: formatters(cleanup, reorderTitle),
4769
4858
  ignore: (m) => {
4770
4859
  if (this.isIgnored(m)) return true;
4860
+ if (m.private && m.tags?.includes("weak-episode")) return true;
4771
4861
  if (m.tags?.includes("weak-episode") || m.tags?.includes("weak-duplicate")) {
4772
4862
  const initiator = m.initiator;
4773
4863
  const startsAtFilepart = m.start === filepart.start || initiator.start === filepart.start;
@@ -4780,6 +4870,19 @@ const _TitleBaseRule = class _TitleBaseRule extends Rule {
4780
4870
  if (firstYearInFilepart && m.end <= firstYearInFilepart.start) {
4781
4871
  return true;
4782
4872
  }
4873
+ if (m.tags?.includes("weak-duplicate")) {
4874
+ const init = m.initiator || m;
4875
+ const laterWds = matches.range(
4876
+ init.end,
4877
+ filepart.end,
4878
+ (other2) => other2.tags?.includes("weak-duplicate") && !other2.private
4879
+ ) || [];
4880
+ const hasLaterDifferent = laterWds.some((other2) => {
4881
+ const otherInit = other2.initiator || other2;
4882
+ return otherInit !== init;
4883
+ });
4884
+ if (hasLaterDifferent) return true;
4885
+ }
4783
4886
  }
4784
4887
  return false;
4785
4888
  },
@@ -5050,12 +5153,21 @@ const _TitleBaseRule = class _TitleBaseRule extends Rule {
5050
5153
  return s.replace(/[''`]/g, "").toLowerCase();
5051
5154
  };
5052
5155
  const existingIdx = toAppend.findIndex((m) => {
5053
- if (m.name !== this.matchName) return false;
5054
5156
  const existingVal = String(m.value ?? "");
5055
5157
  return norm(existingVal) === norm(newVal) && existingVal !== newVal;
5056
5158
  });
5057
5159
  if (existingIdx !== -1) {
5058
- toAppend[existingIdx].value = newVal;
5160
+ const existing = toAppend[existingIdx];
5161
+ if (existing.name === this.matchName) {
5162
+ existing.value = newVal;
5163
+ } else if (existing.name === this.alternativePropertyName) {
5164
+ existing.value = newVal;
5165
+ const mainTitle = toAppend.find((m) => m.name === this.matchName);
5166
+ if (mainTitle) {
5167
+ mainTitle.name = this.alternativePropertyName || "alternative_title";
5168
+ existing.name = this.matchName;
5169
+ }
5170
+ }
5059
5171
  continue;
5060
5172
  }
5061
5173
  const isSuperset = toAppend.some((m) => {
@@ -6410,7 +6522,7 @@ const _SubtitleExtensionRule = class _SubtitleExtensionRule extends Rule {
6410
6522
  };
6411
6523
  _SubtitleExtensionRule.SUBTITLE_EXTENSIONS = /* @__PURE__ */ new Set(["srt", "sub", "smi", "ssa", "ass", "vtt", "idx", "sup"]);
6412
6524
  let SubtitleExtensionRule = _SubtitleExtensionRule;
6413
- class RemoveCommonWordsLanguageRule extends Rule {
6525
+ const _RemoveCommonWordsLanguageRule = class _RemoveCommonWordsLanguageRule extends Rule {
6414
6526
  constructor() {
6415
6527
  super(...arguments);
6416
6528
  this.consequence = RemoveMatch;
@@ -6443,7 +6555,9 @@ class RemoveCommonWordsLanguageRule extends Rule {
6443
6555
  }
6444
6556
  return toRemove.length > 0 ? toRemove : false;
6445
6557
  }
6446
- }
6558
+ };
6559
+ _RemoveCommonWordsLanguageRule.priority = 32;
6560
+ let RemoveCommonWordsLanguageRule = _RemoveCommonWordsLanguageRule;
6447
6561
  class RemoveLanguageRule extends Rule {
6448
6562
  constructor() {
6449
6563
  super(...arguments);
@@ -6456,7 +6570,7 @@ class RemoveLanguageRule extends Rule {
6456
6570
  return matches.named("language") || false;
6457
6571
  }
6458
6572
  }
6459
- class RemoveUndeterminedLanguagesRule2 extends Rule {
6573
+ const _RemoveUndeterminedLanguagesRule = class _RemoveUndeterminedLanguagesRule extends Rule {
6460
6574
  constructor() {
6461
6575
  super(...arguments);
6462
6576
  this.consequence = RemoveMatch;
@@ -6477,7 +6591,9 @@ class RemoveUndeterminedLanguagesRule2 extends Rule {
6477
6591
  }
6478
6592
  return toRemove.length > 0 ? toRemove : false;
6479
6593
  }
6480
- }
6594
+ };
6595
+ _RemoveUndeterminedLanguagesRule.priority = 32;
6596
+ let RemoveUndeterminedLanguagesRule = _RemoveUndeterminedLanguagesRule;
6481
6597
  function language(config, commonWords) {
6482
6598
  const subtitleBoth = config.subtitle_affixes;
6483
6599
  const subtitlePrefixes = [
@@ -6543,7 +6659,7 @@ function language(config, commonWords) {
6543
6659
  },
6544
6660
  {
6545
6661
  properties: { language: [null] },
6546
- disabled: (context) => isDisabled(context, "language")
6662
+ disabled: (context) => isDisabled(context, "language") && isDisabled(context, "subtitle_language")
6547
6663
  }
6548
6664
  );
6549
6665
  rebulk.rules(
@@ -6552,7 +6668,7 @@ function language(config, commonWords) {
6552
6668
  SubtitleExtensionRule,
6553
6669
  RemoveCommonWordsLanguageRule,
6554
6670
  RemoveLanguageRule,
6555
- RemoveUndeterminedLanguagesRule2
6671
+ RemoveUndeterminedLanguagesRule
6556
6672
  );
6557
6673
  return rebulk;
6558
6674
  }