guessit-js 4.1.0 → 4.2.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.
- package/dist/guessit-js.cjs +310 -51
- package/dist/guessit-js.cjs.map +1 -1
- package/dist/guessit-js.js +310 -51
- package/dist/guessit-js.js.map +1 -1
- package/dist/rules/processors.d.ts +7 -0
- package/package.json +1 -1
package/dist/guessit-js.cjs
CHANGED
|
@@ -3289,6 +3289,18 @@ function episodesSeasonChainBreaker(matches, config) {
|
|
|
3289
3289
|
return false;
|
|
3290
3290
|
}
|
|
3291
3291
|
function seasonEpisodeConflictSolver(match, other2) {
|
|
3292
|
+
const famChild = (p) => {
|
|
3293
|
+
if (p?.name) return null;
|
|
3294
|
+
const ch = [...p?.children ?? []];
|
|
3295
|
+
return ch.find((c) => c.name === "season" || c.name === "episode") ?? null;
|
|
3296
|
+
};
|
|
3297
|
+
const mChild = famChild(match);
|
|
3298
|
+
const oChild = famChild(other2);
|
|
3299
|
+
if (mChild && oChild) {
|
|
3300
|
+
const mNumfirst = !!mChild.tags?.includes("numfirst");
|
|
3301
|
+
const oNumfirst = !!oChild.tags?.includes("numfirst");
|
|
3302
|
+
if (mNumfirst !== oNumfirst) return null;
|
|
3303
|
+
}
|
|
3292
3304
|
if (match.name !== other2.name) {
|
|
3293
3305
|
if (match.name === "episode" && other2.name === "year") {
|
|
3294
3306
|
return match;
|
|
@@ -3320,7 +3332,7 @@ function seasonEpisodeConflictSolver(match, other2) {
|
|
|
3320
3332
|
while (i >= 0 && i < input.length && seps.includes(input[i])) i += dir;
|
|
3321
3333
|
let tok = "";
|
|
3322
3334
|
while (i >= 0 && i < input.length && /\d/.test(input[i])) {
|
|
3323
|
-
tok =
|
|
3335
|
+
tok = tok + input[i];
|
|
3324
3336
|
i += dir;
|
|
3325
3337
|
}
|
|
3326
3338
|
return tok;
|
|
@@ -3333,8 +3345,9 @@ function seasonEpisodeConflictSolver(match, other2) {
|
|
|
3333
3345
|
return t.length >= 1 && t.length <= 4 && !isYearLike(t);
|
|
3334
3346
|
})();
|
|
3335
3347
|
const wfDangling = (() => {
|
|
3336
|
-
const
|
|
3337
|
-
|
|
3348
|
+
const before = input.slice(Math.max(0, wfInit.start - 12), wfInit.start);
|
|
3349
|
+
const m = /(\d{1,3})(?:ª|º|°|a|o|-?(?:й|я|е|го|ая|ый|ое))?[\s.,_\-–]*$/iu.exec(before);
|
|
3350
|
+
return !!(m && !isYearLike(m[1]));
|
|
3338
3351
|
})();
|
|
3339
3352
|
if (wfDangling && !nfDangling) return wf;
|
|
3340
3353
|
return nf;
|
|
@@ -3390,11 +3403,41 @@ function seasonWordNotYear(match) {
|
|
|
3390
3403
|
function episodes(config) {
|
|
3391
3404
|
config.range_separators;
|
|
3392
3405
|
const discreteSeparators = config.discrete_separators;
|
|
3393
|
-
seps.split("").filter((s) => !config.range_separators.includes(s));
|
|
3406
|
+
const weakDiscreteSeparators = seps.split("").filter((s) => !config.range_separators.includes(s) && s !== "/" && s !== "\\");
|
|
3394
3407
|
const allSeparators = [
|
|
3395
3408
|
...config.range_separators,
|
|
3396
|
-
...discreteSeparators
|
|
3409
|
+
...discreteSeparators,
|
|
3410
|
+
...weakDiscreteSeparators
|
|
3397
3411
|
];
|
|
3412
|
+
const moduleOrderingValidator = orderingValidator;
|
|
3413
|
+
const localOrderingValidator = (match) => {
|
|
3414
|
+
if (!moduleOrderingValidator(match)) return false;
|
|
3415
|
+
const isConsecutive = (prop) => {
|
|
3416
|
+
let previous = null;
|
|
3417
|
+
let valid = true;
|
|
3418
|
+
const children = match.children;
|
|
3419
|
+
const named = children?.named?.(prop) ?? [];
|
|
3420
|
+
for (const current of Array.isArray(named) ? named : [named]) {
|
|
3421
|
+
if (previous) {
|
|
3422
|
+
const separator = children.previous?.(current, (m) => m.name === prop + "Separator", 0);
|
|
3423
|
+
if (separator) {
|
|
3424
|
+
const sraw = String(separator.raw ?? "");
|
|
3425
|
+
if (!config.range_separators.includes(sraw) && weakDiscreteSeparators.includes(sraw)) {
|
|
3426
|
+
const gap = Number(current.value) - Number(previous.value);
|
|
3427
|
+
if (!(gap > 0 && gap <= config.max_range_gap + 1)) valid = false;
|
|
3428
|
+
}
|
|
3429
|
+
if (discreteSeparators.includes(sraw)) {
|
|
3430
|
+
valid = true;
|
|
3431
|
+
break;
|
|
3432
|
+
}
|
|
3433
|
+
}
|
|
3434
|
+
}
|
|
3435
|
+
previous = current;
|
|
3436
|
+
}
|
|
3437
|
+
return valid;
|
|
3438
|
+
};
|
|
3439
|
+
return isConsecutive("episode") && isConsecutive("season");
|
|
3440
|
+
};
|
|
3398
3441
|
const wordNumerals = [
|
|
3399
3442
|
"zero",
|
|
3400
3443
|
"one",
|
|
@@ -3466,7 +3509,7 @@ function episodes(config) {
|
|
|
3466
3509
|
tags: ["SxxExx"],
|
|
3467
3510
|
validateAll: true,
|
|
3468
3511
|
validator: {
|
|
3469
|
-
__parent__: and_(sepsSurround,
|
|
3512
|
+
__parent__: and_(sepsSurround, localOrderingValidator)
|
|
3470
3513
|
},
|
|
3471
3514
|
chainBreaker: (matches) => episodesSeasonChainBreaker(matches, config),
|
|
3472
3515
|
disabled: isSeasonEpisodeDisabled
|
|
@@ -3600,13 +3643,13 @@ function episodes(config) {
|
|
|
3600
3643
|
rebulk.chain({
|
|
3601
3644
|
tags: ["weak-episode"],
|
|
3602
3645
|
disabled: (context) => context?.type === "movie" || isDisabled(context, "episode")
|
|
3603
|
-
}).defaults({ validator: null, tags: ["weak-episode"] }).regex(`(?<episode>\\d{2})(?!(?:st|nd|rd|th)\\b)`).regex(`v(?<version>\\d+)`).repeater("?").regex(`(?<episodeSeparator>[x-])(?<episode>\\d{2})`, {
|
|
3646
|
+
}).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})`, {
|
|
3604
3647
|
abbreviations: null
|
|
3605
3648
|
}).repeater("*");
|
|
3606
3649
|
rebulk.chain({
|
|
3607
3650
|
tags: ["weak-episode"],
|
|
3608
3651
|
disabled: (context) => context?.type === "movie" || isDisabled(context, "episode")
|
|
3609
|
-
}).defaults({ validator: null, tags: ["weak-episode"] }).regex(`0(?<episode>\\d{1,2})`).regex(`v(?<version>\\d+)`).repeater("?").regex(`(?<episodeSeparator>[x-])0(?<episode>\\d{1,2})`, {
|
|
3652
|
+
}).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})`, {
|
|
3610
3653
|
abbreviations: null
|
|
3611
3654
|
}).repeater("*");
|
|
3612
3655
|
rebulk.chain({
|
|
@@ -3617,13 +3660,13 @@ function episodes(config) {
|
|
|
3617
3660
|
validator: null,
|
|
3618
3661
|
tags: ["weak-episode"],
|
|
3619
3662
|
name: "weak_episode"
|
|
3620
|
-
}).regex(`(?<episode>\\d{3,4})`).regex(`v(?<version>\\d+)`).repeater("?").regex(`(?<episodeSeparator>[x-])(?<episode>\\d{3,4})`, {
|
|
3663
|
+
}).regex(`(?<![^\\W_])(?<episode>\\d{3,4})(?!(?![vV]\\d)[^\\W_])`).regex(`v(?<version>\\d+)`).repeater("?").regex(`(?<episodeSeparator>[x-])(?<episode>\\d{3,4})`, {
|
|
3621
3664
|
abbreviations: null
|
|
3622
3665
|
}).repeater("*");
|
|
3623
3666
|
rebulk.chain({
|
|
3624
3667
|
tags: ["weak-episode"],
|
|
3625
3668
|
disabled: (context) => context?.type !== "episode" || isDisabled(context, "episode")
|
|
3626
|
-
}).defaults({ validator: null, tags: ["weak-episode"] }).regex(`(?<episode>\\d)`).regex(`v(?<version>\\d+)`).repeater("?").regex(`(?<episodeSeparator>[x-])(?<episode>\\d{1,2})`, {
|
|
3669
|
+
}).defaults({ validator: null, tags: ["weak-episode"] }).regex(`(?<![^\\W_])(?<episode>\\d)(?!-[a-z])(?!(?![vV]\\d)[^\\W_])`).regex(`v(?<version>\\d+)`).repeater("?").regex(`(?<episodeSeparator>[x-])(?<episode>\\d{1,2})`, {
|
|
3627
3670
|
abbreviations: null
|
|
3628
3671
|
}).repeater("*");
|
|
3629
3672
|
rebulk.chain({
|
|
@@ -3652,7 +3695,7 @@ function episodes(config) {
|
|
|
3652
3695
|
name: "weak_duplicate",
|
|
3653
3696
|
validator: null,
|
|
3654
3697
|
conflictSolver: seasonEpisodeConflictSolver
|
|
3655
|
-
}).regex(`(?<season>\\d{1,2})(?<episode>\\d{2})`).regex(`v(?<version>\\d+)`).repeater("?").regex(`(?<episodeSeparator>x|-)(?<episode>\\d{2})`, {
|
|
3698
|
+
}).regex(`(?<![^\\W_])(?<season>\\d{1,2})(?<episode>\\d{2})(?!(?![vV]\\d)[^\\W_])`).regex(`v(?<version>\\d+)`).repeater("?").regex(`(?<episodeSeparator>x|-)(?<episode>\\d{2})`, {
|
|
3656
3699
|
abbreviations: null
|
|
3657
3700
|
}).repeater("*");
|
|
3658
3701
|
rebulk.regex(`v(?<version>\\d+)`, {
|
|
@@ -3704,22 +3747,28 @@ const _RemoveNumfirstMarkerCollision = class _RemoveNumfirstMarkerCollision exte
|
|
|
3704
3747
|
when(matches, _context) {
|
|
3705
3748
|
const toRemove = [];
|
|
3706
3749
|
const isWeak = (m) => !!(m.tags?.includes("weak-episode") || ["weak_episode", "weak_duplicate"].includes(m.initiator?.name));
|
|
3707
|
-
const
|
|
3750
|
+
const removeWithParent = (m) => {
|
|
3751
|
+
const init = m.initiator ?? m;
|
|
3752
|
+
if (!toRemove.includes(m)) toRemove.push(m);
|
|
3753
|
+
for (const child of init.children ?? []) {
|
|
3754
|
+
if (!toRemove.includes(child)) toRemove.push(child);
|
|
3755
|
+
}
|
|
3756
|
+
};
|
|
3757
|
+
const all = [...matches];
|
|
3758
|
+
const numfirsts = all.filter((m) => (m.name === "season" || m.name === "episode") && m.tags?.includes("numfirst"));
|
|
3708
3759
|
for (const nf of numfirsts) {
|
|
3709
3760
|
const nfInit = nf.initiator ?? nf;
|
|
3710
|
-
const
|
|
3761
|
+
const wordFirst = all.find((w) => {
|
|
3711
3762
|
if (w.name !== "season" && w.name !== "episode") return false;
|
|
3712
3763
|
if (w.tags?.includes("numfirst") || isWeak(w)) return false;
|
|
3713
3764
|
const wInit = w.initiator ?? w;
|
|
3714
3765
|
if (wInit === nfInit) return false;
|
|
3715
3766
|
return wInit.start < nfInit.end && nfInit.start < wInit.end;
|
|
3716
3767
|
});
|
|
3717
|
-
if (
|
|
3718
|
-
|
|
3719
|
-
|
|
3720
|
-
|
|
3721
|
-
}
|
|
3722
|
-
}
|
|
3768
|
+
if (!wordFirst) continue;
|
|
3769
|
+
const claimed = all.some((m) => !m.private && (m.name === "screen_size" || m.name === "year") && m.start < wordFirst.end && wordFirst.start < m.end);
|
|
3770
|
+
if (claimed) removeWithParent(wordFirst);
|
|
3771
|
+
else removeWithParent(nf);
|
|
3723
3772
|
}
|
|
3724
3773
|
return toRemove.length ? toRemove : false;
|
|
3725
3774
|
}
|
|
@@ -4946,6 +4995,10 @@ const COMPOUND_PROFILES = {
|
|
|
4946
4995
|
"Dolby Digital": "EX"
|
|
4947
4996
|
};
|
|
4948
4997
|
const _CompoundAudioProfileRule = class _CompoundAudioProfileRule extends Rule {
|
|
4998
|
+
constructor() {
|
|
4999
|
+
super(...arguments);
|
|
5000
|
+
this.priority = 128;
|
|
5001
|
+
}
|
|
4949
5002
|
enabled(context) {
|
|
4950
5003
|
return !isDisabled(context, "audio_profile");
|
|
4951
5004
|
}
|
|
@@ -4988,6 +5041,7 @@ const _CompoundAudioProfileRule = class _CompoundAudioProfileRule extends Rule {
|
|
|
4988
5041
|
}
|
|
4989
5042
|
}
|
|
4990
5043
|
};
|
|
5044
|
+
_CompoundAudioProfileRule.priority = 128;
|
|
4991
5045
|
_CompoundAudioProfileRule.consequence = AppendMatch;
|
|
4992
5046
|
let CompoundAudioProfileRule = _CompoundAudioProfileRule;
|
|
4993
5047
|
const _AudioProfileRule = class _AudioProfileRule extends Rule {
|
|
@@ -5072,17 +5126,29 @@ const _AudioValidatorRule = class _AudioValidatorRule extends Rule {
|
|
|
5072
5126
|
}
|
|
5073
5127
|
when(matches, _context) {
|
|
5074
5128
|
const ret = [];
|
|
5075
|
-
const
|
|
5129
|
+
const AUDIO_PROPS = ["audio_codec", "audio_profile", "audio_channels"];
|
|
5130
|
+
const audioProps = AUDIO_PROPS.flatMap((n) => [...matches.named(n)]);
|
|
5076
5131
|
for (const prop of audioProps) {
|
|
5077
5132
|
if (!sepsBefore(prop)) {
|
|
5078
|
-
const
|
|
5079
|
-
|
|
5133
|
+
const validBefore = matches.range(
|
|
5134
|
+
prop.start - 1,
|
|
5135
|
+
prop.start,
|
|
5136
|
+
(m) => AUDIO_PROPS.includes(m.name ?? "")
|
|
5137
|
+
);
|
|
5138
|
+
if (!(Array.isArray(validBefore) ? validBefore.length : validBefore)) {
|
|
5080
5139
|
ret.push(prop);
|
|
5140
|
+
continue;
|
|
5081
5141
|
}
|
|
5082
|
-
}
|
|
5083
|
-
|
|
5084
|
-
|
|
5142
|
+
}
|
|
5143
|
+
if (!sepsAfter(prop)) {
|
|
5144
|
+
const validAfter = matches.range(
|
|
5145
|
+
prop.end,
|
|
5146
|
+
prop.end + 1,
|
|
5147
|
+
(m) => AUDIO_PROPS.includes(m.name ?? "")
|
|
5148
|
+
);
|
|
5149
|
+
if (!(Array.isArray(validAfter) ? validAfter.length : validAfter)) {
|
|
5085
5150
|
ret.push(prop);
|
|
5151
|
+
continue;
|
|
5086
5152
|
}
|
|
5087
5153
|
}
|
|
5088
5154
|
}
|
|
@@ -5706,9 +5772,46 @@ function date(config) {
|
|
|
5706
5772
|
disabled: (context) => isDisabled(context, "date"),
|
|
5707
5773
|
conflictSolver: (match, other2) => other2.name === "episode" || other2.name === "season" || other2.name === "crc32" ? other2 : "__default__"
|
|
5708
5774
|
});
|
|
5709
|
-
rebulk.rules(KeepMarkedYearInFilepart, RemoveGroupedYearWithSxxExx);
|
|
5775
|
+
rebulk.rules(KeepMarkedYearInFilepart, RemoveGroupedYearWithSxxExx, new AbsorbWeekdayPrefix(config["weekday_words"] ?? []));
|
|
5710
5776
|
return rebulk;
|
|
5711
5777
|
}
|
|
5778
|
+
class AbsorbWeekdayPrefix extends Rule {
|
|
5779
|
+
constructor(weekdayWords) {
|
|
5780
|
+
super();
|
|
5781
|
+
this.consequence = RemoveMatch;
|
|
5782
|
+
const sepsClass = "[" + seps.replace(/[.*+?^${}()|[\]\\]/g, "\\$&") + "]";
|
|
5783
|
+
this.weekdayRe = new RegExp(
|
|
5784
|
+
"(?:^|" + sepsClass + ")(" + buildOrPattern(weekdayWords.length ? weekdayWords : ["\\bnever\\b"]) + ")" + sepsClass + "*$",
|
|
5785
|
+
"i"
|
|
5786
|
+
);
|
|
5787
|
+
}
|
|
5788
|
+
enabled(context) {
|
|
5789
|
+
return !isDisabled(context, "date");
|
|
5790
|
+
}
|
|
5791
|
+
when(matches, _context) {
|
|
5792
|
+
const input = matches.inputString ?? "";
|
|
5793
|
+
const ret = [];
|
|
5794
|
+
for (const dateMatch of matches.named("date") ?? []) {
|
|
5795
|
+
const filepart = matches.markers.atMatch(dateMatch, (m) => m.name === "path", 0);
|
|
5796
|
+
const lower = filepart ? filepart.start : 0;
|
|
5797
|
+
const segment = input.slice(lower, dateMatch.start);
|
|
5798
|
+
const weekday = this.weekdayRe.exec(segment);
|
|
5799
|
+
if (!weekday) continue;
|
|
5800
|
+
const groupStart = lower + weekday.index + weekday[0].indexOf(weekday[1]);
|
|
5801
|
+
const claimed = matches.range(groupStart, dateMatch.start, (m) => !m.private);
|
|
5802
|
+
if ((Array.isArray(claimed) ? claimed.length : claimed ? 1 : 0) > 0) continue;
|
|
5803
|
+
ret.push([dateMatch, groupStart]);
|
|
5804
|
+
}
|
|
5805
|
+
return ret.length ? ret : false;
|
|
5806
|
+
}
|
|
5807
|
+
then(matches, whenResponse, _context) {
|
|
5808
|
+
for (const [dateMatch, newStart] of whenResponse) {
|
|
5809
|
+
matches.remove(dateMatch);
|
|
5810
|
+
dateMatch.start = newStart;
|
|
5811
|
+
matches.append(dateMatch);
|
|
5812
|
+
}
|
|
5813
|
+
}
|
|
5814
|
+
}
|
|
5712
5815
|
function markerComparatorPredicate(m) {
|
|
5713
5816
|
return !m.private && m.name !== "proper_count" && m.name !== "title" && !(m.name === "container" && m.tags?.includes("extension")) && !(m.name === "other" && m.value === "Rip");
|
|
5714
5817
|
}
|
|
@@ -5720,10 +5823,11 @@ function markerWeight(matches, marker, predicate) {
|
|
|
5720
5823
|
}
|
|
5721
5824
|
function markerSorted(markers, matches, predicate = markerComparatorPredicate) {
|
|
5722
5825
|
const markersArr = [...markers];
|
|
5826
|
+
const originalIndex = new Map(markersArr.map((m, i) => [m, i]));
|
|
5723
5827
|
return markersArr.sort((a, b) => {
|
|
5724
5828
|
const weightDiff = markerWeight(matches, b, predicate) - markerWeight(matches, a, predicate);
|
|
5725
5829
|
if (weightDiff !== 0) return weightDiff;
|
|
5726
|
-
return
|
|
5830
|
+
return (originalIndex.get(b) ?? 0) - (originalIndex.get(a) ?? 0);
|
|
5727
5831
|
});
|
|
5728
5832
|
}
|
|
5729
5833
|
function buildExpectedFunction(optionName) {
|
|
@@ -5936,7 +6040,7 @@ const _TitleBaseRule = class _TitleBaseRule extends Rule {
|
|
|
5936
6040
|
* Check and extract titles from a filepart.
|
|
5937
6041
|
* Mirrors Python's TitleBaseRule.check_titles_in_filepart().
|
|
5938
6042
|
*/
|
|
5939
|
-
checkTitlesInFilepart(filepart, matches) {
|
|
6043
|
+
checkTitlesInFilepart(filepart, matches, context) {
|
|
5940
6044
|
const toAppend = [];
|
|
5941
6045
|
const toRemove = [];
|
|
5942
6046
|
const firstYearInFilepart = matches.range(
|
|
@@ -6007,6 +6111,16 @@ const _TitleBaseRule = class _TitleBaseRule extends Rule {
|
|
|
6007
6111
|
(m) => this.isIgnored(m)
|
|
6008
6112
|
);
|
|
6009
6113
|
const ignoredArray = Array.isArray(ignoredInHole) ? ignoredInHole : ignoredInHole ? [ignoredInHole] : [];
|
|
6114
|
+
if (ignoredArray.length > 0 && ignoredArray.every((m) => m.name === "language" || m.name === "country")) {
|
|
6115
|
+
const inpFull = matches.inputString ?? "";
|
|
6116
|
+
let rest = inpFull.slice(hole.start, hole.end);
|
|
6117
|
+
for (const m of ignoredArray) {
|
|
6118
|
+
const rel = m.start - hole.start;
|
|
6119
|
+
rest = rest.slice(0, rel) + " ".repeat(m.end - m.start) + rest.slice(m.end - hole.start);
|
|
6120
|
+
}
|
|
6121
|
+
const hasTitleText = [...rest].some((c) => !seps.includes(c) && c !== " ");
|
|
6122
|
+
if (!hasTitleText) continue;
|
|
6123
|
+
}
|
|
6010
6124
|
let trimmedHole = hole;
|
|
6011
6125
|
const inp = matches.inputString ?? "";
|
|
6012
6126
|
while (trimmedHole.start < trimmedHole.end && seps.includes(inp[trimmedHole.start])) {
|
|
@@ -6112,7 +6226,7 @@ const _TitleBaseRule = class _TitleBaseRule extends Rule {
|
|
|
6112
6226
|
console.log(` result: hole=[${trimmedHole.start},${trimmedHole.end}) length=${trimmedHole.length} value="${trimmedHole.value}"`);
|
|
6113
6227
|
}
|
|
6114
6228
|
if (trimmedHole.length > 0 && !this.shouldRemove(trimmedHole) && trimmedHole.value) {
|
|
6115
|
-
const splitResult = this.splitTitleAlternative(trimmedHole, inp);
|
|
6229
|
+
const splitResult = this.alternativePropertyName && !isDisabled(context, this.alternativePropertyName) ? this.splitTitleAlternative(trimmedHole, inp) : null;
|
|
6116
6230
|
if (splitResult) {
|
|
6117
6231
|
splitResult.title.name = this.matchName;
|
|
6118
6232
|
toAppend.push(splitResult.title);
|
|
@@ -6238,7 +6352,7 @@ const _TitleBaseRule = class _TitleBaseRule extends Rule {
|
|
|
6238
6352
|
for (const filepart of sortedFileparts) {
|
|
6239
6353
|
yearFileparts.delete(filepart);
|
|
6240
6354
|
if (!this.filepartFilter(filepart)) continue;
|
|
6241
|
-
const result = this.checkTitlesInFilepart(filepart, matches);
|
|
6355
|
+
const result = this.checkTitlesInFilepart(filepart, matches, context);
|
|
6242
6356
|
if (result.toAppend.length > 0 || result.toRemove.length > 0) {
|
|
6243
6357
|
if (serieNameMatch) {
|
|
6244
6358
|
const normTitle = (s) => foldDiacritics(s).replace(/[''`]/g, "").replace(/\.+$/, "").toLowerCase().trim();
|
|
@@ -6255,7 +6369,7 @@ const _TitleBaseRule = class _TitleBaseRule extends Rule {
|
|
|
6255
6369
|
}
|
|
6256
6370
|
for (const filepart of yearFileparts) {
|
|
6257
6371
|
if (!this.filepartFilter(filepart)) continue;
|
|
6258
|
-
const result = this.checkTitlesInFilepart(filepart, matches);
|
|
6372
|
+
const result = this.checkTitlesInFilepart(filepart, matches, context);
|
|
6259
6373
|
const filteredAppend = [];
|
|
6260
6374
|
for (const newTitle of result.toAppend) {
|
|
6261
6375
|
if (newTitle.name !== this.matchName) {
|
|
@@ -6389,7 +6503,11 @@ const _ExtendLoneArticleTitle = class _ExtendLoneArticleTitle extends Rule {
|
|
|
6389
6503
|
const inp = matches.inputString || "";
|
|
6390
6504
|
const out = [];
|
|
6391
6505
|
const titles = matches.named("title");
|
|
6392
|
-
const
|
|
6506
|
+
const epTitles = matches.named("episode_title");
|
|
6507
|
+
const titleArr = [
|
|
6508
|
+
...Array.isArray(titles) ? titles : titles ? [titles] : [],
|
|
6509
|
+
...Array.isArray(epTitles) ? epTitles : epTitles ? [epTitles] : []
|
|
6510
|
+
];
|
|
6393
6511
|
for (const title2 of titleArr) {
|
|
6394
6512
|
if (!ARTICLES.has(String(title2.value ?? "").trim().toLowerCase())) continue;
|
|
6395
6513
|
const filepart = matches.markers.atMatch(title2, (m) => m.name === "path", 0);
|
|
@@ -6491,6 +6609,49 @@ const _TitleWordAtTitlePosition = class _TitleWordAtTitlePosition extends Rule {
|
|
|
6491
6609
|
};
|
|
6492
6610
|
_TitleWordAtTitlePosition.priority = 64;
|
|
6493
6611
|
let TitleWordAtTitlePosition = _TitleWordAtTitlePosition;
|
|
6612
|
+
const NON_LATIN_SCRIPT_RE = /[\u0370-\u03FF\u0400-\u04FF\u0590-\u05FF\u0600-\u06FF\u0E00-\u0E7F\u3000-\u303F\u3040-\u30FF\u3400-\u4DBF\u4E00-\u9FFF\uAC00-\uD7AF\uFF00-\uFFEF]/;
|
|
6613
|
+
const _SplitOriginalScriptTitle = class _SplitOriginalScriptTitle extends Rule {
|
|
6614
|
+
constructor() {
|
|
6615
|
+
super(...arguments);
|
|
6616
|
+
this.priority = POST_PROCESS;
|
|
6617
|
+
this.consequence = [RemoveMatch, AppendMatch];
|
|
6618
|
+
}
|
|
6619
|
+
when(matches, context) {
|
|
6620
|
+
if (isDisabled(context, "alternative_title")) return false;
|
|
6621
|
+
const input = matches.inputString ?? "";
|
|
6622
|
+
const toRemove = [];
|
|
6623
|
+
const toAppend = [];
|
|
6624
|
+
for (const titleMatch of matches.named("title")) {
|
|
6625
|
+
if (titleMatch.tags?.includes("expected")) continue;
|
|
6626
|
+
const raw = input.slice(titleMatch.start, titleMatch.end);
|
|
6627
|
+
const latin = new RegExp("(?:^|[" + sepsPattern + "])([A-Za-z])").exec(raw);
|
|
6628
|
+
if (!latin) continue;
|
|
6629
|
+
const latinOffset = latin.index + latin[0].indexOf(latin[1]);
|
|
6630
|
+
const prefix = raw.slice(0, latinOffset);
|
|
6631
|
+
if (!NON_LATIN_SCRIPT_RE.test(prefix)) continue;
|
|
6632
|
+
let prefixTrim = prefix;
|
|
6633
|
+
while (prefixTrim.length && seps.includes(prefixTrim[prefixTrim.length - 1])) prefixTrim = prefixTrim.slice(0, -1);
|
|
6634
|
+
const prefixEnd = titleMatch.start + prefixTrim.length;
|
|
6635
|
+
const latinStart = titleMatch.start + latinOffset;
|
|
6636
|
+
if (prefixEnd <= titleMatch.start) continue;
|
|
6637
|
+
toRemove.push(titleMatch);
|
|
6638
|
+
toAppend.push(new Match(titleMatch.start, prefixEnd, {
|
|
6639
|
+
name: "alternative_title",
|
|
6640
|
+
value: cleanup(input.slice(titleMatch.start, prefixEnd)),
|
|
6641
|
+
inputString: input
|
|
6642
|
+
}));
|
|
6643
|
+
toAppend.push(new Match(latinStart, titleMatch.end, {
|
|
6644
|
+
name: "title",
|
|
6645
|
+
tags: ["title"],
|
|
6646
|
+
value: cleanup(input.slice(latinStart, titleMatch.end)),
|
|
6647
|
+
inputString: input
|
|
6648
|
+
}));
|
|
6649
|
+
}
|
|
6650
|
+
return toRemove.length || toAppend.length ? [toRemove, toAppend] : false;
|
|
6651
|
+
}
|
|
6652
|
+
};
|
|
6653
|
+
_SplitOriginalScriptTitle.priority = POST_PROCESS;
|
|
6654
|
+
let SplitOriginalScriptTitle = _SplitOriginalScriptTitle;
|
|
6494
6655
|
const _PropertyAtTitlePositionAsTitle = class _PropertyAtTitlePositionAsTitle extends Rule {
|
|
6495
6656
|
constructor() {
|
|
6496
6657
|
super(...arguments);
|
|
@@ -6638,7 +6799,7 @@ function title(config) {
|
|
|
6638
6799
|
const rebulk = new Rebulk({
|
|
6639
6800
|
disabled: (context) => isDisabled(context, "title")
|
|
6640
6801
|
});
|
|
6641
|
-
rebulk.rules(CountryAtTitlePosition, TitleWordAtTitlePosition, TitleFromPosition, PreferTitleWithYear, ExtendLoneArticleTitle, PropertyAtTitlePositionAsTitle, RemoveNumericAlternativeTitle, RemoveTailAlternativeTitle, RemoveTailTitle);
|
|
6802
|
+
rebulk.rules(CountryAtTitlePosition, TitleWordAtTitlePosition, SplitOriginalScriptTitle, TitleFromPosition, PreferTitleWithYear, ExtendLoneArticleTitle, PropertyAtTitlePositionAsTitle, RemoveNumericAlternativeTitle, RemoveTailAlternativeTitle, RemoveTailTitle);
|
|
6642
6803
|
const expectedTitle = buildExpectedFunction("expected_title");
|
|
6643
6804
|
rebulk.functional(expectedTitle, {
|
|
6644
6805
|
name: "title",
|
|
@@ -7428,7 +7589,9 @@ class Filepart2EpisodeTitle extends Rule {
|
|
|
7428
7589
|
);
|
|
7429
7590
|
if (episodeNumber) {
|
|
7430
7591
|
const season = matches.range(directory.start, directory.end, (m) => m.name === "season", 0) || matches.range(filename.start, filename.end, (m) => m.name === "season", 0);
|
|
7431
|
-
|
|
7592
|
+
const anySeason = matches.named("season");
|
|
7593
|
+
const hasAnySeason = Array.isArray(anySeason) ? anySeason.length > 0 : !!anySeason;
|
|
7594
|
+
if (season || !hasAnySeason) {
|
|
7432
7595
|
const hole = parentTitleHole(matches, directory.start, directory.end);
|
|
7433
7596
|
if (hole) {
|
|
7434
7597
|
const groupMarkers = matches.markers.named("group");
|
|
@@ -8627,14 +8790,6 @@ class DashSeparatedReleaseGroup extends Rule {
|
|
|
8627
8790
|
if (matches.range(candidate.start, candidate.end, (m) => m.name === "episode", 0)) {
|
|
8628
8791
|
return false;
|
|
8629
8792
|
}
|
|
8630
|
-
if (candidate.start === start && matches.range(
|
|
8631
|
-
candidate.end,
|
|
8632
|
-
end,
|
|
8633
|
-
(m) => ["season", "episode", "date"].includes(m.name ?? "") && !m.private,
|
|
8634
|
-
0
|
|
8635
|
-
)) {
|
|
8636
|
-
return false;
|
|
8637
|
-
}
|
|
8638
8793
|
const firstHole = matches.holes(
|
|
8639
8794
|
candidate.end,
|
|
8640
8795
|
end,
|
|
@@ -8643,6 +8798,16 @@ class DashSeparatedReleaseGroup extends Rule {
|
|
|
8643
8798
|
if (!firstHole) {
|
|
8644
8799
|
return false;
|
|
8645
8800
|
}
|
|
8801
|
+
const holeRaw = String(firstHole.raw ?? "");
|
|
8802
|
+
const holeCore = holeRaw.replace(new RegExp("^[" + sepsPattern + "]+|[" + sepsPattern + "]+$", "g"), "");
|
|
8803
|
+
if (candidate.start === start && !holeCore.includes(".") && !holeCore.includes(" ") && matches.range(
|
|
8804
|
+
candidate.end,
|
|
8805
|
+
end,
|
|
8806
|
+
(m) => ["season", "episode", "date"].includes(m.name ?? "") && !m.private,
|
|
8807
|
+
0
|
|
8808
|
+
)) {
|
|
8809
|
+
return false;
|
|
8810
|
+
}
|
|
8646
8811
|
const rawValue = firstHole.raw;
|
|
8647
8812
|
return rawValue[0] === "-" && !rawValue.slice(1).includes("-") && rawValue.includes(".") && !rawValue.includes(" ");
|
|
8648
8813
|
}
|
|
@@ -8811,6 +8976,32 @@ const _SceneReleaseGroup = class _SceneReleaseGroup extends Rule {
|
|
|
8811
8976
|
}
|
|
8812
8977
|
);
|
|
8813
8978
|
if (lastHole) {
|
|
8979
|
+
const holeGroup = matches.markers.atMatch(lastHole, (m) => m.name === "group", 0);
|
|
8980
|
+
if (holeGroup && String(holeGroup.raw ?? "").startsWith("(")) {
|
|
8981
|
+
const hasEpisodeish = (matches.range(
|
|
8982
|
+
start,
|
|
8983
|
+
end,
|
|
8984
|
+
(m) => m.name === "episode" || m.name === "season"
|
|
8985
|
+
) ?? []).length > 0;
|
|
8986
|
+
if (hasEpisodeish) {
|
|
8987
|
+
const firstGroup = matches.markers.range(
|
|
8988
|
+
start,
|
|
8989
|
+
end,
|
|
8990
|
+
(m) => m.name === "group" && m.start === start,
|
|
8991
|
+
0
|
|
8992
|
+
);
|
|
8993
|
+
if (firstGroup) {
|
|
8994
|
+
const inner = matches.range(
|
|
8995
|
+
firstGroup.start,
|
|
8996
|
+
firstGroup.end,
|
|
8997
|
+
(mm) => !mm.tags.includes("weak-language")
|
|
8998
|
+
) ?? [];
|
|
8999
|
+
const core = String(firstGroup.value ?? "").replace(new RegExp(`[${sepsPattern}]`, "g"), "");
|
|
9000
|
+
const emptyish = inner.length === 0 || inner.every((mm) => mm.name === "container" && mm.tags?.includes("subtitle"));
|
|
9001
|
+
if (emptyish && core && !intCoercable(core)) continue;
|
|
9002
|
+
}
|
|
9003
|
+
}
|
|
9004
|
+
}
|
|
8814
9005
|
const previousMatchFilter = (match) => {
|
|
8815
9006
|
if (match.start < filepart.start) {
|
|
8816
9007
|
return false;
|
|
@@ -8874,7 +9065,6 @@ const _AnimeReleaseGroup = class _AnimeReleaseGroup extends Rule {
|
|
|
8874
9065
|
(mm) => !mm.tags.includes("weak-language")
|
|
8875
9066
|
);
|
|
8876
9067
|
if (innerMatches.length === 0) return true;
|
|
8877
|
-
if (innerMatches.every((mm) => mm.name === "other")) return true;
|
|
8878
9068
|
if (m.start === filepart.start && innerMatches.every((mm) => mm.name === "container" && mm.tags?.includes("subtitle"))) {
|
|
8879
9069
|
return true;
|
|
8880
9070
|
}
|
|
@@ -9917,9 +10107,35 @@ function film(config) {
|
|
|
9917
10107
|
rebulk.regexDefaults({ flags: "i", abbreviations: [dash] }).stringDefaults({ ignoreCase: true });
|
|
9918
10108
|
rebulk.defaults({ name: "film", validator: sepsSurround });
|
|
9919
10109
|
loadConfigPatterns(rebulk, config["film"]);
|
|
9920
|
-
rebulk.rules(FilmTitleRule);
|
|
10110
|
+
rebulk.rules(LeadingFilmNumberRule, FilmTitleRule);
|
|
9921
10111
|
return rebulk;
|
|
9922
10112
|
}
|
|
10113
|
+
const _LeadingFilmNumberRule = class _LeadingFilmNumberRule extends Rule {
|
|
10114
|
+
constructor() {
|
|
10115
|
+
super(...arguments);
|
|
10116
|
+
this.consequence = RemoveMatch;
|
|
10117
|
+
}
|
|
10118
|
+
when(matches, _context) {
|
|
10119
|
+
const toRemove = [];
|
|
10120
|
+
const films = matches.named("film", (m) => !m.private) ?? [];
|
|
10121
|
+
for (const filmMatch of Array.isArray(films) ? films : [films]) {
|
|
10122
|
+
const filepath = matches.markers.atMatch(filmMatch, (m) => m.name === "path", 0);
|
|
10123
|
+
if (!filepath) continue;
|
|
10124
|
+
const hole = matches.holes(
|
|
10125
|
+
filepath.start,
|
|
10126
|
+
filmMatch.start + 1,
|
|
10127
|
+
{ formatter: cleanup, index: 0 }
|
|
10128
|
+
);
|
|
10129
|
+
if (!(hole && hole.value)) {
|
|
10130
|
+
toRemove.push(filmMatch);
|
|
10131
|
+
if (filmMatch.parent) toRemove.push(filmMatch.parent);
|
|
10132
|
+
}
|
|
10133
|
+
}
|
|
10134
|
+
return toRemove.length ? toRemove : false;
|
|
10135
|
+
}
|
|
10136
|
+
};
|
|
10137
|
+
_LeadingFilmNumberRule.consequence = RemoveMatch;
|
|
10138
|
+
let LeadingFilmNumberRule = _LeadingFilmNumberRule;
|
|
9923
10139
|
const _FilmTitleRule = class _FilmTitleRule extends Rule {
|
|
9924
10140
|
enabled(context) {
|
|
9925
10141
|
return !isDisabled(context, "film_title");
|
|
@@ -10484,17 +10700,40 @@ const _RemoveAmbiguous = class _RemoveAmbiguous extends Rule {
|
|
|
10484
10700
|
_RemoveAmbiguous.priority = POST_PROCESS;
|
|
10485
10701
|
_RemoveAmbiguous.consequence = RemoveMatch;
|
|
10486
10702
|
let RemoveAmbiguous = _RemoveAmbiguous;
|
|
10703
|
+
const sxxExxWeightPredicate = (m) => (m.name === "season" || m.name === "episode") && m.tags.includes("SxxExx");
|
|
10487
10704
|
class RemoveLessSpecificSeasonEpisode extends RemoveAmbiguous {
|
|
10488
10705
|
constructor(name) {
|
|
10489
10706
|
super(
|
|
10490
|
-
|
|
10491
|
-
|
|
10492
|
-
|
|
10493
|
-
|
|
10494
|
-
),
|
|
10707
|
+
// Sort fileparts most-valuable-first: a SxxExx-tagged season/episode outweighs a
|
|
10708
|
+
// weaker one, so the filename's S44E03 beats a season-only or weak-number parent
|
|
10709
|
+
// directory (upstream #797/#772).
|
|
10710
|
+
(markers, matches) => markerSorted(markers, matches, sxxExxWeightPredicate),
|
|
10495
10711
|
(m) => m.name === name
|
|
10496
10712
|
);
|
|
10497
10713
|
}
|
|
10714
|
+
when(matches, context) {
|
|
10715
|
+
const markers = matches.markers.named("path");
|
|
10716
|
+
const markerArr = Array.isArray(markers) ? markers : markers ? [markers] : [];
|
|
10717
|
+
if (markerArr.length > 1) {
|
|
10718
|
+
const weights = markerArr.map((marker) => {
|
|
10719
|
+
const inRange = matches.range(marker.start, marker.end, sxxExxWeightPredicate);
|
|
10720
|
+
return new Set((Array.isArray(inRange) ? inRange : []).map((m) => m.name)).size;
|
|
10721
|
+
});
|
|
10722
|
+
const top = Math.max(...weights);
|
|
10723
|
+
if (weights.filter((w) => w === top).length > 1) return [];
|
|
10724
|
+
}
|
|
10725
|
+
return super.when(matches, context);
|
|
10726
|
+
}
|
|
10727
|
+
}
|
|
10728
|
+
class RemoveLessSpecificSeason extends RemoveLessSpecificSeasonEpisode {
|
|
10729
|
+
constructor() {
|
|
10730
|
+
super("season");
|
|
10731
|
+
}
|
|
10732
|
+
}
|
|
10733
|
+
class RemoveLessSpecificEpisode extends RemoveLessSpecificSeasonEpisode {
|
|
10734
|
+
constructor() {
|
|
10735
|
+
super("episode");
|
|
10736
|
+
}
|
|
10498
10737
|
}
|
|
10499
10738
|
const _SeasonYear = class _SeasonYear extends Rule {
|
|
10500
10739
|
when(matches, _context) {
|
|
@@ -10587,8 +10826,8 @@ function processors(_config) {
|
|
|
10587
10826
|
return new Rebulk().rules(
|
|
10588
10827
|
EnlargeGroupMatches,
|
|
10589
10828
|
EquivalentHoles,
|
|
10590
|
-
|
|
10591
|
-
|
|
10829
|
+
RemoveLessSpecificSeason,
|
|
10830
|
+
RemoveLessSpecificEpisode,
|
|
10592
10831
|
RemoveAmbiguous,
|
|
10593
10832
|
SeasonYear,
|
|
10594
10833
|
YearSeason,
|
|
@@ -12301,6 +12540,26 @@ const advanced_config = {
|
|
|
12301
12540
|
date: {
|
|
12302
12541
|
week_words: [
|
|
12303
12542
|
"week"
|
|
12543
|
+
],
|
|
12544
|
+
weekday_words: [
|
|
12545
|
+
"monday",
|
|
12546
|
+
"tuesday",
|
|
12547
|
+
"wednesday",
|
|
12548
|
+
"thursday",
|
|
12549
|
+
"friday",
|
|
12550
|
+
"saturday",
|
|
12551
|
+
"sunday",
|
|
12552
|
+
"mon",
|
|
12553
|
+
"tue",
|
|
12554
|
+
"tues",
|
|
12555
|
+
"wed",
|
|
12556
|
+
"weds",
|
|
12557
|
+
"thu",
|
|
12558
|
+
"thur",
|
|
12559
|
+
"thurs",
|
|
12560
|
+
"fri",
|
|
12561
|
+
"sat",
|
|
12562
|
+
"sun"
|
|
12304
12563
|
]
|
|
12305
12564
|
}
|
|
12306
12565
|
};
|