guessit-js 4.5.0 → 4.5.2
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/README.md +3 -3
- package/dist/guessit-js.cjs +123 -21
- package/dist/guessit-js.cjs.map +1 -1
- package/dist/guessit-js.js +123 -21
- package/dist/guessit-js.js.map +1 -1
- package/package.json +2 -2
package/dist/guessit-js.js
CHANGED
|
@@ -370,6 +370,11 @@ class _BaseMatches {
|
|
|
370
370
|
toArray() {
|
|
371
371
|
return [...this._delegate];
|
|
372
372
|
}
|
|
373
|
+
/** All matches as an array. Ported Python code reads `matches.matches` — without
|
|
374
|
+
* this getter that silently evaluated to undefined and turned rules into no-ops. */
|
|
375
|
+
get matches() {
|
|
376
|
+
return [...this._delegate];
|
|
377
|
+
}
|
|
373
378
|
// ── Cache accessors ──────────────────────────────────────────────────────
|
|
374
379
|
get nameDict() {
|
|
375
380
|
if (!this._nameDict) {
|
|
@@ -1619,12 +1624,10 @@ function executeRule(rule, matches, context) {
|
|
|
1619
1624
|
}
|
|
1620
1625
|
function toposortRules(rules) {
|
|
1621
1626
|
const graph = /* @__PURE__ */ new Map();
|
|
1622
|
-
const
|
|
1627
|
+
const classToDeps = /* @__PURE__ */ new Map();
|
|
1623
1628
|
for (const rule of rules) {
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
}
|
|
1627
|
-
classToDep.set(rule.constructor, rule);
|
|
1629
|
+
const cls = rule.constructor;
|
|
1630
|
+
classToDeps.set(cls, [...classToDeps.get(cls) ?? [], rule]);
|
|
1628
1631
|
}
|
|
1629
1632
|
for (const rule of rules) {
|
|
1630
1633
|
const deps = /* @__PURE__ */ new Set();
|
|
@@ -1632,18 +1635,20 @@ function toposortRules(rules) {
|
|
|
1632
1635
|
if (rawDeps) {
|
|
1633
1636
|
const depArr = Array.isArray(rawDeps) ? rawDeps : [rawDeps];
|
|
1634
1637
|
for (const dep of depArr) {
|
|
1635
|
-
let resolved;
|
|
1638
|
+
let resolved = [];
|
|
1636
1639
|
if (typeof dep === "string") {
|
|
1637
|
-
for (const [cls,
|
|
1640
|
+
for (const [cls, insts] of classToDeps) {
|
|
1638
1641
|
if (cls.name === dep) {
|
|
1639
|
-
resolved =
|
|
1642
|
+
resolved = insts;
|
|
1640
1643
|
break;
|
|
1641
1644
|
}
|
|
1642
1645
|
}
|
|
1643
1646
|
} else {
|
|
1644
|
-
resolved =
|
|
1647
|
+
resolved = classToDeps.get(dep) ?? [];
|
|
1648
|
+
}
|
|
1649
|
+
for (const inst of resolved) {
|
|
1650
|
+
if (inst !== rule) deps.add(inst);
|
|
1645
1651
|
}
|
|
1646
|
-
if (resolved) deps.add(resolved);
|
|
1647
1652
|
}
|
|
1648
1653
|
}
|
|
1649
1654
|
graph.set(rule, deps);
|
|
@@ -3679,13 +3684,13 @@ function episodes(config) {
|
|
|
3679
3684
|
rebulk.chain({
|
|
3680
3685
|
tags: ["weak-episode"],
|
|
3681
3686
|
disabled: (context) => context?.type === "movie" || isDisabled(context, "episode")
|
|
3682
|
-
}).defaults({ validator: null, tags: ["weak-episode"] }).regex(`(?<![^\\W_])(?<episode>\\d{2})(?!(?:st|nd|rd|th)\\b)(?:[a-d](?![a-z0-9]))?(?!(?![vV]\\d)[^\\W_])`).regex(`v(?<version>\\d+)`).repeater("?").regex(`(?<episodeSeparator>[x-])(?<episode>\\d{2})`, {
|
|
3687
|
+
}).defaults({ validator: null, tags: ["weak-episode"] }).regex(`(?<![^\\W_])(?<episode>\\d{2})(?!(?:st|nd|rd|th)\\b)(?!%)(?:[a-d](?![a-z0-9]))?(?!(?![vV]\\d)[^\\W_])`).regex(`v(?<version>\\d+)`).repeater("?").regex(`(?<episodeSeparator>[x-])(?<episode>\\d{2})`, {
|
|
3683
3688
|
abbreviations: null
|
|
3684
3689
|
}).repeater("*");
|
|
3685
3690
|
rebulk.chain({
|
|
3686
3691
|
tags: ["weak-episode"],
|
|
3687
3692
|
disabled: (context) => context?.type === "movie" || isDisabled(context, "episode")
|
|
3688
|
-
}).defaults({ validator: null, tags: ["weak-episode"] }).regex(`(?<![^\\W_])0(?<episode>\\d{1,2})(?:[a-d](?![a-z0-9]))?(?!(?![vV]\\d)[^\\W_])`).regex(`v(?<version>\\d+)`).repeater("?").regex(`(?<episodeSeparator>[x-])0(?<episode>\\d{1,2})`, {
|
|
3693
|
+
}).defaults({ validator: null, tags: ["weak-episode"] }).regex(`(?<![^\\W_])0(?<episode>\\d{1,2})(?!%)(?:[a-d](?![a-z0-9]))?(?!(?![vV]\\d)[^\\W_])`).regex(`v(?<version>\\d+)`).repeater("?").regex(`(?<episodeSeparator>[x-])0(?<episode>\\d{1,2})`, {
|
|
3689
3694
|
abbreviations: null
|
|
3690
3695
|
}).repeater("*");
|
|
3691
3696
|
rebulk.chain({
|
|
@@ -3696,13 +3701,13 @@ function episodes(config) {
|
|
|
3696
3701
|
validator: null,
|
|
3697
3702
|
tags: ["weak-episode"],
|
|
3698
3703
|
name: "weak_episode"
|
|
3699
|
-
}).regex(`(?<![^\\W_])(?<episode>\\d{3,4})(?:[a-d](?![a-z0-9]))?(?!(?![vV]\\d)[^\\W_])`).regex(`v(?<version>\\d+)`).repeater("?").regex(`(?<episodeSeparator>[x-])(?<episode>\\d{3,4})`, {
|
|
3704
|
+
}).regex(`(?<![^\\W_])(?<episode>\\d{3,4})(?!%)(?:[a-d](?![a-z0-9]))?(?!(?![vV]\\d)[^\\W_])`).regex(`v(?<version>\\d+)`).repeater("?").regex(`(?<episodeSeparator>[x-])(?<episode>\\d{3,4})`, {
|
|
3700
3705
|
abbreviations: null
|
|
3701
3706
|
}).repeater("*");
|
|
3702
3707
|
rebulk.chain({
|
|
3703
3708
|
tags: ["weak-episode"],
|
|
3704
3709
|
disabled: (context) => context?.type !== "episode" || isDisabled(context, "episode")
|
|
3705
|
-
}).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})`, {
|
|
3710
|
+
}).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})`, {
|
|
3706
3711
|
abbreviations: null
|
|
3707
3712
|
}).repeater("*");
|
|
3708
3713
|
rebulk.chain({
|
|
@@ -3731,7 +3736,7 @@ function episodes(config) {
|
|
|
3731
3736
|
name: "weak_duplicate",
|
|
3732
3737
|
validator: null,
|
|
3733
3738
|
conflictSolver: seasonEpisodeConflictSolver
|
|
3734
|
-
}).regex(`(?<![^\\W_])(?<season>\\d{1,2})(?<episode>\\d{2})(?!(?![vV]\\d)[^\\W_])`).regex(`v(?<version>\\d+)`).repeater("?").regex(`(?<episodeSeparator>x|-)(?<episode>\\d{2})`, {
|
|
3739
|
+
}).regex(`(?<![^\\W_])(?<season>\\d{1,2})(?<episode>\\d{2})(?!%)(?!(?![vV]\\d)[^\\W_])`).regex(`v(?<version>\\d+)`).repeater("?").regex(`(?<episodeSeparator>x|-)(?<episode>\\d{2})`, {
|
|
3735
3740
|
abbreviations: null
|
|
3736
3741
|
}).repeater("*");
|
|
3737
3742
|
rebulk.regex(`v(?<version>\\d+)`, {
|
|
@@ -3759,6 +3764,7 @@ function episodes(config) {
|
|
|
3759
3764
|
disabled: (context) => isDisabled(context, "episode_format")
|
|
3760
3765
|
});
|
|
3761
3766
|
rebulk.rules(
|
|
3767
|
+
EventNumberAsTitleRule,
|
|
3762
3768
|
EpisodeWordBeforeYearAsTitle,
|
|
3763
3769
|
RemoveGroupSuffixSeason,
|
|
3764
3770
|
AnimeTrailingEpisodeRule,
|
|
@@ -3816,6 +3822,45 @@ const _RemoveGroupSuffixSeason = class _RemoveGroupSuffixSeason extends Rule {
|
|
|
3816
3822
|
};
|
|
3817
3823
|
_RemoveGroupSuffixSeason.priority = 72;
|
|
3818
3824
|
let RemoveGroupSuffixSeason = _RemoveGroupSuffixSeason;
|
|
3825
|
+
const _EventNumberAsTitleRule = class _EventNumberAsTitleRule extends Rule {
|
|
3826
|
+
constructor() {
|
|
3827
|
+
super(...arguments);
|
|
3828
|
+
this.priority = 60;
|
|
3829
|
+
this.consequence = RemoveMatch;
|
|
3830
|
+
}
|
|
3831
|
+
when(matches, _context) {
|
|
3832
|
+
const input = matches.inputString ?? "";
|
|
3833
|
+
const toRemove = [];
|
|
3834
|
+
const isWeak = (m) => !!(m.tags?.includes("weak-episode") || ["weak_episode", "weak_duplicate"].includes(m.initiator?.name));
|
|
3835
|
+
for (const filepart of matches.markers.named("path") ?? []) {
|
|
3836
|
+
const weaks = matches.range(
|
|
3837
|
+
filepart.start,
|
|
3838
|
+
filepart.end,
|
|
3839
|
+
(m) => m.name === "episode" && !m.private && isWeak(m)
|
|
3840
|
+
) ?? [];
|
|
3841
|
+
if (!weaks.length) continue;
|
|
3842
|
+
const strong = matches.range(filepart.start, filepart.end, (m) => !m.private && (m.name === "season" || m.name === "year" || m.name === "date" || m.name === "episode" && m.tags?.includes("SxxExx")), 0);
|
|
3843
|
+
for (const w of weaks) {
|
|
3844
|
+
const init = w.initiator ?? w;
|
|
3845
|
+
const after = input.slice(init.end, init.end + 5);
|
|
3846
|
+
if (/^[\s._-]?PPV/i.test(after)) {
|
|
3847
|
+
for (const c of [init, ...init.children ?? []]) if (!toRemove.includes(c)) toRemove.push(c);
|
|
3848
|
+
continue;
|
|
3849
|
+
}
|
|
3850
|
+
if (!strong && init.start === filepart.start && /^[1-9]\d$/.test(String(init.raw ?? ""))) {
|
|
3851
|
+
const rest = input.slice(init.end, filepart.end);
|
|
3852
|
+
const words = rest.match(/[A-Za-z][a-z]+/g) ?? [];
|
|
3853
|
+
if (words.length >= 2) {
|
|
3854
|
+
for (const c of [init, ...init.children ?? []]) if (!toRemove.includes(c)) toRemove.push(c);
|
|
3855
|
+
}
|
|
3856
|
+
}
|
|
3857
|
+
}
|
|
3858
|
+
}
|
|
3859
|
+
return toRemove.length ? toRemove : false;
|
|
3860
|
+
}
|
|
3861
|
+
};
|
|
3862
|
+
_EventNumberAsTitleRule.priority = 60;
|
|
3863
|
+
let EventNumberAsTitleRule = _EventNumberAsTitleRule;
|
|
3819
3864
|
const _EpisodeWordBeforeYearAsTitle = class _EpisodeWordBeforeYearAsTitle extends Rule {
|
|
3820
3865
|
constructor() {
|
|
3821
3866
|
super(...arguments);
|
|
@@ -7059,8 +7104,10 @@ const _BracketedTitleFallback = class _BracketedTitleFallback extends Rule {
|
|
|
7059
7104
|
const toRemove = [];
|
|
7060
7105
|
const toAppend = [];
|
|
7061
7106
|
for (const filepart of matches.markers.named("path")) {
|
|
7062
|
-
const
|
|
7063
|
-
|
|
7107
|
+
const titlesHere = matches.range(filepart.start, filepart.end, (m) => m.name === "title") ?? [];
|
|
7108
|
+
const realTitle = titlesHere.find((t) => /[\p{L}\p{N}]/u.test(String(t.value ?? "")));
|
|
7109
|
+
if (realTitle) continue;
|
|
7110
|
+
toRemove.push(...titlesHere);
|
|
7064
7111
|
const groups2 = matches.markers.range(filepart.start, filepart.end, (m) => m.name === "group") ?? [];
|
|
7065
7112
|
if (!groups2.length) continue;
|
|
7066
7113
|
const rg = matches.range(filepart.start, filepart.end, (m) => m.name === "release_group", 0);
|
|
@@ -7069,6 +7116,25 @@ const _BracketedTitleFallback = class _BracketedTitleFallback extends Rule {
|
|
|
7069
7116
|
if (rg && g.start <= rg.start && g.end >= rg.end) continue;
|
|
7070
7117
|
const core = input.slice(g.start + 1, g.end - 1);
|
|
7071
7118
|
if (!/[a-zA-Z]{2,}/.test(core)) continue;
|
|
7119
|
+
const softInner = matches.range(
|
|
7120
|
+
g.start,
|
|
7121
|
+
g.end,
|
|
7122
|
+
(m) => !m.private && ["episode_title", "alternative_title"].includes(m.name ?? "")
|
|
7123
|
+
) ?? [];
|
|
7124
|
+
const hardInner = matches.range(
|
|
7125
|
+
g.start,
|
|
7126
|
+
g.end,
|
|
7127
|
+
(m) => !m.private && !["episode_title", "alternative_title"].includes(m.name ?? "")
|
|
7128
|
+
) ?? [];
|
|
7129
|
+
if (softInner.length && !hardInner.length) {
|
|
7130
|
+
toRemove.push(...softInner);
|
|
7131
|
+
candidate = new Match(g.start + 1, g.end - 1, {
|
|
7132
|
+
name: "title",
|
|
7133
|
+
value: cleanup(input.slice(g.start + 1, g.end - 1)),
|
|
7134
|
+
inputString: input
|
|
7135
|
+
});
|
|
7136
|
+
break;
|
|
7137
|
+
}
|
|
7072
7138
|
const hole = matches.holes(g.start + 1, g.end - 1, {
|
|
7073
7139
|
formatter: cleanup,
|
|
7074
7140
|
predicate: (h) => !!h.value,
|
|
@@ -7171,6 +7237,41 @@ const _BonusAtTitlePositionRule = class _BonusAtTitlePositionRule extends Rule {
|
|
|
7171
7237
|
};
|
|
7172
7238
|
_BonusAtTitlePositionRule.priority = 64;
|
|
7173
7239
|
let BonusAtTitlePositionRule = _BonusAtTitlePositionRule;
|
|
7240
|
+
const _LanguageWordInAnimeTitle = class _LanguageWordInAnimeTitle extends Rule {
|
|
7241
|
+
constructor() {
|
|
7242
|
+
super(...arguments);
|
|
7243
|
+
this.priority = 64;
|
|
7244
|
+
this.consequence = RemoveMatch;
|
|
7245
|
+
}
|
|
7246
|
+
when(matches, context) {
|
|
7247
|
+
if (isDisabled(context, "language")) return false;
|
|
7248
|
+
const toRemove = [];
|
|
7249
|
+
for (const lang of matches.named("language") ?? []) {
|
|
7250
|
+
const raw = String(lang.raw ?? "");
|
|
7251
|
+
if (raw.length > 3 || !/^[A-Z][a-z]{0,2}$/.test(raw)) continue;
|
|
7252
|
+
const filepart = matches.markers.atMatch(lang, (m) => m.name === "path", 0);
|
|
7253
|
+
if (!filepart) continue;
|
|
7254
|
+
const leadingBracket = matches.markers.range(
|
|
7255
|
+
filepart.start,
|
|
7256
|
+
filepart.end,
|
|
7257
|
+
(m) => m.name === "group" && m.start === filepart.start,
|
|
7258
|
+
0
|
|
7259
|
+
);
|
|
7260
|
+
if (!leadingBracket) continue;
|
|
7261
|
+
const anchor = matches.range(
|
|
7262
|
+
lang.end,
|
|
7263
|
+
filepart.end,
|
|
7264
|
+
(m) => !m.private && ["episode", "season", "year", "date"].includes(m.name ?? ""),
|
|
7265
|
+
0
|
|
7266
|
+
);
|
|
7267
|
+
if (!anchor) continue;
|
|
7268
|
+
toRemove.push(lang);
|
|
7269
|
+
}
|
|
7270
|
+
return toRemove.length ? toRemove : false;
|
|
7271
|
+
}
|
|
7272
|
+
};
|
|
7273
|
+
_LanguageWordInAnimeTitle.priority = 64;
|
|
7274
|
+
let LanguageWordInAnimeTitle = _LanguageWordInAnimeTitle;
|
|
7174
7275
|
const _PropertyAtTitlePositionAsTitle = class _PropertyAtTitlePositionAsTitle extends Rule {
|
|
7175
7276
|
constructor() {
|
|
7176
7277
|
super(...arguments);
|
|
@@ -7331,7 +7432,7 @@ function title(config) {
|
|
|
7331
7432
|
const rebulk = new Rebulk({
|
|
7332
7433
|
disabled: (context) => isDisabled(context, "title")
|
|
7333
7434
|
});
|
|
7334
|
-
rebulk.rules(CountryAtTitlePosition, TitleWordAtTitlePosition, WordNumeralPartAtTitlePosition, BonusAtTitlePositionRule, SplitOriginalScriptTitle, TitleFromPosition, PreferTitleWithYear, ExtendLoneArticleTitle, PropertyAtTitlePositionAsTitle, RemoveNumericAlternativeTitle, RemoveTailAlternativeTitle, RemoveTailTitle, BracketedTitleFallback, PreBracketJunkTitle, TrimSeasonWordFromTitle);
|
|
7435
|
+
rebulk.rules(CountryAtTitlePosition, TitleWordAtTitlePosition, WordNumeralPartAtTitlePosition, BonusAtTitlePositionRule, LanguageWordInAnimeTitle, SplitOriginalScriptTitle, TitleFromPosition, PreferTitleWithYear, ExtendLoneArticleTitle, PropertyAtTitlePositionAsTitle, RemoveNumericAlternativeTitle, RemoveTailAlternativeTitle, RemoveTailTitle, BracketedTitleFallback, PreBracketJunkTitle, TrimSeasonWordFromTitle);
|
|
7335
7436
|
const expectedTitle = buildExpectedFunction("expected_title");
|
|
7336
7437
|
rebulk.functional(expectedTitle, {
|
|
7337
7438
|
name: "title",
|
|
@@ -11540,8 +11641,8 @@ const advanced_config = {
|
|
|
11540
11641
|
"sub"
|
|
11541
11642
|
],
|
|
11542
11643
|
groups: {
|
|
11543
|
-
starting: "([{",
|
|
11544
|
-
ending: ")]}"
|
|
11644
|
+
starting: "([{【「(",
|
|
11645
|
+
ending: ")]}】」)"
|
|
11545
11646
|
},
|
|
11546
11647
|
audio_codec: {
|
|
11547
11648
|
audio_codec: {
|
|
@@ -12693,7 +12794,8 @@ const advanced_config = {
|
|
|
12693
12794
|
string: [
|
|
12694
12795
|
"Ova",
|
|
12695
12796
|
"Oav"
|
|
12696
|
-
]
|
|
12797
|
+
],
|
|
12798
|
+
tags: "title-word"
|
|
12697
12799
|
},
|
|
12698
12800
|
"Original Net Animation": "Ona",
|
|
12699
12801
|
"Original Animation DVD": "Oad",
|