@boy-offi9-inc/tidepull 0.17.1 → 0.18.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/dist/main.js +55 -8
- package/package.json +1 -1
package/dist/main.js
CHANGED
|
@@ -3,6 +3,7 @@ import { DEFAULT_FORMAT, selectFormats } from "./core/selector.js";
|
|
|
3
3
|
import { TidepullError, errMsg } from "./core/errors.js";
|
|
4
4
|
import { existsSync, readFileSync } from "node:fs";
|
|
5
5
|
import { spawnSync } from "node:child_process";
|
|
6
|
+
import { homedir } from "node:os";
|
|
6
7
|
import { isPlaylist } from "./core/pipeline.js";
|
|
7
8
|
import { Archive, configArgs, parseRate, readUrlList } from "./cliutil.js";
|
|
8
9
|
import { cookieJar, loadCookieFile } from "./cookies.js";
|
|
@@ -86,6 +87,7 @@ Network:
|
|
|
86
87
|
--to SEC VOD HLS only: stop at SEC seconds into the media (whole segments)
|
|
87
88
|
--cookies FILE Send cookies from a Netscape cookies.txt file, only to the hosts they belong to
|
|
88
89
|
-N, --concurrent-fragments N HLS segments fetched in parallel (default: 4)
|
|
90
|
+
--parallel N Download N playlist / multi-URL items concurrently (default: 1, max 16)
|
|
89
91
|
-R, --retries N Retries per request (default: 3)
|
|
90
92
|
--header "Name: value" Extra request header (repeatable). Secret-looking headers (Authorization,
|
|
91
93
|
Cookie, tokens...) are sent only to the URL's own origin...
|
|
@@ -178,6 +180,7 @@ export async function main(argv) {
|
|
|
178
180
|
"batch-file": { type: "string", short: "a" },
|
|
179
181
|
"download-archive": { type: "string" },
|
|
180
182
|
"limit-rate": { type: "string" },
|
|
183
|
+
"parallel": { type: "string" },
|
|
181
184
|
"write-subs": { type: "boolean" },
|
|
182
185
|
live: { type: "boolean" },
|
|
183
186
|
"max-duration": { type: "string" },
|
|
@@ -323,21 +326,29 @@ export async function main(argv) {
|
|
|
323
326
|
const dim = (s) => paint(theme.dim, s);
|
|
324
327
|
const ok = (s) => paint(theme.success, s);
|
|
325
328
|
const ff = ffmpegProbe();
|
|
329
|
+
const shortDir = defDir.startsWith(homedir())
|
|
330
|
+
? `~${defDir.slice(homedir().length)}`
|
|
331
|
+
: defDir;
|
|
326
332
|
process.stderr.write([
|
|
327
333
|
"",
|
|
328
|
-
dim(
|
|
329
|
-
dim("more") + " " + dim("'tidepull --help' for every option · github.com/boy-offi9-inc/Tidepull"),
|
|
334
|
+
dim(`${ok(ff)} · ${plugins.length} plugin${plugins.length === 1 ? "" : "s"} · ${shortDir}`),
|
|
330
335
|
"",
|
|
331
336
|
].join("\n"));
|
|
332
|
-
|
|
337
|
+
process.stderr.write(dim("give it a URL: tidepull <url>\n"));
|
|
333
338
|
return 2;
|
|
334
339
|
}
|
|
340
|
+
const parallelRaw = values.parallel === undefined ? undefined : Number(values.parallel);
|
|
341
|
+
if (parallelRaw !== undefined && (!Number.isInteger(parallelRaw) || parallelRaw < 1 || parallelRaw > 16)) {
|
|
342
|
+
log.error("--parallel must be an integer between 1 and 16");
|
|
343
|
+
return 2;
|
|
344
|
+
}
|
|
345
|
+
const parallel = parallelRaw ?? 1;
|
|
335
346
|
const tp = createTidepull({
|
|
336
347
|
http: { headers, headerHosts: values["header-host"] ?? [], userAgent: values["user-agent"], retries: num(values.retries, 3), cookies },
|
|
337
348
|
plugins: [...plugins, dash, feeds],
|
|
338
349
|
ffmpeg: values["ffmpeg-location"],
|
|
339
350
|
});
|
|
340
|
-
tp.on(values["progress-json"] ? jsonRenderer() : humanRenderer(log, { progress: !values["no-progress"] && !values.quiet, theme }));
|
|
351
|
+
tp.on(values["progress-json"] ? jsonRenderer() : humanRenderer(log, { progress: !values["no-progress"] && !values.quiet && parallel === 1, theme }));
|
|
341
352
|
for (const p of plugins)
|
|
342
353
|
log.debug(`Loaded plugin "${p.name}" (${p.extractors?.length ?? 0} extractor(s))`);
|
|
343
354
|
if (values["list-extractors"]) {
|
|
@@ -435,7 +446,22 @@ export async function main(argv) {
|
|
|
435
446
|
}
|
|
436
447
|
continue;
|
|
437
448
|
}
|
|
438
|
-
|
|
449
|
+
const items = resolveItems(tp, resolved, { signal: ctl.signal, items: values["playlist-items"] });
|
|
450
|
+
const iter = items[Symbol.asyncIterator]();
|
|
451
|
+
let exhausted = false;
|
|
452
|
+
let aborted = false;
|
|
453
|
+
let iterError;
|
|
454
|
+
const nextItem = async () => {
|
|
455
|
+
if (exhausted)
|
|
456
|
+
return undefined;
|
|
457
|
+
const r = await iter.next();
|
|
458
|
+
if (r.done) {
|
|
459
|
+
exhausted = true;
|
|
460
|
+
return undefined;
|
|
461
|
+
}
|
|
462
|
+
return r.value;
|
|
463
|
+
};
|
|
464
|
+
const runItem = async (item) => {
|
|
439
465
|
stopSpin();
|
|
440
466
|
try {
|
|
441
467
|
if (item.error)
|
|
@@ -443,11 +469,32 @@ export async function main(argv) {
|
|
|
443
469
|
await handle(item.info, playlistFields(item));
|
|
444
470
|
}
|
|
445
471
|
catch (e) {
|
|
446
|
-
if (ctl.signal.aborted)
|
|
447
|
-
|
|
472
|
+
if (ctl.signal.aborted) {
|
|
473
|
+
aborted = true;
|
|
474
|
+
return;
|
|
475
|
+
}
|
|
448
476
|
report(e, item.entry?.url ?? url);
|
|
449
477
|
}
|
|
450
|
-
}
|
|
478
|
+
};
|
|
479
|
+
await Promise.all(Array.from({ length: parallel }, async () => {
|
|
480
|
+
for (;;) {
|
|
481
|
+
let item;
|
|
482
|
+
try {
|
|
483
|
+
item = await nextItem();
|
|
484
|
+
}
|
|
485
|
+
catch (e) {
|
|
486
|
+
iterError ??= e;
|
|
487
|
+
return;
|
|
488
|
+
}
|
|
489
|
+
if (item === undefined)
|
|
490
|
+
return;
|
|
491
|
+
await runItem(item);
|
|
492
|
+
}
|
|
493
|
+
}));
|
|
494
|
+
if (iterError)
|
|
495
|
+
throw iterError;
|
|
496
|
+
if (aborted || ctl.signal.aborted)
|
|
497
|
+
throw new TidepullError("interrupted", 130);
|
|
451
498
|
}
|
|
452
499
|
catch (e) {
|
|
453
500
|
stopSpin();
|
package/package.json
CHANGED