@boy-offi9-inc/tidepull 0.5.0 → 0.7.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 +5 -5
  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 +43 -9
  25. package/dist/dash/parse.d.ts +1 -3
  26. package/dist/dash/parse.js +83 -83
  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,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);
@@ -1,4 +1,3 @@
1
1
  export declare function fmtBytes(n: number): string;
2
2
  export declare function fmtTime(sec: number): string;
3
- /** Simple left-aligned table. */
4
3
  export declare function table(rows: string[][]): string;
package/dist/ui/format.js CHANGED
@@ -19,7 +19,6 @@ export function fmtTime(sec) {
19
19
  const ss = String(s % 60).padStart(2, "0");
20
20
  return h ? `${h}:${m}:${ss}` : `${m}:${ss}`;
21
21
  }
22
- /** Simple left-aligned table. */
23
22
  export function table(rows) {
24
23
  const widths = rows[0].map((_, c) => Math.max(...rows.map((r) => (r[c] ?? "").length)));
25
24
  return rows.map((r) => r.map((cell, c) => (cell ?? "").padEnd(widths[c])).join(" ").trimEnd()).join("\n");
package/dist/ui/log.d.ts CHANGED
@@ -5,9 +5,7 @@ export interface LoggerOptions {
5
5
  color?: boolean;
6
6
  theme?: Theme | string;
7
7
  }
8
- /** Honors NO_COLOR / FORCE_COLOR, and only colors a real terminal. */
9
8
  export declare function shouldUseColor(env?: NodeJS.ProcessEnv, isTTY?: boolean): boolean;
10
- /** All human-facing output goes to stderr. stdout is reserved for data you can pipe. */
11
9
  export declare class Logger {
12
10
  quiet: boolean;
13
11
  verbose: boolean;
package/dist/ui/log.js CHANGED
@@ -1,5 +1,4 @@
1
1
  import { getTheme } from "./theme.js";
2
- /** Honors NO_COLOR / FORCE_COLOR, and only colors a real terminal. */
3
2
  export function shouldUseColor(env = process.env, isTTY = !!process.stderr.isTTY) {
4
3
  if (env.NO_COLOR)
5
4
  return false;
@@ -7,7 +6,6 @@ export function shouldUseColor(env = process.env, isTTY = !!process.stderr.isTTY
7
6
  return true;
8
7
  return isTTY && env.TERM !== "dumb";
9
8
  }
10
- /** All human-facing output goes to stderr. stdout is reserved for data you can pipe. */
11
9
  export class Logger {
12
10
  quiet;
13
11
  verbose;
@@ -1,11 +1,9 @@
1
1
  import type { TidepullEvent } from "../core/events.js";
2
2
  import type { Logger } from "./log.js";
3
3
  import type { Theme } from "./theme.js";
4
- /** Renders engine events as terminal output on stderr, redrawing one progress line on a TTY. */
5
4
  export declare function humanRenderer(log: Logger, o: {
6
5
  progress: boolean;
7
6
  stream?: NodeJS.WriteStream;
8
7
  theme?: Theme | string;
9
8
  }): (e: TidepullEvent) => void;
10
- /** Writes one JSON event per line to stdout (NDJSON). */
11
9
  export declare const jsonRenderer: () => ((e: TidepullEvent) => void);
package/dist/ui/render.js CHANGED
@@ -1,6 +1,5 @@
1
1
  import { fmtBytes, fmtTime } from "./format.js";
2
2
  import { getTheme } from "./theme.js";
3
- /** Renders engine events as terminal output on stderr, redrawing one progress line on a TTY. */
4
3
  export function humanRenderer(log, o) {
5
4
  const stream = o.stream ?? process.stderr;
6
5
  const theme = typeof o.theme === "string" ? getTheme(o.theme) : (o.theme ?? log.theme);
@@ -37,7 +36,6 @@ export function humanRenderer(log, o) {
37
36
  const size = e.total ? ` of ${e.estimated ? "~" : ""}${fmtBytes(e.total)}` : ` ${fmtBytes(e.downloaded)}`;
38
37
  const rate = e.speed ? ` at ${fmtBytes(e.speed)}/s` : "";
39
38
  const eta = e.eta !== undefined ? ` ETA ${fmtTime(e.eta)}` : "";
40
- // Keep the line narrower than the terminal: a wrapped line cannot be redrawn in place.
41
39
  let line = `[download] ${pct}${size}${rate}${eta}`;
42
40
  if (line.length >= cols)
43
41
  line = `[download] ${pct}${size}${rate}`;
@@ -76,5 +74,4 @@ export function humanRenderer(log, o) {
76
74
  }
77
75
  };
78
76
  }
79
- /** Writes one JSON event per line to stdout (NDJSON). */
80
77
  export const jsonRenderer = () => (e) => void process.stdout.write(JSON.stringify(e) + "\n");
@@ -4,11 +4,6 @@ export interface SpinnerOptions {
4
4
  env?: NodeJS.ProcessEnv;
5
5
  interval?: number;
6
6
  }
7
- /**
8
- * Single-line activity spinner on stderr. Never touches stdout, and never
9
- * starts at all when stderr is not a TTY or CI is detected: machine modes
10
- * must see zero bytes from it.
11
- */
12
7
  export declare class Spinner {
13
8
  private timer;
14
9
  private frame;
@@ -1,9 +1,4 @@
1
1
  const FRAMES = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧"];
2
- /**
3
- * Single-line activity spinner on stderr. Never touches stdout, and never
4
- * starts at all when stderr is not a TTY or CI is detected: machine modes
5
- * must see zero bytes from it.
6
- */
7
2
  export class Spinner {
8
3
  timer;
9
4
  frame = 0;
@@ -1,4 +1,3 @@
1
- /** Named ANSI color palettes for the CLI output. */
2
1
  export interface Theme {
3
2
  name: string;
4
3
  tag: string;
@@ -9,14 +8,10 @@ export interface Theme {
9
8
  progress: string;
10
9
  success: string;
11
10
  reset: string;
12
- /** Glyph used for the single-line progress redraw. */
13
11
  progressGlyph: string;
14
- /** Labels use bold instead of color when true (e.g. mono). */
15
12
  boldLabels: boolean;
16
13
  }
17
14
  export declare const THEMES: Record<string, Theme>;
18
15
  export declare const THEME_NAMES: string[];
19
- /** Resolves a theme name; throws with the available names when unknown. */
20
16
  export declare function getTheme(name: string | undefined): Theme;
21
- /** --theme flag wins over TIDEPULL_THEME; neither means the default. */
22
17
  export declare function pickTheme(flag: string | undefined, env?: NodeJS.ProcessEnv): Theme;
package/dist/ui/theme.js CHANGED
@@ -22,7 +22,6 @@ export const THEMES = {
22
22
  },
23
23
  };
24
24
  export const THEME_NAMES = Object.keys(THEMES);
25
- /** Resolves a theme name; throws with the available names when unknown. */
26
25
  export function getTheme(name) {
27
26
  const key = name ?? "tide";
28
27
  const t = THEMES[key];
@@ -30,7 +29,6 @@ export function getTheme(name) {
30
29
  throw new Error(`Unknown theme "${key}". Available themes: ${THEME_NAMES.join(", ")}`);
31
30
  return t;
32
31
  }
33
- /** --theme flag wins over TIDEPULL_THEME; neither means the default. */
34
32
  export function pickTheme(flag, env = process.env) {
35
33
  return getTheme(flag ?? env.TIDEPULL_THEME);
36
34
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@boy-offi9-inc/tidepull",
3
- "version": "0.5.0",
3
+ "version": "0.7.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",