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.
@@ -0,0 +1,42 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>guessit-js API Documentation</title>
7
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/swagger-ui-dist@5.18.2/swagger-ui.css">
8
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/swagger-themes@1/themes/dark.css">
9
+ <style>
10
+ .swagger-ui .topbar { display: none; }
11
+ .swagger-ui { max-width: 1100px; margin: 0 auto; padding: 0 16px 40px; }
12
+ .info-banner {
13
+ background: #1a1a2a; color: #cbd5e1; padding: 10px 20px; text-align: center;
14
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; font-size: 14px;
15
+ border-bottom: 1px solid #333;
16
+ }
17
+ .info-banner a { color: #93c5fd; text-decoration: none; }
18
+ .info-banner a:hover { text-decoration: underline; }
19
+ .info-banner strong { color: #fff; }
20
+ </style>
21
+ </head>
22
+ <body>
23
+ <div class="info-banner">
24
+ <strong>guessit-js</strong> v3.9.0 API Reference &mdash;
25
+ <a href="../">Homepage</a> |
26
+ <a href="https://github.com/opensubtitles/guessit-js">GitHub</a> |
27
+ <a href="https://www.npmjs.com/package/guessit-js">npm</a>
28
+ </div>
29
+ <div id="swagger-ui"></div>
30
+ <script src="https://cdn.jsdelivr.net/npm/swagger-ui-dist@5.18.2/swagger-ui-bundle.js"></script>
31
+ <script>
32
+ SwaggerUIBundle({
33
+ url: '../openapi.json',
34
+ dom_id: '#swagger-ui',
35
+ deepLinking: true,
36
+ defaultModelsExpandDepth: 2,
37
+ defaultModelExpandDepth: 2,
38
+ docExpansion: 'list',
39
+ });
40
+ </script>
41
+ </body>
42
+ </html>
@@ -2,6 +2,7 @@
2
2
  var __defProp = Object.defineProperty;
3
3
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4
4
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
+ var _a;
5
6
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
6
7
  function defaultFormatter(value) {
7
8
  return value;
@@ -2616,13 +2617,13 @@ function episodes(config) {
2616
2617
  ).repeater("*");
2617
2618
  const episodeWordPattern = buildOrPattern(config.episode_words, "episodeMarker");
2618
2619
  rebulk.regex(
2619
- `(?<![a-zA-Z])` + episodeWordPattern + `@?(?<episode>\\d+)(?:v(?<version>\\d+))?(?:@?` + ofWordPattern + `@?(?<count>\\d+))?`,
2620
+ `(?<![a-zA-Z\\d])` + episodeWordPattern + `@?(?<episode>\\d+)(?:v(?<version>\\d+))?(?:@?` + ofWordPattern + `@?(?<count>\\d+))?`,
2620
2621
  {
2621
2622
  disabled: (context) => context?.type === "episode" || isDisabled(context, "episode")
2622
2623
  }
2623
2624
  );
2624
2625
  rebulk.regex(
2625
- `(?<![a-zA-Z])` + episodeWordPattern + `@?(?<episode>${numeral})(?:v(?<version>\\d+))?(?:@?` + ofWordPattern + `@?(?<count>\\d+))?`,
2626
+ `(?<![a-zA-Z\\d])` + episodeWordPattern + `@?(?<episode>${numeral})(?:v(?<version>\\d+))?(?:@?` + ofWordPattern + `@?(?<count>\\d+))?`,
2626
2627
  {
2627
2628
  validator: { episode: validateRoman },
2628
2629
  formatter: { episode: parseNumber },
@@ -2675,7 +2676,7 @@ function episodes(config) {
2675
2676
  }).repeater("*");
2676
2677
  rebulk.chain({
2677
2678
  disabled: (context) => isDisabled(context, "episode")
2678
- }).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})`, {
2679
+ }).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})`, {
2679
2680
  abbreviations: null
2680
2681
  }).repeater("*");
2681
2682
  rebulk.chain({
@@ -2722,6 +2723,7 @@ function episodes(config) {
2722
2723
  FixCorruptedGroupBoundaryValues,
2723
2724
  new RangeExpansionRule(config),
2724
2725
  WeakConflictSolverRule,
2726
+ RemoveWeakDuplicateRule,
2725
2727
  RemoveWeakIfSxxExxRule,
2726
2728
  AbsoluteEpisodeInGroupRule,
2727
2729
  RemoveInvalidSeasonRule,
@@ -2730,7 +2732,7 @@ function episodes(config) {
2730
2732
  );
2731
2733
  return rebulk;
2732
2734
  }
2733
- class DiscMarkerRule extends Rule {
2735
+ const _DiscMarkerRule = class _DiscMarkerRule extends Rule {
2734
2736
  constructor(config) {
2735
2737
  super();
2736
2738
  this.priority = 128;
@@ -2757,14 +2759,29 @@ class DiscMarkerRule extends Rule {
2757
2759
  }
2758
2760
  return toRename.length > 0 ? toRename : false;
2759
2761
  }
2760
- then(matches, toRename, _context) {
2762
+ then(matches, toRename, context) {
2763
+ const discExcluded = isDisabled(context, "disc");
2761
2764
  for (const ep of toRename) {
2762
- matches.remove(ep);
2763
- ep.name = "disc";
2764
- matches.append(ep);
2765
+ if (discExcluded) {
2766
+ const initiator = ep.initiator;
2767
+ matches.remove(ep);
2768
+ if (initiator) {
2769
+ const siblings = initiator.children ? typeof initiator.children[Symbol.iterator] === "function" ? [...initiator.children] : [] : [];
2770
+ for (const sib of siblings) {
2771
+ if (matches.includes(sib)) matches.remove(sib);
2772
+ }
2773
+ if (matches.includes(initiator)) matches.remove(initiator);
2774
+ }
2775
+ } else {
2776
+ matches.remove(ep);
2777
+ ep.name = "disc";
2778
+ matches.append(ep);
2779
+ }
2765
2780
  }
2766
2781
  }
2767
- }
2782
+ };
2783
+ _DiscMarkerRule.priority = 128;
2784
+ let DiscMarkerRule = _DiscMarkerRule;
2768
2785
  class FixCorruptedGroupBoundaryValues extends Rule {
2769
2786
  when(matches, _context) {
2770
2787
  const toFix = [];
@@ -2857,7 +2874,7 @@ class RangeExpansionRule extends Rule {
2857
2874
  return toAppend.length > 0 ? toAppend : false;
2858
2875
  }
2859
2876
  }
2860
- class RemoveInvalidSeasonRule extends Rule {
2877
+ const _RemoveInvalidSeasonRule = class _RemoveInvalidSeasonRule extends Rule {
2861
2878
  constructor() {
2862
2879
  super(...arguments);
2863
2880
  this.consequence = RemoveMatch;
@@ -2890,8 +2907,10 @@ class RemoveInvalidSeasonRule extends Rule {
2890
2907
  }
2891
2908
  return toRemove.length > 0 ? toRemove : false;
2892
2909
  }
2893
- }
2894
- class RemoveInvalidEpisodeRule extends Rule {
2910
+ };
2911
+ _RemoveInvalidSeasonRule.priority = 64;
2912
+ let RemoveInvalidSeasonRule = _RemoveInvalidSeasonRule;
2913
+ const _RemoveInvalidEpisodeRule = class _RemoveInvalidEpisodeRule extends Rule {
2895
2914
  constructor() {
2896
2915
  super(...arguments);
2897
2916
  this.consequence = RemoveMatch;
@@ -2941,8 +2960,44 @@ class RemoveInvalidEpisodeRule extends Rule {
2941
2960
  (m) => !m.private && ["episodeMarker", "episodeSeparator"].includes(m.name)
2942
2961
  )?.[0];
2943
2962
  }
2944
- }
2945
- let RemoveUndeterminedLanguagesRule$1 = class RemoveUndeterminedLanguagesRule extends Rule {
2963
+ };
2964
+ _RemoveInvalidEpisodeRule.priority = 64;
2965
+ let RemoveInvalidEpisodeRule = _RemoveInvalidEpisodeRule;
2966
+ const _RemoveWeakDuplicateRule = class _RemoveWeakDuplicateRule extends Rule {
2967
+ constructor() {
2968
+ super(...arguments);
2969
+ this.consequence = RemoveMatch;
2970
+ this.priority = 64;
2971
+ }
2972
+ when(matches, _context) {
2973
+ const toRemove = [];
2974
+ const fileparts = matches.markers?.named("path") || [];
2975
+ const filepartArr = Array.isArray(fileparts) ? fileparts : fileparts ? [fileparts] : [];
2976
+ for (const filepart of filepartArr) {
2977
+ const weakDups = (matches.range?.(
2978
+ filepart.start,
2979
+ filepart.end,
2980
+ (m) => m.tags?.includes("weak-duplicate")
2981
+ ) || []).slice().reverse();
2982
+ const seen = {};
2983
+ for (const match of weakDups) {
2984
+ const name = match.name ?? "";
2985
+ const pattern = match.initiator?.pattern ?? match.pattern ?? null;
2986
+ if (!pattern) continue;
2987
+ if (!seen[name]) seen[name] = /* @__PURE__ */ new Set();
2988
+ if (seen[name].has(pattern)) {
2989
+ toRemove.push(match);
2990
+ } else {
2991
+ seen[name].add(pattern);
2992
+ }
2993
+ }
2994
+ }
2995
+ return toRemove.length > 0 ? toRemove : false;
2996
+ }
2997
+ };
2998
+ _RemoveWeakDuplicateRule.priority = 64;
2999
+ let RemoveWeakDuplicateRule = _RemoveWeakDuplicateRule;
3000
+ let RemoveUndeterminedLanguagesRule$1 = (_a = class extends Rule {
2946
3001
  constructor() {
2947
3002
  super(...arguments);
2948
3003
  this.consequence = RemoveMatch;
@@ -2951,8 +3006,8 @@ let RemoveUndeterminedLanguagesRule$1 = class RemoveUndeterminedLanguagesRule ex
2951
3006
  when(matches, context) {
2952
3007
  return false;
2953
3008
  }
2954
- };
2955
- class WeakConflictSolverRule extends Rule {
3009
+ }, _a.priority = 32, _a);
3010
+ const _WeakConflictSolverRule = class _WeakConflictSolverRule extends Rule {
2956
3011
  constructor() {
2957
3012
  super(...arguments);
2958
3013
  this.consequence = RemoveMatch;
@@ -3031,8 +3086,10 @@ class WeakConflictSolverRule extends Rule {
3031
3086
  }
3032
3087
  return toRemove.length > 0 ? toRemove : false;
3033
3088
  }
3034
- }
3035
- class AbsoluteEpisodeInGroupRule extends Rule {
3089
+ };
3090
+ _WeakConflictSolverRule.priority = 128;
3091
+ let WeakConflictSolverRule = _WeakConflictSolverRule;
3092
+ const _AbsoluteEpisodeInGroupRule = class _AbsoluteEpisodeInGroupRule extends Rule {
3036
3093
  constructor() {
3037
3094
  super(...arguments);
3038
3095
  this.priority = -1;
@@ -3070,8 +3127,10 @@ class AbsoluteEpisodeInGroupRule extends Rule {
3070
3127
  matches.append(match);
3071
3128
  }
3072
3129
  }
3073
- }
3074
- class RemoveWeakIfSxxExxRule extends Rule {
3130
+ };
3131
+ _AbsoluteEpisodeInGroupRule.priority = -1;
3132
+ let AbsoluteEpisodeInGroupRule = _AbsoluteEpisodeInGroupRule;
3133
+ const _RemoveWeakIfSxxExxRule = class _RemoveWeakIfSxxExxRule extends Rule {
3075
3134
  constructor() {
3076
3135
  super(...arguments);
3077
3136
  this.consequence = RemoveMatch;
@@ -3136,7 +3195,9 @@ class RemoveWeakIfSxxExxRule extends Rule {
3136
3195
  matches.append(match);
3137
3196
  }
3138
3197
  }
3139
- }
3198
+ };
3199
+ _RemoveWeakIfSxxExxRule.priority = 64;
3200
+ let RemoveWeakIfSxxExxRule = _RemoveWeakIfSxxExxRule;
3140
3201
  function container(config) {
3141
3202
  const rebulk = new Rebulk({ disabled: (context) => isDisabled(context, "container") });
3142
3203
  rebulk.regexDefaults({ flags: "i" }).stringDefaults({ ignoreCase: true });
@@ -3844,6 +3905,9 @@ const COMPOUND_PROFILES = {
3844
3905
  "Dolby Digital": "EX"
3845
3906
  };
3846
3907
  const _CompoundAudioProfileRule = class _CompoundAudioProfileRule extends Rule {
3908
+ enabled(context) {
3909
+ return !isDisabled(context, "audio_profile");
3910
+ }
3847
3911
  when(matches) {
3848
3912
  const codecs = matches.named("audio_codec");
3849
3913
  for (const codec of codecs) {
@@ -4513,6 +4577,31 @@ const _KeepMarkedYearInFilepart = class _KeepMarkedYearInFilepart extends Rule {
4513
4577
  };
4514
4578
  _KeepMarkedYearInFilepart.priority = 64;
4515
4579
  let KeepMarkedYearInFilepart = _KeepMarkedYearInFilepart;
4580
+ const _RemoveGroupedYearWithSxxExx = class _RemoveGroupedYearWithSxxExx extends Rule {
4581
+ constructor() {
4582
+ super(...arguments);
4583
+ this.consequence = RemoveMatch;
4584
+ }
4585
+ when(matches, _context) {
4586
+ const ret = [];
4587
+ const hasSxxExx = matches.named("episode").some(
4588
+ (m) => m.tags?.includes("SxxExx")
4589
+ );
4590
+ if (!hasSxxExx) return ret;
4591
+ for (const year of matches.named("year")) {
4592
+ const group = matches.markers.atMatch(year, (m) => m.name === "group", 0);
4593
+ if (!group) continue;
4594
+ const groupLen = group.end - group.start;
4595
+ const yearLen = year.end - year.start;
4596
+ if (groupLen - yearLen > 4) {
4597
+ ret.push(year);
4598
+ }
4599
+ }
4600
+ return ret;
4601
+ }
4602
+ };
4603
+ _RemoveGroupedYearWithSxxExx.priority = 64;
4604
+ let RemoveGroupedYearWithSxxExx = _RemoveGroupedYearWithSxxExx;
4516
4605
  function date(config) {
4517
4606
  const rebulk = new Rebulk().defaults({ validator: sepsSurround });
4518
4607
  rebulk.regex("\\d{4}", {
@@ -4552,7 +4641,7 @@ function date(config) {
4552
4641
  disabled: (context) => isDisabled(context, "date"),
4553
4642
  conflictSolver: (match, other2) => other2.name === "episode" || other2.name === "season" || other2.name === "crc32" ? other2 : "__default__"
4554
4643
  });
4555
- rebulk.rules(KeepMarkedYearInFilepart);
4644
+ rebulk.rules(KeepMarkedYearInFilepart, RemoveGroupedYearWithSxxExx);
4556
4645
  return rebulk;
4557
4646
  }
4558
4647
  function markerComparatorPredicate(m) {
@@ -4770,6 +4859,7 @@ const _TitleBaseRule = class _TitleBaseRule extends Rule {
4770
4859
  formatter: formatters(cleanup, reorderTitle),
4771
4860
  ignore: (m) => {
4772
4861
  if (this.isIgnored(m)) return true;
4862
+ if (m.private && m.tags?.includes("weak-episode")) return true;
4773
4863
  if (m.tags?.includes("weak-episode") || m.tags?.includes("weak-duplicate")) {
4774
4864
  const initiator = m.initiator;
4775
4865
  const startsAtFilepart = m.start === filepart.start || initiator.start === filepart.start;
@@ -4782,6 +4872,19 @@ const _TitleBaseRule = class _TitleBaseRule extends Rule {
4782
4872
  if (firstYearInFilepart && m.end <= firstYearInFilepart.start) {
4783
4873
  return true;
4784
4874
  }
4875
+ if (m.tags?.includes("weak-duplicate")) {
4876
+ const init = m.initiator || m;
4877
+ const laterWds = matches.range(
4878
+ init.end,
4879
+ filepart.end,
4880
+ (other2) => other2.tags?.includes("weak-duplicate") && !other2.private
4881
+ ) || [];
4882
+ const hasLaterDifferent = laterWds.some((other2) => {
4883
+ const otherInit = other2.initiator || other2;
4884
+ return otherInit !== init;
4885
+ });
4886
+ if (hasLaterDifferent) return true;
4887
+ }
4785
4888
  }
4786
4889
  return false;
4787
4890
  },
@@ -5052,12 +5155,21 @@ const _TitleBaseRule = class _TitleBaseRule extends Rule {
5052
5155
  return s.replace(/[''`]/g, "").toLowerCase();
5053
5156
  };
5054
5157
  const existingIdx = toAppend.findIndex((m) => {
5055
- if (m.name !== this.matchName) return false;
5056
5158
  const existingVal = String(m.value ?? "");
5057
5159
  return norm(existingVal) === norm(newVal) && existingVal !== newVal;
5058
5160
  });
5059
5161
  if (existingIdx !== -1) {
5060
- toAppend[existingIdx].value = newVal;
5162
+ const existing = toAppend[existingIdx];
5163
+ if (existing.name === this.matchName) {
5164
+ existing.value = newVal;
5165
+ } else if (existing.name === this.alternativePropertyName) {
5166
+ existing.value = newVal;
5167
+ const mainTitle = toAppend.find((m) => m.name === this.matchName);
5168
+ if (mainTitle) {
5169
+ mainTitle.name = this.alternativePropertyName || "alternative_title";
5170
+ existing.name = this.matchName;
5171
+ }
5172
+ }
5061
5173
  continue;
5062
5174
  }
5063
5175
  const isSuperset = toAppend.some((m) => {
@@ -6412,7 +6524,7 @@ const _SubtitleExtensionRule = class _SubtitleExtensionRule extends Rule {
6412
6524
  };
6413
6525
  _SubtitleExtensionRule.SUBTITLE_EXTENSIONS = /* @__PURE__ */ new Set(["srt", "sub", "smi", "ssa", "ass", "vtt", "idx", "sup"]);
6414
6526
  let SubtitleExtensionRule = _SubtitleExtensionRule;
6415
- class RemoveCommonWordsLanguageRule extends Rule {
6527
+ const _RemoveCommonWordsLanguageRule = class _RemoveCommonWordsLanguageRule extends Rule {
6416
6528
  constructor() {
6417
6529
  super(...arguments);
6418
6530
  this.consequence = RemoveMatch;
@@ -6445,7 +6557,9 @@ class RemoveCommonWordsLanguageRule extends Rule {
6445
6557
  }
6446
6558
  return toRemove.length > 0 ? toRemove : false;
6447
6559
  }
6448
- }
6560
+ };
6561
+ _RemoveCommonWordsLanguageRule.priority = 32;
6562
+ let RemoveCommonWordsLanguageRule = _RemoveCommonWordsLanguageRule;
6449
6563
  class RemoveLanguageRule extends Rule {
6450
6564
  constructor() {
6451
6565
  super(...arguments);
@@ -6458,7 +6572,7 @@ class RemoveLanguageRule extends Rule {
6458
6572
  return matches.named("language") || false;
6459
6573
  }
6460
6574
  }
6461
- class RemoveUndeterminedLanguagesRule2 extends Rule {
6575
+ const _RemoveUndeterminedLanguagesRule = class _RemoveUndeterminedLanguagesRule extends Rule {
6462
6576
  constructor() {
6463
6577
  super(...arguments);
6464
6578
  this.consequence = RemoveMatch;
@@ -6479,7 +6593,9 @@ class RemoveUndeterminedLanguagesRule2 extends Rule {
6479
6593
  }
6480
6594
  return toRemove.length > 0 ? toRemove : false;
6481
6595
  }
6482
- }
6596
+ };
6597
+ _RemoveUndeterminedLanguagesRule.priority = 32;
6598
+ let RemoveUndeterminedLanguagesRule = _RemoveUndeterminedLanguagesRule;
6483
6599
  function language(config, commonWords) {
6484
6600
  const subtitleBoth = config.subtitle_affixes;
6485
6601
  const subtitlePrefixes = [
@@ -6545,7 +6661,7 @@ function language(config, commonWords) {
6545
6661
  },
6546
6662
  {
6547
6663
  properties: { language: [null] },
6548
- disabled: (context) => isDisabled(context, "language")
6664
+ disabled: (context) => isDisabled(context, "language") && isDisabled(context, "subtitle_language")
6549
6665
  }
6550
6666
  );
6551
6667
  rebulk.rules(
@@ -6554,7 +6670,7 @@ function language(config, commonWords) {
6554
6670
  SubtitleExtensionRule,
6555
6671
  RemoveCommonWordsLanguageRule,
6556
6672
  RemoveLanguageRule,
6557
- RemoveUndeterminedLanguagesRule2
6673
+ RemoveUndeterminedLanguagesRule
6558
6674
  );
6559
6675
  return rebulk;
6560
6676
  }