veodl 1.8.2 → 1.9.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/CHANGELOG.md +28 -0
- package/README.md +796 -725
- package/docs/AGENT_GUIDE.md +82 -66
- package/package.json +1 -2
- package/src/alias.js +258 -0
- package/src/cli.js +613 -454
- package/src/config-diagnostics.js +145 -144
- package/src/config-editor.js +285 -281
- package/src/config-template.js +224 -171
- package/src/config.js +217 -213
- package/src/doctor.js +1 -1
- package/src/downloader.js +601 -600
- package/src/interactive.js +115 -82
- package/src/output.js +1 -1
- package/src/runs.js +343 -333
- package/src/source-discovery.js +251 -0
- package/src/state.js +27 -27
- package/src/uninstall.js +222 -0
- package/src/updater.js +5 -3
package/src/cli.js
CHANGED
|
@@ -1,454 +1,613 @@
|
|
|
1
|
-
import { outputOptions, outputStream, withOutputSettings } from './output.js';
|
|
2
|
-
import { validateTemplate } from './naming.js';
|
|
3
|
-
import { parseArgs } from 'node:util';
|
|
4
|
-
import path from 'node:path';
|
|
5
|
-
import { readFile } from 'node:fs/promises';
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
--
|
|
28
|
-
--
|
|
29
|
-
--
|
|
30
|
-
|
|
31
|
-
--
|
|
32
|
-
|
|
33
|
-
--
|
|
34
|
-
--
|
|
35
|
-
--
|
|
36
|
-
--
|
|
37
|
-
--
|
|
38
|
-
--
|
|
39
|
-
--
|
|
40
|
-
--
|
|
41
|
-
--
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
--
|
|
45
|
-
|
|
46
|
-
--
|
|
47
|
-
--
|
|
48
|
-
--embed-
|
|
49
|
-
--
|
|
50
|
-
|
|
51
|
-
--
|
|
52
|
-
|
|
53
|
-
--
|
|
54
|
-
|
|
55
|
-
--
|
|
56
|
-
|
|
57
|
-
--
|
|
58
|
-
--
|
|
59
|
-
--
|
|
60
|
-
--
|
|
61
|
-
--
|
|
62
|
-
--
|
|
63
|
-
--
|
|
64
|
-
--
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
veo
|
|
77
|
-
veo
|
|
78
|
-
veo
|
|
79
|
-
veo
|
|
80
|
-
veo
|
|
81
|
-
veo
|
|
82
|
-
veo
|
|
83
|
-
veo
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
veo
|
|
92
|
-
veo
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
'
|
|
113
|
-
|
|
114
|
-
'
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
'
|
|
119
|
-
'
|
|
120
|
-
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
'
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
'
|
|
138
|
-
'
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
'
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
'
|
|
181
|
-
'
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
const
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
const
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
if (
|
|
220
|
-
if (
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
}
|
|
227
|
-
if (values
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
if (values['
|
|
247
|
-
|
|
248
|
-
if (values.
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
if (values.
|
|
258
|
-
|
|
259
|
-
if (
|
|
260
|
-
if (
|
|
261
|
-
if (
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
if (
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
if (
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
if (
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
if (args[0] === '
|
|
359
|
-
try {
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
if (
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
if (
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
const {
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
process.
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
1
|
+
import { outputOptions, outputStream, withOutputSettings } from './output.js';
|
|
2
|
+
import { validateTemplate } from './naming.js';
|
|
3
|
+
import { parseArgs } from 'node:util';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { readFile } from 'node:fs/promises';
|
|
6
|
+
import { createInterface } from 'node:readline/promises';
|
|
7
|
+
import { createReporter } from './progress.js';
|
|
8
|
+
import { openFile } from './open-file.js';
|
|
9
|
+
import { maybeUpdateNotice, updateMain, UPDATE_HELP, defaultRegistry, packageVersion } from './updater.js';
|
|
10
|
+
import { applyProfile, configMain, loadConfig } from './config.js';
|
|
11
|
+
import { validateItems, describeEstimate } from './playlist.js';
|
|
12
|
+
import { parseSourceTimeout } from './source-discovery.js';
|
|
13
|
+
import { retryOptions, runJob, jobFilePath } from './jobs.js';
|
|
14
|
+
import { QUALITIES, VIDEO_FORMATS, AUDIO_FORMATS, validateUrl, readableError, cleanText, validateCookieFile, validateBrowserSpec, cookieFileWarning } from './utils.js';
|
|
15
|
+
|
|
16
|
+
export const HELP = `veo - simple video downloader
|
|
17
|
+
|
|
18
|
+
Usage:
|
|
19
|
+
veo <url> [<url>...] [options]
|
|
20
|
+
|
|
21
|
+
Options:
|
|
22
|
+
-q, --quality <quality> Video quality (best, 2160p, 1440p, 1080p, 720p, 480p, 360p)
|
|
23
|
+
Numeric qualities are an upper bound: -q 720p never
|
|
24
|
+
downloads 2160p. Use --closest-quality for the nearest
|
|
25
|
+
available resolution instead.
|
|
26
|
+
-o, --output <path> Output directory (default: current directory)
|
|
27
|
+
-r, --rename <name> Filename without extension; * inserts the original title
|
|
28
|
+
--closest-quality Pick the nearest available resolution, above or below
|
|
29
|
+
--open Open the saved file with your default app
|
|
30
|
+
--audio Download audio only (default: mp3)
|
|
31
|
+
--format <format> Video: mp4, mkv, webm, mov; audio: mp3, m4a, aac, opus, flac, wav
|
|
32
|
+
Video uses lossless remux; incompatible codecs fail.
|
|
33
|
+
--compatible Ensure MP4 H.264/AAC; converts only when needed (may lose quality)
|
|
34
|
+
--recode Allow video conversion (requires --format; may lose quality)
|
|
35
|
+
--concurrent-downloads <n> Parallel URLs/batch entries (1-4; default: 2)
|
|
36
|
+
--adaptive-concurrency Reduce connections and retry temporary failures (default: on)
|
|
37
|
+
--filename-template <s> Filename without extension, e.g. {index} - {title}
|
|
38
|
+
--folder-template <s> Relative folders, e.g. {channel}/{year}
|
|
39
|
+
--check-space Estimate cache/output space before downloading (default: on)
|
|
40
|
+
--timings Show phase timings (default: on; --no-timings disables)
|
|
41
|
+
--no-color Disable terminal colors (also respects NO_COLOR)
|
|
42
|
+
--playlist-concurrency <n> Simultaneous playlist downloads (1-4; default: 2)
|
|
43
|
+
--playlist Download every entry of a playlist or channel URL
|
|
44
|
+
-N, --concurrent-fragments <n>
|
|
45
|
+
Download this many fragments in parallel (1-16; default: 8)
|
|
46
|
+
--subs Download subtitles (default languages: en)
|
|
47
|
+
--sub-langs <langs> Subtitle languages, e.g. "de,en" (implies --subs)
|
|
48
|
+
--embed-subs Embed subtitles into the video file
|
|
49
|
+
--embed-metadata Embed title, date and other metadata
|
|
50
|
+
--embed-thumbnail Embed the thumbnail
|
|
51
|
+
--sponsorblock-remove <categories>
|
|
52
|
+
Remove sponsor segments, e.g. "sponsor,selfpromo"
|
|
53
|
+
--section <range> Download only a time range, e.g. "*10:00-12:00"
|
|
54
|
+
--cookies <file> Netscape cookie file, for content you may access
|
|
55
|
+
--cookies-from-browser <browser[:profile]>
|
|
56
|
+
Read cookies from an installed browser
|
|
57
|
+
--resume Keep partial data and continue an interrupted download
|
|
58
|
+
--list-formats Show the available formats and exit
|
|
59
|
+
--list-sources Find video sources loaded by a web page and exit
|
|
60
|
+
--auto-list-sources Search automatically after no downloadable video is found
|
|
61
|
+
--source <n> Select source number from that page (also for scripts)
|
|
62
|
+
--deep-scan Check every media candidate found during source search
|
|
63
|
+
--timeout <duration> Source search deadline, e.g. 30, 30s or 2m (5s-10m)
|
|
64
|
+
--dry-run Show what would be downloaded and exit
|
|
65
|
+
--json Print one JSON object per URL instead of prose
|
|
66
|
+
--profile <name> Apply a named config profile
|
|
67
|
+
--batch-file <file> Read URLs from a file (one per line; # comments)
|
|
68
|
+
--retry-failed <file> Retry failed/unfinished items from a saved job
|
|
69
|
+
--playlist-items <list> Select playlist entries, e.g. 1,3-5 (implies --playlist)
|
|
70
|
+
--skip-existing Skip matching downloads still present on disk
|
|
71
|
+
--no-<boolean-option> Disable a stored boolean default, e.g. --no-open
|
|
72
|
+
-v, --version Show installed version (also: veo version)
|
|
73
|
+
-h, --help Show help (also: veo help)
|
|
74
|
+
|
|
75
|
+
Commands:
|
|
76
|
+
veo update|up [--check] Update veo itself with npm (up is a short alias)
|
|
77
|
+
veo backend update Install a newer yt-dlp release (see veo backend --help)
|
|
78
|
+
veo doctor Diagnose the local setup
|
|
79
|
+
veo flush Stop veo runs and clear temporary downloads and jobs
|
|
80
|
+
veo stats Show persistent download statistics
|
|
81
|
+
veo history Show the last 5 downloads (--json for scripting)
|
|
82
|
+
veo retry --last Retry the newest failed or unfinished job
|
|
83
|
+
veo history --failed --limit 20 Filter and extend download history
|
|
84
|
+
veo runs [id] List active runs; add --json for metadata and progress
|
|
85
|
+
veo inspect <file> Read media metadata; --check-audio measures audio signal
|
|
86
|
+
veo inspect run <id> Inspect saved files from a finished run by its id
|
|
87
|
+
veo stop [id] Stop one run, or every active run
|
|
88
|
+
veo alias list|add|remove Manage extra command names (wrappers calling veo)
|
|
89
|
+
veo uninstall [-p <name>] Remove one alias, or everything with --yes
|
|
90
|
+
veo version Show the installed version
|
|
91
|
+
veo config edit|path|profiles|check|show|reset Manage defaults and named profiles
|
|
92
|
+
veo config edit [--external|--terminal] Choose the configuration editor
|
|
93
|
+
|
|
94
|
+
Run veo without arguments in a terminal for interactive setup.
|
|
95
|
+
Agent workflow: see docs/AGENT_GUIDE.md in the repository or installed package.
|
|
96
|
+
|
|
97
|
+
Defaults can be stored in the veo config file; veo doctor prints its location.
|
|
98
|
+
|
|
99
|
+
Examples:
|
|
100
|
+
veo "https://youtube.com/watch?v=..."
|
|
101
|
+
veo <url> -q 1080p
|
|
102
|
+
veo <url> --audio
|
|
103
|
+
veo <url> -o ./downloads
|
|
104
|
+
veo <url> -r "My Video" --open
|
|
105
|
+
veo <url1> <url2> --subs --embed-metadata
|
|
106
|
+
veo update --check
|
|
107
|
+
|
|
108
|
+
Only download content you are authorized or legally permitted to download.
|
|
109
|
+
`;
|
|
110
|
+
|
|
111
|
+
const STRING_OPTIONS = {
|
|
112
|
+
quality: { short: 'q' },
|
|
113
|
+
output: { short: 'o' },
|
|
114
|
+
rename: { short: 'r' },
|
|
115
|
+
format: {},
|
|
116
|
+
'playlist-concurrency': {},
|
|
117
|
+
'concurrent-downloads': {},
|
|
118
|
+
'filename-template': {},
|
|
119
|
+
'folder-template': {},
|
|
120
|
+
cookies: {},
|
|
121
|
+
'cookies-from-browser': {},
|
|
122
|
+
'concurrent-fragments': { short: 'N' },
|
|
123
|
+
'sub-langs': {},
|
|
124
|
+
'sponsorblock-remove': {},
|
|
125
|
+
section: {},
|
|
126
|
+
profile: {},
|
|
127
|
+
'batch-file': {},
|
|
128
|
+
'retry-failed': {},
|
|
129
|
+
'playlist-items': {},
|
|
130
|
+
source: {},
|
|
131
|
+
timeout: {},
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
const BOOLEAN_OPTIONS = {
|
|
135
|
+
compatible: {},
|
|
136
|
+
recode: {},
|
|
137
|
+
'adaptive-concurrency': {},
|
|
138
|
+
'check-space': {},
|
|
139
|
+
timings: {},
|
|
140
|
+
color: {},
|
|
141
|
+
open: {},
|
|
142
|
+
audio: {},
|
|
143
|
+
resume: {},
|
|
144
|
+
playlist: {},
|
|
145
|
+
subs: {},
|
|
146
|
+
'embed-subs': {},
|
|
147
|
+
'embed-metadata': {},
|
|
148
|
+
'embed-thumbnail': {},
|
|
149
|
+
'closest-quality': {},
|
|
150
|
+
'list-formats': {},
|
|
151
|
+
'list-sources': {},
|
|
152
|
+
'auto-list-sources': {},
|
|
153
|
+
'deep-scan': {},
|
|
154
|
+
'dry-run': {},
|
|
155
|
+
json: {},
|
|
156
|
+
help: { short: 'h' },
|
|
157
|
+
version: { short: 'v' },
|
|
158
|
+
'skip-existing': {},
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
// Config defaults, so an explicit flag always wins but a stored preference does not.
|
|
162
|
+
export function optionDefaults(config = {}) {
|
|
163
|
+
return {
|
|
164
|
+
quality: config.quality ?? 'best',
|
|
165
|
+
output: config.output ?? process.cwd(),
|
|
166
|
+
rename: config.rename,
|
|
167
|
+
format: config.format,
|
|
168
|
+
compatible: config.compatible ?? false,
|
|
169
|
+
recode: config.recode ?? false,
|
|
170
|
+
'concurrent-downloads': String(config.concurrentDownloads ?? 2),
|
|
171
|
+
'filename-template': config.filenameTemplate,
|
|
172
|
+
'folder-template': config.folderTemplate,
|
|
173
|
+
'adaptive-concurrency': config.adaptiveConcurrency ?? true,
|
|
174
|
+
'check-space': config.checkSpace ?? true,
|
|
175
|
+
timings: config.timings ?? true,
|
|
176
|
+
color: config.color ?? true,
|
|
177
|
+
'playlist-concurrency': String(config.playlistConcurrency ?? 2),
|
|
178
|
+
cookies: config.cookies,
|
|
179
|
+
'cookies-from-browser': config.cookiesFromBrowser,
|
|
180
|
+
'concurrent-fragments': String(config.concurrentFragments ?? 8),
|
|
181
|
+
'sub-langs': config.subLangs,
|
|
182
|
+
'sponsorblock-remove': config.sponsorblockRemove,
|
|
183
|
+
section: config.section,
|
|
184
|
+
open: config.open ?? false,
|
|
185
|
+
audio: config.audio ?? false,
|
|
186
|
+
resume: config.resume ?? false,
|
|
187
|
+
playlist: config.playlist ?? false,
|
|
188
|
+
subs: config.subs ?? false,
|
|
189
|
+
'embed-subs': config.embedSubs ?? false,
|
|
190
|
+
'embed-metadata': config.embedMetadata ?? false,
|
|
191
|
+
'embed-thumbnail': config.embedThumbnail ?? false,
|
|
192
|
+
'closest-quality': config.closestQuality ?? false,
|
|
193
|
+
json: config.json ?? false,
|
|
194
|
+
'skip-existing': config.skipExisting ?? false,
|
|
195
|
+
'playlist-items': config.playlistItems,
|
|
196
|
+
source: config.source,
|
|
197
|
+
timeout: config.timeout,
|
|
198
|
+
'deep-scan': config.deepScan ?? false,
|
|
199
|
+
'list-sources': config.listSources ?? false,
|
|
200
|
+
'auto-list-sources': config.autoListSources ?? false,
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export function cliOptions(config = {}) {
|
|
205
|
+
const defaults = optionDefaults(config);
|
|
206
|
+
const options = {};
|
|
207
|
+
for (const [name, extra] of Object.entries(STRING_OPTIONS)) {
|
|
208
|
+
options[name] = { type: 'string', ...extra };
|
|
209
|
+
if (defaults[name] !== undefined) options[name].default = defaults[name];
|
|
210
|
+
}
|
|
211
|
+
for (const [name, extra] of Object.entries(BOOLEAN_OPTIONS)) {
|
|
212
|
+
options[name] = { type: 'boolean', ...extra };
|
|
213
|
+
if (defaults[name] !== undefined) options[name].default = defaults[name];
|
|
214
|
+
}
|
|
215
|
+
return options;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
export function parseCli(args, { config = {} } = {}) {
|
|
219
|
+
if (args[0] === 'help') args = ['--help', ...args.slice(1)];
|
|
220
|
+
if (args[0] === 'version') {
|
|
221
|
+
if (args.length !== 1) throw new Error('Usage: veo version');
|
|
222
|
+
return { version: true };
|
|
223
|
+
}
|
|
224
|
+
const preliminary = parseArgs({ args, allowPositionals: true, strict: true, allowNegative: true, options: cliOptions() });
|
|
225
|
+
config = applyProfile(config, preliminary.values.profile);
|
|
226
|
+
const { values, positionals, tokens } = parseArgs({ args, tokens: true, allowNegative: true, allowPositionals: true, strict: true, options: cliOptions(config) });
|
|
227
|
+
if (values.help || values.version) return values;
|
|
228
|
+
// A stored default conflicting with a flag typed right now is a user error;
|
|
229
|
+
// a stored default merely ignored by another flag is not.
|
|
230
|
+
const typed = {
|
|
231
|
+
quality: tokens.some(token => token.name === 'quality'),
|
|
232
|
+
closest: tokens.some(token => token.name === 'closest-quality'),
|
|
233
|
+
audio: tokens.some(token => ['audio', 'no-audio'].includes(token.name)),
|
|
234
|
+
};
|
|
235
|
+
// An explicit numeric --quality states video intent, so it overrides an
|
|
236
|
+
// audio-only default instead of turning into a confusing conflict error.
|
|
237
|
+
if (typed.quality && values.quality !== 'best' && values.audio && !typed.audio) values.audio = false;
|
|
238
|
+
if (!positionals.length && !values['batch-file'] && !values['retry-failed']) throw new Error('Provide at least one video URL. Run veo --help for usage.');
|
|
239
|
+
if (!QUALITIES.includes(values.quality) && !/^[1-9]\d{1,4}p$/.test(values.quality)) throw new Error(`Invalid quality. Choose: ${QUALITIES.join(', ')} or a numeric resolution.`);
|
|
240
|
+
if (values['playlist-items']) {
|
|
241
|
+
if (values.playlist === false && tokens.some(token => token.name === 'playlist')) {
|
|
242
|
+
if (tokens.some(token => token.name === 'playlist-items')) throw new Error('--playlist-items cannot be combined with --no-playlist.');
|
|
243
|
+
values['playlist-items'] = undefined;
|
|
244
|
+
} else { validateItems(values['playlist-items']); values.playlist = true; }
|
|
245
|
+
}
|
|
246
|
+
if (values['retry-failed'] && (positionals.length || values['batch-file'])) throw new Error('--retry-failed cannot be combined with URLs or --batch-file.');
|
|
247
|
+
if (!values.output.trim()) throw new Error('The output directory cannot be empty.');
|
|
248
|
+
if (values.rename !== undefined && !cleanText(values.rename)) throw new Error('The custom filename cannot be empty.');
|
|
249
|
+
if (positionals.length > 1 && values.rename !== undefined && !values.rename.includes('*')) throw new Error('--rename only applies to a single URL unless the name contains * for the original title.');
|
|
250
|
+
if (values.audio && values.quality !== 'best' && typed.quality) throw new Error('--quality is for video; omit it when using --audio.');
|
|
251
|
+
if (values.audio && values['closest-quality'] && typed.closest) throw new Error('--closest-quality is for video; omit it when using --audio.');
|
|
252
|
+
if (values['closest-quality'] && values.quality === 'best' && typed.closest) throw new Error('--closest-quality requires a numeric --quality such as 1080p.');
|
|
253
|
+
if (values['list-formats'] && (values.audio || values.format)) throw new Error('--list-formats cannot be combined with --audio or --format.');
|
|
254
|
+
if (values['list-formats'] && positionals.length > 1) throw new Error('--list-formats accepts exactly one URL.');
|
|
255
|
+
if (values.source && (!/^[1-9]\d*$/.test(values.source) || !Number.isSafeInteger(Number(values.source)))) throw new Error('--source requires a positive source number.');
|
|
256
|
+
if (values.source && values['list-sources'] && !tokens.some(token => token.name === 'list-sources')) values['list-sources'] = false;
|
|
257
|
+
if (values['list-sources'] && !tokens.some(token => token.name === 'list-sources')
|
|
258
|
+
&& (positionals.length !== 1 || values['batch-file'] || values['retry-failed'])) values['list-sources'] = false;
|
|
259
|
+
if (values['list-sources'] && (positionals.length !== 1 || values['batch-file'] || values['retry-failed'])) throw new Error('--list-sources accepts exactly one URL.');
|
|
260
|
+
if (values.source && (positionals.length > 1 || values['batch-file'])) throw new Error('--source accepts exactly one URL.');
|
|
261
|
+
if (values.source && values['list-sources']) throw new Error('--source and --list-sources are separate actions.');
|
|
262
|
+
if (values.timeout) parseSourceTimeout(values.timeout);
|
|
263
|
+
if ((values.source || values['list-sources']) && !tokens.some(token => ['playlist', 'playlist-items'].includes(token.name))) {
|
|
264
|
+
values.playlist = false;
|
|
265
|
+
values['playlist-items'] = undefined;
|
|
266
|
+
}
|
|
267
|
+
if ((values.source || values['list-sources']) && values.playlist) throw new Error('--source and --list-sources cannot be combined with --playlist.');
|
|
268
|
+
if (values['concurrent-fragments'] !== undefined) {
|
|
269
|
+
const fragments = Number(values['concurrent-fragments']);
|
|
270
|
+
if (!Number.isInteger(fragments) || fragments < 1 || fragments > 16) throw new Error('--concurrent-fragments must be a whole number between 1 and 16.');
|
|
271
|
+
}
|
|
272
|
+
const concurrency = Number(values['playlist-concurrency']);
|
|
273
|
+
if (!Number.isInteger(concurrency) || concurrency < 1 || concurrency > 4) throw new Error('--playlist-concurrency must be a whole number between 1 and 4.');
|
|
274
|
+
if (values.compatible && (values.audio || (values.format && values.format !== 'mp4') || values.recode || values['embed-subs'] || values['embed-thumbnail'])) throw new Error('--compatible requires video MP4 without --recode, --embed-subs or --embed-thumbnail.');
|
|
275
|
+
if (values.compatible) values.format = 'mp4';
|
|
276
|
+
if (values.recode && (!values.format || values.audio)) throw new Error('--recode requires --format and video mode.');
|
|
277
|
+
if (values.section && !/^[*\d]/.test(values.section.trim())) throw new Error('--section requires a range such as "*10:00-12:00" or "10:00-12:00".');
|
|
278
|
+
if (values['sponsorblock-remove'] && !/^[a-z_,-]+$/i.test(values['sponsorblock-remove'].trim())) throw new Error('--sponsorblock-remove takes comma-separated category names, e.g. "sponsor,selfpromo".');
|
|
279
|
+
const formats = values.audio ? AUDIO_FORMATS : VIDEO_FORMATS;
|
|
280
|
+
if (values.format && !formats.includes(values.format)) throw new Error(`Invalid ${values.audio ? 'audio' : 'video'} format. Choose: ${formats.join(', ')}.${!values.audio && AUDIO_FORMATS.includes(values.format) ? ' Use --audio for audio formats.' : ''}`);
|
|
281
|
+
|
|
282
|
+
const options = {};
|
|
283
|
+
for (const [name, value] of Object.entries(values)) {
|
|
284
|
+
if (value === undefined) continue;
|
|
285
|
+
options[name.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase())] = value;
|
|
286
|
+
}
|
|
287
|
+
options.urls = positionals.map(validateUrl);
|
|
288
|
+
options.url = options.urls[0];
|
|
289
|
+
if (values.cookies !== undefined) options.cookies = validateCookieFile(values.cookies);
|
|
290
|
+
if (values['cookies-from-browser'] !== undefined) options.cookiesFromBrowser = validateBrowserSpec(values['cookies-from-browser']);
|
|
291
|
+
if (options.section) options.section = options.section.trim();
|
|
292
|
+
if (options.sponsorblockRemove) options.sponsorblockRemove = options.sponsorblockRemove.trim();
|
|
293
|
+
if (options.concurrentFragments !== undefined) options.concurrentFragments = Number(options.concurrentFragments);
|
|
294
|
+
if (options.timeout) options.timeoutMs = parseSourceTimeout(options.timeout);
|
|
295
|
+
options.playlistConcurrency = concurrency;
|
|
296
|
+
options.concurrentDownloads = Number(values['concurrent-downloads']);
|
|
297
|
+
if (!Number.isInteger(options.concurrentDownloads) || options.concurrentDownloads < 1 || options.concurrentDownloads > 4) throw new Error('--concurrent-downloads must be a whole number between 1 and 4.');
|
|
298
|
+
if (options.filenameTemplate !== undefined) validateTemplate(options.filenameTemplate);
|
|
299
|
+
if (options.folderTemplate !== undefined) validateTemplate(options.folderTemplate, { folders: true });
|
|
300
|
+
if (options.rename && options.filenameTemplate) throw new Error('--rename and --filename-template cannot be combined.');
|
|
301
|
+
const disableSubs = values.subs === false && tokens.some(token => token.name === 'subs');
|
|
302
|
+
if (options.subLangs && !disableSubs) options.subs = true;
|
|
303
|
+
if (disableSubs) {
|
|
304
|
+
options.subLangs = undefined;
|
|
305
|
+
options.embedSubs = false;
|
|
306
|
+
}
|
|
307
|
+
return options;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
export async function main(args = process.argv.slice(2), { config } = {}) {
|
|
311
|
+
if (args[0] === 'help') args = ['--help', ...args.slice(1)];
|
|
312
|
+
let color = !args.includes('--no-color') && !args.includes('--json');
|
|
313
|
+
let display;
|
|
314
|
+
try {
|
|
315
|
+
display = outputOptions(args);
|
|
316
|
+
const loaded = config ?? await loadConfig();
|
|
317
|
+
color = !args.includes('--json') && (display.color ?? applyProfile(loaded.config || {}, display.profile).color ?? true);
|
|
318
|
+
// Validate explicit profiles even when a color flag overrides their setting.
|
|
319
|
+
if (display.profile) applyProfile(loaded.config || {}, display.profile);
|
|
320
|
+
} catch (error) {
|
|
321
|
+
if (!display || display.profile) {
|
|
322
|
+
process.stderr.write(`veo: ${readableError(error)}\n`);
|
|
323
|
+
return 1;
|
|
324
|
+
}
|
|
325
|
+
// The command's own validation reports configuration errors.
|
|
326
|
+
}
|
|
327
|
+
if (['stats', 'history', 'flush', 'runs', 'inspect', 'stop', 'update', 'up', 'upgrade', 'check', 'doctor', 'backend', 'alias', 'uninstall'].includes(args[0])) args = display.remaining;
|
|
328
|
+
const code = await withOutputSettings(color, () => runMain(args, { config }));
|
|
329
|
+
// One throttled (once per day) update hint after every successful command.
|
|
330
|
+
// Failures, cancellations, help/version output and the update commands
|
|
331
|
+
// themselves never trigger it; VEO_NO_UPDATE_CHECK=1 disables it for scripts.
|
|
332
|
+
if (code === 0 && shouldUpdateNotice(args)) {
|
|
333
|
+
try {
|
|
334
|
+
const notice = await maybeUpdateNotice({ currentVersion: await packageVersion() });
|
|
335
|
+
if (notice) process.stderr.write(`${notice}\n`);
|
|
336
|
+
} catch {
|
|
337
|
+
// Informational only: a broken notice must never fail the command.
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
return code;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
// Help, version and the update commands report versions themselves;
|
|
344
|
+
// anything else earns the daily update hint on success.
|
|
345
|
+
export function shouldUpdateNotice(args = []) {
|
|
346
|
+
if (args.includes('-h') || args.includes('--help') || args.includes('-v') || args.includes('--version')) return false;
|
|
347
|
+
if (['update', 'up', 'upgrade', 'check', 'version', 'help'].includes(args[0])) return false;
|
|
348
|
+
return true;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
async function runMain(args, { config }) {
|
|
352
|
+
const stdout = outputStream(process.stdout, { plain: args.includes('--json') });
|
|
353
|
+
const stderr = outputStream(process.stderr, { plain: args.includes('--json') });
|
|
354
|
+
if (args[0] === 'stats') {
|
|
355
|
+
try { return await (await import('./stats.js')).statsMain(args.slice(1)); }
|
|
356
|
+
catch (error) { stderr.write(`veo: ${readableError(error)}\n`); return 1; }
|
|
357
|
+
}
|
|
358
|
+
if (args[0] === 'history') {
|
|
359
|
+
try { return await (await import('./history.js')).historyMain(args.slice(1)); }
|
|
360
|
+
catch (error) { stderr.write(`veo: ${readableError(error)}\n`); return 1; }
|
|
361
|
+
}
|
|
362
|
+
if (args[0] === 'flush') {
|
|
363
|
+
try { return await (await import('./flush.js')).flushMain(args.slice(1)); }
|
|
364
|
+
catch (error) { stderr.write(`veo: ${readableError(error)}\n`); return 1; }
|
|
365
|
+
}
|
|
366
|
+
if (args[0] === 'runs') {
|
|
367
|
+
try { return await (await import('./runs.js')).runsMain(args.slice(1)); }
|
|
368
|
+
catch (error) { stderr.write(`veo: ${readableError(error)}\n`); return 1; }
|
|
369
|
+
}
|
|
370
|
+
if (args[0] === 'inspect') {
|
|
371
|
+
try { return await (await import('./inspect-media.js')).inspectMain(args.slice(1)); }
|
|
372
|
+
catch (error) { stderr.write(`veo: ${readableError(error)}\n`); return error.name === 'AbortError' ? 130 : 1; }
|
|
373
|
+
}
|
|
374
|
+
if (args[0] === 'stop') {
|
|
375
|
+
try { return await (await import('./runs.js')).stopMain(args.slice(1)); }
|
|
376
|
+
catch (error) { stderr.write(`veo: ${readableError(error)}\n`); return 1; }
|
|
377
|
+
}
|
|
378
|
+
if (args[0] === 'retry') {
|
|
379
|
+
if (args[1] !== '--last') {
|
|
380
|
+
stderr.write('veo: Usage: veo retry --last [download options]\n');
|
|
381
|
+
return 1;
|
|
382
|
+
}
|
|
383
|
+
try {
|
|
384
|
+
const { latestFailedJob } = await import('./jobs.js');
|
|
385
|
+
args = ['--retry-failed', await latestFailedJob(), ...args.slice(2)];
|
|
386
|
+
} catch (error) { stderr.write(`veo: ${readableError(error)}\n`); return 1; }
|
|
387
|
+
}
|
|
388
|
+
const { cleanupDownloadCache } = await import('./download-cache.js');
|
|
389
|
+
await cleanupDownloadCache().catch(error => stderr.write(`veo: Could not clean expired local downloads: ${readableError(error)}\n`));
|
|
390
|
+
// update/upgrade/up/check subcommands are handled before URL validation.
|
|
391
|
+
if (['update', 'up', 'upgrade', 'check'].includes(args[0])) {
|
|
392
|
+
if (args[0] === 'up') args = ['update', ...args.slice(1)];
|
|
393
|
+
if (args[0] === 'check' && args[1] !== 'update') {
|
|
394
|
+
stdout.write(UPDATE_HELP);
|
|
395
|
+
return 0;
|
|
396
|
+
}
|
|
397
|
+
return updateMain(args, { registry: defaultRegistry() });
|
|
398
|
+
}
|
|
399
|
+
if (args[0] === 'config') {
|
|
400
|
+
try { return await configMain(args.slice(1)); }
|
|
401
|
+
catch (error) { stderr.write(`veo: ${readableError(error)}\n`); return 1; }
|
|
402
|
+
}
|
|
403
|
+
if (args[0] === 'doctor') {
|
|
404
|
+
try {
|
|
405
|
+
const { doctorMain } = await import('./doctor.js');
|
|
406
|
+
return await doctorMain(args.slice(1));
|
|
407
|
+
} catch (error) {
|
|
408
|
+
stderr.write(`veo: ${readableError(error)}\n`);
|
|
409
|
+
return 1;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
if (args[0] === 'backend') {
|
|
413
|
+
try {
|
|
414
|
+
const { backendUpdateMain } = await import('./backend-update.js');
|
|
415
|
+
return await backendUpdateMain(args.slice(1));
|
|
416
|
+
} catch (error) {
|
|
417
|
+
stderr.write(`veo: ${readableError(error)}\n`);
|
|
418
|
+
return 1;
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
if (args[0] === 'alias') {
|
|
422
|
+
try {
|
|
423
|
+
const { aliasMain } = await import('./alias.js');
|
|
424
|
+
return await aliasMain(args.slice(1));
|
|
425
|
+
} catch (error) {
|
|
426
|
+
stderr.write(`veo: ${readableError(error)}\n`);
|
|
427
|
+
return 1;
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
if (args[0] === 'uninstall') {
|
|
431
|
+
try {
|
|
432
|
+
const { uninstallMain } = await import('./uninstall.js');
|
|
433
|
+
return await uninstallMain(args.slice(1));
|
|
434
|
+
} catch (error) {
|
|
435
|
+
stderr.write(`veo: ${readableError(error)}\n`);
|
|
436
|
+
return 1;
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
const reporter = createReporter();
|
|
440
|
+
const controller = new AbortController();
|
|
441
|
+
const cancel = () => controller.abort();
|
|
442
|
+
let run;
|
|
443
|
+
process.once('SIGINT', cancel);
|
|
444
|
+
process.once('SIGTERM', cancel);
|
|
445
|
+
try {
|
|
446
|
+
if (!args.includes('--help') && !args.includes('-h') && !args.includes('--version')) {
|
|
447
|
+
run = await (await import('./runs.js')).registerRun(cancel);
|
|
448
|
+
}
|
|
449
|
+
const loaded = config ?? await loadConfig();
|
|
450
|
+
for (const warning of loaded.warnings || []) stderr.write(`veo: ${warning}\n`);
|
|
451
|
+
if (!args.length && process.stdin.isTTY && process.stderr.isTTY) {
|
|
452
|
+
const { interactiveArgs } = await import('./interactive.js');
|
|
453
|
+
args = await interactiveArgs(loaded.config || {}, { signal: controller.signal });
|
|
454
|
+
if (!args) return 0;
|
|
455
|
+
}
|
|
456
|
+
let options = parseCli(args, { config: loaded.config });
|
|
457
|
+
if (options.help) { stdout.write(HELP); return 0; }
|
|
458
|
+
if (options.version) {
|
|
459
|
+
const pkg = JSON.parse(await readFile(new URL('../package.json', import.meta.url), 'utf8'));
|
|
460
|
+
stdout.write(`${pkg.version}\n`);
|
|
461
|
+
return 0;
|
|
462
|
+
}
|
|
463
|
+
let retryItems;
|
|
464
|
+
if (options.retryFailed) {
|
|
465
|
+
retryItems = await retryOptions(options.retryFailed);
|
|
466
|
+
// Revalidate stored options and apply only flags explicitly supplied now.
|
|
467
|
+
const retryArgs = args.filter((arg, index) => arg !== '--retry-failed' && args[index - 1] !== '--retry-failed' && !arg.startsWith('--retry-failed='));
|
|
468
|
+
retryItems = retryItems.map(item => parseCli([item.url, ...retryArgs], { config: { ...item, profiles: loaded.config?.profiles } }));
|
|
469
|
+
options = { ...retryItems[0], urls: retryItems.map(item => item.url) };
|
|
470
|
+
}
|
|
471
|
+
if (options.batchFile) {
|
|
472
|
+
const lines = (await readFile(options.batchFile, 'utf8')).replace(/^\uFEFF/, '').split(/\r?\n/).map(line => line.trim()).filter(line => line && !line.startsWith('#'));
|
|
473
|
+
options.urls.push(...lines.map(validateUrl));
|
|
474
|
+
options.url = options.urls[0];
|
|
475
|
+
if (!options.urls.length) throw new Error('The URL list is empty.');
|
|
476
|
+
if (options.rename && options.urls.length > 1 && !options.rename.includes('*')) throw new Error('--rename only applies to a single URL unless the name contains * for the original title.');
|
|
477
|
+
if (options.listFormats && options.urls.length > 1) throw new Error('--list-formats accepts exactly one URL.');
|
|
478
|
+
}
|
|
479
|
+
// The job file is created before the first download, so another terminal can
|
|
480
|
+
// follow this run's per-item progress with `veo runs <id>`.
|
|
481
|
+
const jobFile = options.listFormats || options.listSources || options.dryRun ? null : jobFilePath();
|
|
482
|
+
await run?.describe({ urls: options.urls, output: options.output ? path.resolve(options.output) : null,
|
|
483
|
+
audio: options.audio, quality: options.quality, format: options.format, playlist: options.playlist, job: jobFile });
|
|
484
|
+
reporter.configure?.({ color: options.color && !options.json });
|
|
485
|
+
reporter.start(options.rename);
|
|
486
|
+
const cookieWarning = cookieFileWarning(options.cookies);
|
|
487
|
+
if (cookieWarning) stderr.write(`veo: ${cookieWarning}\n`);
|
|
488
|
+
|
|
489
|
+
// For a single page, fall back to media requests observed while its player loads.
|
|
490
|
+
// Explicit --source always rediscovers: signed media URLs can expire between runs.
|
|
491
|
+
if (!retryItems && options.urls.length === 1 && (!options.playlist || options.listSources)) {
|
|
492
|
+
const discovery = await resolvePageSource(options, { signal: controller.signal, stderr });
|
|
493
|
+
if (options.listSources) {
|
|
494
|
+
if (options.json) stdout.write(`${JSON.stringify({ url: options.url, status: 'sources', timedOut: Boolean(discovery.sources.timedOut), sources: discovery.sources.map(({ url, pageUrl, ...safe }) => safe) })}\n`);
|
|
495
|
+
else for (const source of discovery.sources) stdout.write(`${discovery.formatSource(source)}\n`);
|
|
496
|
+
if (discovery.sources.timedOut) stderr.write(`veo: Source search timed out after ${options.timeout || (options.deepScan ? '120s' : '45s')}; showing verified sources found so far.\n`);
|
|
497
|
+
if (!discovery.sources.length) stderr.write(discovery.sources.timedOut
|
|
498
|
+
? 'veo: No sources were verified before the timeout.\n'
|
|
499
|
+
: 'veo: No downloadable sources were found on this page.\n');
|
|
500
|
+
return discovery.sources.length && !discovery.sources.timedOut ? 0 : 1;
|
|
501
|
+
}
|
|
502
|
+
if (discovery.needsSelection) {
|
|
503
|
+
if (options.json) stdout.write(`${JSON.stringify({ url: options.url, status: 'sources', timedOut: Boolean(discovery.sources.timedOut), sources: discovery.sources.map(({ url, pageUrl, ...safe }) => safe) })}\n`);
|
|
504
|
+
else for (const source of discovery.sources) stdout.write(`${discovery.formatSource(source)}\n`);
|
|
505
|
+
stderr.write('veo: Select a source with --source <number>.\n');
|
|
506
|
+
return 1;
|
|
507
|
+
}
|
|
508
|
+
if (discovery.mediaUrl) {
|
|
509
|
+
options.mediaUrl = discovery.mediaUrl;
|
|
510
|
+
options.source = String(discovery.source);
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
if (retryItems) for (const item of retryItems) {
|
|
514
|
+
if (!item.source) continue;
|
|
515
|
+
const discovery = await resolvePageSource(item, { signal: controller.signal, stderr });
|
|
516
|
+
item.mediaUrl = discovery.mediaUrl;
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
if (options.listFormats) {
|
|
520
|
+
const { listFormats } = await import('./downloader.js');
|
|
521
|
+
stdout.write(await listFormats(options, { signal: controller.signal, reporter }));
|
|
522
|
+
return 0;
|
|
523
|
+
}
|
|
524
|
+
if (options.dryRun) {
|
|
525
|
+
const { planDownload } = await import('./downloader.js');
|
|
526
|
+
for (const request of retryItems || options.urls.map(url => ({ ...options, url }))) {
|
|
527
|
+
const { url } = request;
|
|
528
|
+
const plan = await planDownload(request, { signal: controller.signal, reporter });
|
|
529
|
+
if (options.json) stdout.write(`${JSON.stringify({ url, status: 'planned', ...plan })}\n`);
|
|
530
|
+
else {
|
|
531
|
+
stdout.write(`URL: ${url}\n`);
|
|
532
|
+
stdout.write(`${describeEstimate(plan)}\n`);
|
|
533
|
+
if (plan.quality) stdout.write(`${plan.quality}\n`);
|
|
534
|
+
for (const entry of plan.entries) stdout.write(`Would save: ${cleanText(entry.path)}\n`);
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
return 0;
|
|
538
|
+
}
|
|
539
|
+
const { download } = await import('./downloader.js');
|
|
540
|
+
const { createStatsRecorder } = await import('./stats.js');
|
|
541
|
+
const { createHistoryRecorder } = await import('./history.js');
|
|
542
|
+
const result = await runJob(options, { download, reporter, signal: controller.signal, openFile, items: retryItems, jobFile: jobFile || undefined, runId: run?.id, recordStats: createStatsRecorder(), recordHistory: createHistoryRecorder() });
|
|
543
|
+
return result;
|
|
544
|
+
} catch (error) {
|
|
545
|
+
reporter.fail(controller.signal.aborted);
|
|
546
|
+
stderr.write(`veo: ${readableError(error)}\n`);
|
|
547
|
+
return controller.signal.aborted || error.name === 'AbortError' ? 130 : 1;
|
|
548
|
+
} finally {
|
|
549
|
+
await run?.unregister();
|
|
550
|
+
process.removeListener('SIGINT', cancel);
|
|
551
|
+
process.removeListener('SIGTERM', cancel);
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
async function askSourceQuestion(prompt, signal) {
|
|
556
|
+
const rl = createInterface({ input: process.stdin, output: process.stderr });
|
|
557
|
+
try { return await rl.question(prompt, { signal }); }
|
|
558
|
+
finally { rl.close(); }
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
export async function resolvePageSource(options, { signal, stderr, inspect, discover, ask = askSourceQuestion,
|
|
562
|
+
backendResolver, interactive = Boolean(process.stdin.isTTY && process.stderr.isTTY && !options.json) }) {
|
|
563
|
+
const { fetchMetadata, prepareBackend, runBackend } = await import('./downloader.js');
|
|
564
|
+
const { discoverSources, formatSource, shouldOfferSourceDiscovery } = await import('./source-discovery.js');
|
|
565
|
+
const backend = inspect ? null : await (backendResolver || prepareBackend)(options, { signal });
|
|
566
|
+
const inspectMedia = (request, requestSignal = signal) => inspect ? inspect(request, requestSignal) : fetchMetadata(request, { signal: requestSignal, backend, runner: runBackend });
|
|
567
|
+
let originalError;
|
|
568
|
+
if (!options.source && !options.listSources) {
|
|
569
|
+
try {
|
|
570
|
+
const metadata = await inspectMedia(options);
|
|
571
|
+
if (!metadata.entries?.length && !metadata.formats?.length && !metadata.url) {
|
|
572
|
+
throw new Error('No downloadable video formats found.');
|
|
573
|
+
}
|
|
574
|
+
return {};
|
|
575
|
+
}
|
|
576
|
+
catch (error) { originalError = error; }
|
|
577
|
+
if (!shouldOfferSourceDiscovery(originalError)) throw originalError;
|
|
578
|
+
if (!interactive && !options.autoListSources) throw new Error(`${originalError.message} Use --list-sources to search this page, then --source <number> to select one.`);
|
|
579
|
+
if (interactive && !options.autoListSources) {
|
|
580
|
+
const answer = (await ask('No downloadable video found. Search this page for other sources? (y/N): ', signal)).trim().toLowerCase();
|
|
581
|
+
if (!['y', 'yes'].includes(answer)) throw originalError;
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
let sources;
|
|
585
|
+
try {
|
|
586
|
+
sources = await (discover || discoverSources)(options.url, {
|
|
587
|
+
signal, deepScan: options.deepScan, timeoutMs: options.timeoutMs,
|
|
588
|
+
inspect: (url, _page, { signal: scanSignal } = {}) => inspectMedia({ ...options, mediaUrl: url }, scanSignal),
|
|
589
|
+
});
|
|
590
|
+
} catch (error) {
|
|
591
|
+
if (signal?.aborted || error?.name === 'AbortError') throw error;
|
|
592
|
+
if (originalError) throw new Error(`${originalError.message} Source discovery also failed: ${error.message}`);
|
|
593
|
+
throw error;
|
|
594
|
+
}
|
|
595
|
+
if (options.listSources) return { sources, formatSource };
|
|
596
|
+
if (sources.timedOut) stderr.write(`veo: Source search timed out after ${options.timeout || (options.deepScan ? '120s' : '45s')}; showing verified sources found so far.\n`);
|
|
597
|
+
if (!sources.length) {
|
|
598
|
+
if (originalError) throw originalError;
|
|
599
|
+
throw new Error('No downloadable video sources were found on this page.');
|
|
600
|
+
}
|
|
601
|
+
let index = Number(options.source);
|
|
602
|
+
if (!index) {
|
|
603
|
+
if (!interactive && options.autoListSources) return { sources, formatSource, needsSelection: true };
|
|
604
|
+
for (const source of sources) stderr.write(`${formatSource(source)}\n`);
|
|
605
|
+
if (!interactive) throw new Error('Select a source with --source <number>.');
|
|
606
|
+
const answer = await ask('Source number (Enter to cancel): ', signal);
|
|
607
|
+
if (!/^[1-9]\d*$/.test(answer.trim())) throw new Error('No source selected.');
|
|
608
|
+
index = Number(answer.trim());
|
|
609
|
+
}
|
|
610
|
+
const selected = sources[index - 1];
|
|
611
|
+
if (!selected) throw new Error(`Source ${index} does not exist; choose 1-${sources.length}.`);
|
|
612
|
+
return { mediaUrl: selected.url, source: index };
|
|
613
|
+
}
|