@boy-offi9-inc/tidepull 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/README.md +3 -3
  2. package/dist/cliutil.d.ts +0 -8
  3. package/dist/cliutil.js +0 -10
  4. package/dist/cookies.d.ts +0 -5
  5. package/dist/cookies.js +0 -10
  6. package/dist/core/downloader.d.ts +1 -10
  7. package/dist/core/downloader.js +44 -9
  8. package/dist/core/errors.d.ts +0 -2
  9. package/dist/core/errors.js +0 -2
  10. package/dist/core/events.d.ts +0 -2
  11. package/dist/core/hls.d.ts +0 -2
  12. package/dist/core/hls.js +2 -3
  13. package/dist/core/http.d.ts +0 -13
  14. package/dist/core/http.js +0 -7
  15. package/dist/core/meter.d.ts +0 -1
  16. package/dist/core/meter.js +0 -1
  17. package/dist/core/pipeline.d.ts +1 -13
  18. package/dist/core/pipeline.js +16 -8
  19. package/dist/core/selector.d.ts +0 -10
  20. package/dist/core/selector.js +0 -1
  21. package/dist/core/template.d.ts +0 -1
  22. package/dist/core/template.js +0 -1
  23. package/dist/core/types.d.ts +7 -13
  24. package/dist/dash/index.js +1 -6
  25. package/dist/dash/parse.d.ts +0 -3
  26. package/dist/dash/parse.js +1 -3
  27. package/dist/dash/xml.js +0 -1
  28. package/dist/extractors/direct.js +0 -1
  29. package/dist/extractors/generic.d.ts +0 -1
  30. package/dist/extractors/generic.js +0 -2
  31. package/dist/extractors/hls.js +6 -3
  32. package/dist/extractors/index.d.ts +0 -1
  33. package/dist/extractors/index.js +0 -1
  34. package/dist/feeds.d.ts +0 -2
  35. package/dist/feeds.js +0 -9
  36. package/dist/index.d.ts +0 -1
  37. package/dist/index.js +0 -1
  38. package/dist/loader.d.ts +0 -2
  39. package/dist/loader.js +0 -3
  40. package/dist/main.d.ts +0 -1
  41. package/dist/main.js +3 -8
  42. package/dist/playlist.d.ts +0 -18
  43. package/dist/playlist.js +0 -15
  44. package/dist/plugins.d.ts +0 -2
  45. package/dist/plugins.js +0 -2
  46. package/dist/tidepull.d.ts +0 -21
  47. package/dist/tidepull.js +0 -18
  48. package/dist/ui/banner.d.ts +0 -1
  49. package/dist/ui/banner.js +0 -2
  50. package/dist/ui/format.d.ts +0 -1
  51. package/dist/ui/format.js +0 -1
  52. package/dist/ui/log.d.ts +0 -2
  53. package/dist/ui/log.js +0 -2
  54. package/dist/ui/render.d.ts +0 -2
  55. package/dist/ui/render.js +0 -3
  56. package/dist/ui/spinner.d.ts +0 -5
  57. package/dist/ui/spinner.js +0 -5
  58. package/dist/ui/theme.d.ts +0 -5
  59. package/dist/ui/theme.js +0 -2
  60. package/package.json +1 -1
