guessit-js 3.9.0 → 4.0.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/README.md CHANGED
@@ -3,19 +3,21 @@
3
3
  Extract metadata (title, year, season, episode, codec, language, etc.) from media filenames — TypeScript port of Python [guessit](https://github.com/guessit-io/guessit).
4
4
 
5
5
  [![npm version](https://img.shields.io/npm/v/guessit-js.svg)](https://www.npmjs.com/package/guessit-js)
6
+ [![Tests](https://github.com/opensubtitles/guessit-js/actions/workflows/ci.yml/badge.svg)](https://github.com/opensubtitles/guessit-js/actions/workflows/ci.yml)
6
7
  [![License: LGPL-3.0](https://img.shields.io/badge/License-LGPL--3.0-blue.svg)](https://www.gnu.org/licenses/lgpl-3.0)
8
+ [![Python guessit compat](https://img.shields.io/badge/guessit_compat-100%25_(1036%2F1036)-brightgreen)](https://github.com/guessit-io/guessit)
7
9
 
8
- **[Live Demo](https://opensubtitles.github.io/guessit-js)** · **[API Docs](https://opensubtitles.github.io/guessit-js/docs)** · **[WASM Test](https://opensubtitles.github.io/guessit-js/wasm-test.html)**
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)**
9
11
 
10
12
  ## Features
11
13
 
12
- - **100% compatibility** with Python guessit (1035/1035 tests passing)
14
+ - **100% compatibility** with Python guessit (1036/1036 fixtures passing) — and **more correct** in places: ships fixes for 32 upstream guessit bugs that Python still has (see [Differences from Python](#differences-from-python-guessit))
13
15
  - **3.5x faster** than Python (6.87ms vs 23.86ms per parse)
14
- - **40+ properties** detected: title, year, season, episode, resolution, codec, language, and more
16
+ - **50 properties** detected: title, year, season, episode, resolution, codec, language, and more — with a [machine-readable schema](#output-schema)
15
17
  - **Single dependency** ([rebulk-js](https://www.npmjs.com/package/rebulk-js))
16
18
  - **Dual format**: ESM and CommonJS
17
- - **TypeScript**: full type definitions included
18
- - **WASM**: runs in any WASI-compatible runtime
19
+ - **TypeScript**: full, precise type definitions (typed `GuessItResult`, enum'd value fields)
20
+ - **WASM**: runs in any WASI-compatible runtime, **bit-identical to the JS build**
19
21
 
20
22
  ## Install
21
23
 
@@ -39,6 +41,11 @@ const result = guessit('The.Dark.Knight.2008.1080p.BluRay.x264-GROUP.mkv');
39
41
  // container: 'mkv',
40
42
  // type: 'movie'
41
43
  // }
44
+
45
+ // Short titles are handled correctly too:
46
+ guessit('X2.2003.720p.DSNP.WEB-DL.DDP5.1.H.264-EVO.mkv');
47
+ // { title: 'X2', year: 2003, screen_size: '720p',
48
+ // streaming_service: 'Disney+', source: 'Web', ... }
42
49
  ```
43
50
 
44
51
  ### CommonJS
@@ -71,33 +78,110 @@ guessit('file.mkv', { excludes: ['release_group'] });
71
78
  | **Audio** | `audio_codec`, `audio_profile`, `audio_channels`, `audio_bit_rate` |
72
79
  | **Source** | `source`, `streaming_service` |
73
80
  | **Release** | `release_group`, `edition`, `other`, `proper_count` |
74
- | **File** | `container`, `mimetype`, `size`, `crc32`, `uuid` |
81
+ | **File** | `container` (video / subtitle / archive / image / nfo / torrent / nzb), `mimetype`, `size`, `crc32`, `uuid` |
75
82
  | **Metadata** | `language`, `subtitle_language`, `country`, `type` |
76
83
 
84
+ ### Output schema
85
+
86
+ The result is fully typed — import `GuessItResult` for autocomplete and type-checking:
87
+
88
+ ```ts
89
+ import { guessit, properties, GUESSIT_SCHEMA, type GuessItResult } from 'guessit-js';
90
+
91
+ const r: GuessItResult = guessit('The.Dark.Knight.2008.1080p.BluRay.x264-GRP.mkv');
92
+ r.source; // typed as the closed enum: "Blu-ray" | "Web" | "HDTV" | …
93
+
94
+ properties(); // { source: ["Blu-ray", "Web", …], type: ["episode","movie"], … } for all 50 properties
95
+ GUESSIT_SCHEMA.source.enum; // the allowed values, programmatically
96
+ ```
97
+
98
+ - **`properties()`** — returns every emittable property with its possible values (value-constrained props list their full enum; free/computed props list `[null]`), mirroring Python guessit's `properties()`.
99
+ - **`GUESSIT_SCHEMA`** — the machine-readable schema (type, cardinality, enum) for all properties.
100
+ - **[`docs/output-schema.json`](docs/output-schema.json)** — a JSON Schema (draft-07) of the output, for validating results or generating clients in other languages.
101
+
102
+ Regenerate the schema (after parsing changes) with `npm run schema`. A test (`test/schema.test.ts`) guarantees it never goes stale — every value emitted across the corpus must be in the schema.
103
+
77
104
  ## REST API
78
105
 
79
106
  ```bash
80
107
  npm start # port 3847
81
-
82
108
  curl "http://localhost:3847/api/guessit?filename=Movie.2024.1080p.mkv"
83
109
  ```
84
110
 
85
111
  ## WASM
86
112
 
87
- Compiles to WebAssembly via [Javy](https://github.com/bytecodealliance/javy) (QuickJS engine). For non-JS environments (Rust, Go, C++, edge compute).
113
+ For non-JS environments (Rust, Go, C++, edge compute). Uses [Javy](https://github.com/bytecodealliance/javy) (QuickJS → WASM).
88
114
 
89
115
  ```bash
90
116
  npm run wasm
91
117
  echo '{"filename":"Movie.2024.1080p.mkv"}' | wasmtime wasm/guessit.wasm
92
118
  ```
93
119
 
120
+ The WASM build is **bit-identical to the JS build** across the entire test corpus
121
+ (1026/1026, including accented titles) — verified by `test/wasm-full.test.ts`.
122
+
123
+ ## Differences from Python guessit
124
+
125
+ guessit-js is a faithful port (1036/1036 fixtures match Python 3.8.0), but it is
126
+ **not bug-for-bug identical** — where Python has a genuine parsing bug, guessit-js
127
+ is corrected. Highlights:
128
+
129
+ - **32 upstream guessit bugs fixed** that Python still gets wrong — e.g. `Us.2019`
130
+ (title vs country `US`), `The.Collector` (title vs edition), `X2.2003…` (short
131
+ title), `grown-ish…[eztv]` (hyphenated title split), `cd`-matching mid-hash, and
132
+ source/codec/extension tokens leaking into `release_group`/`title`. Full ledger:
133
+ [`docs/upstream-issues.md`](docs/upstream-issues.md).
134
+ - **More properties / better detection:** `imdb_id`/`tmdb_id`/`tvdb_id`, `volume`,
135
+ archive & image **containers** (`.rar`/`.7z`/`.jpg`…), artwork classification
136
+ (`poster`/`fanart` → `other`), VR / Opening-Ending credits, month-name dates,
137
+ CJK season/episode markers, and detection of Telugu/Spanish that Python misses.
138
+ - **Typed, schema-described output:** a precise `GuessItResult` interface, a
139
+ complete `properties()` (Python's is partial), and a JSON Schema.
140
+ - **No Python runtime:** zero runtime dependencies, ESM + CJS + WASM, ~3.5x faster.
141
+ - **Intentional divergences** (cases where guessit-js is *more* correct than
142
+ Python) are catalogued per-example in [`docs/python-parity.md`](docs/python-parity.md).
143
+
144
+ ## Known issues
145
+
146
+ - **Music files are not supported** ([#599](https://github.com/guessit-io/guessit/issues/599)):
147
+ `Artist - Album/01 Track.flac` is parsed with the video vocabulary (title /
148
+ alternative_title), not `artist`/`album`/`track`. Out of scope for now.
149
+ - **No composite `quality` field** ([#802](https://github.com/guessit-io/guessit/issues/802)):
150
+ `screen_size`, `source` and `video_codec` are returned separately, not combined
151
+ into one string (the request is underspecified).
152
+ - **A few ambiguous anime conventions** remain
153
+ ([#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)):
154
+ e.g. `Re ZERO …- Season 2 - 15`, romaji + `(English title)` — no unambiguous
155
+ correct parse.
156
+ - **12 debatable cases** vs Python (neither clearly right) are listed under
157
+ "② NEUTRAL" in [`docs/python-parity.md`](docs/python-parity.md).
158
+
94
159
  ## Performance
95
160
 
96
- | Runtime | ms/parse | vs Python |
97
- |---------|----------|-----------|
98
- | **Python 3.8** (guessit 3.8.0) | 23.86 ms | baseline |
99
- | **Node.js 22** (guessit-js) | 6.87 ms | **3.5x faster** |
100
- | **Browser** (IIFE bundle) | ~2-3 ms | **~10x faster** |
161
+ Warm per-parse, measured on one machine (absolute numbers are hardware-dependent —
162
+ the [live demo](https://opensubtitles.github.io/guessit-js) times it in your browser):
163
+
164
+ | Runtime | ms/parse | Notes |
165
+ |---------|----------|-------|
166
+ | **Browser (V8)** | ~2–3 ms | fastest; JIT-compiled |
167
+ | **Node.js 22 (V8)** | ~4.4 ms | **~3.5× faster than Python** (same machine) — recommended for servers/CLI |
168
+ | **Python 3.8** | ~15.5 ms | reference |
169
+ | **WASM (QuickJS/Javy)** | ~35 ms warm · ~150 ms cold | for portability, **not** speed (see below) |
170
+
171
+ **About the WASM build.** It exists so you can run guessit in environments without
172
+ a JS engine (Rust, Go, C/C++, edge/WASI runtimes). Javy compiles the bundle to
173
+ **QuickJS**, which is an *interpreter* (no JIT), so per-parse compute (~35 ms) is
174
+ slower than V8 and even than Python — that's inherent to the engine, not the code.
175
+ If you want speed, use the Node/browser build (V8). If you need WASM, the levers
176
+ that actually help:
177
+
178
+ - **Amortize startup** — instantiate the module once and parse many filenames;
179
+ most of the ~150 ms single-shot cost is wasmtime + module init, not parsing.
180
+ - **AOT-compile the module** (`wasmtime compile guessit.wasm -o guessit.cwasm`)
181
+ to skip per-run JIT of the wasm itself (~30 ms off cold start).
182
+ - The ~35 ms warm floor is QuickJS interpretation; beating it would require a
183
+ JIT-capable WASI JS engine (none production-ready) or a native port — out of
184
+ scope. WASM correctness is **bit-identical** to the JS build.
101
185
 
102
186
  ## License
103
187
 
package/dist/api.d.ts CHANGED
@@ -1,15 +1,15 @@
1
1
  import { Rebulk } from 'rebulk-js';
2
2
  import { AdvancedConfig } from './rules/index.js';
3
3
  import { RawOptions } from './options.js';
4
+ import { GuessItResult } from './schema.js';
4
5
 
6
+ export type { GuessItResult, GuessitLanguage, PropertySchema } from './schema.js';
7
+ export { GUESSIT_SCHEMA } from './schema.js';
5
8
  export declare class GuessItException extends Error {
6
9
  string: string;
7
10
  options: Record<string, unknown>;
8
11
  constructor(string: string, options: Record<string, unknown>, cause?: unknown);
9
12
  }
10
- export interface GuessItResult {
11
- [key: string]: unknown;
12
- }
13
13
  export declare class GuessItApi {
14
14
  private _rebulk;
15
15
  private _config;