guessit-js 4.8.0 → 4.9.1
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 +67 -20
- package/bin/cli.mjs +38 -2
- package/dist/api.d.ts +30 -0
- package/dist/guessit-js.cjs +2 -2
- package/dist/guessit-js.cjs.map +1 -1
- package/dist/guessit-js.js +4547 -3779
- package/dist/guessit-js.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/language/data.d.ts +7 -0
- package/dist/rules/common/numeral.d.ts +7 -0
- package/dist/rules/properties/episodes.d.ts +7 -0
- package/dist/schema.d.ts +6 -6
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -5,17 +5,18 @@ 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
|
-
[](https://github.com/guessit-io/guessit)
|
|
9
9
|
[](https://github.com/opensubtitles/guessit-js/actions/workflows/ci.yml)
|
|
10
10
|
|
|
11
11
|
**[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)**
|
|
12
12
|
|
|
13
13
|
## Features
|
|
14
14
|
|
|
15
|
-
- **
|
|
16
|
-
-
|
|
15
|
+
- **Runs 2191 of the 2229 cases in Python guessit's own test suite** (upstream 4.5.1, its corpus *and* its per-rule files) — and is **more correct**: fixes for 32 historical upstream bugs, Python's still-open #877, and 114 of the 276 cross-parser cases Python admits failing (see [Differences from Python](#differences-from-python-guessit))
|
|
16
|
+
- **~2x faster** than Python per parse ([measured](#performance))
|
|
17
17
|
- **50 properties** detected: title, year, season, episode, resolution, codec, language, and more — with a [machine-readable schema](#output-schema)
|
|
18
|
-
- **
|
|
18
|
+
- **Batch parsing**: `guessitMany()` in-process, or one POST for up to 100 names
|
|
19
|
+
- **Zero runtime dependencies** ([rebulk-js](https://www.npmjs.com/package/rebulk-js) is bundled at build time)
|
|
19
20
|
- **Dual format**: ESM and CommonJS
|
|
20
21
|
- **TypeScript**: full, precise type definitions (typed `GuessItResult`, enum'd value fields)
|
|
21
22
|
- **WASM**: runs in any WASI-compatible runtime, **bit-identical to the JS build**
|
|
@@ -85,6 +86,28 @@ guessit('X2.2003.720p.DSNP.WEB-DL.DDP5.1.H.264-EVO.mkv');
|
|
|
85
86
|
// streaming_service: 'Disney+', source: 'Web', ... }
|
|
86
87
|
```
|
|
87
88
|
|
|
89
|
+
### Batch
|
|
90
|
+
|
|
91
|
+
`guessitMany()` parses a list in one pass. `guessit()` re-parses the options and
|
|
92
|
+
re-merges them with the whole config on every call — more work than matching a
|
|
93
|
+
short name — so hoisting that out of the loop is the point. Each entry carries
|
|
94
|
+
the `input_string` plus either a `result` or the `error` that name produced, so
|
|
95
|
+
one unparseable name cannot abort the rest, and entries can be correlated without
|
|
96
|
+
relying on array position.
|
|
97
|
+
|
|
98
|
+
```typescript
|
|
99
|
+
import { guessitMany } from 'guessit-js';
|
|
100
|
+
|
|
101
|
+
guessitMany(['A.2020.1080p.mkv', 'B.S01E02.mkv'], { type: 'episode' });
|
|
102
|
+
// [
|
|
103
|
+
// { input_string: 'A.2020.1080p.mkv', result: { title: 'A', year: 2020, ... } },
|
|
104
|
+
// { input_string: 'B.S01E02.mkv', result: { title: 'B', season: 1, ... } }
|
|
105
|
+
// ]
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
In-process there is no cap — pass the whole library. The 100-name cap applies
|
|
109
|
+
only to the HTTP surfaces, where it bounds one request's shape.
|
|
110
|
+
|
|
88
111
|
### CommonJS
|
|
89
112
|
|
|
90
113
|
```javascript
|
|
@@ -159,7 +182,7 @@ curl -X POST https://guessit.opensubtitles.com/api/guessit \
|
|
|
159
182
|
> production, self-host (`npx guessit-js --serve`, one command) or better,
|
|
160
183
|
> call the library in-process (~1.5 ms per parse, no HTTP at all).
|
|
161
184
|
|
|
162
|
-
Runs on Cloudflare Workers at the edge, CORS enabled, batch up to
|
|
185
|
+
Runs on Cloudflare Workers at the edge, CORS enabled, batch up to 100
|
|
163
186
|
filenames per POST, redeployed automatically with every release.
|
|
164
187
|
|
|
165
188
|
**Self-hosted** — no install needed beyond the package itself:
|
|
@@ -176,6 +199,20 @@ CLI parsing flags become server defaults: `guessit-js --serve -t episode -L en`.
|
|
|
176
199
|
The repo also ships a fuller dev server (`npm start`) with the demo page,
|
|
177
200
|
Swagger UI at `/docs`, and static WASM serving.
|
|
178
201
|
|
|
202
|
+
**Batch contract**, identical on all three HTTP surfaces (hosted worker,
|
|
203
|
+
`--serve`, `npm start`):
|
|
204
|
+
|
|
205
|
+
| | |
|
|
206
|
+
|---|---|
|
|
207
|
+
| Request | `POST /api/guessit` with `{"filenames": [...], "options": {...}}` |
|
|
208
|
+
| Response | one entry per name, in request order, each `{input_string, result}` or `{input_string, error}` |
|
|
209
|
+
| Limits | 100 names per request, 1024 characters per name, 1 MiB body |
|
|
210
|
+
| Errors | `400` for a malformed body, `413` for any limit exceeded |
|
|
211
|
+
|
|
212
|
+
A name that fails to parse becomes an `error` entry — the request still answers
|
|
213
|
+
`200`. The caps bound the shape of one request, not throughput: for 10k names,
|
|
214
|
+
send 100 requests, or skip HTTP and call `guessitMany()` in-process.
|
|
215
|
+
|
|
179
216
|
## WASM
|
|
180
217
|
|
|
181
218
|
For non-JS environments (Rust, Go, C++, edge compute). Uses [Javy](https://github.com/bytecodealliance/javy) (QuickJS → WASM).
|
|
@@ -190,19 +227,24 @@ The WASM build is **bit-identical to the JS build** across the entire test corpu
|
|
|
190
227
|
|
|
191
228
|
## Differences from Python guessit
|
|
192
229
|
|
|
193
|
-
guessit-js is a faithful port (
|
|
194
|
-
|
|
195
|
-
|
|
230
|
+
guessit-js is a faithful port (tracking Python 4.5.1), but it is **not
|
|
231
|
+
bug-for-bug identical** — where Python has a genuine parsing bug, guessit-js is
|
|
232
|
+
corrected. Run against a live Python guessit 4.5.1 over all 2490 corpus inputs,
|
|
233
|
+
**2247 (90.2%) come back identical**; every remaining difference is listed, with a
|
|
234
|
+
verdict, in [`docs/python-parity.md`](docs/python-parity.md). Highlights:
|
|
196
235
|
|
|
197
|
-
- **Cases the released Python 4.
|
|
236
|
+
- **Cases the released Python 4.5.1 still gets wrong** (each verified against the
|
|
198
237
|
real Python CLI; the [demo](https://opensubtitles.github.io/guessit-js) shows
|
|
199
238
|
live side-by-sides): `X2.2003…` (Python: `bonus: 2`, no title), Python's
|
|
200
|
-
|
|
239
|
+
[#875](https://github.com/guessit-io/guessit/issues/875) (fixed upstream in
|
|
240
|
+
4.5.1, years after it was fixed here) and still-open
|
|
201
241
|
[#877](https://github.com/guessit-io/guessit/issues/877) (`Season 3 - 11`,
|
|
202
242
|
anchored weak episodes, `0x539` ids), Python's dead
|
|
203
243
|
`RemoveLessSpecificSeasonEpisode("episode")` pass
|
|
204
|
-
([#961](https://github.com/guessit-io/guessit/issues/961)
|
|
205
|
-
[#962](https://github.com/guessit-io/guessit/pull/962)
|
|
244
|
+
([#961](https://github.com/guessit-io/guessit/issues/961) — diagnosed from this
|
|
245
|
+
port in [#962](https://github.com/guessit-io/guessit/pull/962), fixed upstream
|
|
246
|
+
by rebulk 6.0.2 plus [#982](https://github.com/guessit-io/guessit/pull/982),
|
|
247
|
+
which carries this port's specificity guard), and **114 of the 276
|
|
206
248
|
cross-parser cases Python's own test data admits failing** — fullwidth CJK
|
|
207
249
|
bracket groups, UFC event numbers, anime compound dash titles, fully-bracketed
|
|
208
250
|
titles, and more.
|
|
@@ -215,7 +257,7 @@ is corrected. Highlights:
|
|
|
215
257
|
enum'd value fields, `properties()` mirroring Python's API, and a JSON Schema
|
|
216
258
|
(draft-07) of the output — none of which Python provides as machine-readable
|
|
217
259
|
artifacts.
|
|
218
|
-
- **No Python runtime:** zero runtime dependencies, ESM + CJS + WASM, ~
|
|
260
|
+
- **No Python runtime:** zero runtime dependencies, ESM + CJS + WASM, ~2x faster.
|
|
219
261
|
- **Intentional divergences** (cases where guessit-js is *more* correct than
|
|
220
262
|
Python) are catalogued per-example in [`docs/python-parity.md`](docs/python-parity.md).
|
|
221
263
|
|
|
@@ -231,19 +273,24 @@ is corrected. Highlights:
|
|
|
231
273
|
([#690](https://github.com/guessit-io/guessit/issues/690)/[#696](https://github.com/guessit-io/guessit/issues/696)/[#747](https://github.com/guessit-io/guessit/issues/747)):
|
|
232
274
|
e.g. `Re ZERO …- Season 2 - 15`, romaji + `(English title)` — no unambiguous
|
|
233
275
|
correct parse.
|
|
234
|
-
- **
|
|
235
|
-
|
|
276
|
+
- **Differences that are nobody's bug** — a bare `2012` read as a title here and a
|
|
277
|
+
year there, Python's 23 allowed languages against this port's 60 — are listed
|
|
278
|
+
with a verdict each in [`docs/python-parity.md`](docs/python-parity.md), and the
|
|
279
|
+
38 upstream cases this port does not satisfy yet are parked in
|
|
280
|
+
`test/fixtures/upstream-rules-pending.yml`.
|
|
236
281
|
|
|
237
282
|
## Performance
|
|
238
283
|
|
|
239
|
-
Warm per-parse
|
|
240
|
-
the
|
|
284
|
+
Warm per-parse. The Node and Python numbers below come from one run of the same
|
|
285
|
+
400 corpus names through each parser on the same machine (Apple silicon, Node 20,
|
|
286
|
+
Python 3.11, guessit 4.5.1), best of three passes after a warm-up — absolute
|
|
287
|
+
numbers are hardware-dependent, and the [live
|
|
288
|
+
demo](https://opensubtitles.github.io/guessit-js) times it in your browser:
|
|
241
289
|
|
|
242
290
|
| Runtime | ms/parse | Notes |
|
|
243
291
|
|---------|----------|-------|
|
|
244
|
-
| **
|
|
245
|
-
| **
|
|
246
|
-
| **Python 3.8** | ~15.5 ms | reference |
|
|
292
|
+
| **Node.js 20 (V8)** | ~1.7 ms | **~2× faster than Python guessit** on identical input — recommended for servers/CLI |
|
|
293
|
+
| **Python guessit 4.5.1** | ~3.5 ms | reference, same 400 names |
|
|
247
294
|
| **WASM (QuickJS/Javy)** | ~35 ms warm · ~150 ms cold | for portability, **not** speed (see below) |
|
|
248
295
|
|
|
249
296
|
**About the WASM build.** It exists so you can run guessit in environments without
|
package/bin/cli.mjs
CHANGED
|
@@ -6,7 +6,19 @@
|
|
|
6
6
|
import { readFileSync, existsSync } from 'fs';
|
|
7
7
|
import { homedir } from 'os';
|
|
8
8
|
import { join } from 'path';
|
|
9
|
-
import { guessit, properties as apiProperties, version } from '../dist/guessit-js.js';
|
|
9
|
+
import { guessit, guessitMany, properties as apiProperties, version } from '../dist/guessit-js.js';
|
|
10
|
+
|
|
11
|
+
// Parsing cost grows with the square of the number of matches a name yields, so
|
|
12
|
+
// a long synthetic string costs far more than its length suggests: 400
|
|
13
|
+
// repetitions of "S01E01" take seconds where a real name takes under 3 ms. The
|
|
14
|
+
// whole fixture corpus tops out at 196 characters, so these bounds only ever
|
|
15
|
+
// reject something that was never a filename. --serve is the only path that
|
|
16
|
+
// takes untrusted input; parsing local arguments stays unbounded.
|
|
17
|
+
const MAX_FILENAME_LENGTH = 1024;
|
|
18
|
+
// 100 names is the documented batch contract across every HTTP surface. It is a
|
|
19
|
+
// request-shape bound, not a throughput one: a caller with 10k names sends 100
|
|
20
|
+
// requests, or skips HTTP and calls guessitMany() in-process, which is unbounded.
|
|
21
|
+
const MAX_BATCH = 100;
|
|
10
22
|
|
|
11
23
|
// Python's GuessitEncoder emits babelfish `.name` in JSON ("English",
|
|
12
24
|
// "UNITED STATES") while YAML uses str() ("en", "pt-BR", "US"). Mirror both.
|
|
@@ -383,6 +395,10 @@ if (serve) {
|
|
|
383
395
|
});
|
|
384
396
|
return;
|
|
385
397
|
}
|
|
398
|
+
if (filename.length > MAX_FILENAME_LENGTH) {
|
|
399
|
+
sendJson(res, 413, { error: `filename exceeds ${MAX_FILENAME_LENGTH} characters` });
|
|
400
|
+
return;
|
|
401
|
+
}
|
|
386
402
|
const opts = { ...baseOptions };
|
|
387
403
|
const type = url.searchParams.get('type');
|
|
388
404
|
if (type === 'movie' || type === 'episode') opts.type = type;
|
|
@@ -399,8 +415,28 @@ if (serve) {
|
|
|
399
415
|
const body = JSON.parse(Buffer.concat(chunks).toString('utf8'));
|
|
400
416
|
const opts = { ...baseOptions, ...(body.options || {}) };
|
|
401
417
|
if (Array.isArray(body.filenames)) {
|
|
402
|
-
|
|
418
|
+
if (body.filenames.length > MAX_BATCH) {
|
|
419
|
+
sendJson(res, 413, { error: `Max ${MAX_BATCH} filenames per request` });
|
|
420
|
+
return;
|
|
421
|
+
}
|
|
422
|
+
const names = body.filenames.map(String);
|
|
423
|
+
if (names.some((f) => f.length > MAX_FILENAME_LENGTH)) {
|
|
424
|
+
sendJson(res, 413, { error: `filename exceeds ${MAX_FILENAME_LENGTH} characters` });
|
|
425
|
+
return;
|
|
426
|
+
}
|
|
427
|
+
// One entry per name, each {input_string, result} or {input_string, error} —
|
|
428
|
+
// the documented contract, shared with server.ts and the Cloudflare worker.
|
|
429
|
+
// guessitMany parses the options once and isolates a name that throws.
|
|
430
|
+
sendJson(res, 200, guessitMany(names, opts).map((entry) => (
|
|
431
|
+
'result' in entry
|
|
432
|
+
? { input_string: entry.input_string, result: display(entry.result, 'json') }
|
|
433
|
+
: entry
|
|
434
|
+
)));
|
|
403
435
|
} else if (typeof body.filename === 'string') {
|
|
436
|
+
if (body.filename.length > MAX_FILENAME_LENGTH) {
|
|
437
|
+
sendJson(res, 413, { error: `filename exceeds ${MAX_FILENAME_LENGTH} characters` });
|
|
438
|
+
return;
|
|
439
|
+
}
|
|
404
440
|
sendJson(res, 200, display(guessit(body.filename, opts), 'json'));
|
|
405
441
|
} else {
|
|
406
442
|
sendJson(res, 400, { error: 'Body must contain "filename" (string) or "filenames" (array)' });
|
package/dist/api.d.ts
CHANGED
|
@@ -10,6 +10,19 @@ export declare class GuessItException extends Error {
|
|
|
10
10
|
options: Record<string, unknown>;
|
|
11
11
|
constructor(string: string, options: Record<string, unknown>, cause?: unknown);
|
|
12
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* One entry of a `guessitMany` batch. A string that parses yields `result`; a
|
|
15
|
+
* string that throws yields `error` instead, so a single bad name cannot abort
|
|
16
|
+
* the rest of the batch. `input_string` is always the string as it was passed in,
|
|
17
|
+
* which lets callers correlate entries without relying on array position.
|
|
18
|
+
*/
|
|
19
|
+
export type GuessItBatchEntry = {
|
|
20
|
+
input_string: string;
|
|
21
|
+
result: GuessItResult;
|
|
22
|
+
} | {
|
|
23
|
+
input_string: string;
|
|
24
|
+
error: string;
|
|
25
|
+
};
|
|
13
26
|
export declare class GuessItApi {
|
|
14
27
|
private _rebulk;
|
|
15
28
|
private _config;
|
|
@@ -18,6 +31,18 @@ export declare class GuessItApi {
|
|
|
18
31
|
reset(): void;
|
|
19
32
|
configure(options?: RawOptions, rulesBuilder?: (config: AdvancedConfig) => Rebulk, force?: boolean, sanitizeOptions?: boolean): Record<string, unknown>;
|
|
20
33
|
guessit(string: string, options?: RawOptions): GuessItResult;
|
|
34
|
+
/**
|
|
35
|
+
* Parse many strings in one pass.
|
|
36
|
+
*
|
|
37
|
+
* `guessit()` re-parses the options and re-merges them with the whole config on
|
|
38
|
+
* every call — work that costs more than matching a short name does. Hoisting it
|
|
39
|
+
* out of the loop is the reason this method exists; the rules never write to the
|
|
40
|
+
* merged options, so one object is safe to share across the batch.
|
|
41
|
+
*/
|
|
42
|
+
guessitMany(strings: string[], options?: RawOptions): GuessItBatchEntry[];
|
|
43
|
+
/** Options → config-merged options, ready to hand to rebulk as its context. */
|
|
44
|
+
private _prepare;
|
|
45
|
+
private _guess;
|
|
21
46
|
properties(options?: RawOptions): Record<string, unknown[]>;
|
|
22
47
|
suggestedExpected(titles: string[], options?: RawOptions): string[];
|
|
23
48
|
}
|
|
@@ -27,6 +52,11 @@ export declare const defaultApi: GuessItApi;
|
|
|
27
52
|
* Guess metadata from a filename or release name.
|
|
28
53
|
*/
|
|
29
54
|
export declare function guessit(string: string, options?: RawOptions): GuessItResult;
|
|
55
|
+
/**
|
|
56
|
+
* Guess metadata for many filenames or release names with one options pass.
|
|
57
|
+
* Each entry carries either a `result` or the `error` that string produced.
|
|
58
|
+
*/
|
|
59
|
+
export declare function guessitMany(strings: string[], options?: RawOptions): GuessItBatchEntry[];
|
|
30
60
|
/**
|
|
31
61
|
* Get all properties that can be detected.
|
|
32
62
|
*/
|