@@ -1,4 +1,3 @@
1
- /** Output templates: "%(title)s [%(id)s].%(ext)s", "%(uploader|unknown)s", "%(title).50s", "%(playlist_index)02d". */
2
1
  export function sanitize(s) {
3
2
  const cleaned = s
4
3
  .replace(/[\\/:*?"<>|\x00-\x1f]/g, "_")
@@ -1,7 +1,6 @@
1
1
  import type { Emit, Log } from "./events.js";
2
2
  import type { Http } from "./http.js";
3
3
  export type Protocol = "https" | "hls" | "dash";
4
- /** One downloadable stream. */
5
4
  export interface Format {
6
5
  format_id: string;
7
6
  url: string;
@@ -10,50 +9,46 @@ export interface Format {
10
9
  width?: number;
11
10
  height?: number;
12
11
  fps?: number;
13
- /** "none" = no video track. "unknown" = present but codec not known. */
14
12
  vcodec: string;
15
- /** "none" = no audio track. */
16
13
  acodec: string;
17
- /** total bitrate, kbit/s */
18
14
  tbr?: number;
19
- /** audio bitrate, kbit/s */
20
15
  abr?: number;
21
16
  filesize?: number;
22
17
  format_note?: string;
23
18
  http_headers?: Record<string, string>;
24
- /** dash: init segment URL (written first) */
25
19
  init?: string;
26
- /** dash: media segment URLs in order */
27
20
  fragments?: string[];
28
21
  }
29
- /** What every extractor returns (the "info dict"). */
22
+ export interface Subtitle {
23
+ lang: string;
24
+ url: string;
25
+ protocol: "hls";
26
+ isDefault?: boolean;
27
+ }
30
28
  export interface Info {
31
29
  id: string;
32
30
  title: string;
33
31
  extractor: string;
34
32
  webpage_url: string;
35
33
  formats: Format[];
34
+ subtitles?: Subtitle[];
36
35
  thumbnail?: string;
37
36
  duration?: number;
38
37
  uploader?: string;
39
38
  upload_date?: string;
40
39
  [key: string]: unknown;
41
40
  }
42
- /** Passed to every extractor call. */
43
41
  export interface Ctx {
44
42
  http: Http;
45
43
  log: Log;
46
44
  emit: Emit;
47
- /** Ordered extractor list (plugins, built-ins, generic last). */
48
45
  extractors: readonly Extractor[];
49
46
  signal?: AbortSignal;
50
47
  }
51
- /** One item of a playlist. It is extracted on its own when it is downloaded. */
52
48
  export interface PlaylistEntry {
53
49
  url: string;
54
50
  title?: string;
55
51
  }
56
- /** A list of items found at one URL (a feed, a playlist file). */
57
52
  export interface Playlist {
58
53
  kind: "playlist";
59
54
  id: string;
@@ -62,7 +57,6 @@ export interface Playlist {
62
57
  webpage_url: string;
63
58
  entries: PlaylistEntry[];
64
59
  }
65
- /** The extractor contract. One file per site. */
66
60
  export interface Extractor {
67
61
  readonly name: string;
68
62
  suitable(url: URL): boolean;
@@ -1,8 +1,3 @@
1
- /**
2
- * Opt-in DASH (VOD) support.
3
- * import dash from "@boy-offi9-inc/tidepull/dash";
4
- * createTidepull({ plugins: [dash] });
5
- */
6
1
  import { TidepullError } from "../core/errors.js";
7
2
  import { extOf, splitCodecs, stem } from "../extractors/util.js";
8
3
  import { definePlugin } from "../plugins.js";
@@ -36,7 +31,7 @@ export async function extractDash(url, ctx) {
36
31
  const formats = [];
37
32
  for (const r of mpd.reps) {
38
33
  if (r.kind === "other")
39
- continue; // subtitles and other tracks are not supported
34
+ continue;
40
35
  const { v, a } = splitCodecs(r.codecs);
41
36
  const video = r.kind === "video";
42
37
  const f = {
@@ -8,10 +8,8 @@ export interface DashRep {
8
8
  height?: number;
9
9
  fps?: number;
10
10
  lang?: string;
11
- /** fragmented: init segment + media segments */
12
11
  init?: string;
13
12
  fragments?: string[];
14
- /** whole-file representation (SegmentBase / plain BaseURL) */
15
13
  single?: string;
16
14
  }
17
15
  export interface DashManifest {
@@ -21,7 +19,6 @@ export interface DashManifest {
21
19
  skipped: string[];
22
20
  }
23
21
  export declare function parseIsoDuration(s?: string): number | undefined;
24
- /** $RepresentationID$, $Number$, $Bandwidth$, $Time$ (+ %0Nd width), $$ */
25
22
  export declare function fillTemplate(tpl: string, v: {
26
23
  RepresentationID: string;
27
24
  Bandwidth: number;
@@ -1,4 +1,3 @@
1
- /** Static (VOD) MPEG-DASH: SegmentTemplate (number / timeline), SegmentList, single-file SegmentBase. No DRM, no live. */
2
1
  import { TidepullError } from "../core/errors.js";
3
2
  import { child, kids, parseXml } from "./xml.js";
4
3
  const MAX_FRAGMENTS = 50_000;
@@ -23,7 +22,6 @@ function resolve(base, rel) {
23
22
  throw new TidepullError(`Refusing non-http(s) URL in manifest: ${u.protocol}`);
24
23
  return u.href;
25
24
  }
26
- /** $RepresentationID$, $Number$, $Bandwidth$, $Time$ (+ %0Nd width), $$ */
27
25
  export function fillTemplate(tpl, v) {
28
26
  return tpl.replace(/\$(RepresentationID|Number|Bandwidth|Time)(?:%0(\d+)d)?\$|\$\$/g, (m, key, width) => {
29
27
  if (m === "$$")
@@ -127,7 +125,7 @@ export function parseMpd(text, manifestUrl) {
127
125
  r.fragments = kids(listNode, "SegmentURL").map((u) => resolve(baseR, u.attrs.media));
128
126
  }
129
127
  else {
130
- r.single = baseR; // SegmentBase / plain BaseURL: one self-contained file
128
+ r.single = baseR;
131
129
  }
132
130
  out.reps.push(r);
133
131
  }
package/dist/dash/xml.js CHANGED
@@ -1,4 +1,3 @@
1
- /** Minimal XML parser: elements, attributes and text. DTDs and custom entities are not expanded; namespace prefixes are dropped. */
2
1
  import { TidepullError } from "../core/errors.js";
3
2
  const ENT = { amp: "&", lt: "<", gt: ">", quot: '"', apos: "'" };
4
3
  const decode = (s) => s.replace(/&(?:#x([0-9a-f]+)|#(\d+)|(\w+));/gi, (m, hex, dec, name) => {
@@ -9,7 +9,6 @@ export const directExtractor = {
9
9
  };
10
10
  export async function extractDirect(url, ctx) {
11
11
  const ext = extOf(url.pathname);
12
- // Try HEAD first; some servers reject it, so fall back to a 1-byte ranged GET.
13
12
  let res = await ctx.http.request(url.href, { method: "HEAD" });
14
13
  let size = res.ok ? Number(res.headers.get("content-length")) || undefined : undefined;
15
14
  if (!res.ok) {
@@ -1,3 +1,2 @@
1
1
  import type { Extractor } from "../core/types.js";
2
- /** Fallback: look at the page itself (media content-type, og:video, <video>, bare media URLs). */
3
2
  export declare const genericExtractor: Extractor;
@@ -33,7 +33,6 @@ function findCandidates(html, base) {
33
33
  found.push(new URL(decodeEntities(u).trim(), base).href);
34
34
  }
35
35
  catch {
36
- /* ignore bad URLs */
37
36
  }
38
37
  };
39
38
  for (const m of html.matchAll(/<meta\b[^>]*>/gi)) {
@@ -58,7 +57,6 @@ async function extractOne(u, ctx) {
58
57
  throw new TidepullError(`${u.href} is a playlist, not a single media item`);
59
58
  return result;
60
59
  }
61
- /** Fallback: look at the page itself (media content-type, og:video, <video>, bare media URLs). */
62
60
  export const genericExtractor = {
63
61
  name: "generic",
64
62
  suitable: () => true,
@@ -11,8 +11,9 @@ export async function extractHls(url, ctx) {
11
11
  if (!text.trimStart().startsWith("#EXTM3U"))
12
12
  throw new TidepullError(`Not an HLS playlist: ${url.href}`);
13
13
  const formats = [];
14
+ let master;
14
15
  if (isMasterPlaylist(text)) {
15
- const master = parseMaster(text, finalUrl);
16
+ master = parseMaster(text, finalUrl);
16
17
  const audioGroups = new Map();
17
18
  for (const r of master.renditions)
18
19
  if (r.type === "AUDIO" && r.uri)
@@ -28,7 +29,6 @@ export async function extractHls(url, ctx) {
28
29
  let audioCodec;
29
30
  for (const v of master.variants) {
30
31
  const { v: vc, a: ac } = splitCodecs(v.codecs);
31
- // Variant points at an external audio group and lists no audio codec => video-only stream.
32
32
  const external = !!v.audioGroup && audioGroups.has(v.audioGroup) && !ac && !!v.codecs;
33
33
  if (ac)
34
34
  audioCodec ??= ac;
@@ -64,9 +64,12 @@ export async function extractHls(url, ctx) {
64
64
  else {
65
65
  formats.push({ format_id: "hls", url: finalUrl, ext: "ts", protocol: "hls", vcodec: "unknown", acodec: "unknown" });
66
66
  }
67
+ const subtitles = master?.renditions
68
+ .filter((r) => r.type === "SUBTITLES" && r.uri)
69
+ .map((r) => ({ lang: r.language || r.name, url: r.uri, protocol: "hls", isDefault: r.isDefault }));
67
70
  let name = stem(url.pathname);
68
71
  if (/^(index|master|playlist|manifest|stream|main)$/i.test(name)) {
69
72
  name = url.pathname.split("/").filter(Boolean).slice(-2, -1)[0] ?? url.hostname;
70
73
  }
71
- return { id: name || url.hostname, title: name || url.hostname, extractor: "hls", webpage_url: url.href, formats };
74
+ return { id: name || url.hostname, title: name || url.hostname, extractor: "hls", webpage_url: url.href, formats, ...(subtitles?.length ? { subtitles } : {}) };
72
75
  }
@@ -1,5 +1,4 @@
1
1
  import type { Extractor } from "../core/types.js";
2
2
  import type { TidepullPlugin } from "../plugins.js";
3
3
  export declare const builtinExtractors: readonly Extractor[];
4
- /** First `suitable()` match wins: plugin extractors (in order), then built-ins, with the generic fallback always last. */
5
4
  export declare function buildRegistry(plugins?: readonly TidepullPlugin[]): Extractor[];
@@ -2,7 +2,6 @@ import { directExtractor } from "./direct.js";
2
2
  import { genericExtractor } from "./generic.js";
3
3
  import { hlsExtractor } from "./hls.js";
4
4
  export const builtinExtractors = [hlsExtractor, directExtractor, genericExtractor];
5
- /** First `suitable()` match wins: plugin extractors (in order), then built-ins, with the generic fallback always last. */
6
5
  export function buildRegistry(plugins = []) {
7
6
  const specific = builtinExtractors.filter((e) => e !== genericExtractor);
8
7
  return [...plugins.flatMap((p) => p.extractors ?? []), ...specific, genericExtractor];
package/dist/feeds.d.ts CHANGED
@@ -3,9 +3,7 @@ export interface ParsedList {
3
3
  title: string;
4
4
  entries: PlaylistEntry[];
5
5
  }
6
- /** Items with a media enclosure from an RSS 2.0, RSS 1.0 or Atom feed. URLs are resolved against `base`. */
7
6
  export declare function parseFeed(text: string, base: string): ParsedList;
8
- /** Entries of an .m3u playlist file (#EXTINF titles, #PLAYLIST name). Only http(s) URLs are kept. */
9
7
  export declare function parseM3u(text: string, base: string): ParsedList;
10
8
  export declare const rssExtractor: {
11
9
  name: string;
package/dist/feeds.js CHANGED
@@ -1,9 +1,3 @@
1
- /**
2
- * Playlist sources (opt-in: "@boy-offi9-inc/tidepull/feeds"): RSS/Atom feeds with media enclosures, and .m3u playlist files.
3
- * import feeds from "@boy-offi9-inc/tidepull/feeds";
4
- * createTidepull({ plugins: [feeds] });
5
- * Each media URL becomes one playlist entry, extracted on its own when it is downloaded.
6
- */
7
1
  import { TidepullError } from "./core/errors.js";
8
2
  import { child, kids, parseXml } from "./dash/xml.js";
9
3
  import { extOf, stem } from "./extractors/util.js";
@@ -11,7 +5,6 @@ import { definePlugin } from "./plugins.js";
11
5
  const MAX_BYTES = 10 * 1024 * 1024;
12
6
  const MAX_ENTRIES = 10_000;
13
7
  const isMedia = (type) => !type || /^(audio|video)\//i.test(type) || /octet-stream/i.test(type);
14
- /** The media URL of an RSS item or Atom entry: <enclosure>, an Atom rel="enclosure" link, or Media RSS <media:content>. */
15
8
  function mediaUrl(item) {
16
9
  const candidates = [
17
10
  ...kids(item, "enclosure").map((e) => ({ url: e.attrs.url, type: e.attrs.type })),
@@ -38,7 +31,6 @@ function toEntry(raw, title, base, seen) {
38
31
  seen.add(url);
39
32
  return title ? { url, title } : { url };
40
33
  }
41
- /** Items with a media enclosure from an RSS 2.0, RSS 1.0 or Atom feed. URLs are resolved against `base`. */
42
34
  export function parseFeed(text, base) {
43
35
  const root = parseXml(text);
44
36
  let title;
@@ -63,7 +55,6 @@ export function parseFeed(text, base) {
63
55
  }
64
56
  return { title: title.trim(), entries };
65
57
  }
66
- /** Entries of an .m3u playlist file (#EXTINF titles, #PLAYLIST name). Only http(s) URLs are kept. */
67
58
  export function parseM3u(text, base) {
68
59
  let title = "";
69
60
  let pending;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- /** Public library API. Everything not exported here is internal. */
2
1
  export { Tidepull, createTidepull } from "./tidepull.js";
3
2
  export type { TidepullOptions, CallOptions, Listener } from "./tidepull.js";
4
3
  export { definePlugin, PLUGIN_API_VERSION } from "./plugins.js";
package/dist/index.js CHANGED
@@ -1,4 +1,3 @@
1
- /** Public library API. Everything not exported here is internal. */
2
1
  export { Tidepull, createTidepull } from "./tidepull.js";
3
2
  export { definePlugin, PLUGIN_API_VERSION } from "./plugins.js";
4
3
  export { isPlaylist } from "./core/pipeline.js";
package/dist/loader.d.ts CHANGED
@@ -1,7 +1,5 @@
1
1
  import { type TidepullPlugin } from "./plugins.js";
2
2
  export declare function validatePlugin(p: unknown, source: string): TidepullPlugin;
3
- /** SECURITY: this executes the file's code with your privileges. Only load plugins you trust. */
4
3
  export declare function loadPlugin(file: string): Promise<TidepullPlugin>;
5
- /** Each path may be a plugin file, or a directory of plugin files and/or `<name>/index.*` folders (not recursive). */
6
4
  export declare function loadPlugins(paths: string[]): Promise<TidepullPlugin[]>;
7
5
  export declare function defaultPluginDir(env?: NodeJS.ProcessEnv): string;
package/dist/loader.js CHANGED
@@ -6,7 +6,6 @@ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExte
6
6
  }
7
7
  return path;
8
8
  };
9
- /** Loads plugins from disk (Node only). Opt-in: `import { loadPlugins } from "@boy-offi9-inc/tidepull/loader"`. */
10
9
  import { readdir, stat } from "node:fs/promises";
11
10
  import os from "node:os";
12
11
  import path from "node:path";
@@ -29,7 +28,6 @@ export function validatePlugin(p, source) {
29
28
  }
30
29
  return o;
31
30
  }
32
- /** SECURITY: this executes the file's code with your privileges. Only load plugins you trust. */
33
31
  export async function loadPlugin(file) {
34
32
  let mod;
35
33
  try {
@@ -42,7 +40,6 @@ export async function loadPlugin(file) {
42
40
  }
43
41
  const FILE_RE = /\.(?:m?js|cjs|mts|ts)$/;
44
42
  const INDEX_RE = /^index\.(?:m?js|mts|ts)$/;
45
- /** Each path may be a plugin file, or a directory of plugin files and/or `<name>/index.*` folders (not recursive). */
46
43
  export async function loadPlugins(paths) {
47
44
  const out = [];
48
45
  for (const p of paths) {
package/dist/main.d.ts CHANGED
@@ -1,3 +1,2 @@
1
- /** Package version, read from package.json. */
2
1
  export declare const VERSION: string;
3
2
  export declare function main(argv: string[]): Promise<number>;
package/dist/main.js CHANGED
@@ -16,7 +16,6 @@ import { humanRenderer, jsonRenderer } from "./ui/render.js";
16
16
  import { renderBanner } from "./ui/banner.js";
17
17
  import { pickTheme, THEME_NAMES } from "./ui/theme.js";
18
18
  import { Spinner } from "./ui/spinner.js";
19
- /** Package version, read from package.json. */
20
19
  export const VERSION = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8")).version;
21
20
  const HELP = `tidepull ${VERSION}: a minimal media downloader
22
21
 
@@ -59,6 +58,7 @@ Config:
59
58
 
60
59
  Network:
61
60
  --limit-rate RATE Maximum download speed per file, e.g. 500K or 1.5M
61
+ --write-subs Download subtitle tracks (HLS SUBTITLES renditions) as .vtt next to the media
62
62
  --cookies FILE Send cookies from a Netscape cookies.txt file, only to the hosts they belong to
63
63
  -N, --concurrent-fragments N HLS segments fetched in parallel (default: 4)
64
64
  -R, --retries N Retries per request (default: 3)
@@ -141,6 +141,7 @@ export async function main(argv) {
141
141
  "batch-file": { type: "string", short: "a" },
142
142
  "download-archive": { type: "string" },
143
143
  "limit-rate": { type: "string" },
144
+ "write-subs": { type: "boolean" },
144
145
  cookies: { type: "string" },
145
146
  "config-location": { type: "string" },
146
147
  "no-config": { type: "boolean" },
@@ -179,8 +180,6 @@ export async function main(argv) {
179
180
  process.stderr.write(`ERROR: ${errMsg(e)}\n`);
180
181
  return 2;
181
182
  }
182
- // Banner: interactive terminals only. Anything machine-facing (quiet, json,
183
- // get-url, simulate, progress-json) or non-TTY stdout suppresses it.
184
183
  const machineMode = values.quiet || values["dump-json"] || values["get-url"] || values.simulate || values["progress-json"];
185
184
  if (process.stdout.isTTY && !machineMode) {
186
185
  process.stderr.write(renderBanner(VERSION, theme, !values["no-color"] && shouldUseColor()) + "\n");
@@ -227,7 +226,6 @@ export async function main(argv) {
227
226
  headers[h.slice(0, i).trim()] = h.slice(i + 1).trim();
228
227
  }
229
228
  const num = (v, d) => (v !== undefined && Number.isFinite(Number(v)) && Number(v) >= 0 ? Number(v) : d);
230
- // plugins: explicit --plugin paths, plus the default dir unless disabled
231
229
  const pluginPaths = [...(values.plugin ?? [])];
232
230
  const defDir = defaultPluginDir();
233
231
  if (!values["no-plugins"] && existsSync(defDir))
@@ -263,11 +261,11 @@ export async function main(argv) {
263
261
  remuxVideo: values["remux-video"],
264
262
  headers,
265
263
  limitRate,
264
+ writeSubs: !!values["write-subs"],
266
265
  };
267
266
  for (const k of Object.keys(opts))
268
267
  if (opts[k] === undefined)
269
268
  delete opts[k];
270
- // Ctrl-C cancels in-flight work cleanly (partial .part files are kept for resume)
271
269
  const ctl = new AbortController();
272
270
  const onSigint = () => ctl.abort();
273
271
  process.once("SIGINT", onSigint);
@@ -280,7 +278,6 @@ export async function main(argv) {
280
278
  process.stderr.write(e.stack + "\n");
281
279
  code = Math.max(code, e instanceof TidepullError ? e.exitCode : 1);
282
280
  };
283
- // Spinner for the resolve/extract phase: TTY stderr only, machine modes never see it.
284
281
  const interactive = process.stdout.isTTY && !machineMode && !values["no-progress"];
285
282
  const spinner = new Spinner({ text: "extracting…", env: process.env });
286
283
  const spin = () => {
@@ -288,7 +285,6 @@ export async function main(argv) {
288
285
  spinner.start();
289
286
  };
290
287
  const stopSpin = (final) => spinner.stop(final);
291
- /** What to do with one extracted item: print info, list formats, print URLs, or download it. */
292
288
  const handle = async (info, fields) => {
293
289
  if (values["dump-json"])
294
290
  process.stdout.write(JSON.stringify(info) + "\n");
@@ -323,7 +319,6 @@ export async function main(argv) {
323
319
  const resolved = await tp.resolve(url, { signal: ctl.signal });
324
320
  if (isPlaylist(resolved) && (values["dump-json"] || values["list-formats"])) {
325
321
  stopSpin(`${resolved.title}: ${resolved.entries.length} item(s)`);
326
- // listing a playlist needs no request per entry
327
322
  if (values["dump-json"])
328
323
  process.stdout.write(JSON.stringify(resolved) + "\n");
329
324
  else {
@@ -1,40 +1,22 @@
1
1
  import { type DownloadOptions } from "./core/pipeline.js";
2
2
  import type { Info, Playlist, PlaylistEntry } from "./core/types.js";
3
3
  import type { CallOptions, Tidepull } from "./tidepull.js";
4
- /** Item numbers from a spec like "1-3,7,10-" (1-based, in the order given, no duplicates). Empty spec selects everything. */
5
4
  export declare function parseItems(spec: string | undefined, total: number): number[];
6
5
  export interface PlaylistItem {
7
- /** 1-based position in the playlist */
8
6
  index: number;
9
- /** 1-based position among the selected items */
10
7
  position: number;
11
- /** number of selected items */
12
8
  total: number;
13
- /** undefined when the URL was a single item */
14
9
  playlist?: Playlist;
15
10
  entry?: PlaylistEntry;
16
11
  info?: Info;
17
- /** why this entry could not be extracted */
18
12
  error?: Error;
19
13
  }
20
- /**
21
- * Template fields for an item: playlist, playlist_id, playlist_index, playlist_count. Empty for a single item.
22
- * When the extractor's own title is just the id (a bare file name), the entry's title from the playlist is used instead.
23
- */
24
14
  export declare const playlistFields: (item: PlaylistItem) => Record<string, string | number>;
25
- /**
26
- * One item for a single URL, or one per selected entry of a playlist (extracted lazily, in order).
27
- * An entry that fails to extract is reported on the item instead of ending the iteration.
28
- * `source` may be a URL or an already resolved Info/Playlist.
29
- */
30
15
  export declare function resolveItems(tp: Tidepull, source: string | Info | Playlist, o?: CallOptions & {
31
16
  items?: string;
32
17
  }): AsyncGenerator<PlaylistItem>;
33
18
  export interface PullAllOptions extends Partial<DownloadOptions>, CallOptions {
34
- /** which playlist items to download, e.g. "1-3,7,10-" (default: all) */
35
19
  items?: string;
36
- /** called for an item that fails; without it the first failure is thrown */
37
20
  onError?: (error: Error, item: PlaylistItem) => void;
38
21
  }
39
- /** Downloads a single item, or every selected entry of a playlist, and returns the files in order. */
40
22
  export declare function pullAll(tp: Tidepull, source: string, o?: PullAllOptions): Promise<string[]>;
package/dist/playlist.js CHANGED
@@ -1,10 +1,5 @@
1
- /**
2
- * Playlist helpers (opt-in: "@boy-offi9-inc/tidepull/playlist"): choose items and download every entry of a playlist.
3
- * Entries are extracted one at a time with `trust: false`, so secret headers never go to hosts named inside a feed.
4
- */
5
1
  import { TidepullError } from "./core/errors.js";
6
2
  import { isPlaylist } from "./core/pipeline.js";
7
- /** Item numbers from a spec like "1-3,7,10-" (1-based, in the order given, no duplicates). Empty spec selects everything. */
8
3
  export function parseItems(spec, total) {
9
4
  if (!spec?.trim())
10
5
  return Array.from({ length: total }, (_, i) => i + 1);
@@ -27,10 +22,6 @@ export function parseItems(spec, total) {
27
22
  }
28
23
  return out;
29
24
  }
30
- /**
31
- * Template fields for an item: playlist, playlist_id, playlist_index, playlist_count. Empty for a single item.
32
- * When the extractor's own title is just the id (a bare file name), the entry's title from the playlist is used instead.
33
- */
34
25
  export const playlistFields = (item) => {
35
26
  if (!item.playlist)
36
27
  return {};
@@ -44,11 +35,6 @@ export const playlistFields = (item) => {
44
35
  fields.title = item.entry.title;
45
36
  return fields;
46
37
  };
47
- /**
48
- * One item for a single URL, or one per selected entry of a playlist (extracted lazily, in order).
49
- * An entry that fails to extract is reported on the item instead of ending the iteration.
50
- * `source` may be a URL or an already resolved Info/Playlist.
51
- */
52
38
  export async function* resolveItems(tp, source, o = {}) {
53
39
  const first = typeof source === "string" ? await tp.resolve(source, o) : source;
54
40
  if (!isPlaylist(first)) {
@@ -71,7 +57,6 @@ export async function* resolveItems(tp, source, o = {}) {
71
57
  }
72
58
  }
73
59
  }
74
- /** Downloads a single item, or every selected entry of a playlist, and returns the files in order. */
75
60
  export async function pullAll(tp, source, o = {}) {
76
61
  const { items, onError, ...rest } = o;
77
62
  const files = [];
package/dist/plugins.d.ts CHANGED
@@ -1,10 +1,8 @@
1
1
  import type { Extractor } from "./core/types.js";
2
- /** Bump when the plugin contract changes in a breaking way. Plugins declare which version they target. */
3
2
  export declare const PLUGIN_API_VERSION = 1;
4
3
  export interface TidepullPlugin {
5
4
  name: string;
6
5
  apiVersion: number;
7
6
  extractors?: Extractor[];
8
7
  }
9
- /** Typed identity helper for plugin authors: `export default definePlugin({...})` */
10
8
  export declare const definePlugin: (p: TidepullPlugin) => TidepullPlugin;
package/dist/plugins.js CHANGED
@@ -1,4 +1,2 @@
1
- /** Bump when the plugin contract changes in a breaking way. Plugins declare which version they target. */
2
1
  export const PLUGIN_API_VERSION = 1;
3
- /** Typed identity helper for plugin authors: `export default definePlugin({...})` */
4
2
  export const definePlugin = (p) => p;
@@ -7,26 +7,13 @@ export type Listener = (e: TidepullEvent) => void;
7
7
  export interface TidepullOptions {
8
8
  http?: HttpOptions;
9
9
  plugins?: TidepullPlugin[];
10
- /** ffmpeg binary or directory (default: search PATH) */
11
10
  ffmpeg?: string;
12
11
  onEvent?: Listener;
13
12
  }
14
13
  export interface CallOptions {
15
14
  signal?: AbortSignal;
16
- /**
17
- * Let headers marked secret (Authorization, tokens) be sent to this URL's origin. Default true.
18
- * Pass false for URLs found inside other documents, such as playlist entries.
19
- */
20
15
  trust?: boolean;
21
16
  }
22
- /**
23
- * The library entry point. No terminal I/O: everything observable goes through events.
24
- *
25
- * const g = createTidepull();
26
- * g.on((e) => e.type === "progress" && console.log(e.downloaded, e.total));
27
- * const info = await g.extract(url);
28
- * const file = await g.download(info, { format: "bv*[height<=720]+ba/b", paths: "./out" });
29
- */
30
17
  export declare class Tidepull {
31
18
  readonly http: Http;
32
19
  private plugins;
@@ -34,25 +21,17 @@ export declare class Tidepull {
34
21
  private listeners;
35
22
  private ffmpeg?;
36
23
  constructor(o?: TidepullOptions);
37
- /** Subscribe to events. Returns an unsubscribe function. A throwing listener never breaks a download. */
38
24
  on(fn: Listener): () => void;
39
- /** Extractor names in priority order. */
40
25
  get extractors(): string[];
41
- /** Register a plugin (takes priority over built-in extractors). */
42
26
  use(plugin: TidepullPlugin): this;
43
- /** Publishes an event to the listeners. */
44
27
  emit(e: TidepullEvent): void;
45
28
  private ctx;
46
29
  private guard;
47
30
  private trustUrl;
48
31
  extract(url: string, o?: CallOptions): Promise<Info>;
49
- /** Like extract(), but a playlist (feed, playlist file) comes back as a Playlist instead of an error. */
50
32
  resolve(url: string, o?: CallOptions): Promise<Info | Playlist>;
51
- /** Which format(s) the selector picks (two or more means merge), or undefined if none match. */
52
33
  select(info: Info, selector?: string): Format[] | undefined;
53
- /** Downloads the selected format(s). Resolves to the final file path. */
54
34
  download(info: Info, o?: Partial<DownloadOptions> & CallOptions): Promise<string>;
55
- /** extract + download */
56
35
  pull(url: string, o?: Partial<DownloadOptions> & CallOptions): Promise<string>;
57
36
  }
58
37
  export declare const createTidepull: (o?: TidepullOptions) => Tidepull;
package/dist/tidepull.js CHANGED
@@ -4,14 +4,6 @@ import { makeLog } from "./core/events.js";
4
4
  import { Http } from "./core/http.js";
5
5
  import { DEFAULT_FORMAT, selectFormats } from "./core/selector.js";
6
6
  import { buildRegistry } from "./extractors/index.js";
7
- /**
8
- * The library entry point. No terminal I/O: everything observable goes through events.
9
- *
10
- * const g = createTidepull();
11
- * g.on((e) => e.type === "progress" && console.log(e.downloaded, e.total));
12
- * const info = await g.extract(url);
13
- * const file = await g.download(info, { format: "bv*[height<=720]+ba/b", paths: "./out" });
14
- */
15
7
  export class Tidepull {
16
8
  http;
17
9
  plugins;
@@ -26,29 +18,24 @@ export class Tidepull {
26
18
  if (o.onEvent)
27
19
  this.listeners.add(o.onEvent);
28
20
  }
29
- /** Subscribe to events. Returns an unsubscribe function. A throwing listener never breaks a download. */
30
21
  on(fn) {
31
22
  this.listeners.add(fn);
32
23
  return () => void this.listeners.delete(fn);
33
24
  }
34
- /** Extractor names in priority order. */
35
25
  get extractors() {
36
26
  return this.registry.map((e) => e.name);
37
27
  }
38
- /** Register a plugin (takes priority over built-in extractors). */
39
28
  use(plugin) {
40
29
  this.plugins.push(plugin);
41
30
  this.registry = buildRegistry(this.plugins);
42
31
  return this;
43
32
  }
44
- /** Publishes an event to the listeners. */
45
33
  emit(e) {
46
34
  for (const l of this.listeners) {
47
35
  try {
48
36
  l(e);
49
37
  }
50
38
  catch {
51
- /* listeners must not break the engine */
52
39
  }
53
40
  }
54
41
  }
@@ -73,23 +60,19 @@ export class Tidepull {
73
60
  this.http.trust(/^[a-z][a-z0-9+.-]*:\/\//i.test(url) ? url : `https://${url}`);
74
61
  }
75
62
  catch {
76
- /* invalid URL: the extraction step reports it */
77
63
  }
78
64
  }
79
65
  extract(url, o = {}) {
80
66
  this.trustUrl(url, o);
81
67
  return this.guard(o.signal, () => extractInfo(url, this.ctx(o.signal)));
82
68
  }
83
- /** Like extract(), but a playlist (feed, playlist file) comes back as a Playlist instead of an error. */
84
69
  resolve(url, o = {}) {
85
70
  this.trustUrl(url, o);
86
71
  return this.guard(o.signal, () => resolveUrl(url, this.ctx(o.signal)));
87
72
  }
88
- /** Which format(s) the selector picks (two or more means merge), or undefined if none match. */
89
73
  select(info, selector = DEFAULT_FORMAT) {
90
74
  return selectFormats(selector, info.formats);
91
75
  }
92
- /** Downloads the selected format(s). Resolves to the final file path. */
93
76
  download(info, o = {}) {
94
77
  const { signal, ...rest } = o;
95
78
  const opts = {
@@ -110,7 +93,6 @@ export class Tidepull {
110
93
  return file;
111
94
  });
112
95
  }
113
- /** extract + download */
114
96
  async pull(url, o = {}) {
115
97
  return this.download(await this.extract(url, o), o);
116
98
  }
@@ -1,3 +1,2 @@
1
1
  import type { Theme } from "./theme.js";
2
- /** Launch banner for interactive terminals; version dimmed beside the logo. */
3
2
  export declare function renderBanner(version: string, theme: Theme, color?: boolean): string;
package/dist/ui/banner.js CHANGED
@@ -7,7 +7,6 @@ const GLYPHS = {
7
7
  u: ["| | ", "| | ", "| | ", "|_| "],
8
8
  l: ["| |", "| |", "| |", "|_|"],
9
9
  };
10
- /** Block-letter logo, assembled row by row so the letters are correct by construction. */
11
10
  function logo() {
12
11
  const rows = ["", "", "", ""];
13
12
  for (const ch of "tidepull") {
@@ -17,7 +16,6 @@ function logo() {
17
16
  }
18
17
  return rows.map((r) => r.trimEnd());
19
18
  }
20
- /** Launch banner for interactive terminals; version dimmed beside the logo. */
21
19
  export function renderBanner(version, theme, color = true) {
22
20
  const plain = !color || !!process.env.NO_COLOR || theme.name === "mono";
23
21
  const paint = (c, s) => (plain ? s : c + s + theme.reset);