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