guessit-js 4.1.0 → 4.3.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 +597 -56
- package/dist/guessit-js.cjs.map +1 -1
- package/dist/guessit-js.js +597 -56
- 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,20 @@ function episodesSeasonChainBreaker(matches, config) {
|
|
|
3289
3289
|
return false;
|
|
3290
3290
|
}
|
|
3291
3291
|
function seasonEpisodeConflictSolver(match, other2) {
|
|
3292
|
+
const weakFamily = (m) => !!(m?.tags?.includes("weak-episode") || ["weak_episode", "weak_duplicate"].includes(m?.initiator?.name) || ["weak_episode", "weak_duplicate"].includes(m?.name));
|
|
3293
|
+
if (weakFamily(match) && weakFamily(other2)) return null;
|
|
3294
|
+
const famChild = (p) => {
|
|
3295
|
+
if (p?.name) return null;
|
|
3296
|
+
const ch = [...p?.children ?? []];
|
|
3297
|
+
return ch.find((c) => c.name === "season" || c.name === "episode") ?? null;
|
|
3298
|
+
};
|
|
3299
|
+
const mChild = famChild(match);
|
|
3300
|
+
const oChild = famChild(other2);
|
|
3301
|
+
if (mChild && oChild) {
|
|
3302
|
+
const mNumfirst = !!mChild.tags?.includes("numfirst");
|
|
3303
|
+
const oNumfirst = !!oChild.tags?.includes("numfirst");
|
|
3304
|
+
if (mNumfirst !== oNumfirst) return null;
|
|
3305
|
+
}
|
|
3292
3306
|
if (match.name !== other2.name) {
|
|
3293
3307
|
if (match.name === "episode" && other2.name === "year") {
|
|
3294
3308
|
return match;
|
|
@@ -3300,6 +3314,10 @@ function seasonEpisodeConflictSolver(match, other2) {
|
|
|
3300
3314
|
"container",
|
|
3301
3315
|
"date"
|
|
3302
3316
|
].includes(other2.name)) {
|
|
3317
|
+
if (other2.name === "video_codec" && /^[hx][\W_]\d/i.test(String(other2.raw ?? ""))) {
|
|
3318
|
+
const before = (other2.inputString ?? "")[other2.start - 1] ?? "";
|
|
3319
|
+
if (/[a-z]/i.test(before)) return other2;
|
|
3320
|
+
}
|
|
3303
3321
|
return match;
|
|
3304
3322
|
}
|
|
3305
3323
|
if (other2.name === "audio_channels" && !other2.tags?.includes("weak-audio_channels") && !match.initiator?.children?.named(match.name + "Marker")?.length || other2.name === "screen_size" && !intCoercable(other2.raw)) {
|
|
@@ -3320,7 +3338,7 @@ function seasonEpisodeConflictSolver(match, other2) {
|
|
|
3320
3338
|
while (i >= 0 && i < input.length && seps.includes(input[i])) i += dir;
|
|
3321
3339
|
let tok = "";
|
|
3322
3340
|
while (i >= 0 && i < input.length && /\d/.test(input[i])) {
|
|
3323
|
-
tok =
|
|
3341
|
+
tok = tok + input[i];
|
|
3324
3342
|
i += dir;
|
|
3325
3343
|
}
|
|
3326
3344
|
return tok;
|
|
@@ -3333,8 +3351,9 @@ function seasonEpisodeConflictSolver(match, other2) {
|
|
|
3333
3351
|
return t.length >= 1 && t.length <= 4 && !isYearLike(t);
|
|
3334
3352
|
})();
|
|
3335
3353
|
const wfDangling = (() => {
|
|
3336
|
-
const
|
|
3337
|
-
|
|
3354
|
+
const before = input.slice(Math.max(0, wfInit.start - 12), wfInit.start);
|
|
3355
|
+
const m = /(\d{1,3})(?:ª|º|°|a|o|-?(?:й|я|е|го|ая|ый|ое))?[\s.,_\-–]*$/iu.exec(before);
|
|
3356
|
+
return !!(m && !isYearLike(m[1]));
|
|
3338
3357
|
})();
|
|
3339
3358
|
if (wfDangling && !nfDangling) return wf;
|
|
3340
3359
|
return nf;
|
|
@@ -3342,7 +3361,7 @@ function seasonEpisodeConflictSolver(match, other2) {
|
|
|
3342
3361
|
const matchIsWeak = !!(match.tags?.includes("weak-episode") || ["weak_episode", "weak_duplicate"].includes(match.initiator?.name));
|
|
3343
3362
|
const otherIsWeak = !!(other2.tags?.includes("weak-episode") || ["weak_episode", "weak_duplicate"].includes(other2.initiator?.name));
|
|
3344
3363
|
if (matchIsWeak && otherIsWeak) {
|
|
3345
|
-
return
|
|
3364
|
+
return null;
|
|
3346
3365
|
}
|
|
3347
3366
|
if (matchIsWeak) return match;
|
|
3348
3367
|
if (otherIsWeak) return other2;
|
|
@@ -3390,11 +3409,41 @@ function seasonWordNotYear(match) {
|
|
|
3390
3409
|
function episodes(config) {
|
|
3391
3410
|
config.range_separators;
|
|
3392
3411
|
const discreteSeparators = config.discrete_separators;
|
|
3393
|
-
seps.split("").filter((s) => !config.range_separators.includes(s));
|
|
3412
|
+
const weakDiscreteSeparators = seps.split("").filter((s) => !config.range_separators.includes(s) && s !== "/" && s !== "\\");
|
|
3394
3413
|
const allSeparators = [
|
|
3395
3414
|
...config.range_separators,
|
|
3396
|
-
...discreteSeparators
|
|
3415
|
+
...discreteSeparators,
|
|
3416
|
+
...weakDiscreteSeparators
|
|
3397
3417
|
];
|
|
3418
|
+
const moduleOrderingValidator = orderingValidator;
|
|
3419
|
+
const localOrderingValidator = (match) => {
|
|
3420
|
+
if (!moduleOrderingValidator(match)) return false;
|
|
3421
|
+
const isConsecutive = (prop) => {
|
|
3422
|
+
let previous = null;
|
|
3423
|
+
let valid = true;
|
|
3424
|
+
const children = match.children;
|
|
3425
|
+
const named = children?.named?.(prop) ?? [];
|
|
3426
|
+
for (const current of Array.isArray(named) ? named : [named]) {
|
|
3427
|
+
if (previous) {
|
|
3428
|
+
const separator = children.previous?.(current, (m) => m.name === prop + "Separator", 0);
|
|
3429
|
+
if (separator) {
|
|
3430
|
+
const sraw = String(separator.raw ?? "");
|
|
3431
|
+
if (!config.range_separators.includes(sraw) && weakDiscreteSeparators.includes(sraw)) {
|
|
3432
|
+
const gap = Number(current.value) - Number(previous.value);
|
|
3433
|
+
if (!(gap > 0 && gap <= config.max_range_gap + 1)) valid = false;
|
|
3434
|
+
}
|
|
3435
|
+
if (discreteSeparators.includes(sraw)) {
|
|
3436
|
+
valid = true;
|
|
3437
|
+
break;
|
|
3438
|
+
}
|
|
3439
|
+
}
|
|
3440
|
+
}
|
|
3441
|
+
previous = current;
|
|
3442
|
+
}
|
|
3443
|
+
return valid;
|
|
3444
|
+
};
|
|
3445
|
+
return isConsecutive("episode") && isConsecutive("season");
|
|
3446
|
+
};
|
|
3398
3447
|
const wordNumerals = [
|
|
3399
3448
|
"zero",
|
|
3400
3449
|
"one",
|
|
@@ -3466,7 +3515,7 @@ function episodes(config) {
|
|
|
3466
3515
|
tags: ["SxxExx"],
|
|
3467
3516
|
validateAll: true,
|
|
3468
3517
|
validator: {
|
|
3469
|
-
__parent__: and_(sepsSurround,
|
|
3518
|
+
__parent__: and_(sepsSurround, localOrderingValidator)
|
|
3470
3519
|
},
|
|
3471
3520
|
chainBreaker: (matches) => episodesSeasonChainBreaker(matches, config),
|
|
3472
3521
|
disabled: isSeasonEpisodeDisabled
|
|
@@ -3485,7 +3534,7 @@ function episodes(config) {
|
|
|
3485
3534
|
},
|
|
3486
3535
|
disabled: isSeasonEpisodeDisabled
|
|
3487
3536
|
}).defaults({ tags: ["SxxExx"] }).regex(
|
|
3488
|
-
`(?<season>\\d+)` + asymmetricSeasonEpMarker + `@?` + seasonEpMarkerPattern + `@?(?<episode>\\d+)`
|
|
3537
|
+
`(?!0x[0-9a-fA-F])(?<season>\\d+)` + asymmetricSeasonEpMarker + `@?` + seasonEpMarkerPattern + `@?(?<episode>\\d+)`
|
|
3489
3538
|
).repeater("+");
|
|
3490
3539
|
rebulk.chain({
|
|
3491
3540
|
tags: ["SxxExx"],
|
|
@@ -3494,7 +3543,7 @@ function episodes(config) {
|
|
|
3494
3543
|
__parent__: and_(sepsSurround, orderingValidator)
|
|
3495
3544
|
},
|
|
3496
3545
|
disabled: isSeasonEpisodeDisabled
|
|
3497
|
-
}).defaults({ tags: ["SxxExx"] }).regex(`(?<season>\\d+)` + asymmetricSeasonEpMarker + `@?` + seasonEpMarkerPattern + `@?(?<episode>\\d+)`).regex(
|
|
3546
|
+
}).defaults({ tags: ["SxxExx"] }).regex(`(?!0x[0-9a-fA-F])(?<season>\\d+)` + asymmetricSeasonEpMarker + `@?` + seasonEpMarkerPattern + `@?(?<episode>\\d+)`).regex(
|
|
3498
3547
|
buildOrPattern(
|
|
3499
3548
|
[...config.season_ep_markers, ...discreteSeparators, ...config.range_separators],
|
|
3500
3549
|
"episodeSeparator",
|
|
@@ -3505,6 +3554,14 @@ function episodes(config) {
|
|
|
3505
3554
|
`t(?<season>\\d{1,2})@?` + buildOrPattern(config.episode_markers, "episodeMarker") + `@?(?<episode>\\d{1,4})`,
|
|
3506
3555
|
{ tags: ["SxxExx"], disabled: isSeasonEpisodeDisabled }
|
|
3507
3556
|
);
|
|
3557
|
+
rebulk.regex(
|
|
3558
|
+
`(?<![^\\W_])(?:SP|EX|OVA|OAV)-?(?<episode>\\d{1,3})(?![^\\W_])`,
|
|
3559
|
+
{ tags: ["SxxExx", "special-episode"], disabled: (context) => isDisabled(context, "episode") }
|
|
3560
|
+
);
|
|
3561
|
+
rebulk.regex(
|
|
3562
|
+
`(?<season>\\d{1,2})(?:st|nd|rd|th)@?(?:season)(?![^\\W_])`,
|
|
3563
|
+
{ tags: ["SxxExx", "numfirst"], disabled: isSeasonEpisodeDisabled }
|
|
3564
|
+
);
|
|
3508
3565
|
const seasonOnlySepPattern = buildOrPattern(
|
|
3509
3566
|
[...config.season_markers, ...discreteSeparators, ...config.range_separators],
|
|
3510
3567
|
"seasonSeparator",
|
|
@@ -3600,13 +3657,13 @@ function episodes(config) {
|
|
|
3600
3657
|
rebulk.chain({
|
|
3601
3658
|
tags: ["weak-episode"],
|
|
3602
3659
|
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})`, {
|
|
3660
|
+
}).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
3661
|
abbreviations: null
|
|
3605
3662
|
}).repeater("*");
|
|
3606
3663
|
rebulk.chain({
|
|
3607
3664
|
tags: ["weak-episode"],
|
|
3608
3665
|
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})`, {
|
|
3666
|
+
}).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
3667
|
abbreviations: null
|
|
3611
3668
|
}).repeater("*");
|
|
3612
3669
|
rebulk.chain({
|
|
@@ -3617,13 +3674,13 @@ function episodes(config) {
|
|
|
3617
3674
|
validator: null,
|
|
3618
3675
|
tags: ["weak-episode"],
|
|
3619
3676
|
name: "weak_episode"
|
|
3620
|
-
}).regex(`(?<episode>\\d{3,4})`).regex(`v(?<version>\\d+)`).repeater("?").regex(`(?<episodeSeparator>[x-])(?<episode>\\d{3,4})`, {
|
|
3677
|
+
}).regex(`(?<![^\\W_])(?<episode>\\d{3,4})(?!(?![vV]\\d)[^\\W_])`).regex(`v(?<version>\\d+)`).repeater("?").regex(`(?<episodeSeparator>[x-])(?<episode>\\d{3,4})`, {
|
|
3621
3678
|
abbreviations: null
|
|
3622
3679
|
}).repeater("*");
|
|
3623
3680
|
rebulk.chain({
|
|
3624
3681
|
tags: ["weak-episode"],
|
|
3625
3682
|
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})`, {
|
|
3683
|
+
}).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
3684
|
abbreviations: null
|
|
3628
3685
|
}).repeater("*");
|
|
3629
3686
|
rebulk.chain({
|
|
@@ -3652,7 +3709,7 @@ function episodes(config) {
|
|
|
3652
3709
|
name: "weak_duplicate",
|
|
3653
3710
|
validator: null,
|
|
3654
3711
|
conflictSolver: seasonEpisodeConflictSolver
|
|
3655
|
-
}).regex(`(?<season>\\d{1,2})(?<episode>\\d{2})`).regex(`v(?<version>\\d+)`).repeater("?").regex(`(?<episodeSeparator>x|-)(?<episode>\\d{2})`, {
|
|
3712
|
+
}).regex(`(?<![^\\W_])(?<season>\\d{1,2})(?<episode>\\d{2})(?!(?![vV]\\d)[^\\W_])`).regex(`v(?<version>\\d+)`).repeater("?").regex(`(?<episodeSeparator>x|-)(?<episode>\\d{2})`, {
|
|
3656
3713
|
abbreviations: null
|
|
3657
3714
|
}).repeater("*");
|
|
3658
3715
|
rebulk.regex(`v(?<version>\\d+)`, {
|
|
@@ -3680,6 +3737,9 @@ function episodes(config) {
|
|
|
3680
3737
|
disabled: (context) => isDisabled(context, "episode_format")
|
|
3681
3738
|
});
|
|
3682
3739
|
rebulk.rules(
|
|
3740
|
+
AnimeTrailingEpisodeRule,
|
|
3741
|
+
PreferAnchoredWeakEpisodeRule,
|
|
3742
|
+
SeasonWordDashedEpisodeRule,
|
|
3683
3743
|
RemoveNumfirstMarkerCollision,
|
|
3684
3744
|
CountValidator,
|
|
3685
3745
|
new DiscMarkerRule(config),
|
|
@@ -3695,6 +3755,178 @@ function episodes(config) {
|
|
|
3695
3755
|
);
|
|
3696
3756
|
return rebulk;
|
|
3697
3757
|
}
|
|
3758
|
+
const _AnimeTrailingEpisodeRule = class _AnimeTrailingEpisodeRule extends Rule {
|
|
3759
|
+
constructor() {
|
|
3760
|
+
super(...arguments);
|
|
3761
|
+
this.priority = -64;
|
|
3762
|
+
this.consequence = [RemoveMatch, AppendMatch];
|
|
3763
|
+
}
|
|
3764
|
+
when(matches, _context) {
|
|
3765
|
+
const input = matches.inputString ?? "";
|
|
3766
|
+
const toRemove = [];
|
|
3767
|
+
const toAppend = [];
|
|
3768
|
+
const episodes2 = matches.named("episode") ?? [];
|
|
3769
|
+
if (episodes2.length) return false;
|
|
3770
|
+
for (const filepart of matches.markers.named("path") ?? []) {
|
|
3771
|
+
const crc2 = matches.range(filepart.start, filepart.end, (m2) => m2.name === "crc32", 0);
|
|
3772
|
+
const animeRg = matches.range(
|
|
3773
|
+
filepart.start,
|
|
3774
|
+
filepart.end,
|
|
3775
|
+
(m2) => m2.name === "release_group" && m2.tags?.includes("anime"),
|
|
3776
|
+
0
|
|
3777
|
+
);
|
|
3778
|
+
if (!crc2 && !animeRg) continue;
|
|
3779
|
+
let done = false;
|
|
3780
|
+
for (const group of matches.markers.range(filepart.start, filepart.end, (m2) => m2.name === "group") ?? []) {
|
|
3781
|
+
const core = input.slice(group.start + 1, group.end - 1).trim();
|
|
3782
|
+
if (!/^\d{1,3}$/.test(core)) continue;
|
|
3783
|
+
const inner = matches.range(group.start, group.end, (m2) => !m2.private) ?? [];
|
|
3784
|
+
if (inner.some((m2) => !["alternative_title", "episode_title"].includes(m2.name ?? "") && !m2.tags?.includes("weak-episode"))) continue;
|
|
3785
|
+
toRemove.push(...inner);
|
|
3786
|
+
toAppend.push(new Match(group.start + 1, group.end - 1, {
|
|
3787
|
+
name: "episode",
|
|
3788
|
+
value: parseInt(core, 10),
|
|
3789
|
+
inputString: input,
|
|
3790
|
+
tags: ["anime"]
|
|
3791
|
+
}));
|
|
3792
|
+
done = true;
|
|
3793
|
+
break;
|
|
3794
|
+
}
|
|
3795
|
+
if (done) continue;
|
|
3796
|
+
const title2 = matches.range(filepart.start, filepart.end, (m2) => m2.name === "title", 0);
|
|
3797
|
+
if (!title2) continue;
|
|
3798
|
+
const m = /^(.*[^\W\d_])[\s._-]+(\d{1,3})$/.exec(input.slice(title2.start, title2.end));
|
|
3799
|
+
if (!m) continue;
|
|
3800
|
+
const numStart = title2.start + m[1].length + (m[0].length - m[1].length - m[2].length);
|
|
3801
|
+
toRemove.push(title2);
|
|
3802
|
+
const newTitle = new Match(title2.start, title2.start + m[1].length, {
|
|
3803
|
+
name: "title",
|
|
3804
|
+
value: cleanup(m[1]),
|
|
3805
|
+
inputString: input
|
|
3806
|
+
});
|
|
3807
|
+
toAppend.push(newTitle);
|
|
3808
|
+
toAppend.push(new Match(numStart, title2.end, {
|
|
3809
|
+
name: "episode",
|
|
3810
|
+
value: parseInt(m[2], 10),
|
|
3811
|
+
inputString: input,
|
|
3812
|
+
tags: ["anime"]
|
|
3813
|
+
}));
|
|
3814
|
+
}
|
|
3815
|
+
return toRemove.length || toAppend.length ? [toRemove, toAppend] : false;
|
|
3816
|
+
}
|
|
3817
|
+
};
|
|
3818
|
+
_AnimeTrailingEpisodeRule.priority = -64;
|
|
3819
|
+
let AnimeTrailingEpisodeRule = _AnimeTrailingEpisodeRule;
|
|
3820
|
+
const _PreferAnchoredWeakEpisodeRule = class _PreferAnchoredWeakEpisodeRule extends Rule {
|
|
3821
|
+
constructor() {
|
|
3822
|
+
super(...arguments);
|
|
3823
|
+
this.priority = 40;
|
|
3824
|
+
this.consequence = RemoveMatch;
|
|
3825
|
+
}
|
|
3826
|
+
when(matches, _context) {
|
|
3827
|
+
const input = matches.inputString ?? "";
|
|
3828
|
+
const toRemove = [];
|
|
3829
|
+
const isWeakEp = (m) => m.name === "episode" && !m.private && (m.tags?.includes("weak-episode") || ["weak_episode", "weak_duplicate"].includes(m.initiator?.name));
|
|
3830
|
+
const removeGroup = (init) => {
|
|
3831
|
+
for (const c of [...init.children ?? [], init]) {
|
|
3832
|
+
if (!toRemove.includes(c)) toRemove.push(c);
|
|
3833
|
+
}
|
|
3834
|
+
if (!init.children?.length && !toRemove.includes(init)) toRemove.push(init);
|
|
3835
|
+
};
|
|
3836
|
+
for (const filepart of matches.markers.named("path") ?? []) {
|
|
3837
|
+
const weaks = matches.range(filepart.start, filepart.end, isWeakEp) ?? [];
|
|
3838
|
+
if (!weaks.length) continue;
|
|
3839
|
+
const strong = matches.range(filepart.start, filepart.end, (m) => m.name === "episode" && !m.private && !isWeakEp(m) && !!m.initiator?.children?.named?.("episodeMarker")?.length, 0);
|
|
3840
|
+
const byInit = /* @__PURE__ */ new Map();
|
|
3841
|
+
for (const w of weaks) {
|
|
3842
|
+
const init = w.initiator ?? w;
|
|
3843
|
+
byInit.set(init, [...byInit.get(init) ?? [], w]);
|
|
3844
|
+
}
|
|
3845
|
+
if (strong) {
|
|
3846
|
+
for (const init of byInit.keys()) removeGroup(init);
|
|
3847
|
+
continue;
|
|
3848
|
+
}
|
|
3849
|
+
if (byInit.size < 2) continue;
|
|
3850
|
+
const score = (init) => {
|
|
3851
|
+
let sc = 0;
|
|
3852
|
+
const raw = String(init.raw ?? "");
|
|
3853
|
+
if (/^0\d/.test(raw)) sc += 4;
|
|
3854
|
+
let i = init.start - 1;
|
|
3855
|
+
while (i >= 0 && (input[i] === " " || input[i] === "." || input[i] === "_")) i--;
|
|
3856
|
+
if (input[i] === "-") sc += 1;
|
|
3857
|
+
if (matches.markers.atMatch(init, (m) => m.name === "group", 0)) sc -= 2;
|
|
3858
|
+
return sc;
|
|
3859
|
+
};
|
|
3860
|
+
const scored = [...byInit.keys()].map((init) => [init, score(init)]);
|
|
3861
|
+
const top = Math.max(...scored.map(([, sc]) => sc));
|
|
3862
|
+
const winners = scored.filter(([, sc]) => sc === top);
|
|
3863
|
+
if (winners.length === scored.length) continue;
|
|
3864
|
+
const winnerValues = new Set(winners.flatMap(([init]) => (byInit.get(init) ?? []).map((w) => Number(w.value))));
|
|
3865
|
+
for (const [init, sc] of scored) {
|
|
3866
|
+
if (sc >= top) continue;
|
|
3867
|
+
const eps = byInit.get(init) ?? [];
|
|
3868
|
+
if (eps.length > 1) continue;
|
|
3869
|
+
if (eps.some((w) => winnerValues.has(Number(w.value)))) continue;
|
|
3870
|
+
removeGroup(init);
|
|
3871
|
+
}
|
|
3872
|
+
}
|
|
3873
|
+
return toRemove.length ? toRemove : false;
|
|
3874
|
+
}
|
|
3875
|
+
};
|
|
3876
|
+
_PreferAnchoredWeakEpisodeRule.priority = 40;
|
|
3877
|
+
let PreferAnchoredWeakEpisodeRule = _PreferAnchoredWeakEpisodeRule;
|
|
3878
|
+
const _SeasonWordDashedEpisodeRule = class _SeasonWordDashedEpisodeRule extends Rule {
|
|
3879
|
+
constructor() {
|
|
3880
|
+
super(...arguments);
|
|
3881
|
+
this.priority = 32;
|
|
3882
|
+
this.consequence = [RemoveMatch, AppendMatch];
|
|
3883
|
+
}
|
|
3884
|
+
when(matches, _context) {
|
|
3885
|
+
const input = matches.inputString ?? "";
|
|
3886
|
+
const toRemove = [];
|
|
3887
|
+
const toAppend = [];
|
|
3888
|
+
const seasons = matches.named("season") ?? [];
|
|
3889
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3890
|
+
for (const season of seasons) {
|
|
3891
|
+
const init = season.initiator ?? season;
|
|
3892
|
+
if (seen.has(init)) continue;
|
|
3893
|
+
seen.add(init);
|
|
3894
|
+
const children = [...init.children ?? []];
|
|
3895
|
+
const marker = children.find((c) => c.name === "seasonMarker");
|
|
3896
|
+
if (!marker) continue;
|
|
3897
|
+
const markerRaw = String(marker.raw ?? "");
|
|
3898
|
+
const isWordMarker = /^[a-zà-ÿа-я]{3,}$/i.test(markerRaw);
|
|
3899
|
+
const inBracket = !!matches.markers.atMatch(season, (m) => m.name === "group", 0);
|
|
3900
|
+
if (!isWordMarker && !(markerRaw.toLowerCase() === "s" && inBracket)) continue;
|
|
3901
|
+
if (isWordMarker && /s$/i.test(markerRaw)) continue;
|
|
3902
|
+
const nums = children.filter((c) => c.name === "season");
|
|
3903
|
+
if (nums.length !== 2) continue;
|
|
3904
|
+
const sep = children.find((c) => c.name === "seasonSeparator");
|
|
3905
|
+
if (!sep || String(sep.raw ?? "").trim() !== "-") continue;
|
|
3906
|
+
if (isWordMarker && (input[sep.start - 1] !== " " || input[sep.end] !== " ")) continue;
|
|
3907
|
+
const filepart = matches.markers.atMatch(season, (m) => m.name === "path", 0);
|
|
3908
|
+
if (filepart) {
|
|
3909
|
+
const complete = matches.range(
|
|
3910
|
+
filepart.start,
|
|
3911
|
+
filepart.end,
|
|
3912
|
+
(m) => m.name === "other" && m.value === "Complete",
|
|
3913
|
+
0
|
|
3914
|
+
);
|
|
3915
|
+
if (complete) continue;
|
|
3916
|
+
}
|
|
3917
|
+
const episodeMatch = new Match(nums[1].start, nums[1].end, {
|
|
3918
|
+
name: "episode",
|
|
3919
|
+
value: nums[1].value,
|
|
3920
|
+
inputString: input
|
|
3921
|
+
});
|
|
3922
|
+
toRemove.push(nums[1]);
|
|
3923
|
+
toAppend.push(episodeMatch);
|
|
3924
|
+
}
|
|
3925
|
+
return toRemove.length || toAppend.length ? [toRemove, toAppend] : false;
|
|
3926
|
+
}
|
|
3927
|
+
};
|
|
3928
|
+
_SeasonWordDashedEpisodeRule.priority = 32;
|
|
3929
|
+
let SeasonWordDashedEpisodeRule = _SeasonWordDashedEpisodeRule;
|
|
3698
3930
|
const _RemoveNumfirstMarkerCollision = class _RemoveNumfirstMarkerCollision extends Rule {
|
|
3699
3931
|
constructor() {
|
|
3700
3932
|
super(...arguments);
|
|
@@ -3704,22 +3936,29 @@ const _RemoveNumfirstMarkerCollision = class _RemoveNumfirstMarkerCollision exte
|
|
|
3704
3936
|
when(matches, _context) {
|
|
3705
3937
|
const toRemove = [];
|
|
3706
3938
|
const isWeak = (m) => !!(m.tags?.includes("weak-episode") || ["weak_episode", "weak_duplicate"].includes(m.initiator?.name));
|
|
3707
|
-
const
|
|
3939
|
+
const removeWithParent = (m) => {
|
|
3940
|
+
const init = m.initiator ?? m;
|
|
3941
|
+
if (!toRemove.includes(m)) toRemove.push(m);
|
|
3942
|
+
for (const child of init.children ?? []) {
|
|
3943
|
+
if (!toRemove.includes(child)) toRemove.push(child);
|
|
3944
|
+
}
|
|
3945
|
+
};
|
|
3946
|
+
const all = [...matches];
|
|
3947
|
+
const numfirsts = all.filter((m) => (m.name === "season" || m.name === "episode") && m.tags?.includes("numfirst"));
|
|
3708
3948
|
for (const nf of numfirsts) {
|
|
3709
3949
|
const nfInit = nf.initiator ?? nf;
|
|
3710
|
-
const
|
|
3950
|
+
const wordFirst = all.find((w) => {
|
|
3711
3951
|
if (w.name !== "season" && w.name !== "episode") return false;
|
|
3712
3952
|
if (w.tags?.includes("numfirst") || isWeak(w)) return false;
|
|
3713
3953
|
const wInit = w.initiator ?? w;
|
|
3714
3954
|
if (wInit === nfInit) return false;
|
|
3715
3955
|
return wInit.start < nfInit.end && nfInit.start < wInit.end;
|
|
3716
3956
|
});
|
|
3717
|
-
if (
|
|
3718
|
-
|
|
3719
|
-
|
|
3720
|
-
|
|
3721
|
-
|
|
3722
|
-
}
|
|
3957
|
+
if (!wordFirst) continue;
|
|
3958
|
+
const claimed = all.some((m) => !m.private && (m.name === "screen_size" || m.name === "year") && m.start < wordFirst.end && wordFirst.start < m.end);
|
|
3959
|
+
const gluedOrdinal = /^(?:st|nd|rd|th|ª|º|°)/i.test(String(matches.inputString ?? "").slice(nf.end, nf.end + 2));
|
|
3960
|
+
if (claimed || gluedOrdinal) removeWithParent(wordFirst);
|
|
3961
|
+
else removeWithParent(nf);
|
|
3723
3962
|
}
|
|
3724
3963
|
return toRemove.length ? toRemove : false;
|
|
3725
3964
|
}
|
|
@@ -4668,12 +4907,13 @@ const _ValidateVideoCodec = class _ValidateVideoCodec extends Rule {
|
|
|
4668
4907
|
when(matches, _context) {
|
|
4669
4908
|
const ret = [];
|
|
4670
4909
|
const codecs = matches.named("video_codec");
|
|
4910
|
+
const hasAny = (v) => Array.isArray(v) ? v.length > 0 : !!v;
|
|
4671
4911
|
for (const codec of codecs) {
|
|
4672
|
-
if (!sepsBefore(codec) && !matches.atIndex(codec.start - 1, (m) => m.tags?.includes("video-codec-prefix"))) {
|
|
4912
|
+
if (!sepsBefore(codec) && !hasAny(matches.atIndex(codec.start - 1, (m) => m.tags?.includes("video-codec-prefix")))) {
|
|
4673
4913
|
ret.push(codec);
|
|
4674
4914
|
continue;
|
|
4675
4915
|
}
|
|
4676
|
-
if (!sepsAfter(codec) && !matches.atIndex(codec.end + 1, (m) => m.tags?.includes("video-codec-suffix"))) {
|
|
4916
|
+
if (!sepsAfter(codec) && !hasAny(matches.atIndex(codec.end + 1, (m) => m.tags?.includes("video-codec-suffix")))) {
|
|
4677
4917
|
ret.push(codec);
|
|
4678
4918
|
continue;
|
|
4679
4919
|
}
|
|
@@ -4946,6 +5186,10 @@ const COMPOUND_PROFILES = {
|
|
|
4946
5186
|
"Dolby Digital": "EX"
|
|
4947
5187
|
};
|
|
4948
5188
|
const _CompoundAudioProfileRule = class _CompoundAudioProfileRule extends Rule {
|
|
5189
|
+
constructor() {
|
|
5190
|
+
super(...arguments);
|
|
5191
|
+
this.priority = 128;
|
|
5192
|
+
}
|
|
4949
5193
|
enabled(context) {
|
|
4950
5194
|
return !isDisabled(context, "audio_profile");
|
|
4951
5195
|
}
|
|
@@ -4988,6 +5232,7 @@ const _CompoundAudioProfileRule = class _CompoundAudioProfileRule extends Rule {
|
|
|
4988
5232
|
}
|
|
4989
5233
|
}
|
|
4990
5234
|
};
|
|
5235
|
+
_CompoundAudioProfileRule.priority = 128;
|
|
4991
5236
|
_CompoundAudioProfileRule.consequence = AppendMatch;
|
|
4992
5237
|
let CompoundAudioProfileRule = _CompoundAudioProfileRule;
|
|
4993
5238
|
const _AudioProfileRule = class _AudioProfileRule extends Rule {
|
|
@@ -5072,17 +5317,29 @@ const _AudioValidatorRule = class _AudioValidatorRule extends Rule {
|
|
|
5072
5317
|
}
|
|
5073
5318
|
when(matches, _context) {
|
|
5074
5319
|
const ret = [];
|
|
5075
|
-
const
|
|
5320
|
+
const AUDIO_PROPS = ["audio_codec", "audio_profile", "audio_channels"];
|
|
5321
|
+
const audioProps = AUDIO_PROPS.flatMap((n) => [...matches.named(n)]);
|
|
5076
5322
|
for (const prop of audioProps) {
|
|
5077
5323
|
if (!sepsBefore(prop)) {
|
|
5078
|
-
const
|
|
5079
|
-
|
|
5324
|
+
const validBefore = matches.range(
|
|
5325
|
+
prop.start - 1,
|
|
5326
|
+
prop.start,
|
|
5327
|
+
(m) => AUDIO_PROPS.includes(m.name ?? "")
|
|
5328
|
+
);
|
|
5329
|
+
if (!(Array.isArray(validBefore) ? validBefore.length : validBefore)) {
|
|
5080
5330
|
ret.push(prop);
|
|
5331
|
+
continue;
|
|
5081
5332
|
}
|
|
5082
|
-
}
|
|
5083
|
-
|
|
5084
|
-
|
|
5333
|
+
}
|
|
5334
|
+
if (!sepsAfter(prop)) {
|
|
5335
|
+
const validAfter = matches.range(
|
|
5336
|
+
prop.end,
|
|
5337
|
+
prop.end + 1,
|
|
5338
|
+
(m) => AUDIO_PROPS.includes(m.name ?? "")
|
|
5339
|
+
);
|
|
5340
|
+
if (!(Array.isArray(validAfter) ? validAfter.length : validAfter)) {
|
|
5085
5341
|
ret.push(prop);
|
|
5342
|
+
continue;
|
|
5086
5343
|
}
|
|
5087
5344
|
}
|
|
5088
5345
|
}
|
|
@@ -5706,9 +5963,46 @@ function date(config) {
|
|
|
5706
5963
|
disabled: (context) => isDisabled(context, "date"),
|
|
5707
5964
|
conflictSolver: (match, other2) => other2.name === "episode" || other2.name === "season" || other2.name === "crc32" ? other2 : "__default__"
|
|
5708
5965
|
});
|
|
5709
|
-
rebulk.rules(KeepMarkedYearInFilepart, RemoveGroupedYearWithSxxExx);
|
|
5966
|
+
rebulk.rules(KeepMarkedYearInFilepart, RemoveGroupedYearWithSxxExx, new AbsorbWeekdayPrefix(config["weekday_words"] ?? []));
|
|
5710
5967
|
return rebulk;
|
|
5711
5968
|
}
|
|
5969
|
+
class AbsorbWeekdayPrefix extends Rule {
|
|
5970
|
+
constructor(weekdayWords) {
|
|
5971
|
+
super();
|
|
5972
|
+
this.consequence = RemoveMatch;
|
|
5973
|
+
const sepsClass = "[" + seps.replace(/[.*+?^${}()|[\]\\]/g, "\\$&") + "]";
|
|
5974
|
+
this.weekdayRe = new RegExp(
|
|
5975
|
+
"(?:^|" + sepsClass + ")(" + buildOrPattern(weekdayWords.length ? weekdayWords : ["\\bnever\\b"]) + ")" + sepsClass + "*$",
|
|
5976
|
+
"i"
|
|
5977
|
+
);
|
|
5978
|
+
}
|
|
5979
|
+
enabled(context) {
|
|
5980
|
+
return !isDisabled(context, "date");
|
|
5981
|
+
}
|
|
5982
|
+
when(matches, _context) {
|
|
5983
|
+
const input = matches.inputString ?? "";
|
|
5984
|
+
const ret = [];
|
|
5985
|
+
for (const dateMatch of matches.named("date") ?? []) {
|
|
5986
|
+
const filepart = matches.markers.atMatch(dateMatch, (m) => m.name === "path", 0);
|
|
5987
|
+
const lower = filepart ? filepart.start : 0;
|
|
5988
|
+
const segment = input.slice(lower, dateMatch.start);
|
|
5989
|
+
const weekday = this.weekdayRe.exec(segment);
|
|
5990
|
+
if (!weekday) continue;
|
|
5991
|
+
const groupStart = lower + weekday.index + weekday[0].indexOf(weekday[1]);
|
|
5992
|
+
const claimed = matches.range(groupStart, dateMatch.start, (m) => !m.private);
|
|
5993
|
+
if ((Array.isArray(claimed) ? claimed.length : claimed ? 1 : 0) > 0) continue;
|
|
5994
|
+
ret.push([dateMatch, groupStart]);
|
|
5995
|
+
}
|
|
5996
|
+
return ret.length ? ret : false;
|
|
5997
|
+
}
|
|
5998
|
+
then(matches, whenResponse, _context) {
|
|
5999
|
+
for (const [dateMatch, newStart] of whenResponse) {
|
|
6000
|
+
matches.remove(dateMatch);
|
|
6001
|
+
dateMatch.start = newStart;
|
|
6002
|
+
matches.append(dateMatch);
|
|
6003
|
+
}
|
|
6004
|
+
}
|
|
6005
|
+
}
|
|
5712
6006
|
function markerComparatorPredicate(m) {
|
|
5713
6007
|
return !m.private && m.name !== "proper_count" && m.name !== "title" && !(m.name === "container" && m.tags?.includes("extension")) && !(m.name === "other" && m.value === "Rip");
|
|
5714
6008
|
}
|
|
@@ -5720,10 +6014,11 @@ function markerWeight(matches, marker, predicate) {
|
|
|
5720
6014
|
}
|
|
5721
6015
|
function markerSorted(markers, matches, predicate = markerComparatorPredicate) {
|
|
5722
6016
|
const markersArr = [...markers];
|
|
6017
|
+
const originalIndex = new Map(markersArr.map((m, i) => [m, i]));
|
|
5723
6018
|
return markersArr.sort((a, b) => {
|
|
5724
6019
|
const weightDiff = markerWeight(matches, b, predicate) - markerWeight(matches, a, predicate);
|
|
5725
6020
|
if (weightDiff !== 0) return weightDiff;
|
|
5726
|
-
return
|
|
6021
|
+
return (originalIndex.get(b) ?? 0) - (originalIndex.get(a) ?? 0);
|
|
5727
6022
|
});
|
|
5728
6023
|
}
|
|
5729
6024
|
function buildExpectedFunction(optionName) {
|
|
@@ -5936,7 +6231,7 @@ const _TitleBaseRule = class _TitleBaseRule extends Rule {
|
|
|
5936
6231
|
* Check and extract titles from a filepart.
|
|
5937
6232
|
* Mirrors Python's TitleBaseRule.check_titles_in_filepart().
|
|
5938
6233
|
*/
|
|
5939
|
-
checkTitlesInFilepart(filepart, matches) {
|
|
6234
|
+
checkTitlesInFilepart(filepart, matches, context) {
|
|
5940
6235
|
const toAppend = [];
|
|
5941
6236
|
const toRemove = [];
|
|
5942
6237
|
const firstYearInFilepart = matches.range(
|
|
@@ -6007,6 +6302,16 @@ const _TitleBaseRule = class _TitleBaseRule extends Rule {
|
|
|
6007
6302
|
(m) => this.isIgnored(m)
|
|
6008
6303
|
);
|
|
6009
6304
|
const ignoredArray = Array.isArray(ignoredInHole) ? ignoredInHole : ignoredInHole ? [ignoredInHole] : [];
|
|
6305
|
+
if (ignoredArray.length > 0 && ignoredArray.every((m) => m.name === "language" || m.name === "country")) {
|
|
6306
|
+
const inpFull = matches.inputString ?? "";
|
|
6307
|
+
let rest = inpFull.slice(hole.start, hole.end);
|
|
6308
|
+
for (const m of ignoredArray) {
|
|
6309
|
+
const rel = m.start - hole.start;
|
|
6310
|
+
rest = rest.slice(0, rel) + " ".repeat(m.end - m.start) + rest.slice(m.end - hole.start);
|
|
6311
|
+
}
|
|
6312
|
+
const hasTitleText = [...rest].some((c) => !seps.includes(c) && c !== " ");
|
|
6313
|
+
if (!hasTitleText) continue;
|
|
6314
|
+
}
|
|
6010
6315
|
let trimmedHole = hole;
|
|
6011
6316
|
const inp = matches.inputString ?? "";
|
|
6012
6317
|
while (trimmedHole.start < trimmedHole.end && seps.includes(inp[trimmedHole.start])) {
|
|
@@ -6112,7 +6417,7 @@ const _TitleBaseRule = class _TitleBaseRule extends Rule {
|
|
|
6112
6417
|
console.log(` result: hole=[${trimmedHole.start},${trimmedHole.end}) length=${trimmedHole.length} value="${trimmedHole.value}"`);
|
|
6113
6418
|
}
|
|
6114
6419
|
if (trimmedHole.length > 0 && !this.shouldRemove(trimmedHole) && trimmedHole.value) {
|
|
6115
|
-
const splitResult = this.splitTitleAlternative(trimmedHole, inp);
|
|
6420
|
+
const splitResult = this.alternativePropertyName && !isDisabled(context, this.alternativePropertyName) ? this.splitTitleAlternative(trimmedHole, inp) : null;
|
|
6116
6421
|
if (splitResult) {
|
|
6117
6422
|
splitResult.title.name = this.matchName;
|
|
6118
6423
|
toAppend.push(splitResult.title);
|
|
@@ -6238,7 +6543,7 @@ const _TitleBaseRule = class _TitleBaseRule extends Rule {
|
|
|
6238
6543
|
for (const filepart of sortedFileparts) {
|
|
6239
6544
|
yearFileparts.delete(filepart);
|
|
6240
6545
|
if (!this.filepartFilter(filepart)) continue;
|
|
6241
|
-
const result = this.checkTitlesInFilepart(filepart, matches);
|
|
6546
|
+
const result = this.checkTitlesInFilepart(filepart, matches, context);
|
|
6242
6547
|
if (result.toAppend.length > 0 || result.toRemove.length > 0) {
|
|
6243
6548
|
if (serieNameMatch) {
|
|
6244
6549
|
const normTitle = (s) => foldDiacritics(s).replace(/[''`]/g, "").replace(/\.+$/, "").toLowerCase().trim();
|
|
@@ -6255,7 +6560,7 @@ const _TitleBaseRule = class _TitleBaseRule extends Rule {
|
|
|
6255
6560
|
}
|
|
6256
6561
|
for (const filepart of yearFileparts) {
|
|
6257
6562
|
if (!this.filepartFilter(filepart)) continue;
|
|
6258
|
-
const result = this.checkTitlesInFilepart(filepart, matches);
|
|
6563
|
+
const result = this.checkTitlesInFilepart(filepart, matches, context);
|
|
6259
6564
|
const filteredAppend = [];
|
|
6260
6565
|
for (const newTitle of result.toAppend) {
|
|
6261
6566
|
if (newTitle.name !== this.matchName) {
|
|
@@ -6389,7 +6694,11 @@ const _ExtendLoneArticleTitle = class _ExtendLoneArticleTitle extends Rule {
|
|
|
6389
6694
|
const inp = matches.inputString || "";
|
|
6390
6695
|
const out = [];
|
|
6391
6696
|
const titles = matches.named("title");
|
|
6392
|
-
const
|
|
6697
|
+
const epTitles = matches.named("episode_title");
|
|
6698
|
+
const titleArr = [
|
|
6699
|
+
...Array.isArray(titles) ? titles : titles ? [titles] : [],
|
|
6700
|
+
...Array.isArray(epTitles) ? epTitles : epTitles ? [epTitles] : []
|
|
6701
|
+
];
|
|
6393
6702
|
for (const title2 of titleArr) {
|
|
6394
6703
|
if (!ARTICLES.has(String(title2.value ?? "").trim().toLowerCase())) continue;
|
|
6395
6704
|
const filepart = matches.markers.atMatch(title2, (m) => m.name === "path", 0);
|
|
@@ -6491,6 +6800,140 @@ const _TitleWordAtTitlePosition = class _TitleWordAtTitlePosition extends Rule {
|
|
|
6491
6800
|
};
|
|
6492
6801
|
_TitleWordAtTitlePosition.priority = 64;
|
|
6493
6802
|
let TitleWordAtTitlePosition = _TitleWordAtTitlePosition;
|
|
6803
|
+
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]/;
|
|
6804
|
+
const _SplitOriginalScriptTitle = class _SplitOriginalScriptTitle extends Rule {
|
|
6805
|
+
constructor() {
|
|
6806
|
+
super(...arguments);
|
|
6807
|
+
this.priority = POST_PROCESS;
|
|
6808
|
+
this.consequence = [RemoveMatch, AppendMatch];
|
|
6809
|
+
}
|
|
6810
|
+
when(matches, context) {
|
|
6811
|
+
if (isDisabled(context, "alternative_title")) return false;
|
|
6812
|
+
const input = matches.inputString ?? "";
|
|
6813
|
+
const toRemove = [];
|
|
6814
|
+
const toAppend = [];
|
|
6815
|
+
for (const titleMatch of matches.named("title")) {
|
|
6816
|
+
if (titleMatch.tags?.includes("expected")) continue;
|
|
6817
|
+
const raw = input.slice(titleMatch.start, titleMatch.end);
|
|
6818
|
+
const latin = new RegExp("(?:^|[" + sepsPattern + "])([A-Za-z])").exec(raw);
|
|
6819
|
+
if (!latin) continue;
|
|
6820
|
+
const latinOffset = latin.index + latin[0].indexOf(latin[1]);
|
|
6821
|
+
const prefix = raw.slice(0, latinOffset);
|
|
6822
|
+
if (!NON_LATIN_SCRIPT_RE.test(prefix)) continue;
|
|
6823
|
+
let prefixTrim = prefix;
|
|
6824
|
+
while (prefixTrim.length && seps.includes(prefixTrim[prefixTrim.length - 1])) prefixTrim = prefixTrim.slice(0, -1);
|
|
6825
|
+
const prefixEnd = titleMatch.start + prefixTrim.length;
|
|
6826
|
+
const latinStart = titleMatch.start + latinOffset;
|
|
6827
|
+
if (prefixEnd <= titleMatch.start) continue;
|
|
6828
|
+
toRemove.push(titleMatch);
|
|
6829
|
+
toAppend.push(new Match(titleMatch.start, prefixEnd, {
|
|
6830
|
+
name: "alternative_title",
|
|
6831
|
+
value: cleanup(input.slice(titleMatch.start, prefixEnd)),
|
|
6832
|
+
inputString: input
|
|
6833
|
+
}));
|
|
6834
|
+
toAppend.push(new Match(latinStart, titleMatch.end, {
|
|
6835
|
+
name: "title",
|
|
6836
|
+
tags: ["title"],
|
|
6837
|
+
value: cleanup(input.slice(latinStart, titleMatch.end)),
|
|
6838
|
+
inputString: input
|
|
6839
|
+
}));
|
|
6840
|
+
}
|
|
6841
|
+
return toRemove.length || toAppend.length ? [toRemove, toAppend] : false;
|
|
6842
|
+
}
|
|
6843
|
+
};
|
|
6844
|
+
_SplitOriginalScriptTitle.priority = POST_PROCESS;
|
|
6845
|
+
let SplitOriginalScriptTitle = _SplitOriginalScriptTitle;
|
|
6846
|
+
const _PreBracketJunkTitle = class _PreBracketJunkTitle extends Rule {
|
|
6847
|
+
constructor() {
|
|
6848
|
+
super(...arguments);
|
|
6849
|
+
this.priority = POST_PROCESS;
|
|
6850
|
+
this.consequence = RemoveMatch;
|
|
6851
|
+
}
|
|
6852
|
+
when(matches, context) {
|
|
6853
|
+
if (isDisabled(context, "title")) return false;
|
|
6854
|
+
const input = matches.inputString ?? "";
|
|
6855
|
+
const toRemove = [];
|
|
6856
|
+
for (const filepart of matches.markers.named("path")) {
|
|
6857
|
+
const titles = (matches.range(filepart.start, filepart.end, (m) => m.name === "title") ?? []).sort((a, b) => a.start - b.start);
|
|
6858
|
+
if (titles.length < 2) continue;
|
|
6859
|
+
const first = titles[0];
|
|
6860
|
+
if (first.start !== filepart.start) continue;
|
|
6861
|
+
if (/[\s._-]/.test(String(first.value ?? "").trim())) continue;
|
|
6862
|
+
const group = matches.markers.range(first.end, filepart.end, (m) => m.name === "group", 0);
|
|
6863
|
+
if (!group || group.start >= titles[1].start) continue;
|
|
6864
|
+
if (![...input.slice(first.end, group.start)].every((c) => seps.includes(c))) continue;
|
|
6865
|
+
const rg = matches.range(
|
|
6866
|
+
group.start,
|
|
6867
|
+
group.end,
|
|
6868
|
+
(m) => m.name === "release_group" && !!m.tags?.includes("anime"),
|
|
6869
|
+
0
|
|
6870
|
+
);
|
|
6871
|
+
if (!rg) continue;
|
|
6872
|
+
toRemove.push(first);
|
|
6873
|
+
}
|
|
6874
|
+
return toRemove.length ? toRemove : false;
|
|
6875
|
+
}
|
|
6876
|
+
};
|
|
6877
|
+
_PreBracketJunkTitle.priority = POST_PROCESS;
|
|
6878
|
+
let PreBracketJunkTitle = _PreBracketJunkTitle;
|
|
6879
|
+
const _BracketedTitleFallback = class _BracketedTitleFallback extends Rule {
|
|
6880
|
+
constructor() {
|
|
6881
|
+
super(...arguments);
|
|
6882
|
+
this.priority = POST_PROCESS;
|
|
6883
|
+
this.consequence = [RemoveMatch, AppendMatch];
|
|
6884
|
+
}
|
|
6885
|
+
when(matches, context) {
|
|
6886
|
+
if (isDisabled(context, "title")) return false;
|
|
6887
|
+
const input = matches.inputString ?? "";
|
|
6888
|
+
const toRemove = [];
|
|
6889
|
+
const toAppend = [];
|
|
6890
|
+
for (const filepart of matches.markers.named("path")) {
|
|
6891
|
+
const hasTitle = matches.range(filepart.start, filepart.end, (m) => m.name === "title", 0);
|
|
6892
|
+
if (hasTitle) continue;
|
|
6893
|
+
const groups2 = matches.markers.range(filepart.start, filepart.end, (m) => m.name === "group") ?? [];
|
|
6894
|
+
if (!groups2.length) continue;
|
|
6895
|
+
const rg = matches.range(filepart.start, filepart.end, (m) => m.name === "release_group", 0);
|
|
6896
|
+
let candidate;
|
|
6897
|
+
for (const g of groups2) {
|
|
6898
|
+
if (rg && g.start <= rg.start && g.end >= rg.end) continue;
|
|
6899
|
+
const core = input.slice(g.start + 1, g.end - 1);
|
|
6900
|
+
if (!/[a-zA-Z]{2,}/.test(core)) continue;
|
|
6901
|
+
const inner = matches.range(g.start, g.end, (m) => !m.private) ?? [];
|
|
6902
|
+
if (inner.length) continue;
|
|
6903
|
+
candidate = g;
|
|
6904
|
+
break;
|
|
6905
|
+
}
|
|
6906
|
+
if (candidate) {
|
|
6907
|
+
toAppend.push(new Match(candidate.start + 1, candidate.end - 1, {
|
|
6908
|
+
name: "title",
|
|
6909
|
+
value: cleanup(input.slice(candidate.start + 1, candidate.end - 1)),
|
|
6910
|
+
inputString: input
|
|
6911
|
+
}));
|
|
6912
|
+
continue;
|
|
6913
|
+
}
|
|
6914
|
+
if (rg && rg.tags?.includes("anime")) {
|
|
6915
|
+
const outside = input.slice(filepart.start, filepart.end).replace(input.slice(rg.start - 1 >= filepart.start ? rg.start - 1 : rg.start, Math.min(rg.end + 1, filepart.end)), "");
|
|
6916
|
+
const outsideMatches = matches.range(
|
|
6917
|
+
filepart.start,
|
|
6918
|
+
filepart.end,
|
|
6919
|
+
(m) => !m.private && m.name !== "release_group" && m.start >= filepart.start
|
|
6920
|
+
) ?? [];
|
|
6921
|
+
const wordyOutside = /[a-zA-Z]{2,}/.test(outside.replace(/\b(mkv|avi|mp4)\b/gi, "")) && outsideMatches.some((m) => ["title", "episode_title", "alternative_title"].includes(m.name ?? ""));
|
|
6922
|
+
if (!wordyOutside) {
|
|
6923
|
+
toRemove.push(rg);
|
|
6924
|
+
toAppend.push(new Match(rg.start, rg.end, {
|
|
6925
|
+
name: "title",
|
|
6926
|
+
value: cleanup(input.slice(rg.start, rg.end)),
|
|
6927
|
+
inputString: input
|
|
6928
|
+
}));
|
|
6929
|
+
}
|
|
6930
|
+
}
|
|
6931
|
+
}
|
|
6932
|
+
return toRemove.length || toAppend.length ? [toRemove, toAppend] : false;
|
|
6933
|
+
}
|
|
6934
|
+
};
|
|
6935
|
+
_BracketedTitleFallback.priority = POST_PROCESS;
|
|
6936
|
+
let BracketedTitleFallback = _BracketedTitleFallback;
|
|
6494
6937
|
const _PropertyAtTitlePositionAsTitle = class _PropertyAtTitlePositionAsTitle extends Rule {
|
|
6495
6938
|
constructor() {
|
|
6496
6939
|
super(...arguments);
|
|
@@ -6638,7 +7081,7 @@ function title(config) {
|
|
|
6638
7081
|
const rebulk = new Rebulk({
|
|
6639
7082
|
disabled: (context) => isDisabled(context, "title")
|
|
6640
7083
|
});
|
|
6641
|
-
rebulk.rules(CountryAtTitlePosition, TitleWordAtTitlePosition, TitleFromPosition, PreferTitleWithYear, ExtendLoneArticleTitle, PropertyAtTitlePositionAsTitle, RemoveNumericAlternativeTitle, RemoveTailAlternativeTitle, RemoveTailTitle);
|
|
7084
|
+
rebulk.rules(CountryAtTitlePosition, TitleWordAtTitlePosition, SplitOriginalScriptTitle, TitleFromPosition, PreferTitleWithYear, ExtendLoneArticleTitle, PropertyAtTitlePositionAsTitle, RemoveNumericAlternativeTitle, RemoveTailAlternativeTitle, RemoveTailTitle, BracketedTitleFallback, PreBracketJunkTitle);
|
|
6642
7085
|
const expectedTitle = buildExpectedFunction("expected_title");
|
|
6643
7086
|
rebulk.functional(expectedTitle, {
|
|
6644
7087
|
name: "title",
|
|
@@ -7428,7 +7871,9 @@ class Filepart2EpisodeTitle extends Rule {
|
|
|
7428
7871
|
);
|
|
7429
7872
|
if (episodeNumber) {
|
|
7430
7873
|
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
|
-
|
|
7874
|
+
const anySeason = matches.named("season");
|
|
7875
|
+
const hasAnySeason = Array.isArray(anySeason) ? anySeason.length > 0 : !!anySeason;
|
|
7876
|
+
if (season || !hasAnySeason) {
|
|
7432
7877
|
const hole = parentTitleHole(matches, directory.start, directory.end);
|
|
7433
7878
|
if (hole) {
|
|
7434
7879
|
const groupMarkers = matches.markers.named("group");
|
|
@@ -8627,14 +9072,6 @@ class DashSeparatedReleaseGroup extends Rule {
|
|
|
8627
9072
|
if (matches.range(candidate.start, candidate.end, (m) => m.name === "episode", 0)) {
|
|
8628
9073
|
return false;
|
|
8629
9074
|
}
|
|
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
9075
|
const firstHole = matches.holes(
|
|
8639
9076
|
candidate.end,
|
|
8640
9077
|
end,
|
|
@@ -8643,6 +9080,16 @@ class DashSeparatedReleaseGroup extends Rule {
|
|
|
8643
9080
|
if (!firstHole) {
|
|
8644
9081
|
return false;
|
|
8645
9082
|
}
|
|
9083
|
+
const holeRaw = String(firstHole.raw ?? "");
|
|
9084
|
+
const holeCore = holeRaw.replace(new RegExp("^[" + sepsPattern + "]+|[" + sepsPattern + "]+$", "g"), "");
|
|
9085
|
+
if (candidate.start === start && !holeCore.includes(".") && !holeCore.includes(" ") && matches.range(
|
|
9086
|
+
candidate.end,
|
|
9087
|
+
end,
|
|
9088
|
+
(m) => ["season", "episode", "date"].includes(m.name ?? "") && !m.private,
|
|
9089
|
+
0
|
|
9090
|
+
)) {
|
|
9091
|
+
return false;
|
|
9092
|
+
}
|
|
8646
9093
|
const rawValue = firstHole.raw;
|
|
8647
9094
|
return rawValue[0] === "-" && !rawValue.slice(1).includes("-") && rawValue.includes(".") && !rawValue.includes(" ");
|
|
8648
9095
|
}
|
|
@@ -8811,6 +9258,32 @@ const _SceneReleaseGroup = class _SceneReleaseGroup extends Rule {
|
|
|
8811
9258
|
}
|
|
8812
9259
|
);
|
|
8813
9260
|
if (lastHole) {
|
|
9261
|
+
const holeGroup = matches.markers.atMatch(lastHole, (m) => m.name === "group", 0);
|
|
9262
|
+
if (holeGroup && String(holeGroup.raw ?? "").startsWith("(")) {
|
|
9263
|
+
const hasEpisodeish = (matches.range(
|
|
9264
|
+
start,
|
|
9265
|
+
end,
|
|
9266
|
+
(m) => m.name === "episode" || m.name === "season"
|
|
9267
|
+
) ?? []).length > 0;
|
|
9268
|
+
if (hasEpisodeish) {
|
|
9269
|
+
const firstGroup = matches.markers.range(
|
|
9270
|
+
start,
|
|
9271
|
+
end,
|
|
9272
|
+
(m) => m.name === "group" && m.start === start,
|
|
9273
|
+
0
|
|
9274
|
+
);
|
|
9275
|
+
if (firstGroup) {
|
|
9276
|
+
const inner = matches.range(
|
|
9277
|
+
firstGroup.start,
|
|
9278
|
+
firstGroup.end,
|
|
9279
|
+
(mm) => !mm.tags.includes("weak-language")
|
|
9280
|
+
) ?? [];
|
|
9281
|
+
const core = String(firstGroup.value ?? "").replace(new RegExp(`[${sepsPattern}]`, "g"), "");
|
|
9282
|
+
const emptyish = inner.length === 0 || inner.every((mm) => mm.name === "container" && mm.tags?.includes("subtitle"));
|
|
9283
|
+
if (emptyish && core && !intCoercable(core)) continue;
|
|
9284
|
+
}
|
|
9285
|
+
}
|
|
9286
|
+
}
|
|
8814
9287
|
const previousMatchFilter = (match) => {
|
|
8815
9288
|
if (match.start < filepart.start) {
|
|
8816
9289
|
return false;
|
|
@@ -8874,7 +9347,6 @@ const _AnimeReleaseGroup = class _AnimeReleaseGroup extends Rule {
|
|
|
8874
9347
|
(mm) => !mm.tags.includes("weak-language")
|
|
8875
9348
|
);
|
|
8876
9349
|
if (innerMatches.length === 0) return true;
|
|
8877
|
-
if (innerMatches.every((mm) => mm.name === "other")) return true;
|
|
8878
9350
|
if (m.start === filepart.start && innerMatches.every((mm) => mm.name === "container" && mm.tags?.includes("subtitle"))) {
|
|
8879
9351
|
return true;
|
|
8880
9352
|
}
|
|
@@ -9917,9 +10389,35 @@ function film(config) {
|
|
|
9917
10389
|
rebulk.regexDefaults({ flags: "i", abbreviations: [dash] }).stringDefaults({ ignoreCase: true });
|
|
9918
10390
|
rebulk.defaults({ name: "film", validator: sepsSurround });
|
|
9919
10391
|
loadConfigPatterns(rebulk, config["film"]);
|
|
9920
|
-
rebulk.rules(FilmTitleRule);
|
|
10392
|
+
rebulk.rules(LeadingFilmNumberRule, FilmTitleRule);
|
|
9921
10393
|
return rebulk;
|
|
9922
10394
|
}
|
|
10395
|
+
const _LeadingFilmNumberRule = class _LeadingFilmNumberRule extends Rule {
|
|
10396
|
+
constructor() {
|
|
10397
|
+
super(...arguments);
|
|
10398
|
+
this.consequence = RemoveMatch;
|
|
10399
|
+
}
|
|
10400
|
+
when(matches, _context) {
|
|
10401
|
+
const toRemove = [];
|
|
10402
|
+
const films = matches.named("film", (m) => !m.private) ?? [];
|
|
10403
|
+
for (const filmMatch of Array.isArray(films) ? films : [films]) {
|
|
10404
|
+
const filepath = matches.markers.atMatch(filmMatch, (m) => m.name === "path", 0);
|
|
10405
|
+
if (!filepath) continue;
|
|
10406
|
+
const hole = matches.holes(
|
|
10407
|
+
filepath.start,
|
|
10408
|
+
filmMatch.start + 1,
|
|
10409
|
+
{ formatter: cleanup, index: 0 }
|
|
10410
|
+
);
|
|
10411
|
+
if (!(hole && hole.value)) {
|
|
10412
|
+
toRemove.push(filmMatch);
|
|
10413
|
+
if (filmMatch.parent) toRemove.push(filmMatch.parent);
|
|
10414
|
+
}
|
|
10415
|
+
}
|
|
10416
|
+
return toRemove.length ? toRemove : false;
|
|
10417
|
+
}
|
|
10418
|
+
};
|
|
10419
|
+
_LeadingFilmNumberRule.consequence = RemoveMatch;
|
|
10420
|
+
let LeadingFilmNumberRule = _LeadingFilmNumberRule;
|
|
9923
10421
|
const _FilmTitleRule = class _FilmTitleRule extends Rule {
|
|
9924
10422
|
enabled(context) {
|
|
9925
10423
|
return !isDisabled(context, "film_title");
|
|
@@ -10484,17 +10982,40 @@ const _RemoveAmbiguous = class _RemoveAmbiguous extends Rule {
|
|
|
10484
10982
|
_RemoveAmbiguous.priority = POST_PROCESS;
|
|
10485
10983
|
_RemoveAmbiguous.consequence = RemoveMatch;
|
|
10486
10984
|
let RemoveAmbiguous = _RemoveAmbiguous;
|
|
10985
|
+
const sxxExxWeightPredicate = (m) => (m.name === "season" || m.name === "episode") && m.tags.includes("SxxExx");
|
|
10487
10986
|
class RemoveLessSpecificSeasonEpisode extends RemoveAmbiguous {
|
|
10488
10987
|
constructor(name) {
|
|
10489
10988
|
super(
|
|
10490
|
-
|
|
10491
|
-
|
|
10492
|
-
|
|
10493
|
-
|
|
10494
|
-
),
|
|
10989
|
+
// Sort fileparts most-valuable-first: a SxxExx-tagged season/episode outweighs a
|
|
10990
|
+
// weaker one, so the filename's S44E03 beats a season-only or weak-number parent
|
|
10991
|
+
// directory (upstream #797/#772).
|
|
10992
|
+
(markers, matches) => markerSorted(markers, matches, sxxExxWeightPredicate),
|
|
10495
10993
|
(m) => m.name === name
|
|
10496
10994
|
);
|
|
10497
10995
|
}
|
|
10996
|
+
when(matches, context) {
|
|
10997
|
+
const markers = matches.markers.named("path");
|
|
10998
|
+
const markerArr = Array.isArray(markers) ? markers : markers ? [markers] : [];
|
|
10999
|
+
if (markerArr.length > 1) {
|
|
11000
|
+
const weights = markerArr.map((marker) => {
|
|
11001
|
+
const inRange = matches.range(marker.start, marker.end, sxxExxWeightPredicate);
|
|
11002
|
+
return new Set((Array.isArray(inRange) ? inRange : []).map((m) => m.name)).size;
|
|
11003
|
+
});
|
|
11004
|
+
const top = Math.max(...weights);
|
|
11005
|
+
if (weights.filter((w) => w === top).length > 1) return [];
|
|
11006
|
+
}
|
|
11007
|
+
return super.when(matches, context);
|
|
11008
|
+
}
|
|
11009
|
+
}
|
|
11010
|
+
class RemoveLessSpecificSeason extends RemoveLessSpecificSeasonEpisode {
|
|
11011
|
+
constructor() {
|
|
11012
|
+
super("season");
|
|
11013
|
+
}
|
|
11014
|
+
}
|
|
11015
|
+
class RemoveLessSpecificEpisode extends RemoveLessSpecificSeasonEpisode {
|
|
11016
|
+
constructor() {
|
|
11017
|
+
super("episode");
|
|
11018
|
+
}
|
|
10498
11019
|
}
|
|
10499
11020
|
const _SeasonYear = class _SeasonYear extends Rule {
|
|
10500
11021
|
when(matches, _context) {
|
|
@@ -10587,8 +11108,8 @@ function processors(_config) {
|
|
|
10587
11108
|
return new Rebulk().rules(
|
|
10588
11109
|
EnlargeGroupMatches,
|
|
10589
11110
|
EquivalentHoles,
|
|
10590
|
-
|
|
10591
|
-
|
|
11111
|
+
RemoveLessSpecificSeason,
|
|
11112
|
+
RemoveLessSpecificEpisode,
|
|
10592
11113
|
RemoveAmbiguous,
|
|
10593
11114
|
SeasonYear,
|
|
10594
11115
|
YearSeason,
|
|
@@ -12301,6 +12822,26 @@ const advanced_config = {
|
|
|
12301
12822
|
date: {
|
|
12302
12823
|
week_words: [
|
|
12303
12824
|
"week"
|
|
12825
|
+
],
|
|
12826
|
+
weekday_words: [
|
|
12827
|
+
"monday",
|
|
12828
|
+
"tuesday",
|
|
12829
|
+
"wednesday",
|
|
12830
|
+
"thursday",
|
|
12831
|
+
"friday",
|
|
12832
|
+
"saturday",
|
|
12833
|
+
"sunday",
|
|
12834
|
+
"mon",
|
|
12835
|
+
"tue",
|
|
12836
|
+
"tues",
|
|
12837
|
+
"wed",
|
|
12838
|
+
"weds",
|
|
12839
|
+
"thu",
|
|
12840
|
+
"thur",
|
|
12841
|
+
"thurs",
|
|
12842
|
+
"fri",
|
|
12843
|
+
"sat",
|
|
12844
|
+
"sun"
|
|
12304
12845
|
]
|
|
12305
12846
|
}
|
|
12306
12847
|
};
|