guessit-js 4.5.4 → 4.6.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
@@ -27,7 +27,9 @@ npm install guessit-js
27
27
 
28
28
  ## CLI
29
29
 
30
- Mirrors the Python `guessit` command:
30
+ **Drop-in replacement** for the Python `guessit` command — same flags, same
31
+ output formats (verified against the real Python CLI in CI). Installs both
32
+ `guessit-js` and `guessit` binaries:
31
33
 
32
34
  ```bash
33
35
  npx guessit-js "The.Dark.Knight.2008.1080p.BluRay.x264-GROUP.mkv"
@@ -47,7 +49,9 @@ npx guessit-js -p # list detectable properties
47
49
  Parsing options match the Python CLI: `-n` name-only, `-Y`/`-D` date order,
48
50
  `-L`/`-C` allowed languages/countries, `-E` episode-prefer-number,
49
51
  `-T`/`-G` expected title/group, `--includes`/`--excludes`, `-s` single-value,
50
- `-c` JSON config file. See `npx guessit-js --help`.
52
+ `-v` verbose. User config is auto-loaded from `~/.guessit/options.json` and
53
+ `~/.config/guessit/options.json` (`.yaml`/`.yml` too; disable with
54
+ `--no-user-config`), plus explicit `-c <file>`. See `npx guessit-js --help`.
51
55
 
52
56
  ## Usage
53
57
 
package/bin/cli.mjs CHANGED
@@ -1,47 +1,70 @@
1
1
  #!/usr/bin/env node
2
- // guessit-js CLI — mirrors the Python `guessit` command-line interface.
2
+ // guessit-js CLI — drop-in replacement for the Python `guessit` command.
3
+ // Same flags, same output formats (For:/GuessIt found:, -j compact JSON with
4
+ // Python separators, -y ?-key YAML), same user-config loading.
3
5
  // Zero dependencies; the library is bundled in dist/.
4
- import { readFileSync } from 'fs';
6
+ import { readFileSync, existsSync } from 'fs';
7
+ import { homedir } from 'os';
8
+ import { join } from 'path';
5
9
  import { guessit, properties as apiProperties, version } from '../dist/guessit-js.js';
6
10
 
7
- const HELP = `guessit-js ${version} — extract metadata from media filenames
11
+ // Python's GuessitEncoder emits babelfish `.name` in JSON ("English",
12
+ // "UNITED STATES") while YAML uses str() ("en", "pt-BR", "US"). Mirror both.
13
+ const ALPHA3_TO_2 = {"eng":"en","fra":"fr","deu":"de","spa":"es","ita":"it","por":"pt","rus":"ru","jpn":"ja","zho":"zh","kor":"ko","ara":"ar","hin":"hi","tur":"tr","pol":"pl","nld":"nl","swe":"sv","dan":"da","nor":"no","fin":"fi","hun":"hu","ces":"cs","ron":"ro","ukr":"uk","heb":"he","cat":"ca","vie":"vi","tha":"th","ind":"id","mal":"ml","tel":"te","tam":"ta","bul":"bg","hrv":"hr","srp":"sr","slk":"sk","slv":"sl","ell":"el","lit":"lt","lav":"lv","est":"et","glg":"gl","eus":"eu","ben":"bn","isl":"is","mkd":"mk","bos":"bs","alb":"sq","per":"fa","msa":"ms","mon":"mn","urd":"ur","pan":"pa","guj":"gu","kan":"kn","mar":"mr","asm":"as","mya":"my","khm":"km","lao":"lo"};
14
+ const LANGUAGE_NAMES = {"eng":"English","fra":"French","deu":"German","spa":"Spanish","ita":"Italian","por":"Portuguese","rus":"Russian","jpn":"Japanese","zho":"Chinese","kor":"Korean","ara":"Arabic","hin":"Hindi","tur":"Turkish","pol":"Polish","nld":"Dutch","swe":"Swedish","dan":"Danish","nor":"Norwegian","fin":"Finnish","hun":"Hungarian","ces":"Czech","ron":"Romanian","ukr":"Ukrainian","heb":"Hebrew","cat":"Catalan","vie":"Vietnamese","tha":"Thai","ind":"Indonesian","mal":"Malayalam","tel":"Telugu","tam":"Tamil","bul":"Bulgarian","hrv":"Croatian","srp":"Serbian","slk":"Slovak","slv":"Slovenian","ell":"Greek","lit":"Lithuanian","lav":"Latvian","est":"Estonian","glg":"Galician","eus":"Basque","ben":"Bengali","isl":"Icelandic","mkd":"Macedonian","bos":"Bosnian","alb":"Albanian","per":"Persian","msa":"Malay","mon":"Mongolian","urd":"Urdu","pan":"Punjabi","guj":"Gujarati","kan":"Kannada","mar":"Marathi","asm":"Assamese","mya":"Burmese","khm":"Khmer","lao":"Lao"};
15
+ const COUNTRY_NAMES = {"US":"UNITED STATES","GB":"UNITED KINGDOM","AU":"AUSTRALIA","CA":"CANADA","NZ":"NEW ZEALAND","IE":"IRELAND","FR":"FRANCE","DE":"GERMANY","ES":"SPAIN","IT":"ITALY","BR":"BRAZIL","PT":"PORTUGAL","RU":"RUSSIAN FEDERATION","JP":"JAPAN","CN":"CHINA","TW":"TAIWAN, PROVINCE OF CHINA","HK":"HONG KONG","KR":"KOREA, REPUBLIC OF","IN":"INDIA","MX":"MEXICO","NL":"NETHERLANDS","SE":"SWEDEN","NO":"NORWAY","DK":"DENMARK","FI":"FINLAND","PL":"POLAND","CH":"SWITZERLAND","AT":"AUSTRIA","BE":"BELGIUM","CZ":"CZECHIA","GR":"GREECE","HU":"HUNGARY","RO":"ROMANIA","TR":"TURKEY","UA":"UKRAINE","AR":"ARGENTINA","ZA":"SOUTH AFRICA"};
8
16
 
