guessit-js 3.8.1 → 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
- - **99.3% compatibility** with Python guessit (1018/1025 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 (wasmtime, wasmer, browsers)
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
 
@@ -29,8 +31,6 @@ npm install guessit-js
29
31
  import { guessit } from 'guessit-js';
30
32
 
31
33
  const result = guessit('The.Dark.Knight.2008.1080p.BluRay.x264-GROUP.mkv');
32
-
33
- console.log(result);
34
34
  // {
35
35
  // title: 'The Dark Knight',
36
36
  // year: 2008,
@@ -41,13 +41,17 @@ console.log(result);
41
41
  // container: 'mkv',
42
42
  // type: 'movie'
43
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', ... }
44
49
  ```
45
50
 
46
51
  ### CommonJS
47
52
 
48
53
  ```javascript
49
54
  const { guessit } = require('guessit-js');
50
-
51
55
  const result = guessit('Breaking.Bad.S01E02.720p.BluRay.x264-DEMAND.mkv');
52
56
  console.log(result.title); // 'Breaking Bad'
53
57
  console.log(result.season); // 1
@@ -57,20 +61,10 @@ console.log(result.episode); // 2
57
61
  ### Options
58
62
 
59
63
  ```typescript
60
- // Force type detection
61
64
  guessit('file.mkv', { type: 'episode' });
62
-
63
- // Provide expected title for ambiguous filenames
64
65
  guessit('my 720p show S01E02', { expected_title: ['my 720p show'] });
65
-
66
- // Restrict language/country detection
67
- guessit('file.mkv', { allowed_languages: ['en', 'fr'], allowed_countries: ['us', 'gb'] });
68
-
69
- // Exclude specific properties
66
+ guessit('file.mkv', { allowed_languages: ['en', 'fr'] });
70
67
  guessit('file.mkv', { excludes: ['release_group'] });
71
-
72
- // Name-only mode (ignore path separators)
73
- guessit('file.mkv', { name_only: true });
74
68
  ```
75
69
 
76
70
  ## Detected Properties
@@ -84,91 +78,111 @@ guessit('file.mkv', { name_only: true });
84
78
  | **Audio** | `audio_codec`, `audio_profile`, `audio_channels`, `audio_bit_rate` |
85
79
  | **Source** | `source`, `streaming_service` |
86
80
  | **Release** | `release_group`, `edition`, `other`, `proper_count` |
87
- | **File** | `container`, `mimetype`, `size`, `crc32`, `uuid` |
81
+ | **File** | `container` (video / subtitle / archive / image / nfo / torrent / nzb), `mimetype`, `size`, `crc32`, `uuid` |
88
82
  | **Metadata** | `language`, `subtitle_language`, `country`, `type` |
89
- | **Film** | `film`, `film_title`, `bonus`, `bonus_title` |
90
83
 
91
- ## REST API
84
+ ### Output schema
92
85
 
93
- Self-host the API server:
86
+ The result is fully typed — import `GuessItResult` for autocomplete and type-checking:
94
87
 
95
- ```bash
96
- npm start # starts on port 3847
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
97
96
  ```
98
97
 
99
- ```bash
100
- # GET
101
- curl "http://localhost:3847/api/guessit?filename=Movie.2024.1080p.mkv"
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.
102
101
 
103
- # POST with options
104
- curl -X POST http://localhost:3847/api/guessit \
105
- -H "Content-Type: application/json" \
106
- -d '{"filename": "file.mkv", "options": {"type": "movie"}}'
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.
107
103
 
108
- # Swagger UI at http://localhost:3847/docs
109
- # OpenAPI spec at http://localhost:3847/openapi.json
104
+ ## REST API
105
+
106
+ ```bash
107
+ npm start # port 3847
108
+ curl "http://localhost:3847/api/guessit?filename=Movie.2024.1080p.mkv"
110
109
  ```
111
110
 
112
111
  ## WASM
113
112
 
114
- guessit-js compiles to WebAssembly via [Javy](https://github.com/bytecodealliance/javy) (QuickJS):
113
+ For non-JS environments (Rust, Go, C++, edge compute). Uses [Javy](https://github.com/bytecodealliance/javy) (QuickJS → WASM).
115
114
 
116
115
  ```bash
117
- # Build
118
116
  npm run wasm
119
-
120
- # Run (stdin/stdout JSON)
121
117
  echo '{"filename":"Movie.2024.1080p.mkv"}' | wasmtime wasm/guessit.wasm
122
118
  ```
123
119
 
124
- **3.9 MB** raw · **1.6 MB** gzipped · Compatible with wasmtime, wasmer, WasmEdge, browsers
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).
125
158
 
126
159
  ## Performance
127
160
 
128
- Benchmark: 1000 parses of 10 diverse filenames on the same machine:
129
-
130
- | Runtime | ms/parse | vs Python |
131
- |---------|----------|-----------|
132
- | **Python 3** (guessit 3.8.0) | 23.86 ms | baseline |
133
- | **Node.js 22** (guessit-js 3.8.1) | 6.87 ms | **3.5x faster** |
134
-
135
- ## Compatibility
136
-
137
- Port of Python guessit v3.8.0. Test suite uses the same YAML fixtures:
138
-
139
- - `movies.yml` — 208 test cases
140
- - `episodes.yml` — 523 test cases
141
- - `various.yml` — 126 test cases
142
- - `streaming_services.yaml` — 197 test cases
143
-
144
- **1018 / 1025 passing** (99.3%)
145
-
146
- ## Architecture
147
-
148
- 4-layer design (~8,400 lines TypeScript across 46 source files):
149
-
150
- 1. **Public API** (`src/api.ts`) — GuessItApi class, config management
151
- 2. **Rebulk Engine** ([rebulk-js](https://www.npmjs.com/package/rebulk-js)) — generic pattern matching engine
152
- 3. **Rules & Properties** (`src/rules/`) — 25 property modules with post-processing rules
153
- 4. **Configuration** (`src/config/options.json`) — JSON-driven pattern definitions
154
-
155
- ## Self-hosting
156
-
157
- ```bash
158
- # Clone and install
159
- git clone https://github.com/opensubtitles/guessit-js
160
- cd guessit-js && npm install
161
-
162
- # Run server (port 3847)
163
- npm start
164
-
165
- # Run tests
166
- npm test
167
-
168
- # Build
169
- npm run build
170
- ```
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.
171
185
 
172
186
  ## License
173
187
 
174
- LGPL-3.0 — same as Python guessit.
188
+ LGPL-3.0
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;