guessit-js 4.5.1 → 4.5.3

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
@@ -5,13 +5,13 @@ Extract metadata (title, year, season, episode, codec, language, etc.) from medi
5
5
  [![npm version](https://img.shields.io/npm/v/guessit-js.svg)](https://www.npmjs.com/package/guessit-js)
6
6
  [![Tests](https://github.com/opensubtitles/guessit-js/actions/workflows/ci.yml/badge.svg)](https://github.com/opensubtitles/guessit-js/actions/workflows/ci.yml)
7
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_(1333%2F1333)-brightgreen)](https://github.com/guessit-io/guessit)
8
+ [![Python guessit compat](https://img.shields.io/badge/guessit_compat-100%25_(1342%2F1342)-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 4.4.0 (1333/1333 fixtures passing, including Python's own grown 4.x corpus) — and **more correct**: ships fixes for 32 historical upstream bugs, Python's still-open #875 and #877, and 104 of the 276 cross-parser cases Python admits failing (see [Differences from Python](#differences-from-python-guessit))
14
+ - **100% compatibility** with Python guessit 4.4.0 (1342/1342 fixtures passing, including Python's own grown 4.x corpus) — and **more correct**: ships fixes for 32 historical upstream bugs, Python's still-open #875 and #877, and 112 of the 276 cross-parser cases Python admits failing (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))
@@ -25,6 +25,18 @@ Extract metadata (title, year, season, episode, codec, language, etc.) from medi
25
25
  npm install guessit-js
26
26
  ```
27
27
 
28
+ ## CLI
29
+
30
+ ```bash
31
+ npx guessit-js "The.Dark.Knight.2008.1080p.BluRay.x264-GROUP.mkv"
32
+ # title: The Dark Knight
33
+ # year: 2008
34
+ # ...
35
+
36
+ npx guessit-js -j "Mob Psycho 100 - 09.mkv" # JSON output
37
+ npx guessit-js -t episode "ambiguous.file.mkv" # force type
38
+ ```
39
+
28
40
  ## Usage
29
41
 
30
42
  ```typescript
@@ -67,6 +79,10 @@ guessit('file.mkv', { allowed_languages: ['en', 'fr'] });
67
79
  guessit('file.mkv', { excludes: ['release_group'] });
68
80
  ```
69
81
 
82
+ ```typescript
83
+ import { version } from 'guessit-js'; // package version string
84
+ ```
85
+
70
86
  ## Detected Properties
71
87
 
72
88
  | Category | Properties |
@@ -118,11 +134,11 @@ echo '{"filename":"Movie.2024.1080p.mkv"}' | wasmtime wasm/guessit.wasm
118
134
  ```
119
135
 
120
136
  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`.
137
+ (1035/1035, including accented titles) — verified by `test/wasm-full.test.ts`.
122
138
 
123
139
  ## Differences from Python guessit
124
140
 
125
- guessit-js is a faithful port (1333/1333 fixtures, tracking Python 4.4.0), but it is
141
+ guessit-js is a faithful port (1342/1342 fixtures, tracking Python 4.4.0), but it is
126
142
  **not bug-for-bug identical** — where Python has a genuine parsing bug, guessit-js
127
143
  is corrected. Highlights:
128
144
 
package/bin/cli.mjs ADDED
@@ -0,0 +1,51 @@
1
+ #!/usr/bin/env node
2
+ // guessit-js CLI — mirrors the Python `guessit` command.
3
+ // guessit-js <filename> [<filename> ...] property: value lines
4
+ // guessit-js -j <filename> JSON output
5
+ // guessit-js -t movie <filename> force type
6
+ import { guessit, version } from '../dist/guessit-js.js';
7
+
8
+ const args = process.argv.slice(2);
9
+ const filenames = [];
10
+ let json = false;
11
+ let type = null;
12
+
13
+ for (let i = 0; i < args.length; i++) {
14
+ const a = args[i];
15
+ if (a === '-j' || a === '--json') json = true;
16
+ else if (a === '-t' || a === '--type') type = args[++i];
17
+ else if (a === '-v' || a === '--version') {
18
+ console.log(version);
19
+ process.exit(0);
20
+ } else if (a === '-h' || a === '--help') {
21
+ console.log(`guessit-js ${version} — extract metadata from media filenames
22
+
23
+ Usage: guessit-js [options] <filename> [<filename> ...]
24
+
25
+ Options:
26
+ -j, --json output JSON (single object, or array for multiple files)
27
+ -t, --type <type> suggested type: movie or episode
28
+ -v, --version print version
29
+ -h, --help this help`);
30
+ process.exit(0);
31
+ } else filenames.push(a);
32
+ }
33
+
34
+ if (!filenames.length) {
35
+ console.error('usage: guessit-js [options] <filename> — see --help');
36
+ process.exit(2);
37
+ }
38
+
39
+ const options = type ? { type } : {};
40
+ const results = filenames.map((f) => guessit(f, options));
41
+
42
+ if (json) {
43
+ console.log(JSON.stringify(filenames.length === 1 ? results[0] : results, null, 2));
44
+ } else {
45
+ results.forEach((r, i) => {
46
+ if (filenames.length > 1) console.log(`${i ? '\n' : ''}For: ${filenames[i]}`);
47
+ for (const [k, v] of Object.entries(r)) {
48
+ console.log(`${k}: ${Array.isArray(v) ? JSON.stringify(v) : v}`);
49
+ }
50
+ });
51
+ }
@@ -372,6 +372,11 @@ class _BaseMatches {
372
372
  toArray() {
373
373
  return [...this._delegate];
374
374
  }
375
+ /** All matches as an array. Ported Python code reads `matches.matches` — without
376
+ * this getter that silently evaluated to undefined and turned rules into no-ops. */
377
+ get matches() {
378
+ return [...this._delegate];
379
+ }
375
380
  // ── Cache accessors ──────────────────────────────────────────────────────
376
381
  get nameDict() {
377
382
  if (!this._nameDict) {
@@ -1621,12 +1626,10 @@ function executeRule(rule, matches, context) {
1621
1626
  }
1622
1627
  function toposortRules(rules) {
1623
1628
  const graph = /* @__PURE__ */ new Map();
1624
- const classToDep = /* @__PURE__ */ new Map();
1629
+ const classToDeps = /* @__PURE__ */ new Map();
1625
1630
  for (const rule of rules) {
1626
- if (classToDep.has(rule.constructor)) {
1627
- throw new Error(`Duplicate class rules are not allowed: ${rule.constructor.name}`);
1628
- }
1629
- classToDep.set(rule.constructor, rule);
1631
+ const cls = rule.constructor;
1632
+ classToDeps.set(cls, [...classToDeps.get(cls) ?? [], rule]);
1630
1633
  }
1631
1634
  for (const rule of rules) {
1632
1635
  const deps = /* @__PURE__ */ new Set();
@@ -1634,18 +1637,20 @@ function toposortRules(rules) {
1634
1637
  if (rawDeps) {
1635
1638
  const depArr = Array.isArray(rawDeps) ? rawDeps : [rawDeps];
1636
1639
  for (const dep of depArr) {
1637
- let resolved;
1640
+ let resolved = [];
1638
1641
  if (typeof dep === "string") {
1639
- for (const [cls, inst] of classToDep) {
1642
+ for (const [cls, insts] of classToDeps) {
1640
1643
  if (cls.name === dep) {
1641
- resolved = inst;
1644
+ resolved = insts;
1642
1645
  break;
1643
1646
  }
1644
1647
  }
1645
1648
  } else {
1646
- resolved = classToDep.get(dep);
1649
+ resolved = classToDeps.get(dep) ?? [];
1650
+ }
1651
+ for (const inst of resolved) {
1652
+ if (inst !== rule) deps.add(inst);
1647
1653
  }
1648
- if (resolved) deps.add(resolved);
1649
1654
  }
1650
1655
  }
1651
1656
  graph.set(rule, deps);
@@ -14511,6 +14516,8 @@ function configure(options, rulesBuilder, force = false) {
14511
14516
  function reset() {
14512
14517
  defaultApi.reset();
14513
14518
  }
14519
+ const version$1 = "4.5.3";
14520
+ const version = version$1;
14514
14521
  exports.GUESSIT_SCHEMA = GUESSIT_SCHEMA;
14515
14522
  exports.GuessItApi = GuessItApi;
14516
14523
  exports.GuessItException = GuessItException;
@@ -14523,4 +14530,5 @@ exports.parseOptions = parseOptions;
14523
14530
  exports.properties = properties;
14524
14531
  exports.rebulkBuilder = rebulkBuilder;
14525
14532
  exports.reset = reset;
14533
+ exports.version = version;
14526
14534
  //# sourceMappingURL=guessit-js.cjs.map