9
- Usage: guessit-js [options] <filename> [<filename> ...]
10
- guessit-js [options] @list.txt filenames from file (one per line)
11
- guessit-js [options] -f list.txt same as @list.txt (use - for stdin)
12
- echo "Movie.mkv" | guessit-js [options] filenames from piped stdin
17
+ const HELP = `usage: guessit-js [options] [filename ...]
18
+
19
+ positional arguments:
20
+ filename Filename or release name to guess (@list.txt reads
21
+ one filename per line; - reads stdin)
22
+
23
+ Naming:
24
+ -t TYPE, --type TYPE The suggested file type: movie or episode
25
+ -n, --name-only Parse files as name only, without extension
26
+ -Y, --date-year-first Take the year first when parsing an ambiguous date
27
+ -D, --date-day-first Take the day first when parsing an ambiguous date
28
+ -L ALLOWED_LANGUAGES, --allowed-languages ALLOWED_LANGUAGES
29
+ Allowed language (comma-separated, repeatable)
30
+ -C ALLOWED_COUNTRIES, --allowed-countries ALLOWED_COUNTRIES
31
+ Allowed country (comma-separated, repeatable)
32
+ -E, --episode-prefer-number
33
+ Guess "serie.213.avi" as episode 213
34
+ -T EXPECTED_TITLE, --expected-title EXPECTED_TITLE
35
+ Expected title (repeatable)
36
+ -G EXPECTED_GROUP, --expected-group EXPECTED_GROUP
37
+ Expected release group (repeatable)
38
+ --includes INCLUDES Properties to include (comma-separated, repeatable)
39
+ --excludes EXCLUDES Properties to exclude (comma-separated, repeatable)
40
+
41
+ Input:
42
+ -f INPUT_FILE, --input-file INPUT_FILE
43
+ Read filenames from this file (- for stdin)
13
44
 
14
45
  Output:
15
- -j, --json JSON (single object, or array for multiple inputs)
16
- --jsonl one JSON object per line (streaming-friendly)
17
- -y, --yaml YAML
18
- -P, --show-property <name> print only this property's value
19
- -i, --output-input-string include the input string in the result
20
-
21
- Parsing options:
22
- -t, --type <type> suggested type: movie or episode
23
- -n, --name-only parse as a name without extension
24
- -Y, --date-year-first ambiguous dates: year first
25
- -D, --date-day-first ambiguous dates: day first
26
- -L, --allowed-languages comma-separated language codes (e.g. en,fr)
27
- -C, --allowed-countries comma-separated country codes (e.g. us,gb)
28
- -E, --episode-prefer-number prefer episode over season for lone numbers
29
- -T, --expected-title expected title (repeatable)
30
- -G, --expected-group expected release group (repeatable)
31
- --includes <props> comma-separated properties to include (repeatable)
32
- --excludes <props> comma-separated properties to exclude (repeatable)
33
- -s, --single-value only the first value per property
34
- -a, --advanced raw match data (start/end/raw per property)
35
- -c, --config <file> JSON file with extra options (merged in)
36
-
37
- Introspection:
38
- -p, --properties list all detectable property names
39
- -V, --values list all property names with their possible values
40
-
41
- Misc:
42
- -v, --version print version
43
- -h, --help this help
44
- -- end of options; everything after is a filename
46
+ -v, --verbose Display debug output
47
+ -P SHOW_PROPERTY, --show-property SHOW_PROPERTY
48
+ Display only the given property value
49
+ -a, --advanced Display advanced information for filename guesses
50
+ -s, --single-value Keep only the first value found for each property
51
+ -j, --json Display information for filename guesses as json output
52
+ --jsonl Alias of --json (one object per line)
53
+ -y, --yaml Display information for filename guesses as yaml output
54
+ -i, --output-input-string
55
+ Add input_string property in the output
56
+
57
+ Configuration:
58
+ -c CONFIG_FILE, --config CONFIG_FILE
59
+ Config file to use (JSON, or simple flat YAML)
60
+ --no-user-config Disable user config (~/.guessit/options.json,
61
+ ~/.config/guessit/options.json, .yaml/.yml variants)
62
+ --no-default-config Disable the embedded default config
63
+
64
+ Information:
65
+ -p, --properties Display properties that can be guessed
66
+ -V, --values Display property values that can be guessed
67
+ --version Display the guessit-js version banner
45
68
 
46
69
  Exit codes: 0 success, 1 processing error, 2 usage error.`;
