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