guessit-js 4.3.0 → 4.3.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 +86 -3
- package/dist/guessit-js.cjs.map +1 -1
- package/dist/guessit-js.js +86 -3
- package/dist/guessit-js.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -5,13 +5,13 @@ Extract metadata (title, year, season, episode, codec, language, etc.) from medi
|
|
|
5
5
|
[](https://www.npmjs.com/package/guessit-js)
|
|
6
6
|
[](https://github.com/opensubtitles/guessit-js/actions/workflows/ci.yml)
|
|
7
7
|
[](https://www.gnu.org/licenses/lgpl-3.0)
|
|
8
|
-
[-brightgreen)](https://github.com/guessit-io/guessit)
|
|
9
9
|
|
|
10
10
|
**[Live Demo](https://opensubtitles.github.io/guessit-js)** · **[API Docs](https://opensubtitles.github.io/guessit-js/docs)** · **[npm](https://www.npmjs.com/package/guessit-js)**
|
|
11
11
|
|
|
12
12
|
## Features
|
|
13
13
|
|
|
14
|
-
- **100% compatibility** with Python guessit (
|
|
14
|
+
- **100% compatibility** with Python guessit 4.4.0 (1289/1289 fixtures passing, including Python's own grown 4.x corpus) — and **more correct**: ships fixes for 32 historical upstream bugs plus Python's still-open #875 and #877 (see [Differences from Python](#differences-from-python-guessit))
|
|
15
15
|
- **3.5x faster** than Python (6.87ms vs 23.86ms per parse)
|
|
16
16
|
- **50 properties** detected: title, year, season, episode, resolution, codec, language, and more — with a [machine-readable schema](#output-schema)
|
|
17
17
|
- **Single dependency** ([rebulk-js](https://www.npmjs.com/package/rebulk-js))
|
|
@@ -122,7 +122,7 @@ The WASM build is **bit-identical to the JS build** across the entire test corpu
|
|
|
122
122
|
|
|
123
123
|
## Differences from Python guessit
|
|
124
124
|
|
|
125
|
-
guessit-js is a faithful port (
|
|
125
|
+
guessit-js is a faithful port (1289/1289 fixtures, tracking Python 4.4.0), but it is
|
|
126
126
|
**not bug-for-bug identical** — where Python has a genuine parsing bug, guessit-js
|
|
127
127
|
is corrected. Highlights:
|
|
128
128
|
|
package/dist/guessit-js.cjs
CHANGED
|
@@ -3377,7 +3377,8 @@ function seasonEpisodeConflictSolver(match, other2) {
|
|
|
3377
3377
|
return "__default__";
|
|
3378
3378
|
}
|
|
3379
3379
|
function orderingValidator(match) {
|
|
3380
|
-
const
|
|
3380
|
+
const dict = match.children?.toDict?.() ?? match.children?.to_dict?.();
|
|
3381
|
+
const values = dict instanceof Map ? Object.fromEntries(dict) : dict || {};
|
|
3381
3382
|
if (values.season && Array.isArray(values.season)) {
|
|
3382
3383
|
const sorted = [...values.season].sort((a, b) => a - b);
|
|
3383
3384
|
if (JSON.stringify(sorted) !== JSON.stringify(values.season)) {
|
|
@@ -4552,6 +4553,14 @@ function source(config) {
|
|
|
4552
4553
|
...buildSourcePattern(["HD-?CAM"], "", optional(ripSuffix)),
|
|
4553
4554
|
{ value: { source: "HD Camera", other: "Rip" } }
|
|
4554
4555
|
);
|
|
4556
|
+
rebulk.regex(
|
|
4557
|
+
...buildSourcePattern(["HQ-?CAM"], "", optional(ripSuffix)),
|
|
4558
|
+
{ value: { source: "Camera", other: "Rip" } }
|
|
4559
|
+
);
|
|
4560
|
+
rebulk.regex(
|
|
4561
|
+
...buildSourcePattern(["S-?Print"], "", optional(ripSuffix)),
|
|
4562
|
+
{ value: { source: "Camera" } }
|
|
4563
|
+
);
|
|
4555
4564
|
rebulk.regex(
|
|
4556
4565
|
...buildSourcePattern(["TELESYNC", "TS"], "", optional(ripSuffix)),
|
|
4557
4566
|
{ value: { source: "Telesync", other: "Rip" }, tags: ["video-codec-prefix"], overrides: ["tags"] }
|
|
@@ -4600,6 +4609,10 @@ function source(config) {
|
|
|
4600
4609
|
...buildSourcePattern(["DVD"], "", optional(ripSuffix)),
|
|
4601
4610
|
{ value: { source: "DVD", other: "Rip" } }
|
|
4602
4611
|
);
|
|
4612
|
+
rebulk.regex(
|
|
4613
|
+
...buildSourcePattern(["DVD-?R[59]"], "", ""),
|
|
4614
|
+
{ value: { source: "DVD" } }
|
|
4615
|
+
);
|
|
4603
4616
|
rebulk.regex(
|
|
4604
4617
|
...buildSourcePattern(["LD"], "", ripSuffix),
|
|
4605
4618
|
{ value: { source: "Laserdisc", other: "Rip" } }
|
|
@@ -6225,6 +6238,7 @@ const _TitleBaseRule = class _TitleBaseRule extends Rule {
|
|
|
6225
6238
|
const lastSeg = createMatch(prevEnd, hole.end);
|
|
6226
6239
|
if (lastSeg) segments.push(lastSeg);
|
|
6227
6240
|
if (segments.length < 2) return null;
|
|
6241
|
+
if (/^\d+$/.test(String(segments[0].value ?? "").trim())) return null;
|
|
6228
6242
|
return { title: segments[0], alternatives: segments.slice(1) };
|
|
6229
6243
|
}
|
|
6230
6244
|
/**
|
|
@@ -6843,6 +6857,38 @@ const _SplitOriginalScriptTitle = class _SplitOriginalScriptTitle extends Rule {
|
|
|
6843
6857
|
};
|
|
6844
6858
|
_SplitOriginalScriptTitle.priority = POST_PROCESS;
|
|
6845
6859
|
let SplitOriginalScriptTitle = _SplitOriginalScriptTitle;
|
|
6860
|
+
const _TrimSeasonWordFromTitle = class _TrimSeasonWordFromTitle extends Rule {
|
|
6861
|
+
constructor() {
|
|
6862
|
+
super(...arguments);
|
|
6863
|
+
this.priority = POST_PROCESS;
|
|
6864
|
+
this.consequence = [RemoveMatch, AppendMatch];
|
|
6865
|
+
}
|
|
6866
|
+
when(matches, context) {
|
|
6867
|
+
if (isDisabled(context, "title")) return false;
|
|
6868
|
+
const input = matches.inputString ?? "";
|
|
6869
|
+
const toRemove = [];
|
|
6870
|
+
const toAppend = [];
|
|
6871
|
+
for (const title2 of matches.named("title") ?? []) {
|
|
6872
|
+
const m = /^(.*\S)[\s._-]+(seasons?|saison)$/i.exec(String(title2.value ?? ""));
|
|
6873
|
+
if (!m) continue;
|
|
6874
|
+
const next = matches.range(title2.end, input.length, (mm) => !mm.private && !!mm.value, 0);
|
|
6875
|
+
if (!next || next.name !== "season") continue;
|
|
6876
|
+
toRemove.push(title2);
|
|
6877
|
+
input.slice(title2.start, title2.end).slice(0, m[1].length + (String(title2.value).length === title2.end - title2.start ? 0 : 0));
|
|
6878
|
+
let newEnd = title2.end;
|
|
6879
|
+
while (newEnd > title2.start && cleanup(input.slice(title2.start, newEnd)).toLowerCase() !== m[1].toLowerCase()) newEnd--;
|
|
6880
|
+
if (newEnd <= title2.start) continue;
|
|
6881
|
+
toAppend.push(new Match(title2.start, newEnd, {
|
|
6882
|
+
name: "title",
|
|
6883
|
+
value: cleanup(input.slice(title2.start, newEnd)),
|
|
6884
|
+
inputString: input
|
|
6885
|
+
}));
|
|
6886
|
+
}
|
|
6887
|
+
return toRemove.length || toAppend.length ? [toRemove, toAppend] : false;
|
|
6888
|
+
}
|
|
6889
|
+
};
|
|
6890
|
+
_TrimSeasonWordFromTitle.priority = POST_PROCESS;
|
|
6891
|
+
let TrimSeasonWordFromTitle = _TrimSeasonWordFromTitle;
|
|
6846
6892
|
const _PreBracketJunkTitle = class _PreBracketJunkTitle extends Rule {
|
|
6847
6893
|
constructor() {
|
|
6848
6894
|
super(...arguments);
|
|
@@ -7081,7 +7127,7 @@ function title(config) {
|
|
|
7081
7127
|
const rebulk = new Rebulk({
|
|
7082
7128
|
disabled: (context) => isDisabled(context, "title")
|
|
7083
7129
|
});
|
|
7084
|
-
rebulk.rules(CountryAtTitlePosition, TitleWordAtTitlePosition, SplitOriginalScriptTitle, TitleFromPosition, PreferTitleWithYear, ExtendLoneArticleTitle, PropertyAtTitlePositionAsTitle, RemoveNumericAlternativeTitle, RemoveTailAlternativeTitle, RemoveTailTitle, BracketedTitleFallback, PreBracketJunkTitle);
|
|
7130
|
+
rebulk.rules(CountryAtTitlePosition, TitleWordAtTitlePosition, SplitOriginalScriptTitle, TitleFromPosition, PreferTitleWithYear, ExtendLoneArticleTitle, PropertyAtTitlePositionAsTitle, RemoveNumericAlternativeTitle, RemoveTailAlternativeTitle, RemoveTailTitle, BracketedTitleFallback, PreBracketJunkTitle, TrimSeasonWordFromTitle);
|
|
7085
7131
|
const expectedTitle = buildExpectedFunction("expected_title");
|
|
7086
7132
|
rebulk.functional(expectedTitle, {
|
|
7087
7133
|
name: "title",
|
|
@@ -7102,6 +7148,39 @@ const LEADING_ARTICLES_RE = /^(the|a|an|le|la|les|l'|el|los|las|der|die|das)\s+/
|
|
|
7102
7148
|
function normalizeTitle(s) {
|
|
7103
7149
|
return s.toLowerCase().replace(LEADING_ARTICLES_RE, "").trim();
|
|
7104
7150
|
}
|
|
7151
|
+
const _FormationRunEpisodeTitle = class _FormationRunEpisodeTitle extends Rule {
|
|
7152
|
+
constructor() {
|
|
7153
|
+
super(...arguments);
|
|
7154
|
+
this.priority = POST_PROCESS;
|
|
7155
|
+
this.consequence = [RemoveMatch, AppendMatch];
|
|
7156
|
+
}
|
|
7157
|
+
when(matches, _context) {
|
|
7158
|
+
const input = matches.inputString ?? "";
|
|
7159
|
+
const toRemove = [];
|
|
7160
|
+
const toAppend = [];
|
|
7161
|
+
const ets = matches.named("episode_title") ?? [];
|
|
7162
|
+
for (const et of ets) {
|
|
7163
|
+
if (!/^\d{1,2}$/.test(String(et.value ?? ""))) continue;
|
|
7164
|
+
const eps = (matches.named("episode") ?? []).filter((e) => e.end <= et.start && !e.private).sort((a, b) => a.start - b.start);
|
|
7165
|
+
if (eps.length < 3) continue;
|
|
7166
|
+
const run = eps.slice(1);
|
|
7167
|
+
const runStart = run[0].start;
|
|
7168
|
+
const span = input.slice(runStart, et.end);
|
|
7169
|
+
if (!/^\d{1,3}(-\d{1,3})+$/.test(span)) continue;
|
|
7170
|
+
const between = input.slice(eps[0].end, runStart);
|
|
7171
|
+
if (!/^[\s._]+$/.test(between)) continue;
|
|
7172
|
+
toRemove.push(...run, et);
|
|
7173
|
+
toAppend.push(new Match(runStart, et.end, {
|
|
7174
|
+
name: "episode_title",
|
|
7175
|
+
value: span,
|
|
7176
|
+
inputString: input
|
|
7177
|
+
}));
|
|
7178
|
+
}
|
|
7179
|
+
return toRemove.length || toAppend.length ? [toRemove, toAppend] : false;
|
|
7180
|
+
}
|
|
7181
|
+
};
|
|
7182
|
+
_FormationRunEpisodeTitle.priority = POST_PROCESS;
|
|
7183
|
+
let FormationRunEpisodeTitle = _FormationRunEpisodeTitle;
|
|
7105
7184
|
function episodeTitle(config) {
|
|
7106
7185
|
const rebulk = new Rebulk({ disabled: (context) => isDisabled(context, "episode_title") });
|
|
7107
7186
|
rebulk.rules(
|
|
@@ -7121,6 +7200,7 @@ function episodeTitle(config) {
|
|
|
7121
7200
|
RemoveSubtitleDescriptorEpisodeTitle,
|
|
7122
7201
|
RemoveHashFilepartJunk,
|
|
7123
7202
|
RemoveTailEpisodeTitle,
|
|
7203
|
+
FormationRunEpisodeTitle,
|
|
7124
7204
|
RenameEpisodeTitleWhenMovieType
|
|
7125
7205
|
);
|
|
7126
7206
|
return rebulk;
|
|
@@ -12215,7 +12295,10 @@ const advanced_config = {
|
|
|
12215
12295
|
},
|
|
12216
12296
|
"High Resolution": "HR",
|
|
12217
12297
|
"Line Dubbed": "LD",
|
|
12218
|
-
"Mic Dubbed":
|
|
12298
|
+
"Mic Dubbed": {
|
|
12299
|
+
string: "MD",
|
|
12300
|
+
tags: "title-word"
|
|
12301
|
+
},
|
|
12219
12302
|
"Micro HD": {
|
|
12220
12303
|
string: [
|
|
12221
12304
|
"mHD",
|