veodl 1.10.0 → 1.11.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/AGENTS.md +3 -3
- package/CHANGELOG.md +29 -0
- package/README.md +128 -67
- package/docs/AGENT_GUIDE.md +23 -9
- package/package.json +61 -58
- package/src/cli.js +227 -133
- package/src/config-diagnostics.js +20 -20
- package/src/config-editor.js +21 -17
- package/src/config-template.js +79 -66
- package/src/config.js +117 -110
- package/src/downloader.js +103 -42
- package/src/experimental-fragments.js +29 -0
- package/src/history.js +1 -1
- package/src/inline-region.js +72 -0
- package/src/inspect-media.js +11 -0
- package/src/interactive.js +9 -4
- package/src/jobs.js +51 -14
- package/src/naming.js +4 -0
- package/src/output.js +77 -60
- package/src/path-links.js +53 -0
- package/src/progress.js +341 -208
- package/src/terminal-size.js +8 -0
package/src/config.js
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { commandOutput } from './output.js';
|
|
2
|
+
import { folderLink } from './path-links.js';
|
|
2
3
|
import path from 'node:path';
|
|
3
4
|
import { mkdir, readFile, writeFile } from 'node:fs/promises';
|
|
4
5
|
import { spawn } from 'node:child_process';
|
|
5
6
|
import { configBase } from './paths.js';
|
|
6
7
|
import { configSyntaxError } from './config-errors.js';
|
|
7
|
-
import { CONFIG_TEMPLATE, CONFIG_GUIDE, stripConfigComments } from './config-template.js';
|
|
8
|
+
import { CONFIG_TEMPLATE, CONFIG_GUIDE, stripConfigComments } from './config-template.js';
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* Keys accepted in the config file, with the CLI flag they act as a default for.
|
|
11
12
|
* Everything here is a default only: an explicit command-line flag always wins.
|
|
12
13
|
*/
|
|
13
|
-
export const CONFIG_KEYS = Object.freeze({
|
|
14
|
+
export const CONFIG_KEYS = Object.freeze({
|
|
14
15
|
concurrentDownloads: 'number',
|
|
15
16
|
adaptiveConcurrency: 'boolean',
|
|
16
17
|
filenameTemplate: 'string',
|
|
@@ -28,13 +29,19 @@ export const CONFIG_KEYS = Object.freeze({
|
|
|
28
29
|
audio: 'boolean',
|
|
29
30
|
open: 'boolean',
|
|
30
31
|
resume: 'boolean',
|
|
32
|
+
incognito: 'boolean',
|
|
33
|
+
neutralFilename: 'boolean',
|
|
31
34
|
closestQuality: 'boolean',
|
|
32
35
|
cookies: 'string',
|
|
33
36
|
cookiesFromBrowser: 'string',
|
|
34
37
|
playlist: 'boolean',
|
|
35
38
|
concurrentFragments: 'number',
|
|
39
|
+
experimentalFragments: 'boolean',
|
|
36
40
|
subs: 'boolean',
|
|
41
|
+
autoSubs: 'boolean',
|
|
37
42
|
subLangs: 'string',
|
|
43
|
+
subFormat: 'string',
|
|
44
|
+
verify: 'boolean',
|
|
38
45
|
embedSubs: 'boolean',
|
|
39
46
|
embedMetadata: 'boolean',
|
|
40
47
|
embedThumbnail: 'boolean',
|
|
@@ -47,9 +54,9 @@ export const CONFIG_KEYS = Object.freeze({
|
|
|
47
54
|
timeout: 'string',
|
|
48
55
|
listSources: 'boolean',
|
|
49
56
|
autoListSources: 'boolean',
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
export const RESERVED_PROFILE_NAMES = Object.freeze(['list', 'reset']);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
export const RESERVED_PROFILE_NAMES = Object.freeze(['list', 'reset']);
|
|
53
60
|
|
|
54
61
|
export function configFile({ env = process.env, platform = process.platform } = {}) {
|
|
55
62
|
const override = env.VEO_CONFIG;
|
|
@@ -96,19 +103,19 @@ export function parseConfigText(text, target = 'config') {
|
|
|
96
103
|
}
|
|
97
104
|
const warnings = [];
|
|
98
105
|
const config = {};
|
|
99
|
-
for (const [key, value] of Object.entries(data)) {
|
|
100
|
-
if (key === '$schema') continue;
|
|
101
|
-
if (key === 'activeProfile') {
|
|
102
|
-
if (typeOf(value) !== 'string' || !value) throw new Error(`Config key "activeProfile" must be a non-empty string (${target}).`);
|
|
103
|
-
config.activeProfile = value;
|
|
104
|
-
continue;
|
|
105
|
-
}
|
|
106
|
+
for (const [key, value] of Object.entries(data)) {
|
|
107
|
+
if (key === '$schema') continue;
|
|
108
|
+
if (key === 'activeProfile') {
|
|
109
|
+
if (typeOf(value) !== 'string' || !value) throw new Error(`Config key "activeProfile" must be a non-empty string (${target}).`);
|
|
110
|
+
config.activeProfile = value;
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
106
113
|
if (key === 'profiles') {
|
|
107
114
|
if (!value || typeOf(value) !== 'object') throw new Error('Config profiles must be an object.');
|
|
108
|
-
config.profiles = Object.create(null);
|
|
109
|
-
for (const [name, profile] of Object.entries(value)) {
|
|
110
|
-
if (RESERVED_PROFILE_NAMES.includes(name)) throw new Error(`Profile name "${name}" is reserved for veo profile ${name}. Rename it in ${target}.`);
|
|
111
|
-
if (!profile || typeOf(profile) !== 'object') throw new Error(`Profile "${name}" must be an object.`);
|
|
115
|
+
config.profiles = Object.create(null);
|
|
116
|
+
for (const [name, profile] of Object.entries(value)) {
|
|
117
|
+
if (RESERVED_PROFILE_NAMES.includes(name)) throw new Error(`Profile name "${name}" is reserved for veo profile ${name}. Rename it in ${target}.`);
|
|
118
|
+
if (!profile || typeOf(profile) !== 'object') throw new Error(`Profile "${name}" must be an object.`);
|
|
112
119
|
const checked = {};
|
|
113
120
|
for (const [setting, item] of Object.entries(profile)) {
|
|
114
121
|
if (!Object.hasOwn(CONFIG_KEYS, setting)) throw new Error(`Unknown setting "${setting}" in profile "${name}".`);
|
|
@@ -127,95 +134,95 @@ export function parseConfigText(text, target = 'config') {
|
|
|
127
134
|
if (typeOf(value) !== expected) {
|
|
128
135
|
throw new Error(`Config key "${key}" must be a ${expected}, not a ${typeOf(value)} (${target}).`);
|
|
129
136
|
}
|
|
130
|
-
config[key] = value;
|
|
131
|
-
}
|
|
132
|
-
if (config.activeProfile && !Object.hasOwn(config.profiles || {}, config.activeProfile)) {
|
|
133
|
-
throw new Error(`Unknown active profile "${config.activeProfile}" in ${target}. Available: ${Object.keys(config.profiles || {}).join(', ') || 'none'}.`);
|
|
134
|
-
}
|
|
135
|
-
return { file: target, exists: true, config, warnings };
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
export function selectedProfileName(config, name) {
|
|
139
|
-
return name || config.activeProfile || (Object.hasOwn(config.profiles || {}, 'default') ? 'default' : undefined);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
export function applyProfile(config, name) {
|
|
143
|
-
const { profiles, activeProfile, ...defaults } = config;
|
|
144
|
-
name = selectedProfileName(config, name);
|
|
145
|
-
if (!name) return defaults;
|
|
146
|
-
if (!profiles || !Object.hasOwn(profiles, name)) throw new Error(`Unknown profile "${name}". Available: ${Object.keys(profiles || {}).join(', ') || 'none'}. Use veo config edit.`);
|
|
147
|
-
return { ...defaults, ...profiles[name] };
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
export async function profileMain(args, { file = configFile(), output = process.stdout } = {}) {
|
|
151
|
-
if (args.length > 1 || args[0]?.startsWith('-')) throw new Error('Usage: veo profile [list|reset|NAME]');
|
|
152
|
-
const loaded = await loadConfig({ file });
|
|
153
|
-
if (!args.length) {
|
|
154
|
-
output.write(`Active profile: ${selectedProfileName(loaded.config) || 'global (no profile)'}\n`);
|
|
155
|
-
output.write(`Available: ${Object.keys(loaded.config.profiles || {}).join(', ') || 'none'}\n`);
|
|
156
|
-
return 0;
|
|
157
|
-
}
|
|
158
|
-
if (args[0] === 'list' && args.length === 1) {
|
|
159
|
-
const names = Object.keys(loaded.config.profiles || {});
|
|
160
|
-
if (!names.length) output.write('No profiles configured. Use veo config edit.\n');
|
|
161
|
-
else {
|
|
162
|
-
const active = selectedProfileName(loaded.config);
|
|
163
|
-
output.write(`Profiles:\n${active ? '' : '* global (no profile)\n'}${names.map(name => `${name === active ? '* ' : ' '}${name}${name === active ? ' (active)' : ''}`).join('\n')}\n`);
|
|
164
|
-
}
|
|
165
|
-
return 0;
|
|
166
|
-
}
|
|
167
|
-
const reset = args[0] === 'reset' && args.length === 1;
|
|
168
|
-
const name = args[0];
|
|
169
|
-
if (!reset) {
|
|
170
|
-
applyProfile(loaded.config, name);
|
|
171
|
-
await effectiveConfig(loaded.config, name);
|
|
172
|
-
}
|
|
173
|
-
if (!loaded.exists) {
|
|
174
|
-
output.write('Active profile: global (no profile)\n');
|
|
175
|
-
return 0;
|
|
176
|
-
}
|
|
177
|
-
const original = await readFile(file, 'utf8');
|
|
178
|
-
// Token locations come from the comment-aware parser, preserving hand-written notes.
|
|
179
|
-
const { configSource } = await import('./config-diagnostics.js');
|
|
180
|
-
const { nodes } = configSource(original);
|
|
181
|
-
const property = nodes.get(JSON.stringify(['activeProfile']));
|
|
182
|
-
let updated;
|
|
183
|
-
if (reset) {
|
|
184
|
-
if (!property) updated = original;
|
|
185
|
-
else {
|
|
186
|
-
const clean = (original.startsWith('\uFEFF') ? ' ' : '') + stripConfigComments(original);
|
|
187
|
-
let start = property.keyStart, end = property.end;
|
|
188
|
-
while (/\s/.test(clean[end] || '')) end++;
|
|
189
|
-
if (clean[end] === ',') end++;
|
|
190
|
-
else {
|
|
191
|
-
let before = start - 1;
|
|
192
|
-
while (before >= 0 && /\s/.test(clean[before])) before--;
|
|
193
|
-
if (clean[before] === ',') start = before;
|
|
194
|
-
end = property.end;
|
|
195
|
-
}
|
|
196
|
-
updated = original.slice(0, start) + original.slice(end);
|
|
197
|
-
}
|
|
198
|
-
} else if (property) updated = original.slice(0, property.start) + JSON.stringify(name) + original.slice(property.end);
|
|
199
|
-
else {
|
|
200
|
-
const root = nodes.get('[]');
|
|
201
|
-
const clean = (original.startsWith('\uFEFF') ? ' ' : '') + stripConfigComments(original);
|
|
202
|
-
const first = root.start + 1 + clean.slice(root.start + 1, root.end - 1).search(/\S/);
|
|
203
|
-
const empty = first === root.start;
|
|
204
|
-
const newline = original.includes('\r\n') ? '\r\n' : '\n';
|
|
205
|
-
const position = empty ? root.end - 1 : first;
|
|
206
|
-
const indent = empty ? ' ' : /^[ \t]*$/.test(original.slice(original.lastIndexOf('\n', position - 1) + 1, position))
|
|
207
|
-
? original.slice(original.lastIndexOf('\n', position - 1) + 1, position) : '';
|
|
208
|
-
updated = original.slice(0, position) + (empty ? `${newline}${indent}` : '') +
|
|
209
|
-
`"activeProfile": ${JSON.stringify(name)}${empty ? `${newline}` : `,${newline}${indent}`}` + original.slice(position);
|
|
210
|
-
}
|
|
211
|
-
parseConfigText(updated, file);
|
|
212
|
-
if (updated !== original) {
|
|
213
|
-
if (await readFile(file, 'utf8') !== original) throw new Error('Config changed while switching profiles. Try again.');
|
|
214
|
-
await writeFile(file, updated, 'utf8');
|
|
215
|
-
}
|
|
216
|
-
output.write(`Active profile: ${reset ? selectedProfileName(parseConfigText(updated, file).config) || 'global (no profile)' : name}\n`);
|
|
217
|
-
return 0;
|
|
218
|
-
}
|
|
137
|
+
config[key] = value;
|
|
138
|
+
}
|
|
139
|
+
if (config.activeProfile && !Object.hasOwn(config.profiles || {}, config.activeProfile)) {
|
|
140
|
+
throw new Error(`Unknown active profile "${config.activeProfile}" in ${target}. Available: ${Object.keys(config.profiles || {}).join(', ') || 'none'}.`);
|
|
141
|
+
}
|
|
142
|
+
return { file: target, exists: true, config, warnings };
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export function selectedProfileName(config, name) {
|
|
146
|
+
return name || config.activeProfile || (Object.hasOwn(config.profiles || {}, 'default') ? 'default' : undefined);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export function applyProfile(config, name) {
|
|
150
|
+
const { profiles, activeProfile, ...defaults } = config;
|
|
151
|
+
name = selectedProfileName(config, name);
|
|
152
|
+
if (!name) return defaults;
|
|
153
|
+
if (!profiles || !Object.hasOwn(profiles, name)) throw new Error(`Unknown profile "${name}". Available: ${Object.keys(profiles || {}).join(', ') || 'none'}. Use veo config edit.`);
|
|
154
|
+
return { ...defaults, ...profiles[name] };
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export async function profileMain(args, { file = configFile(), output = process.stdout } = {}) {
|
|
158
|
+
if (args.length > 1 || args[0]?.startsWith('-')) throw new Error('Usage: veo profile [list|reset|NAME]');
|
|
159
|
+
const loaded = await loadConfig({ file });
|
|
160
|
+
if (!args.length) {
|
|
161
|
+
output.write(`Active profile: ${selectedProfileName(loaded.config) || 'global (no profile)'}\n`);
|
|
162
|
+
output.write(`Available: ${Object.keys(loaded.config.profiles || {}).join(', ') || 'none'}\n`);
|
|
163
|
+
return 0;
|
|
164
|
+
}
|
|
165
|
+
if (args[0] === 'list' && args.length === 1) {
|
|
166
|
+
const names = Object.keys(loaded.config.profiles || {});
|
|
167
|
+
if (!names.length) output.write('No profiles configured. Use veo config edit.\n');
|
|
168
|
+
else {
|
|
169
|
+
const active = selectedProfileName(loaded.config);
|
|
170
|
+
output.write(`Profiles:\n${active ? '' : '* global (no profile)\n'}${names.map(name => `${name === active ? '* ' : ' '}${name}${name === active ? ' (active)' : ''}`).join('\n')}\n`);
|
|
171
|
+
}
|
|
172
|
+
return 0;
|
|
173
|
+
}
|
|
174
|
+
const reset = args[0] === 'reset' && args.length === 1;
|
|
175
|
+
const name = args[0];
|
|
176
|
+
if (!reset) {
|
|
177
|
+
applyProfile(loaded.config, name);
|
|
178
|
+
await effectiveConfig(loaded.config, name);
|
|
179
|
+
}
|
|
180
|
+
if (!loaded.exists) {
|
|
181
|
+
output.write('Active profile: global (no profile)\n');
|
|
182
|
+
return 0;
|
|
183
|
+
}
|
|
184
|
+
const original = await readFile(file, 'utf8');
|
|
185
|
+
// Token locations come from the comment-aware parser, preserving hand-written notes.
|
|
186
|
+
const { configSource } = await import('./config-diagnostics.js');
|
|
187
|
+
const { nodes } = configSource(original);
|
|
188
|
+
const property = nodes.get(JSON.stringify(['activeProfile']));
|
|
189
|
+
let updated;
|
|
190
|
+
if (reset) {
|
|
191
|
+
if (!property) updated = original;
|
|
192
|
+
else {
|
|
193
|
+
const clean = (original.startsWith('\uFEFF') ? ' ' : '') + stripConfigComments(original);
|
|
194
|
+
let start = property.keyStart, end = property.end;
|
|
195
|
+
while (/\s/.test(clean[end] || '')) end++;
|
|
196
|
+
if (clean[end] === ',') end++;
|
|
197
|
+
else {
|
|
198
|
+
let before = start - 1;
|
|
199
|
+
while (before >= 0 && /\s/.test(clean[before])) before--;
|
|
200
|
+
if (clean[before] === ',') start = before;
|
|
201
|
+
end = property.end;
|
|
202
|
+
}
|
|
203
|
+
updated = original.slice(0, start) + original.slice(end);
|
|
204
|
+
}
|
|
205
|
+
} else if (property) updated = original.slice(0, property.start) + JSON.stringify(name) + original.slice(property.end);
|
|
206
|
+
else {
|
|
207
|
+
const root = nodes.get('[]');
|
|
208
|
+
const clean = (original.startsWith('\uFEFF') ? ' ' : '') + stripConfigComments(original);
|
|
209
|
+
const first = root.start + 1 + clean.slice(root.start + 1, root.end - 1).search(/\S/);
|
|
210
|
+
const empty = first === root.start;
|
|
211
|
+
const newline = original.includes('\r\n') ? '\r\n' : '\n';
|
|
212
|
+
const position = empty ? root.end - 1 : first;
|
|
213
|
+
const indent = empty ? ' ' : /^[ \t]*$/.test(original.slice(original.lastIndexOf('\n', position - 1) + 1, position))
|
|
214
|
+
? original.slice(original.lastIndexOf('\n', position - 1) + 1, position) : '';
|
|
215
|
+
updated = original.slice(0, position) + (empty ? `${newline}${indent}` : '') +
|
|
216
|
+
`"activeProfile": ${JSON.stringify(name)}${empty ? `${newline}` : `,${newline}${indent}`}` + original.slice(position);
|
|
217
|
+
}
|
|
218
|
+
parseConfigText(updated, file);
|
|
219
|
+
if (updated !== original) {
|
|
220
|
+
if (await readFile(file, 'utf8') !== original) throw new Error('Config changed while switching profiles. Try again.');
|
|
221
|
+
await writeFile(file, updated, 'utf8');
|
|
222
|
+
}
|
|
223
|
+
output.write(`Active profile: ${reset ? selectedProfileName(parseConfigText(updated, file).config) || 'global (no profile)' : name}\n`);
|
|
224
|
+
return 0;
|
|
225
|
+
}
|
|
219
226
|
|
|
220
227
|
export async function prepareConfigEdit(file) {
|
|
221
228
|
await mkdir(path.dirname(file), { recursive: true });
|
|
@@ -223,7 +230,7 @@ export async function prepareConfigEdit(file) {
|
|
|
223
230
|
catch (error) {
|
|
224
231
|
if (error.code !== 'EEXIST') throw error;
|
|
225
232
|
const original = await readFile(file, 'utf8');
|
|
226
|
-
if (!original.replace(/^\uFEFF/, '').trim()) await writeFile(file, CONFIG_TEMPLATE, 'utf8');
|
|
233
|
+
if (!original.replace(/^\uFEFF/, '').trim()) await writeFile(file, CONFIG_TEMPLATE, 'utf8');
|
|
227
234
|
}
|
|
228
235
|
}
|
|
229
236
|
|
|
@@ -231,7 +238,7 @@ export async function configMain(args) {
|
|
|
231
238
|
const editorColor = !args.includes('--no-color') && !Object.hasOwn(process.env, 'NO_COLOR');
|
|
232
239
|
let stdout;
|
|
233
240
|
[args, stdout] = commandOutput(args, process.stdout);
|
|
234
|
-
if (args[0] === 'show' || args[0] === 'guide') stdout = process.stdout;
|
|
241
|
+
if (args[0] === 'show' || args[0] === 'guide') stdout = process.stdout;
|
|
235
242
|
const file = configFile();
|
|
236
243
|
if (args[0] === 'reset') {
|
|
237
244
|
if (args.length !== 1) throw new Error('Usage: veo config reset');
|
|
@@ -261,9 +268,9 @@ export async function configMain(args) {
|
|
|
261
268
|
if (args.length > 2 || (args[1] && !['--external', '--terminal'].includes(args[1]))) throw new Error('Usage: veo config edit [--external|--terminal]');
|
|
262
269
|
editorMode = args[1]?.slice(2) || process.env.VEO_CONFIG_EDITOR || 'auto';
|
|
263
270
|
if (!['auto', 'external', 'terminal'].includes(editorMode)) throw new Error('VEO_CONFIG_EDITOR must be auto, external or terminal.');
|
|
264
|
-
} else if (args.length !== 1 || !['path', 'profiles', 'guide'].includes(args[0])) throw new Error('Usage: veo config edit|path|profiles|guide|check|show|reset');
|
|
265
|
-
if (args[0] === 'path') { stdout.write(`${file}\n`); return 0; }
|
|
266
|
-
if (args[0] === 'guide') { stdout.write(CONFIG_GUIDE); return 0; }
|
|
271
|
+
} else if (args.length !== 1 || !['path', 'profiles', 'guide'].includes(args[0])) throw new Error('Usage: veo config edit|path|profiles|guide|check|show|reset');
|
|
272
|
+
if (args[0] === 'path') { stdout.write(`${folderLink(stdout, file)}\n`); return 0; }
|
|
273
|
+
if (args[0] === 'guide') { stdout.write(CONFIG_GUIDE); return 0; }
|
|
267
274
|
if (args[0] === 'profiles') {
|
|
268
275
|
const loaded = await loadConfig();
|
|
269
276
|
stdout.write(`${Object.keys(loaded.config.profiles || {}).join('\n') || 'No profiles configured. Use veo config edit.'}\n`);
|
package/src/downloader.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ensureCompatibility } from './compatibility.js';
|
|
2
|
-
import { adaptiveRun, reducedLimit, phaseTimer } from './execution.js';
|
|
2
|
+
import { adaptiveRun, reducedLimit, phaseTimer } from './execution.js';
|
|
3
3
|
import { mediaDestination, prepareDestination } from './naming.js';
|
|
4
4
|
import { estimateMediaBytes, reserveSpace } from './disk-space.js';
|
|
5
5
|
import { spawn } from 'node:child_process';
|
|
@@ -9,6 +9,7 @@ import path from 'node:path';
|
|
|
9
9
|
import { resolveBackend } from './backend.js';
|
|
10
10
|
import { availableHeights, cappedHeight, closestHeight, saveUnique, sanitizeTitle } from './utils.js';
|
|
11
11
|
import { digest, readJson, writeJson } from './state.js';
|
|
12
|
+
import { isMediaFile } from './run-archive.js';
|
|
12
13
|
import { cleanupDownloadCache, downloadCacheRoot, TRANSFER_RETENTION_MS } from './download-cache.js';
|
|
13
14
|
import { selectedEntries, sizeEstimate, describeEstimate } from './playlist.js';
|
|
14
15
|
|
|
@@ -157,6 +158,8 @@ function downloadSettings(options) {
|
|
|
157
158
|
embedMetadata: false, embedThumbnail: false, ...options };
|
|
158
159
|
const settings = Object.fromEntries(['quality', 'audio', 'format', 'closestQuality', 'subs', 'subLangs', 'embedSubs',
|
|
159
160
|
'embedMetadata', 'embedThumbnail', 'sponsorblockRemove', 'section'].map(key => [key, options[key] ?? null]));
|
|
161
|
+
if (options.autoSubs) settings.autoSubs = true;
|
|
162
|
+
if (options.subFormat) settings.subFormat = options.subFormat;
|
|
160
163
|
// Existing conversion jobs retain their keys; remux requests must not reuse them.
|
|
161
164
|
if (options.format && !options.audio && !options.recode) settings.videoRemux = true;
|
|
162
165
|
if (options.compatible) settings.compatible = true;
|
|
@@ -229,6 +232,7 @@ function backendArgs(options, backend) {
|
|
|
229
232
|
'--socket-timeout', '30', '--retries', '3', '--fragment-retries', '3',
|
|
230
233
|
'--no-js-runtimes', '--js-runtimes', `node:${process.execPath}`,
|
|
231
234
|
'--ffmpeg-location', backend.ffmpegLocation];
|
|
235
|
+
if (options.incognito) common.push('--no-cache-dir');
|
|
232
236
|
if (!options.playlist) common.push('--no-playlist');
|
|
233
237
|
if (options._entryIndex) common.push('--playlist-items', String(options._entryIndex));
|
|
234
238
|
common.push('--concurrent-fragments', String(options.concurrentFragments ?? 8));
|
|
@@ -265,9 +269,12 @@ function mediaArgs(options, quality) {
|
|
|
265
269
|
// WebM keep their own source selection. Resolution remains the primary choice.
|
|
266
270
|
const selectedSort = options.recode || options.format === 'webm' ? quality.sort : sort;
|
|
267
271
|
if (!options.audio && selectedSort) args.push('-S', selectedSort);
|
|
268
|
-
if (options.subs || options.subLangs || options.embedSubs) {
|
|
269
|
-
args.push('--write-subs'
|
|
272
|
+
if (options.subs || options.autoSubs || options.subLangs || options.embedSubs) {
|
|
273
|
+
if (options.subs || (options.embedSubs && !options.autoSubs)) args.push('--write-subs');
|
|
274
|
+
if (options.autoSubs) args.push('--write-auto-subs');
|
|
275
|
+
args.push('--sub-langs', options.subLangs || 'en.*,en');
|
|
270
276
|
}
|
|
277
|
+
if (options.subFormat) args.push('--sub-format', options.subFormat);
|
|
271
278
|
if (options.embedSubs) args.push('--embed-subs');
|
|
272
279
|
if (options.embedMetadata) args.push('--embed-metadata');
|
|
273
280
|
if (options.embedThumbnail) args.push('--embed-thumbnail');
|
|
@@ -288,26 +295,26 @@ export async function fetchMetadata(options, { signal, backend, runner, reporter
|
|
|
288
295
|
const args = [...common, '--dump-single-json', '--skip-download'];
|
|
289
296
|
if (options.playlist && !options._entryIndex) args.push('--flat-playlist');
|
|
290
297
|
args.push('--', options.mediaUrl || options.url);
|
|
291
|
-
try {
|
|
292
|
-
let metadata = JSON.parse(await runner(backend.ytDlp, args, { signal }));
|
|
293
|
-
if (options._entryIndex && metadata.entries) metadata = metadata.entries.find(Boolean);
|
|
294
|
-
if (!metadata) throw new Error('The selected playlist entry is unavailable.');
|
|
295
|
-
if (!options.playlist && (metadata._type === 'playlist' || metadata.entries)) {
|
|
296
|
-
throw new Error('This URL is a collection. Add --playlist to download every entry.');
|
|
297
|
-
}
|
|
298
|
-
if (metadata.is_live) throw new Error('Live streams are not supported. Please use a finished video.');
|
|
299
|
-
if (metadata.has_drm) throw new Error('This content is DRM-protected.');
|
|
300
|
-
reporter?.finishStatus?.('Reading video…', 'done');
|
|
301
|
-
return metadata;
|
|
302
|
-
} catch (error) {
|
|
303
|
-
if (!signal?.aborted && error?.name !== 'AbortError') reporter?.finishStatus?.('Reading video…', 'failed');
|
|
304
|
-
throw error;
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
export async function prepareBackend(options, { signal, backendResolver = resolveBackend, reporter } = {}) {
|
|
309
|
-
return backendResolver({ signal, onStatus: message => reporter?.status(message), onStatusDone: (message, outcome) => reporter?.finishStatus?.(message, outcome) });
|
|
310
|
-
}
|
|
298
|
+
try {
|
|
299
|
+
let metadata = JSON.parse(await runner(backend.ytDlp, args, { signal }));
|
|
300
|
+
if (options._entryIndex && metadata.entries) metadata = metadata.entries.find(Boolean);
|
|
301
|
+
if (!metadata) throw new Error('The selected playlist entry is unavailable.');
|
|
302
|
+
if (!options.playlist && (metadata._type === 'playlist' || metadata.entries)) {
|
|
303
|
+
throw new Error('This URL is a collection. Add --playlist to download every entry.');
|
|
304
|
+
}
|
|
305
|
+
if (metadata.is_live) throw new Error('Live streams are not supported. Please use a finished video.');
|
|
306
|
+
if (metadata.has_drm) throw new Error('This content is DRM-protected.');
|
|
307
|
+
reporter?.finishStatus?.('Reading video…', 'done');
|
|
308
|
+
return metadata;
|
|
309
|
+
} catch (error) {
|
|
310
|
+
if (!signal?.aborted && error?.name !== 'AbortError') reporter?.finishStatus?.('Reading video…', 'failed');
|
|
311
|
+
throw error;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
export async function prepareBackend(options, { signal, backendResolver = resolveBackend, reporter } = {}) {
|
|
316
|
+
return backendResolver({ signal, onStatus: message => reporter?.status(message), onStatusDone: (message, outcome) => reporter?.finishStatus?.(message, outcome) });
|
|
317
|
+
}
|
|
311
318
|
|
|
312
319
|
/** The extension the finished file will most likely have, for previews. */
|
|
313
320
|
export function predictedExtension(options) {
|
|
@@ -324,6 +331,29 @@ export async function previewPath(directory, title, extension, { exists = async
|
|
|
324
331
|
}
|
|
325
332
|
}
|
|
326
333
|
|
|
334
|
+
/** Summarize source resolutions without downloading media. */
|
|
335
|
+
export async function listQualities(options, { signal, backendResolver = resolveBackend, runner = runBackend, reporter } = {}) {
|
|
336
|
+
const backend = await prepareBackend(options, { signal, backendResolver, reporter });
|
|
337
|
+
const metadata = await fetchMetadata({ ...options, playlist: false }, { signal, backend, runner, reporter });
|
|
338
|
+
const formats = (metadata.formats || [metadata]).filter(format => format && format.vcodec !== 'none' && !format.has_drm && format.ext !== 'mhtml' && format.protocol !== 'mhtml');
|
|
339
|
+
if (!formats.length) throw new Error('No downloadable video formats found.');
|
|
340
|
+
const qualities = availableHeights(formats).sort((a, b) => b - a).map(height => height + 'p');
|
|
341
|
+
return { url: options.url, status: 'qualities', title: metadata.title || null, qualities };
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
/** List subtitle languages and source formats without exposing signed subtitle URLs. */
|
|
345
|
+
export async function listSubtitles(options, { signal, backendResolver = resolveBackend, runner = runBackend, reporter } = {}) {
|
|
346
|
+
const backend = await prepareBackend(options, { signal, backendResolver, reporter });
|
|
347
|
+
const metadata = await fetchMetadata({ ...options, playlist: false }, { signal, backend, runner, reporter });
|
|
348
|
+
const summarize = source => Object.entries(source || {}).map(([language, tracks]) => ({
|
|
349
|
+
language,
|
|
350
|
+
name: Array.isArray(tracks) ? tracks.find(track => typeof track?.name === 'string')?.name || null : null,
|
|
351
|
+
formats: Array.isArray(tracks) ? [...new Set(tracks.map(track => track?.ext).filter(ext => typeof ext === 'string' && /^[a-z0-9]+$/i.test(ext)))].sort() : [],
|
|
352
|
+
})).sort((a, b) => a.language.localeCompare(b.language));
|
|
353
|
+
return { url: options.url, status: 'subtitles', title: metadata.title || null,
|
|
354
|
+
manual: summarize(metadata.subtitles), automatic: summarize(metadata.automatic_captions) };
|
|
355
|
+
}
|
|
356
|
+
|
|
327
357
|
/** `veo --list-formats`: print the backend's own format table and stop. */
|
|
328
358
|
export async function listFormats(options, { signal, backendResolver = resolveBackend, runner = runBackend, reporter } = {}) {
|
|
329
359
|
const backend = await prepareBackend(options, { signal, backendResolver, reporter });
|
|
@@ -395,8 +425,9 @@ async function downloadCollection(options, metadata, dependencies) {
|
|
|
395
425
|
} catch (error) {
|
|
396
426
|
if (signal?.aborted) throw error;
|
|
397
427
|
failures.push({ index, error: error.message });
|
|
428
|
+
results[offset] = error.files || [];
|
|
398
429
|
reporter?.status(`Entry ${index} failed: ${error.message}`);
|
|
399
|
-
outcome = { index, status: 'failed', error: error.message };
|
|
430
|
+
outcome = { index, status: 'failed', error: error.message, files: error.files || [] };
|
|
400
431
|
}
|
|
401
432
|
await notify(outcome);
|
|
402
433
|
}
|
|
@@ -407,7 +438,9 @@ async function downloadCollection(options, metadata, dependencies) {
|
|
|
407
438
|
if (rejected) throw rejected.reason;
|
|
408
439
|
const files = results.flatMap(files => files || []);
|
|
409
440
|
failures.sort((a, b) => a.index - b.index);
|
|
410
|
-
return { url: options.url, title: metadata.title || metadata.id || 'Playlist', files, saved, skipped, failures,
|
|
441
|
+
return { url: options.url, title: metadata.title || metadata.id || 'Playlist', files, saved, skipped, failures,
|
|
442
|
+
...(options.verify && !failures.length && !skipped ? { verified: true } : {}),
|
|
443
|
+
...(entryTimings.length ? { entryTimings: entryTimings.sort((a, b) => a.index - b.index) } : {}),
|
|
411
444
|
status: failures.length ? 'failed' : saved ? 'saved' : 'skipped' };
|
|
412
445
|
}
|
|
413
446
|
|
|
@@ -415,12 +448,12 @@ async function downloadCollection(options, metadata, dependencies) {
|
|
|
415
448
|
* Download one URL. Returns every file that was saved, in the order the
|
|
416
449
|
* backend produced them, so collections and subtitle sidecars are reported.
|
|
417
450
|
*/
|
|
418
|
-
export async function download(options, { signal, reporter, backendResolver = resolveBackend, runner = runBackend, onEntry, localRoot = downloadCacheRoot(), skipCacheCleanup = false, adaptiveState = { divisor: 1 }, wait, diskChecker = reserveSpace, now, compatibilityRunner = runBackend } = {}) {
|
|
451
|
+
export async function download(options, { signal, reporter, backendResolver = resolveBackend, runner = runBackend, onEntry, localRoot = downloadCacheRoot(), skipCacheCleanup = false, adaptiveState = { divisor: 1 }, wait, diskChecker = reserveSpace, now, compatibilityRunner = runBackend, verifier } = {}) {
|
|
419
452
|
const timer = phaseTimer(now);
|
|
420
|
-
const timingResult = () => {
|
|
421
|
-
if (options.timings === false) return {};
|
|
422
|
-
return { timings: timer.result() };
|
|
423
|
-
};
|
|
453
|
+
const timingResult = () => {
|
|
454
|
+
if (options.timings === false) return {};
|
|
455
|
+
return { timings: timer.result() };
|
|
456
|
+
};
|
|
424
457
|
let directory = path.resolve(options.output);
|
|
425
458
|
localRoot = path.resolve(localRoot);
|
|
426
459
|
if (!skipCacheCleanup) await cleanupDownloadCache(localRoot);
|
|
@@ -428,13 +461,13 @@ export async function download(options, { signal, reporter, backendResolver = re
|
|
|
428
461
|
const stagingPath = path.join(localRoot, `${PARTIAL_PREFIX}${requestKey}`);
|
|
429
462
|
const existingStage = await lstat(stagingPath).catch(error => { if (error.code === 'ENOENT') return null; throw error; });
|
|
430
463
|
if (existingStage && (!existingStage.isDirectory() || existingStage.isSymbolicLink())) throw new Error(`The partial download path is not a plain directory: ${stagingPath}`);
|
|
431
|
-
const cached = await readJson(path.join(stagingPath, 'job.json'), null);
|
|
464
|
+
const cached = options.incognito ? null : await readJson(path.join(stagingPath, 'job.json'), null);
|
|
432
465
|
const readyToTransfer = cached?.requestKey === requestKey && cached.ready?.length && cached.metadata
|
|
433
466
|
&& (cached.backendSucceeded === true || cached.compatibilityChecked === true || cached.files?.length);
|
|
434
467
|
const backend = readyToTransfer ? null : await prepareBackend(options, { signal, backendResolver, reporter });
|
|
435
468
|
timer.switch('metadata');
|
|
436
469
|
const metadata = readyToTransfer ? cached.metadata : await adaptiveRun(() => fetchMetadata(options, { signal, backend, runner, reporter }), { enabled: options.adaptiveConcurrency !== false, state: adaptiveState, signal, reporter, wait, timer });
|
|
437
|
-
if (metadata.entries && !options._entryIndex) return downloadCollection(options, metadata, { signal, reporter, backendResolver: async () => backend, runner, onEntry, localRoot, adaptiveState, wait, diskChecker, now, compatibilityRunner });
|
|
470
|
+
if (metadata.entries && !options._entryIndex) return downloadCollection(options, metadata, { signal, reporter, backendResolver: async () => backend, runner, onEntry, localRoot, adaptiveState, wait, diskChecker, now, compatibilityRunner, verifier });
|
|
438
471
|
const destination = mediaDestination(options, metadata, stagedTitle('media.mp4', metadata, options.rename));
|
|
439
472
|
directory = destination.directory;
|
|
440
473
|
await prepareDestination(options.output, directory);
|
|
@@ -446,10 +479,23 @@ export async function download(options, { signal, reporter, backendResolver = re
|
|
|
446
479
|
|
|
447
480
|
const key = partialKey(metadata, options.url, options);
|
|
448
481
|
const historyFile = path.join(directory, '.veo-history', `${key}.json`);
|
|
449
|
-
const history = options.skipExisting || (options.resume && options._entryIndex) ? await readJson(historyFile, null) : null;
|
|
450
|
-
if (await pruneHistoryRecord(historyFile, directory, history)) {
|
|
482
|
+
const history = !options.incognito && (options.skipExisting || (options.resume && options._entryIndex)) ? await readJson(historyFile, null) : null;
|
|
483
|
+
if (!options.incognito && await pruneHistoryRecord(historyFile, directory, history)) {
|
|
484
|
+
if (options.verify) {
|
|
485
|
+
const verifyFile = verifier || (await import('./inspect-media.js')).verifySavedMedia;
|
|
486
|
+
try {
|
|
487
|
+
const media = history.files.filter(isMediaFile);
|
|
488
|
+
if (!media.length) throw new Error('Verification failed: no saved media file was found.');
|
|
489
|
+
for (const file of media) await verifyFile(file, { audio: Boolean(options.audio), signal });
|
|
490
|
+
} catch (error) {
|
|
491
|
+
error.files = history.files;
|
|
492
|
+
error.verificationFailed = true;
|
|
493
|
+
throw error;
|
|
494
|
+
}
|
|
495
|
+
}
|
|
451
496
|
reporter?.status('Already downloaded; skipped.');
|
|
452
|
-
return { url: options.url, title: metadata.title, files: [], status: 'skipped', saved: 0, skipped: 1,
|
|
497
|
+
return { url: options.url, title: metadata.title, files: [], status: 'skipped', saved: 0, skipped: 1,
|
|
498
|
+
...(options.verify ? { verified: true } : {}), ...timingResult() };
|
|
453
499
|
}
|
|
454
500
|
const staging = await prepareStaging(stagingPath);
|
|
455
501
|
const lockPath = path.join(staging, '.lock');
|
|
@@ -552,15 +598,30 @@ export async function download(options, { signal, reporter, backendResolver = re
|
|
|
552
598
|
files.push(saved);
|
|
553
599
|
files.push(...await saveSidecars(staging, resolved, saved, { signal, manifest, manifestFile }));
|
|
554
600
|
}
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
601
|
+
if (options.verify) {
|
|
602
|
+
const media = files.filter(isMediaFile);
|
|
603
|
+
if (!media.length) throw new Error('Verification failed: no saved media file was found.');
|
|
604
|
+
const verifyFile = verifier || (await import('./inspect-media.js')).verifySavedMedia;
|
|
605
|
+
try {
|
|
606
|
+
reporter?.status('Verifying saved media…');
|
|
607
|
+
for (const file of media) await verifyFile(file, { audio: Boolean(options.audio), signal });
|
|
608
|
+
reporter?.status('Media verification passed.');
|
|
609
|
+
} catch (error) {
|
|
610
|
+
error.files = files;
|
|
611
|
+
error.verificationFailed = true;
|
|
612
|
+
throw error;
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
if (!options.incognito) await writeJson(historyFile, { version: 1, source: sourceKey(metadata, options.url), settings: downloadSettings(options), files });
|
|
616
|
+
return { url: options.url, title: metadata.title || metadata.id || 'video', files, status: 'saved', saved: 1, skipped: 0,
|
|
617
|
+
...(options.verify ? { verified: true } : {}), ...timingResult() };
|
|
618
|
+
} catch (error) {
|
|
619
|
+
if (!signal?.aborted) reporter?.failStep?.();
|
|
620
|
+
// A kept staging directory is the whole point of --resume, and cancellation
|
|
560
621
|
// is the most common reason to want one.
|
|
561
|
-
keepPartial = Boolean(options.resume || manifest?.ready?.length || unconfirmedOutput);
|
|
622
|
+
keepPartial = !options.incognito && !error.verificationFailed && Boolean(options.resume || manifest?.ready?.length || unconfirmedOutput);
|
|
562
623
|
if (manifest && unconfirmedOutput) manifest.unconfirmedOutput = true;
|
|
563
|
-
if (manifest?.ready?.length || (unconfirmedOutput && !options.resume)) {
|
|
624
|
+
if (keepPartial && (manifest?.ready?.length || (unconfirmedOutput && !options.resume))) {
|
|
564
625
|
manifest.expiresAt = Date.now() + TRANSFER_RETENTION_MS;
|
|
565
626
|
await writeJson(manifestFile, manifest);
|
|
566
627
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { createInterface } from 'node:readline/promises';
|
|
2
|
+
|
|
3
|
+
export function validateFragments(value) {
|
|
4
|
+
if (!Number.isInteger(value) || value < 1 || value > 64) {
|
|
5
|
+
throw new Error('--concurrent-fragments must be a whole number between 1 and 64.');
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export async function confirmExperimentalFragments(requests, {
|
|
10
|
+
input = process.stdin, output = process.stderr, confirm, signal,
|
|
11
|
+
} = {}) {
|
|
12
|
+
for (const request of requests) validateFragments(request.concurrentFragments ?? 8);
|
|
13
|
+
const pending = requests.filter(request => (request.concurrentFragments ?? 8) > 16
|
|
14
|
+
&& !request.experimentalFragments && !request.dryRun && !request.listQualities && !request.listFormats && !request.listSources);
|
|
15
|
+
if (!pending.length) return;
|
|
16
|
+
if (!confirm && (!input.isTTY || !output.isTTY || pending.some(request => request.json))) {
|
|
17
|
+
throw new Error('17-64 concurrent fragments are experimental. Explicitly accept with --experimental-fragments or experimentalFragments: true in your config/profile.');
|
|
18
|
+
}
|
|
19
|
+
const maximum = Math.max(...pending.map(request => request.concurrentFragments));
|
|
20
|
+
const prompt = `Experimental: up to ${maximum} concurrent fragments. More connections may trigger server limits and may not improve speed. Continue? [y/N] `;
|
|
21
|
+
let answer;
|
|
22
|
+
if (confirm) answer = await confirm(prompt);
|
|
23
|
+
else {
|
|
24
|
+
const rl = createInterface({ input, output });
|
|
25
|
+
try { answer = await rl.question(prompt, { signal }); }
|
|
26
|
+
finally { rl.close(); }
|
|
27
|
+
}
|
|
28
|
+
if (!/^y(?:es)?$/i.test(answer.trim())) throw new Error('Experimental fragment download cancelled.');
|
|
29
|
+
}
|
package/src/history.js
CHANGED
|
@@ -132,7 +132,7 @@ export function formatHistory(entries, limit = HISTORY_LIMIT, { failed = false }
|
|
|
132
132
|
lines.push(` Date: ${localStamp(entry.at)}${entry.elapsedMs ? ` (${describeDuration(entry.elapsedMs)})` : ''}`);
|
|
133
133
|
lines.push(` URL: ${entry.url}`);
|
|
134
134
|
if (entry.error) lines.push(` Error: ${entry.error}`);
|
|
135
|
-
if (entry.job) lines.push(` Retry: veo --retry-failed "${entry.job}"`);
|
|
135
|
+
if (entry.job) lines.push(` Retry: veo --retry-failed ${entry.runId || `"${entry.job}"`}`);
|
|
136
136
|
for (const [position, file] of entry.files.slice(0, SHOWN_FILES).entries()) {
|
|
137
137
|
lines.push(`${position ? ' ' : ' Saved: '}${file}`);
|
|
138
138
|
}
|