47
70
 
@@ -55,14 +78,50 @@ function readLines(path) {
55
78
  return text.split(/\r?\n/).map((l) => l.trim()).filter(Boolean);
56
79
  }
57
80
 
81
+ // Minimal config-file reader: JSON first, then a flat "key: value" YAML subset
82
+ // (scalars, [a, b] inline lists, "- item" block lists).
83
+ function readConfigFile(path) {
84
+ const text = readFileSync(path, 'utf8');
85
+ try { return JSON.parse(text); } catch { /* fall through to flat YAML */ }
86
+ const out = {};
87
+ let listKey = null;
88
+ for (const rawLine of text.split(/\r?\n/)) {
89
+ const line = rawLine.replace(/#.*$/, '').trimEnd();
90
+ if (!line.trim()) continue;
91
+ const item = line.match(/^\s+-\s+(.*)$/);
92
+ if (item && listKey) { out[listKey].push(parseScalar(item[1])); continue; }
93
+ const kv = line.match(/^([\w-]+):\s*(.*)$/);
94
+ if (!kv) continue;
95
+ const [, key, value] = kv;
96
+ if (!value) { out[key] = []; listKey = key; continue; }
97
+ listKey = null;
98
+ if (value.startsWith('[') && value.endsWith(']')) {
99
+ out[key] = value.slice(1, -1).split(',').map((s) => parseScalar(s.trim())).filter((s) => s !== '');
100
+ } else {
101
+ out[key] = parseScalar(value);
102
+ }
103
+ }
104
+ return out;
105
+ }
106
+ function parseScalar(s) {
107
+ if (s === 'true' || s === 'yes') return true;
108
+ if (s === 'false' || s === 'no') return false;
109
+ if (s === 'null' || s === '~') return null;
110
+ if (/^-?\d+(\.\d+)?$/.test(s)) return Number(s);
111
+ return s.replace(/^['"]|['"]$/g, '');
112
+ }
113
+
58
114
  // ---- argument parsing -------------------------------------------------------
59
115
  const args = process.argv.slice(2);
60
116
  const filenames = [];
61
- const options = {};
62
- let output = 'lines';
117
+ const cliOptions = {};
118
+ const configOptions = {};
119
+ let output = 'default';
63
120
  let showProperty = null;
121
+ let verbose = false;
64
122
  let listProperties = false;
65
123
  let listValues = false;
124
+ let noUserConfig = false;
66
125
  let endOfOptions = false;
67
126
 
68
127
  const needsValue = (a, i) => {
@@ -70,7 +129,7 @@ const needsValue = (a, i) => {
70
129
  return args[i + 1];
71
130
  };
72
131
  const pushList = (key, raw) => {
73
- options[key] = (options[key] || []).concat(raw.split(',').map((s) => s.trim()).filter(Boolean));
132
+ cliOptions[key] = (cliOptions[key] || []).concat(raw.split(',').map((s) => s.trim()).filter(Boolean));
74
133
  };
75
134
 
76
135
  for (let i = 0; i < args.length; i++) {
@@ -83,45 +142,130 @@ for (let i = 0; i < args.length; i++) {
83
142
  }
84
143
  switch (a) {
85
144
  case '--': endOfOptions = true; break;
86
- case '-j': case '--json': output = 'json'; break;
87
- case '--jsonl': output = 'jsonl'; break;
145
+ case '-j': case '--json': case '--jsonl': output = 'json'; break;
88
146
  case '-y': case '--yaml': output = 'yaml'; break;
89
147
  case '-P': case '--show-property': showProperty = needsValue(a, i); i++; break;
90
148
  case '-f': case '--input-file': filenames.push(...readLines(needsValue(a, i))); i++; break;
91
- case '-i': case '--output-input-string': options.output_input_string = true; break;
92
- case '-t': case '--type': options.type = needsValue(a, i); i++; break;
93
- case '-n': case '--name-only': options.name_only = true; break;
94
- case '-Y': case '--date-year-first': options.date_year_first = true; break;
95
- case '-D': case '--date-day-first': options.date_day_first = true; break;
149
+ case '-i': case '--output-input-string': cliOptions.output_input_string = true; break;
150
+ case '-t': case '--type': cliOptions.type = needsValue(a, i); i++; break;
151
+ case '-n': case '--name-only': cliOptions.name_only = true; break;
152
+ case '-Y': case '--date-year-first': cliOptions.date_year_first = true; break;
153
+ case '-D': case '--date-day-first': cliOptions.date_day_first = true; break;
96
154
  case '-L': case '--allowed-languages': pushList('allowed_languages', needsValue(a, i)); i++; break;
97
155
  case '-C': case '--allowed-countries': pushList('allowed_countries', needsValue(a, i)); i++; break;
98
- case '-E': case '--episode-prefer-number': options.episode_prefer_number = true; break;
156
+ case '-E': case '--episode-prefer-number': cliOptions.episode_prefer_number = true; break;
99
157
  case '-T': case '--expected-title': pushList('expected_title', needsValue(a, i)); i++; break;
100
158
  case '-G': case '--expected-group': pushList('expected_group', needsValue(a, i)); i++; break;
101
159
  case '--includes': pushList('includes', needsValue(a, i)); i++; break;
102
160
  case '--excludes': pushList('excludes', needsValue(a, i)); i++; break;
103
- case '-s': case '--single-value': options.single_value = true; break;
104
- case '-a': case '--advanced': options.advanced = true; break;
161
+ case '-s': case '--single-value': cliOptions.single_value = true; break;
162
+ case '-a': case '--advanced': cliOptions.advanced = true; break;
163
+ case '-v': case '--verbose': verbose = true; break;
105
164
  case '-c': case '--config': {
106
165
  const path = needsValue(a, i); i++;
107
- try { Object.assign(options, JSON.parse(readFileSync(path, 'utf8'))); }
166
+ try { Object.assign(configOptions, readConfigFile(path)); }
108
167
  catch (e) { fail(`cannot read config ${path}: ${e.message}`); }
109
168
  break;
110
169
  }
170
+ case '--no-user-config': noUserConfig = true; cliOptions.no_user_config = true; break;
171
+ case '--no-default-config': cliOptions.no_default_config = true; break;
111
172
  case '-p': case '--properties': listProperties = true; break;
112
173
  case '-V': case '--values': listValues = true; break;
113
- case '-v': case '--version': console.log(version); process.exit(0); break;
174
+ case '--version': {
175
+ console.log('+-------------------------------------------------------+');
176
+ console.log(`+ GuessIt-JS ${version}`.padEnd(56) + '+');
177
+ console.log('+-------------------------------------------------------+');
178
+ console.log('| Please report any bug or feature request at |');
179
+ console.log('| https://github.com/opensubtitles/guessit-js/issues. |');
180
+ console.log('+-------------------------------------------------------+');
181
+ process.exit(0);
182
+ break;
183
+ }
114
184
  case '-h': case '--help': console.log(HELP); process.exit(0); break;
115
185
  default: fail(`unknown option: ${a} — see --help`);
116
186
  }
117
187
  }
118
188
 
189
+ // User config, same locations as Python guessit.
190
+ if (!noUserConfig) {
191
+ const home = homedir();
192
+ for (const dir of [join(home, '.guessit'), join(home, '.config', 'guessit')]) {
193
+ for (const ext of ['json', 'yaml', 'yml']) {
194
+ const path = join(dir, `options.${ext}`);
195
+ if (existsSync(path)) {
196
+ try { Object.assign(configOptions, readConfigFile(path)); } catch { /* ignore broken user config */ }
197
+ }
198
+ }
199
+ }
200
+ }
201
+
202
+ // Precedence: user/explicit config < CLI flags.
203
+ const options = { ...configOptions, ...cliOptions };
204
+ for (const key of ['allowed_languages', 'allowed_countries', 'expected_title', 'expected_group', 'includes', 'excludes']) {
205
+ if (configOptions[key] && cliOptions[key]) options[key] = [...configOptions[key], ...cliOptions[key]];
206
+ }
207
+
119
208
  if (options.type && options.type !== 'movie' && options.type !== 'episode') {
120
209
  fail(`invalid --type "${options.type}": must be movie or episode`);
121
210
  }
122
211
 
123
- // ---- output helpers ---------------------------------------------------------
124
- function toYaml(value, indent = '') {
212
+ // ---- value + output formatting ---------------------------------------------
213
+ // Python: JSON output uses babelfish .name ("English", "UNITED STATES"),
214
+ // YAML output uses str() ("en", "pt-BR", "US"); dates become ISO strings.
215
+ function display(v, mode, key) {
216
+ if (Array.isArray(v)) return v.map((x) => display(x, mode, key));
217
+ if (v instanceof Date) return v.toISOString().slice(0, 10);
218
+ if (v && typeof v === 'object') {
219
+ if (typeof v.alpha3 === 'string') {
220
+ if (mode === 'yaml') {
221
+ const base = ALPHA3_TO_2[v.alpha3] || v.alpha3;
222
+ return v.country ? `${base}-${v.country}` : base;
223
+ }
224
+ return LANGUAGE_NAMES[v.alpha3] || v.alpha3;
225
+ }
226
+ const out = {};
227
+ for (const [k, val] of Object.entries(v)) out[k] = display(val, mode, k);
228
+ return out;
229
+ }
230
+ if (key === 'country' && typeof v === 'string' && mode !== 'yaml') {
231
+ return COUNTRY_NAMES[v] || v;
232
+ }
233
+ return v;
234
+ }
235
+
236
+ // json.dumps-compatible emitters (Python uses ", " / ": " separators).
237
+ function pyJson(v) {
238
+ if (Array.isArray(v)) return '[' + v.map(pyJson).join(', ') + ']';
239
+ if (v && typeof v === 'object') {
240
+ return '{' + Object.entries(v).map(([k, val]) => `${JSON.stringify(k)}: ${pyJson(val)}`).join(', ') + '}';
241
+ }
242
+ return JSON.stringify(v);
243
+ }
244
+ function pyJsonIndent(v, level = 1) {
245
+ const pad = ' '.repeat(level);
246
+ const close = ' '.repeat(level - 1);
247
+ if (Array.isArray(v)) {
248
+ if (!v.length) return '[]';
249
+ return '[\n' + v.map((x) => pad + pyJsonIndent(x, level + 1)).join(',\n') + `\n${close}]`;
250
+ }
251
+ if (v && typeof v === 'object') {
252
+ const entries = Object.entries(v);
253
+ if (!entries.length) return '{}';
254
+ return '{\n' + entries.map(([k, x]) => `${pad}${JSON.stringify(k)}: ${pyJsonIndent(x, level + 1)}`).join(',\n') + `\n${close}}`;
255
+ }
256
+ return JSON.stringify(v);
257
+ }
258
+
259
+ function yamlScalar(v) {
260
+ if (typeof v !== 'string') return String(v);
261
+ const needsQuote =
262
+ /^[\s'"&*?|>%@`!,\[\]{}#-]/.test(v) || /: /.test(v) || / #/.test(v) ||
263
+ /[\n\t]/.test(v) || /\s$/.test(v) || v.endsWith(':') ||
264
+ /^(true|false|null|yes|no|on|off|~)$/i.test(v) || /^-?[\d.]+$/.test(v);
265
+ // pyyaml prefers single-quoted style
266
+ return needsQuote ? `'${v.replace(/'/g, "''")}'` : v;
267
+ }
268
+ function toYaml(value, indent) {
125
269
  if (Array.isArray(value)) {
126
270
  return value.map((v) =>
127
271
  typeof v === 'object' && v !== null
@@ -130,26 +274,26 @@ function toYaml(value, indent = '') {
130
274
  ).join('\n');
131
275
  }
132
276
  if (typeof value === 'object' && value !== null) {
133
- return Object.entries(value).map(([k, v]) =>
134
- typeof v === 'object' && v !== null
135
- ? `${indent}${k}:\n${toYaml(v, indent + ' ')}`
136
- : `${indent}${k}: ${yamlScalar(v)}`
137
- ).join('\n');
277
+ return Object.entries(value).map(([k, v]) => {
278
+ if (Array.isArray(v)) return `${indent}${k}:\n${toYaml(v, indent)}`; // pyyaml: list items at key level
279
+ if (typeof v === 'object' && v !== null) return `${indent}${k}:\n${toYaml(v, indent + ' ')}`;
280
+ return `${indent}${k}: ${yamlScalar(v)}`;
281
+ }).join('\n');
138
282
  }
139
283
  return indent + yamlScalar(value);
140
284
  }
141
- function yamlScalar(v) {
142
- if (typeof v !== 'string') return String(v);
143
- return /^[\w][\w .+-]*$/.test(v) && !/^(true|false|null|yes|no|on|off|[\d.]+)$/i.test(v)
144
- ? v
145
- : JSON.stringify(v);
146
- }
147
285
 
148
- function printLines(name, result, many) {
149
- if (many) console.log(`For: ${name}`);
150
- for (const [k, v] of Object.entries(result)) {
151
- console.log(`${many ? ' ' : ''}${k}: ${typeof v === 'object' && v !== null ? JSON.stringify(v) : v}`);
286
+ // Advanced mode returns live Match objects; reduce them to the Python shape.
287
+ function simplifyAdvanced(v) {
288
+ if (Array.isArray(v)) return v.map(simplifyAdvanced);
289
+ if (v && typeof v === 'object' && 'start' in v && 'end' in v) {
290
+ const out = { value: display(v.value, 'json') };
291
+ if (v.raw) out.raw = v.raw; // Python omits raw for synthesized matches
292
+ out.start = v.start;
293
+ out.end = v.end;
294
+ return out;
152
295
  }
296
+ return v;
153
297
  }
154
298
 
155
299
  // ---- introspection modes ----------------------------------------------------
@@ -172,49 +316,49 @@ if (!process.stdin.isTTY && !filenames.length) {
172
316
  }
173
317
  if (!filenames.length) fail('usage: guessit-js [options] <filename> — see --help');
174
318
 
175
- // Advanced mode returns live Match objects; reduce them to the Python-CLI shape
176
- // ({value, raw, start, end}) instead of dumping engine internals.
177
- function simplifyAdvanced(v) {
178
- if (Array.isArray(v)) return v.map(simplifyAdvanced);
179
- if (v && typeof v === 'object' && 'start' in v && 'end' in v) {
180
- return { value: v.value, raw: v.raw, start: v.start, end: v.end };
181
- }
182
- return v;
183
- }
184
-
185
319
  let hadError = false;
186
- const results = filenames.map((f) => {
320
+ for (const filename of filenames) {
321
+ let result;
187
322
  try {
188
- const r = guessit(f, options);
189
- if (!options.advanced) return r;
190
- const out = {};
191
- for (const [k, v] of Object.entries(r)) out[k] = simplifyAdvanced(v);
192
- return out;
323
+ const raw = guessit(filename, options);
324
+ if (options.advanced) {
325
+ result = {};
326
+ for (const [k, v] of Object.entries(raw)) result[k] = simplifyAdvanced(v);
327
+ } else {
328
+ result = display(raw, output === 'yaml' ? 'yaml' : 'json');
329
+ }
193
330
  } catch (e) {
194
331
  hadError = true;
195
- return { error: String(e && e.message || e) };
196
- }
197
- });
198
-
199
- if (showProperty) {
200
- results.forEach((r) => {
201
- const v = r[showProperty];
202
- console.log(v === undefined ? '' : typeof v === 'object' && v !== null ? JSON.stringify(v) : String(v));
203
- });
204
- } else if (output === 'json') {
205
- console.log(JSON.stringify(filenames.length === 1 ? results[0] : results, null, 2));
206
- } else if (output === 'jsonl') {
207
- results.forEach((r) => console.log(JSON.stringify(r)));
208
- } else if (output === 'yaml') {
209
- results.forEach((r, i) => {
210
- if (filenames.length > 1) console.log(`${i ? '\n' : ''}? ${yamlScalar(filenames[i])}\n:`);
211
- console.log(toYaml(r, filenames.length > 1 ? ' ' : ''));
212
- });
213
- } else {
214
- results.forEach((r, i) => {
215
- if (i) console.log('');
216
- printLines(filenames[i], r, filenames.length > 1);
217
- });
332
+ result = { error: String((e && e.message) || e) };
333
+ }
334
+
335
+ if (verbose && output === 'default' && !showProperty) {
336
+ // Approximation of Python's rebulk debug log: one line per final match.
337
+ try {
338
+ const adv = guessit(filename, { ...options, advanced: true });
339
+ for (const [name, v] of Object.entries(adv)) {
340
+ for (const m of Array.isArray(v) ? v : [v]) {
341
+ if (m && typeof m === 'object' && 'start' in m) {
342
+ console.log(`Match found. (<${m.raw}:(${m.start}, ${m.end})+name=${name}>)`);
343
+ }
344
+ }
345
+ }
346
+ } catch { /* debug output is best-effort */ }
347
+ }
348
+
349
+ if (showProperty) {
350
+ const v = result[showProperty];
351
+ console.log(v === undefined ? '' : typeof v === 'object' && v !== null ? pyJson(v) : String(v));
352
+ } else if (output === 'json') {
353
+ console.log(pyJson(result));
354
+ } else if (output === 'yaml') {
355
+ console.log(`? ${yamlScalar(filename)}`);
356
+ const body = toYaml(result, ' ');
357
+ console.log(':' + body.slice(1));
358
+ } else {
359
+ console.log(`For: ${filename}`);
360
+ console.log(`GuessIt found: ${pyJsonIndent(result)}`);
361
+ }
218
362
  }
219
363
 
220
364
  process.exit(hadError ? 1 : 0);
@@ -14516,7 +14516,7 @@ function configure(options, rulesBuilder, force = false) {
14516
14516
  function reset() {
14517
14517
  defaultApi.reset();
14518
14518
  }
14519
- const version$1 = "4.5.4";
14519
+ const version$1 = "4.6.0";
14520
14520
  const version = version$1;
14521
14521
  exports.GUESSIT_SCHEMA = GUESSIT_SCHEMA;
14522
14522
  exports.GuessItApi = GuessItApi;
@@ -14514,7 +14514,7 @@ function configure(options, rulesBuilder, force = false) {
14514
14514
  function reset() {
14515
14515
  defaultApi.reset();
14516
14516
  }
14517
- const version$1 = "4.5.4";
14517
+ const version$1 = "4.6.0";
14518
14518
  const version = version$1;
14519
14519
  export {
14520
14520
  GUESSIT_SCHEMA,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "guessit-js",
3
- "version": "4.5.4",
3
+ "version": "4.6.0",
4
4
  "description": "Extract metadata (title, year, season, episode, codec, language, etc.) from media filenames — TypeScript port of Python guessit",
5
5
  "keywords": [
6
6
  "guessit",
@@ -35,7 +35,8 @@
35
35
  "types": "./dist/index.d.ts",
36
36
  "sideEffects": false,
37
37
  "bin": {
38
- "guessit-js": "./bin/cli.mjs"
38
+ "guessit-js": "./bin/cli.mjs",
39
+ "guessit": "./bin/cli.mjs"
39
40
  },
40
41
  "engines": {
41
42
  "node": ">=18"