@boy-offi9-inc/tidepull 0.3.0 → 0.4.1

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/README.md CHANGED
@@ -1,3 +1,15 @@
1
+ <p align="center">
2
+ <img src="docs/assets/logo.svg" alt="tidepull logo" width="88" height="88">
3
+ </p>
4
+
5
+ [![npm version](https://img.shields.io/npm/v/@boy-offi9-inc/tidepull)](https://www.npmjs.com/package/@boy-offi9-inc/tidepull)
6
+ [![npm downloads/month](https://img.shields.io/npm/dm/@boy-offi9-inc/tidepull)](https://www.npmjs.com/package/@boy-offi9-inc/tidepull)
7
+ [![CI](https://github.com/boy-offi9-inc/Tidepull/actions/workflows/ci.yml/badge.svg)](https://github.com/boy-offi9-inc/Tidepull/actions/workflows/ci.yml)
8
+ ![Node](https://img.shields.io/badge/node-%3E%3D22.18-339933)
9
+ ![dependencies](https://img.shields.io/badge/dependencies-zero-brightgreen)
10
+ [![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)
11
+ ![TypeScript](https://img.shields.io/badge/TypeScript-5-3178c6)
12
+
1
13
  # tidepull
2
14
 
3
15
  A minimal, from-scratch media downloader **library** (and CLI) for Node. Minimal by design: a ~22 KB minified core with no runtime dependencies today (~9 KB gzip), fully typed, no terminal code in the core. Everything that isn't needed by every user is opt-in.
@@ -52,6 +64,19 @@ const files = await pullAll(g, "https://example.com/podcast.rss", { items: "1-3,
52
64
 
53
65
  `g.resolve(url)` returns an `Info` or a `Playlist` (`isPlaylist(x)` tells you which). `g.extract(url)` still returns a single `Info` and refuses a playlist with a clear error. A failing item is thrown by default; pass `onError` to report it and continue. Template fields for playlist items: `%(playlist)s`, `%(playlist_index)02d`, `%(playlist_count)s`, `%(playlist_id)s`.
54
66
 
67
+ ## Example
68
+ ```console
69
+ $ tidepull -F URL # list formats
70
+ ID EXT RESOLUTION FPS | SIZE TBR PROTO | VCODEC ACODEC NOTE
71
+ hls-600 ts 640x360 | 600k hls | unknown unknown
72
+ hls-1200 ts 1280x720 | 1200k hls | unknown unknown
73
+
74
+ $ tidepull URL -P ~/Videos
75
+ [download] Destination: ~/Videos/master.ts
76
+ [download] 100% of 439.45KiB in 00:00
77
+ [done] ~/Videos/master.ts
78
+ ```
79
+
55
80
  ## API (everything else is internal)
56
81
  | Export | Purpose |
57
82
  |---|---|
@@ -86,6 +111,18 @@ export default definePlugin({
86
111
  ```
87
112
  Plugins run before built-ins; the generic fallback is always last. From disk: `import { loadPlugins } from "@boy-offi9-inc/tidepull/loader"` (the CLI does this for you, and bundles DASH). A plugin targeting a different `apiVersion` is refused with a clear message instead of failing mysteriously. **Plugins execute with your privileges. Only load code you trust.** See `src/extractors/_template.ts`.
88
113
 
114
+ Ready-made site plugins live in the public [boy-offi9-inc/tidepull-plugins](https://github.com/boy-offi9-inc/tidepull-plugins) repo; its `docs/PLUGINS.md` is the contract a plugin must satisfy (naming, `apiVersion`, what an extractor may touch, how it is reviewed) before it can be loaded there.
115
+
116
+ Ready-made plugins today: [`@boy-offi9-inc/tidepull-plugin-example`](https://github.com/boy-offi9-inc/tidepull-plugins/tree/main/plugins/example) (og:video / og:audio metas) and [`@boy-offi9-inc/tidepull-plugin-soundcloud`](https://github.com/boy-offi9-inc/tidepull-plugins/tree/main/plugins/soundcloud) (public SoundCloud tracks).
117
+
118
+ ### Ecosystem
119
+
120
+ | Repo | Package | What it is |
121
+ |---|---|---|
122
+ | [Tidepull](https://github.com/boy-offi9-inc/Tidepull) (here) | `@boy-offi9-inc/tidepull` | the core: extract, select, download — zero dependencies |
123
+ | [tidepull-plugins](https://github.com/boy-offi9-inc/tidepull-plugins) | `@boy-offi9-inc/tidepull-plugin-*` | site plugins and the authoring template, contract in its `docs/PLUGINS.md` |
124
+ | [reqkit](https://github.com/boy-offi9-inc/reqkit) | — | transport/resilience helpers for plugin authors (planned) |
125
+
89
126
  An extractor may instead return a `Playlist` (`{ kind: "playlist", id, title, extractor, webpage_url, entries: [{ url, title? }] }`) for a page that lists several items; each entry is then extracted on its own by the same extractors.
90
127
 
91
128
  ## CLI
@@ -109,6 +146,24 @@ tidepull --playlist-items 1-3,7 URL # only some items (-F lists a
109
146
 
110
147
  **Config file.** Defaults go in `~/.config/tidepull/config` (or `--config-location FILE`): one or more options per line, `#` for comments, for example `-P ~/Videos` and `--limit-rate 2M`. Options on the command line win; `--no-config` ignores the file.
111
148
 
149
+ ### Terminal themes
150
+
151
+ The CLI colors its output from a named theme. `--theme NAME` picks one for that run; `TIDEPULL_THEME` sets the default in your environment or config file. The flag wins over the variable.
152
+
153
+ | Theme | Look | Progress glyph |
154
+ |---|---|---|
155
+ | `tide` (default) | cyan tags, green success, the house look | `▓` |
156
+ | `mono` | no color, bold labels only (for pipes, CI logs, e-ink) | `#` |
157
+ | `high-contrast` | bright, heavy colors and bold labels for low-vision use | `█` |
158
+ | `amber` | retro CRT amber on dark | `▓` |
159
+
160
+ ```bash
161
+ tidepull --theme amber -F URL
162
+ TIDEPULL_THEME=high-contrast tidepull URL # --theme still wins if you also pass it
163
+ ```
164
+
165
+ A theme only decides *which* codes are emitted: `--no-color`, `NO_COLOR` and a non-TTY stderr still strip every escape sequence, so redirected output and CI logs stay plain text.
166
+
112
167
  From a clone, `node src/cli.ts <args>` runs the TypeScript source directly (Node >= 22.18); `npm run build` emits JS + `.d.ts`.
113
168
 
114
169
  ## Capabilities and limits
package/dist/main.js CHANGED
@@ -13,6 +13,7 @@ import { defaultPluginDir, loadPlugins } from "./loader.js";
13
13
  import { table, fmtBytes } from "./ui/format.js";
14
14
  import { Logger, shouldUseColor } from "./ui/log.js";
15
15
  import { humanRenderer, jsonRenderer } from "./ui/render.js";
16
+ import { pickTheme, THEME_NAMES } from "./ui/theme.js";
16
17
  /** Package version, read from package.json. */
17
18
  export const VERSION = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8")).version;
18
19
  const HELP = `tidepull ${VERSION}: a minimal media downloader
@@ -70,6 +71,7 @@ General:
70
71
  --no-progress Disable the progress line
71
72
  --progress-json Emit engine events as NDJSON on stdout (for GUIs/scripts)
72
73
  --no-color Disable colors (also honors NO_COLOR)
74
+ --theme NAME Output theme: ${THEME_NAMES.join(", ")} (or TIDEPULL_THEME; --theme wins)
73
75
  -h, --help Show this help
74
76
  --version Show version
75
77
 
@@ -142,6 +144,7 @@ export async function main(argv) {
142
144
  "no-config": { type: "boolean" },
143
145
  "playlist-items": { type: "string" },
144
146
  "no-color": { type: "boolean" },
147
+ theme: { type: "string" },
145
148
  help: { type: "boolean", short: "h" },
146
149
  version: { type: "boolean" },
147
150
  },
@@ -166,10 +169,19 @@ export async function main(argv) {
166
169
  return void process.stdout.write(HELP + "\n"), 0;
167
170
  if (values.version)
168
171
  return void process.stdout.write(VERSION + "\n"), 0;
172
+ let theme;
173
+ try {
174
+ theme = pickTheme(values.theme);
175
+ }
176
+ catch (e) {
177
+ process.stderr.write(`ERROR: ${errMsg(e)}\n`);
178
+ return 2;
179
+ }
169
180
  const log = new Logger({
170
181
  quiet: values.quiet,
171
182
  verbose: values.verbose,
172
183
  color: !values["no-color"] && shouldUseColor(),
184
+ theme,
173
185
  });
174
186
  const urls = [...positionals];
175
187
  let limitRate;
@@ -225,7 +237,7 @@ export async function main(argv) {
225
237
  plugins: [...plugins, dash, feeds],
226
238
  ffmpeg: values["ffmpeg-location"],
227
239
  });
228
- tp.on(values["progress-json"] ? jsonRenderer() : humanRenderer(log, { progress: !values["no-progress"] && !values.quiet }));
240
+ tp.on(values["progress-json"] ? jsonRenderer() : humanRenderer(log, { progress: !values["no-progress"] && !values.quiet, theme }));
229
241
  for (const p of plugins)
230
242
  log.debug(`Loaded plugin "${p.name}" (${p.extractors?.length ?? 0} extractor(s))`);
231
243
  if (values["list-extractors"]) {
package/dist/ui/log.d.ts CHANGED
@@ -1,7 +1,9 @@
1
+ import type { Theme } from "./theme.js";
1
2
  export interface LoggerOptions {
2
3
  quiet?: boolean;
3
4
  verbose?: boolean;
4
5
  color?: boolean;
6
+ theme?: Theme | string;
5
7
  }
6
8
  /** Honors NO_COLOR / FORCE_COLOR, and only colors a real terminal. */
7
9
  export declare function shouldUseColor(env?: NodeJS.ProcessEnv, isTTY?: boolean): boolean;
@@ -10,6 +12,7 @@ export declare class Logger {
10
12
  quiet: boolean;
11
13
  verbose: boolean;
12
14
  color: boolean;
15
+ theme: Theme;
13
16
  constructor(o?: LoggerOptions);
14
17
  private paint;
15
18
  tag(tag: string, msg: string): void;
package/dist/ui/log.js CHANGED
@@ -1,4 +1,4 @@
1
- const C = { red: "\x1b[31m", yellow: "\x1b[33m", cyan: "\x1b[36m", dim: "\x1b[2m", reset: "\x1b[0m" };
1
+ import { getTheme } from "./theme.js";
2
2
  /** Honors NO_COLOR / FORCE_COLOR, and only colors a real terminal. */
3
3
  export function shouldUseColor(env = process.env, isTTY = !!process.stderr.isTTY) {
4
4
  if (env.NO_COLOR)
@@ -12,26 +12,28 @@ export class Logger {
12
12
  quiet;
13
13
  verbose;
14
14
  color;
15
+ theme;
15
16
  constructor(o = {}) {
16
17
  this.quiet = o.quiet ?? false;
17
18
  this.verbose = o.verbose ?? false;
18
19
  this.color = o.color ?? false;
20
+ this.theme = typeof o.theme === "string" ? getTheme(o.theme) : (o.theme ?? getTheme(undefined));
19
21
  }
20
22
  paint(c, s) {
21
- return this.color ? c + s + C.reset : s;
23
+ return this.color ? c + s + this.theme.reset : s;
22
24
  }
23
25
  tag(tag, msg) {
24
26
  if (!this.quiet)
25
- process.stderr.write(`${this.paint(C.cyan, `[${tag}]`)} ${msg}\n`);
27
+ process.stderr.write(`${this.paint(this.theme.tag, `[${tag}]`)} ${msg}\n`);
26
28
  }
27
29
  debug(msg) {
28
30
  if (this.verbose)
29
- process.stderr.write(`${this.paint(C.dim, "[debug]")} ${msg}\n`);
31
+ process.stderr.write(`${this.paint(this.theme.dim, "[debug]")} ${msg}\n`);
30
32
  }
31
33
  warn(msg) {
32
- process.stderr.write(`${this.paint(C.yellow, "WARNING:")} ${msg}\n`);
34
+ process.stderr.write(`${this.paint(this.theme.warn, "WARNING:")} ${msg}\n`);
33
35
  }
34
36
  error(msg) {
35
- process.stderr.write(`${this.paint(C.red, "ERROR:")} ${msg}\n`);
37
+ process.stderr.write(`${this.paint(this.theme.error, "ERROR:")} ${msg}\n`);
36
38
  }
37
39
  }
@@ -1,9 +1,11 @@
1
1
  import type { TidepullEvent } from "../core/events.js";
2
2
  import type { Logger } from "./log.js";
3
+ import type { Theme } from "./theme.js";
3
4
  /** Renders engine events as terminal output on stderr, redrawing one progress line on a TTY. */
4
5
  export declare function humanRenderer(log: Logger, o: {
5
6
  progress: boolean;
6
7
  stream?: NodeJS.WriteStream;
8
+ theme?: Theme | string;
7
9
  }): (e: TidepullEvent) => void;
8
10
  /** Writes one JSON event per line to stdout (NDJSON). */
9
11
  export declare const jsonRenderer: () => ((e: TidepullEvent) => void);
package/dist/ui/render.js CHANGED
@@ -1,7 +1,10 @@
1
1
  import { fmtBytes, fmtTime } from "./format.js";
2
+ import { getTheme } from "./theme.js";
2
3
  /** Renders engine events as terminal output on stderr, redrawing one progress line on a TTY. */
3
4
  export function humanRenderer(log, o) {
4
5
  const stream = o.stream ?? process.stderr;
6
+ const theme = typeof o.theme === "string" ? getTheme(o.theme) : (o.theme ?? log.theme);
7
+ const colorize = (c, s) => (log.color ? c + s + theme.reset : s);
5
8
  const live = o.progress && !!stream.isTTY;
6
9
  let drawn = false;
7
10
  const clear = () => {
@@ -44,13 +47,13 @@ export function humanRenderer(log, o) {
44
47
  line = `${pct}${size}`.trim();
45
48
  if (line.length >= cols)
46
49
  line = (pct || fmtBytes(e.downloaded)).trim();
47
- stream.write(`\r\x1b[K${line.slice(0, Math.max(1, cols - 1))}`);
50
+ stream.write(`\r\x1b[K${colorize(theme.progress, line.slice(0, Math.max(1, cols - 1)))}`);
48
51
  drawn = true;
49
52
  break;
50
53
  }
51
54
  case "finish":
52
55
  clear();
53
- log.tag("download", `100% of ${fmtBytes(e.bytes)} in ${fmtTime(e.seconds)}${e.speed ? ` at ${fmtBytes(e.speed)}/s` : ""}`);
56
+ log.tag("download", colorize(theme.success, `100% of ${fmtBytes(e.bytes)} in ${fmtTime(e.seconds)}${e.speed ? ` at ${fmtBytes(e.speed)}/s` : ""}`));
54
57
  break;
55
58
  case "merge":
56
59
  log.tag("merger", `Merging formats into "${e.output}"`);
@@ -65,7 +68,7 @@ export function humanRenderer(log, o) {
65
68
  log.tag("item", `${e.position}/${e.total}${e.title ? ` ${e.title}` : ""}`);
66
69
  break;
67
70
  case "done":
68
- log.tag("done", e.file);
71
+ log.tag("done", colorize(theme.success, e.file));
69
72
  break;
70
73
  case "error":
71
74
  clear();
@@ -0,0 +1,22 @@
1
+ /** Named ANSI color palettes for the CLI output. */
2
+ export interface Theme {
3
+ name: string;
4
+ tag: string;
5
+ warn: string;
6
+ error: string;
7
+ dim: string;
8
+ accent: string;
9
+ progress: string;
10
+ success: string;
11
+ reset: string;
12
+ /** Glyph used for the single-line progress redraw. */
13
+ progressGlyph: string;
14
+ /** Labels use bold instead of color when true (e.g. mono). */
15
+ boldLabels: boolean;
16
+ }
17
+ export declare const THEMES: Record<string, Theme>;
18
+ export declare const THEME_NAMES: string[];
19
+ /** Resolves a theme name; throws with the available names when unknown. */
20
+ export declare function getTheme(name: string | undefined): Theme;
21
+ /** --theme flag wins over TIDEPULL_THEME; neither means the default. */
22
+ export declare function pickTheme(flag: string | undefined, env?: NodeJS.ProcessEnv): Theme;
@@ -0,0 +1,36 @@
1
+ const R = "\x1b[0m";
2
+ export const THEMES = {
3
+ tide: {
4
+ name: "tide", tag: "\x1b[36m", warn: "\x1b[33m", error: "\x1b[31m", dim: "\x1b[2m",
5
+ accent: "\x1b[96m", progress: "\x1b[36m", success: "\x1b[92m", reset: R,
6
+ progressGlyph: "\u2593", boldLabels: false,
7
+ },
8
+ mono: {
9
+ name: "mono", tag: "\x1b[1m", warn: "\x1b[1m", error: "\x1b[1m", dim: "\x1b[2m",
10
+ accent: "\x1b[1m", progress: "\x1b[1m", success: "\x1b[1m", reset: "\x1b[0m\x1b[22m",
11
+ progressGlyph: "#", boldLabels: true,
12
+ },
13
+ "high-contrast": {
14
+ name: "high-contrast", tag: "\x1b[97m", warn: "\x1b[93;1m", error: "\x1b[91;1m", dim: "\x1b[97m",
15
+ accent: "\x1b[96;1m", progress: "\x1b[96;1m", success: "\x1b[92;1m", reset: R,
16
+ progressGlyph: "\u2588", boldLabels: true,
17
+ },
18
+ amber: {
19
+ name: "amber", tag: "\x1b[33m", warn: "\x1b[33;1m", error: "\x1b[31;1m", dim: "\x1b[2m",
20
+ accent: "\x1b[93m", progress: "\x1b[93m", success: "\x1b[92m", reset: R,
21
+ progressGlyph: "\u2593", boldLabels: false,
22
+ },
23
+ };
24
+ export const THEME_NAMES = Object.keys(THEMES);
25
+ /** Resolves a theme name; throws with the available names when unknown. */
26
+ export function getTheme(name) {
27
+ const key = name ?? "tide";
28
+ const t = THEMES[key];
29
+ if (!t)
30
+ throw new Error(`Unknown theme "${key}". Available themes: ${THEME_NAMES.join(", ")}`);
31
+ return t;
32
+ }
33
+ /** --theme flag wins over TIDEPULL_THEME; neither means the default. */
34
+ export function pickTheme(flag, env = process.env) {
35
+ return getTheme(flag ?? env.TIDEPULL_THEME);
36
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@boy-offi9-inc/tidepull",
3
- "version": "0.3.0",
3
+ "version": "0.4.1",
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",
@@ -25,7 +25,8 @@
25
25
  "build": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\" && tsc -p tsconfig.build.json && node scripts/fix-dts.mjs",
26
26
  "prepack": "npm run build",
27
27
  "prepublishOnly": "npm run typecheck && npm test",
28
- "size": "node scripts/size.mjs dist/index.js --budget=50"
28
+ "size": "node scripts/size.mjs dist/index.js --budget=50",
29
+ "lint:imports": "node scripts/lint-imports.mjs"
29
30
  },
30
31
  "devDependencies": {
31
32
  "@types/node": "^22.0.0",