@boy-offi9-inc/tidepull 0.17.2 → 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.
Files changed (2) hide show
  1. package/dist/main.js +49 -5
  2. package/package.json +1 -1
package/dist/main.js CHANGED
@@ -87,6 +87,7 @@ Network:
87
87
  --to SEC VOD HLS only: stop at SEC seconds into the media (whole segments)
88
88
  --cookies FILE Send cookies from a Netscape cookies.txt file, only to the hosts they belong to
89
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)
90
91
  -R, --retries N Retries per request (default: 3)
91
92
  --header "Name: value" Extra request header (repeatable). Secret-looking headers (Authorization,
92
93
  Cookie, tokens...) are sent only to the URL's own origin...
@@ -179,6 +180,7 @@ export async function main(argv) {
179
180
  "batch-file": { type: "string", short: "a" },
180
181
  "download-archive": { type: "string" },
181
182
  "limit-rate": { type: "string" },
183
+ "parallel": { type: "string" },
182
184
  "write-subs": { type: "boolean" },
183
185
  live: { type: "boolean" },
184
186
  "max-duration": { type: "string" },
@@ -335,12 +337,18 @@ export async function main(argv) {
335
337
  process.stderr.write(dim("give it a URL: tidepull <url>\n"));
336
338
  return 2;
337
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;
338
346
  const tp = createTidepull({
339
347
  http: { headers, headerHosts: values["header-host"] ?? [], userAgent: values["user-agent"], retries: num(values.retries, 3), cookies },
340
348
  plugins: [...plugins, dash, feeds],
341
349
  ffmpeg: values["ffmpeg-location"],
342
350
  });
343
- 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 }));
344
352
  for (const p of plugins)
345
353
  log.debug(`Loaded plugin "${p.name}" (${p.extractors?.length ?? 0} extractor(s))`);
346
354
  if (values["list-extractors"]) {
@@ -438,7 +446,22 @@ export async function main(argv) {
438
446
  }
439
447
  continue;
440
448
  }
441
- for await (const item of resolveItems(tp, resolved, { signal: ctl.signal, items: values["playlist-items"] })) {
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) => {
442
465
  stopSpin();
443
466
  try {
444
467
  if (item.error)
@@ -446,11 +469,32 @@ export async function main(argv) {
446
469
  await handle(item.info, playlistFields(item));
447
470
  }
448
471
  catch (e) {
449
- if (ctl.signal.aborted)
450
- throw e;
472
+ if (ctl.signal.aborted) {
473
+ aborted = true;
474
+ return;
475
+ }
451
476
  report(e, item.entry?.url ?? url);
452
477
  }
453
- }
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);
454
498
  }
455
499
  catch (e) {
456
500
  stopSpin();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@boy-offi9-inc/tidepull",
3
- "version": "0.17.2",
3
+ "version": "0.18.0",
4
4
  "description": "A minimal, from-scratch media downloader library: extractor plugins, yt-dlp-style format selection, resumable downloads.",
5
5
  "type": "module",
6
6
  "license": "MIT",