guessit-js 3.8.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 +174 -0
- package/dist/api.d.ts +41 -0
- package/dist/config/index.d.ts +9 -0
- package/dist/guessit-js.cjs +10050 -0
- package/dist/guessit-js.cjs.map +1 -0
- package/dist/guessit-js.js +10050 -0
- package/dist/guessit-js.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.html +675 -0
- package/dist/language/data.d.ts +24 -0
- package/dist/language/index.d.ts +68 -0
- package/dist/openapi.json +617 -0
- package/dist/options.d.ts +35 -0
- package/dist/reutils.d.ts +8 -0
- package/dist/rules/common/comparators.d.ts +12 -0
- package/dist/rules/common/date.d.ts +6 -0
- package/dist/rules/common/expected.d.ts +7 -0
- package/dist/rules/common/formatters.d.ts +20 -0
- package/dist/rules/common/index.d.ts +27 -0
- package/dist/rules/common/numeral.d.ts +7 -0
- package/dist/rules/common/pattern.d.ts +7 -0
- package/dist/rules/common/quantity.d.ts +21 -0
- package/dist/rules/common/validators.d.ts +8 -0
- package/dist/rules/common/words.d.ts +6 -0
- package/dist/rules/index.d.ts +23 -0
- package/dist/rules/markers/groups.d.ts +9 -0
- package/dist/rules/markers/path.d.ts +3 -0
- package/dist/rules/processors.d.ts +53 -0
- package/dist/rules/properties/audio_codec.d.ts +3 -0
- package/dist/rules/properties/bit_rate.d.ts +3 -0
- package/dist/rules/properties/bonus.d.ts +3 -0
- package/dist/rules/properties/cd.d.ts +3 -0
- package/dist/rules/properties/container.d.ts +3 -0
- package/dist/rules/properties/country.d.ts +3 -0
- package/dist/rules/properties/crc.d.ts +3 -0
- package/dist/rules/properties/date.d.ts +6 -0
- package/dist/rules/properties/edition.d.ts +3 -0
- package/dist/rules/properties/episode_title.d.ts +3 -0
- package/dist/rules/properties/episodes.d.ts +22 -0
- package/dist/rules/properties/film.d.ts +3 -0
- package/dist/rules/properties/language.d.ts +17 -0
- package/dist/rules/properties/mimetype.d.ts +3 -0
- package/dist/rules/properties/other.d.ts +4 -0
- package/dist/rules/properties/part.d.ts +3 -0
- package/dist/rules/properties/release_group.d.ts +3 -0
- package/dist/rules/properties/screen_size.d.ts +10 -0
- package/dist/rules/properties/size.d.ts +3 -0
- package/dist/rules/properties/source.d.ts +3 -0
- package/dist/rules/properties/streaming_service.d.ts +3 -0
- package/dist/rules/properties/title.d.ts +6 -0
- package/dist/rules/properties/type.d.ts +6 -0
- package/dist/rules/properties/video_codec.d.ts +3 -0
- package/dist/rules/properties/website.d.ts +3 -0
- package/dist/wasm-test.html +467 -0
- package/package.json +70 -0
package/README.md
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
# guessit-js
|
|
2
|
+
|
|
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
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/guessit-js)
|
|
6
|
+
[](https://www.gnu.org/licenses/lgpl-3.0)
|
|
7
|
+
|
|
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)**
|
|
9
|
+
|
|
10
|
+
## Features
|
|
11
|
+
|
|
12
|
+
- **99.3% compatibility** with Python guessit (1018/1025 tests passing)
|
|
13
|
+
- **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
|
|
15
|
+
- **Single dependency** ([rebulk-js](https://www.npmjs.com/package/rebulk-js))
|
|
16
|
+
- **Dual format**: ESM and CommonJS
|
|
17
|
+
- **TypeScript**: full type definitions included
|
|
18
|
+
- **WASM**: runs in any WASI-compatible runtime (wasmtime, wasmer, browsers)
|
|
19
|
+
|
|
20
|
+
## Install
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install guessit-js
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Usage
|
|
27
|
+
|
|
28
|
+
```typescript
|
|
29
|
+
import { guessit } from 'guessit-js';
|
|
30
|
+
|
|
31
|
+
const result = guessit('The.Dark.Knight.2008.1080p.BluRay.x264-GROUP.mkv');
|
|
32
|
+
|
|
33
|
+
console.log(result);
|
|
34
|
+
// {
|
|
35
|
+
// title: 'The Dark Knight',
|
|
36
|
+
// year: 2008,
|
|
37
|
+
// screen_size: '1080p',
|
|
38
|
+
// source: 'Blu-ray',
|
|
39
|
+
// video_codec: 'H.264',
|
|
40
|
+
// release_group: 'GROUP',
|
|
41
|
+
// container: 'mkv',
|
|
42
|
+
// type: 'movie'
|
|
43
|
+
// }
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### CommonJS
|
|
47
|
+
|
|
48
|
+
```javascript
|
|
49
|
+
const { guessit } = require('guessit-js');
|
|
50
|
+
|
|
51
|
+
const result = guessit('Breaking.Bad.S01E02.720p.BluRay.x264-DEMAND.mkv');
|
|
52
|
+
console.log(result.title); // 'Breaking Bad'
|
|
53
|
+
console.log(result.season); // 1
|
|
54
|
+
console.log(result.episode); // 2
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Options
|
|
58
|
+
|
|
59
|
+
```typescript
|
|
60
|
+
// Force type detection
|
|
61
|
+
guessit('file.mkv', { type: 'episode' });
|
|
62
|
+
|
|
63
|
+
// Provide expected title for ambiguous filenames
|
|
64
|
+
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
|
|
70
|
+
guessit('file.mkv', { excludes: ['release_group'] });
|
|
71
|
+
|
|
72
|
+
// Name-only mode (ignore path separators)
|
|
73
|
+
guessit('file.mkv', { name_only: true });
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Detected Properties
|
|
77
|
+
|
|
78
|
+
| Category | Properties |
|
|
79
|
+
|----------|-----------|
|
|
80
|
+
| **Title** | `title`, `alternative_title`, `episode_title` |
|
|
81
|
+
| **Episode** | `season`, `episode`, `episode_details`, `episode_count`, `season_count`, `absolute_episode`, `disc`, `part` |
|
|
82
|
+
| **Date** | `year`, `date` |
|
|
83
|
+
| **Video** | `screen_size`, `aspect_ratio`, `frame_rate`, `video_codec`, `video_profile`, `color_depth` |
|
|
84
|
+
| **Audio** | `audio_codec`, `audio_profile`, `audio_channels`, `audio_bit_rate` |
|
|
85
|
+
| **Source** | `source`, `streaming_service` |
|
|
86
|
+
| **Release** | `release_group`, `edition`, `other`, `proper_count` |
|
|
87
|
+
| **File** | `container`, `mimetype`, `size`, `crc32`, `uuid` |
|
|
88
|
+
| **Metadata** | `language`, `subtitle_language`, `country`, `type` |
|
|
89
|
+
| **Film** | `film`, `film_title`, `bonus`, `bonus_title` |
|
|
90
|
+
|
|
91
|
+
## REST API
|
|
92
|
+
|
|
93
|
+
Self-host the API server:
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
npm start # starts on port 3847
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
# GET
|
|
101
|
+
curl "http://localhost:3847/api/guessit?filename=Movie.2024.1080p.mkv"
|
|
102
|
+
|
|
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"}}'
|
|
107
|
+
|
|
108
|
+
# Swagger UI at http://localhost:3847/docs
|
|
109
|
+
# OpenAPI spec at http://localhost:3847/openapi.json
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## WASM
|
|
113
|
+
|
|
114
|
+
guessit-js compiles to WebAssembly via [Javy](https://github.com/bytecodealliance/javy) (QuickJS):
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
# Build
|
|
118
|
+
npm run wasm
|
|
119
|
+
|
|
120
|
+
# Run (stdin/stdout JSON)
|
|
121
|
+
echo '{"filename":"Movie.2024.1080p.mkv"}' | wasmtime wasm/guessit.wasm
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
**3.9 MB** raw · **1.6 MB** gzipped · Compatible with wasmtime, wasmer, WasmEdge, browsers
|
|
125
|
+
|
|
126
|
+
## Performance
|
|
127
|
+
|
|
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
|
+
```
|
|
171
|
+
|
|
172
|
+
## License
|
|
173
|
+
|
|
174
|
+
LGPL-3.0 — same as Python guessit.
|
package/dist/api.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Rebulk } from 'rebulk-js';
|
|
2
|
+
import { AdvancedConfig } from './rules/index.js';
|
|
3
|
+
import { RawOptions } from './options.js';
|
|
4
|
+
|
|
5
|
+
export declare class GuessItException extends Error {
|
|
6
|
+
string: string;
|
|
7
|
+
options: Record<string, unknown>;
|
|
8
|
+
constructor(string: string, options: Record<string, unknown>, cause?: unknown);
|
|
9
|
+
}
|
|
10
|
+
export interface GuessItResult {
|
|
11
|
+
[key: string]: unknown;
|
|
12
|
+
}
|
|
13
|
+
export declare class GuessItApi {
|
|
14
|
+
private _rebulk;
|
|
15
|
+
private _config;
|
|
16
|
+
private _loadConfigOptions;
|
|
17
|
+
private _advancedConfig;
|
|
18
|
+
reset(): void;
|
|
19
|
+
configure(options?: RawOptions, rulesBuilder?: (config: AdvancedConfig) => Rebulk, force?: boolean, sanitizeOptions?: boolean): Record<string, unknown>;
|
|
20
|
+
guessit(string: string, options?: RawOptions): GuessItResult;
|
|
21
|
+
properties(options?: RawOptions): Record<string, unknown[]>;
|
|
22
|
+
suggestedExpected(titles: string[], options?: RawOptions): string[];
|
|
23
|
+
}
|
|
24
|
+
/** Default singleton API instance */
|
|
25
|
+
export declare const defaultApi: GuessItApi;
|
|
26
|
+
/**
|
|
27
|
+
* Guess metadata from a filename or release name.
|
|
28
|
+
*/
|
|
29
|
+
export declare function guessit(string: string, options?: RawOptions): GuessItResult;
|
|
30
|
+
/**
|
|
31
|
+
* Get all properties that can be detected.
|
|
32
|
+
*/
|
|
33
|
+
export declare function properties(options?: RawOptions): Record<string, unknown[]>;
|
|
34
|
+
/**
|
|
35
|
+
* Configure the default API instance.
|
|
36
|
+
*/
|
|
37
|
+
export declare function configure(options?: RawOptions, rulesBuilder?: (config: AdvancedConfig) => Rebulk, force?: boolean): void;
|
|
38
|
+
/**
|
|
39
|
+
* Reset the default API instance.
|
|
40
|
+
*/
|
|
41
|
+
export declare function reset(): void;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Rebulk } from 'rebulk-js';
|
|
2
|
+
|
|
3
|
+
export declare function registerFunction(name: string, fn: unknown): void;
|
|
4
|
+
export declare function loadPatterns(rebulk: Rebulk, patternType: 'regex' | 'string', patterns: string[], options?: Record<string | symbol, unknown>): void;
|
|
5
|
+
/**
|
|
6
|
+
* Load patterns defined in the given config dict into the rebulk builder.
|
|
7
|
+
* Mirrors Python's load_config_patterns().
|
|
8
|
+
*/
|
|
9
|
+
export declare function loadConfigPatterns(rebulk: Rebulk, config: Record<string, unknown> | undefined, options?: Record<string | symbol, unknown>): void;
|