@boy-offi9-inc/tidepull 0.7.7 → 0.8.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/README.md CHANGED
@@ -164,7 +164,7 @@ TIDEPULL_THEME=high-contrast tidepull URL # --theme still wins if you also
164
164
 
165
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
166
 
167
- On an interactive terminal the CLI shows a launch banner and a spinner while resolving a URL; quiet, JSON, `-g`, simulate and non-TTY modes suppress both so piped output stays data-only.
167
+ On an interactive terminal the CLI shows a launch banner while a download is queued and a spinner while resolving a URL; a bare call, `--help`, `--version`, quiet, JSON, `-g`, simulate and non-TTY modes show neither, so piped and one-off output stays data-only. The banner is a dash-border box (`⬢ tidepull vX.Y.Z` in the top border) with labeled stat rows — version, stdout policy, detected plugins.
168
168
 
169
169
  From a clone, `node src/cli.ts <args>` runs the TypeScript source directly (Node >= 22.18); `npm run build` emits JS + `.d.ts`.
170
170
 
@@ -199,13 +199,14 @@ From a clone, `node src/cli.ts <args>` runs the TypeScript source directly (Node
199
199
  | Cookies | Netscape `cookies.txt`; matched by domain, path, `Secure` and expiry; re-evaluated on every redirect hop |
200
200
  | CLI conveniences | `-a` batch input, `--download-archive`, `--limit-rate`, `--config-location` |
201
201
  | Merge / remux | ffmpeg |
202
+ | Audio extraction | `-x` pulls the audio track into its own container with ffmpeg (`--audio-format`: mp3, m4a, opus, ogg, flac, wav, `best`); with no explicit `--format` the selector defaults to `ba/b` |
202
203
 
203
204
  ## Footprint (enforced in CI)
204
205
  The core does only what every user needs: extract → select → download, events, cancellation. Everything else is a plugin or an opt-in subpath.
205
206
 
206
207
  | Import | Files | Raw | Gzip | Minified (gzip) |
207
208
  |---|---|---|---|---|
208
- | `@boy-offi9-inc/tidepull` (core: direct, HLS, generic page, selector, templates, resume, merge, playlists contract) | 18 | 49.6 KB | 13.7 KB | 23 KB (9.7 KB) |
209
+ | `@boy-offi9-inc/tidepull` (core: direct, HLS, generic page, selector, templates, resume, merge, audio extraction, playlists contract) | 18 | 50.5 KB | 14.0 KB | 23 KB (9.7 KB) |
209
210
  | `@boy-offi9-inc/tidepull/dash` (adds XML + MPD parsing) | +6 | +14 KB | +4.7 KB | +7.1 KB (+3.3 KB) |
210
211
  | `@boy-offi9-inc/tidepull/feeds` (RSS/Atom + .m3u; shares the XML parser with dash) | +5 | +9 KB | +3.3 KB | +3.8 KB (+1.9 KB) |
211
212
  | `@boy-offi9-inc/tidepull/playlist` (`pullAll`, item selection) | +1 | +3.9 KB | +1.5 KB | +1.9 KB (+1.0 KB) |
@@ -29,6 +29,9 @@ export type TidepullEvent = {
29
29
  } | {
30
30
  type: "merge";
31
31
  output: string;
32
+ } | {
33
+ type: "extract-audio";
34
+ output: string;
32
35
  } | {
33
36
  type: "remux";
34
37
  output: string;
@@ -1,3 +1,4 @@
1
1
  export declare function findFfmpeg(location?: string): string | undefined;
2
2
  export declare const mergeStreams: (bin: string, video: string, audio: string, out: string) => Promise<void>;
3
3
  export declare const remux: (bin: string, input: string, out: string) => Promise<void>;
4
+ export declare const extractAudio: (bin: string, input: string, out: string, format: string) => Promise<void>;
@@ -36,3 +36,13 @@ function run(bin, args) {
36
36
  }
37
37
  export const mergeStreams = (bin, video, audio, out) => run(bin, ["-i", video, "-i", audio, "-map", "0:v:0", "-map", "1:a:0", "-c", "copy", out]);
38
38
  export const remux = (bin, input, out) => run(bin, ["-i", input, "-c", "copy", out]);
39
+ export const extractAudio = (bin, input, out, format) => run(bin, ["-i", input, "-vn", "-c:a", audioCodec(format), out]);
40
+ const AUDIO_CODECS = {
41
+ mp3: "libmp3lame", m4a: "aac", opus: "libopus", ogg: "libvorbis", flac: "flac", wav: "pcm_s16le", best: "copy",
42
+ };
43
+ function audioCodec(format) {
44
+ const c = AUDIO_CODECS[format];
45
+ if (!c)
46
+ throw new TidepullError(`Unsupported audio format: ${format} (available: ${Object.keys(AUDIO_CODECS).join(", ")})`, 2);
47
+ return c;
48
+ }
@@ -9,6 +9,7 @@ export interface DownloadOptions {
9
9
  concurrency: number;
10
10
  mergeFormat: string;
11
11
  remuxVideo?: string;
12
+ extractAudio?: string;
12
13
  ffmpeg?: string;
13
14
  headers: Record<string, string>;
14
15
  limitRate?: number;
@@ -2,7 +2,7 @@ import { mkdir, rename, rm, stat } from "node:fs/promises";
2
2
  import path from "node:path";
3
3
  import { downloadDash, downloadHls, downloadHlsSubtitles, downloadHttp, RateLimiter } from "./downloader.js";
4
4
  import { TidepullError } from "./errors.js";
5
- import { findFfmpeg, mergeStreams, remux } from "./ffmpeg.js";
5
+ import { findFfmpeg, mergeStreams, remux, extractAudio } from "./ffmpeg.js";
6
6
  import { Meter } from "./meter.js";
7
7
  import { selectFormats } from "./selector.js";
8
8
  import { renderTemplate } from "./template.js";
@@ -52,6 +52,9 @@ export async function downloadInfo(info, opts, ctx) {
52
52
  if (merging && !ffmpeg) {
53
53
  throw new TidepullError(`ffmpeg is required to merge ${chosen.map((f) => f.format_id).join("+")}. Install it, or pick one format (-f b).`);
54
54
  }
55
+ if (opts.extractAudio && !ffmpeg) {
56
+ throw new TidepullError("ffmpeg is required for --extract-audio. Install it, or drop -x.");
57
+ }
55
58
  const predictedExt = merging ? opts.mergeFormat : chosen[0].ext;
56
59
  const fields = {
57
60
  ...scalars(info),
@@ -129,6 +132,13 @@ export async function downloadInfo(info, opts, ctx) {
129
132
  await Promise.all(tmp.map((t) => rm(t, { force: true })));
130
133
  }
131
134
  }
135
+ if (opts.extractAudio) {
136
+ const out = `${base}.${opts.extractAudio === "best" ? "mka" : opts.extractAudio}`;
137
+ ctx.emit({ type: "extract-audio", output: out });
138
+ await extractAudio(ffmpeg, target, out, opts.extractAudio);
139
+ await rm(target, { force: true });
140
+ target = out;
141
+ }
132
142
  if (opts.remuxVideo && path.extname(target).slice(1) !== opts.remuxVideo) {
133
143
  if (!ffmpeg)
134
144
  throw new TidepullError("ffmpeg is required for --remux-video");
package/dist/main.js CHANGED
@@ -35,6 +35,8 @@ Output:
35
35
  --no-continue Do not resume partial downloads
36
36
  --merge-output-format Container when merging video+audio (default: mp4)
37
37
  --remux-video EXT Remux the result into EXT with ffmpeg (e.g. mp4)
38
+ -x, --extract-audio Extract the audio track into an audio file (ffmpeg required)
39
+ --audio-format FORMAT Audio container for -x: mp3, m4a, opus, ogg, flac, wav, best (default: best)
38
40
  --ffmpeg-location PATH ffmpeg binary or directory
39
41
 
40
42
  Info only (nothing is downloaded):
@@ -121,6 +123,8 @@ export async function main(argv) {
121
123
  "no-continue": { type: "boolean" },
122
124
  "merge-output-format": { type: "string" },
123
125
  "remux-video": { type: "string" },
126
+ "extract-audio": { type: "boolean", short: "x" },
127
+ "audio-format": { type: "string" },
124
128
  "ffmpeg-location": { type: "string" },
125
129
  "dump-json": { type: "boolean", short: "j" },
126
130
  "get-url": { type: "boolean", short: "g" },
@@ -181,7 +185,8 @@ export async function main(argv) {
181
185
  return 2;
182
186
  }
183
187
  const machineMode = values.quiet || values["dump-json"] || values["get-url"] || values.simulate || values["progress-json"];
184
- const showBanner = process.stdout.isTTY && !machineMode;
188
+ const interactiveStdout = process.stdout.isTTY && !machineMode && !values["list-extractors"];
189
+ let showBanner = false;
185
190
  const log = new Logger({
186
191
  quiet: values.quiet,
187
192
  verbose: values.verbose,
@@ -236,6 +241,7 @@ export async function main(argv) {
236
241
  log.error(errMsg(e));
237
242
  return e instanceof TidepullError ? e.exitCode : 1;
238
243
  }
244
+ showBanner = interactiveStdout && urls.length > 0;
239
245
  if (showBanner) {
240
246
  const pluginNames = plugins.map((p) => p.name);
241
247
  process.stderr.write(renderBanner(VERSION, theme, !values["no-color"] && shouldUseColor(), pluginNames) + "\n");
@@ -253,7 +259,7 @@ export async function main(argv) {
253
259
  return 0;
254
260
  }
255
261
  const opts = {
256
- format: values.format ?? DEFAULT_FORMAT,
262
+ format: values.format ?? (values["extract-audio"] ? "ba/b" : DEFAULT_FORMAT),
257
263
  output: values.output,
258
264
  paths: values.paths,
259
265
  resume: !values["no-continue"],
@@ -261,6 +267,7 @@ export async function main(argv) {
261
267
  concurrency: Math.max(1, num(values["concurrent-fragments"], 4)),
262
268
  mergeFormat: values["merge-output-format"],
263
269
  remuxVideo: values["remux-video"],
270
+ extractAudio: values["extract-audio"] ? (values["audio-format"] ?? "best") : undefined,
264
271
  headers,
265
272
  limitRate,
266
273
  writeSubs: !!values["write-subs"],
@@ -1,2 +1,5 @@
1
1
  import type { Theme } from "./theme.js";
2
+ declare function termWidth(): number;
2
3
  export declare function renderBanner(version: string, theme: Theme, color?: boolean, plugins?: string[], width?: number): string;
4
+ export declare const _visibleWidth: (s: string) => number;
5
+ export { termWidth };
package/dist/ui/banner.js CHANGED
@@ -1,94 +1,40 @@
1
- const GLYPHS = {
2
- t: ["▀█▀ ", " █ ", " ▀ "],
3
- i: ["█ ", "█ ", "▀ "],
4
- d: ["█▀▀▄ ", "█ █ ", "▀▀▀▀ "],
5
- e: ["█▀▀▀ ", "█▀▀ ", "▀▀▀▀ "],
6
- p: ["█▀▀▄ ", "█▀▀ ", "▀ ▀ "],
7
- u: ["█ █ ", "█ █ ", "▀▀▀▀ "],
8
- l: ["█ ", "█ ", "▀▀▀▀ "],
9
- };
10
- function gradientStops(theme) {
11
- switch (theme.name) {
12
- case "amber":
13
- return ["\x1b[93m", "\x1b[93m", "\x1b[33m", "\x1b[33m", "\x1b[33;1m", "\x1b[31m", "\x1b[31;1m", "\x1b[31;1m"];
14
- case "high-contrast":
15
- return ["\x1b[96;1m", "\x1b[96;1m", "\x1b[96;1m", "\x1b[97;1m", "\x1b[97;1m", "\x1b[97;1m", "\x1b[97;1m", "\x1b[97;1m"];
16
- case "tide":
17
- return ["\x1b[96m", "\x1b[96m", "\x1b[36m", "\x1b[36m", "\x1b[36m", "\x1b[92m", "\x1b[92m", "\x1b[92m"];
18
- default:
19
- return [];
20
- }
21
- }
22
- function logo() {
23
- const rows = ["", "", ""];
24
- for (const ch of "tidepull") {
25
- const g = GLYPHS[ch];
26
- for (let r = 0; r < 3; r++)
27
- rows[r] += g[r];
28
- }
29
- return rows.map((r) => r.trimEnd());
1
+ const GLYPH = "\u2b22";
2
+ const visible = (s) => s.replace(/\x1b\[[0-9;]*m/g, "").length;
3
+ function termWidth() {
4
+ return process.stdout.columns ?? 80;
30
5
  }
31
- function infoLines(version, theme, plain, plugins) {
6
+ function infoRows(version, theme, plain, plugins) {
32
7
  const dim = (s) => (plain ? s : theme.dim + s + theme.reset);
33
8
  const ok = (s) => (plain ? s : theme.success + s + theme.reset);
34
9
  const tag = (s) => (plain ? s : theme.tag + s + theme.reset);
35
- const rows = [dim("media downloader"), `${dim("version")} ${ok(`v${version}`)}`, `${dim("stdout")} ${ok("data only")}`];
36
- if (plugins.length)
37
- rows.push(`${dim("plugins")} ${tag(plugins.join(", "))}`);
10
+ const rows = [
11
+ ["media downloader", ok(`v${version}`)],
12
+ ["stdout", ok("data only")],
13
+ ];
14
+ rows.push(["plugins", plugins.length ? tag(plugins.join(", ")) : dim("none")]);
38
15
  return rows;
39
16
  }
40
- function termWidth() {
41
- return process.stdout.columns ?? 80;
42
- }
43
- const visible = (s) => s.replace(/\x1b\[[0-9;]*m/g, "").length;
44
- function chooseLayout(logoWidth, infoWidths, width) {
45
- const maxInfo = Math.max(...infoWidths);
46
- return logoWidth + 3 + maxInfo <= width - 1 ? "side" : "stack";
47
- }
48
17
  export function renderBanner(version, theme, color = true, plugins = [], width) {
49
18
  const plain = !color || !!process.env.NO_COLOR || theme.name === "mono";
50
19
  const paint = (c, s) => (plain ? s : c + s + theme.reset);
51
- const rows = logo();
52
- const logoWidth = Math.max(...rows.map((r) => r.length));
53
- const info = infoLines(version, theme, plain, plugins);
54
- const infoWidths = info.map(visible);
55
- const w = width ?? termWidth();
56
- const layout = chooseLayout(logoWidth, infoWidths, w);
57
- let painted;
58
- if (plain) {
59
- painted = rows;
60
- }
61
- else {
62
- const stops = gradientStops(theme);
63
- const starts = [0, 5, 9, 14, 19, 24, 29, 34];
64
- const widths = [5, 4, 5, 5, 5, 5, 5, 5];
65
- painted = ["", "", ""];
66
- for (let li = 0; li < 8; li++) {
67
- const c = stops[li] ?? theme.accent;
68
- for (let r = 0; r < 3; r++)
69
- painted[r] += paint(c, rows[r].slice(starts[li], starts[li] + widths[li]));
70
- }
71
- for (let r = 0; r < 3; r++)
72
- painted[r] = painted[r].trimEnd() + theme.reset;
73
- }
20
+ const accent = (s) => paint(theme.accent, s);
21
+ const dim = (s) => paint(theme.dim, s);
22
+ const w = Math.max(24, Math.min(width ?? termWidth(), 60));
23
+ const rows = infoRows(version, theme, plain, plugins);
24
+ const LABEL = Math.max(...rows.map(([k]) => k.length)) + 2;
25
+ const inner = w - 2;
74
26
  const lines = [];
75
- if (layout === "side") {
76
- const col = logoWidth + 4;
77
- for (let r = 0; r < 3; r++) {
78
- const pad = Math.max(2, col - visible(painted[r]));
79
- lines.push(painted[r] + " ".repeat(pad) + (info[r] ?? ""));
80
- }
81
- for (let r = 3; r < info.length; r++)
82
- lines.push(" ".repeat(col + 1) + info[r]);
83
- }
84
- else {
85
- lines.push(...painted);
86
- for (const row of info)
87
- lines.push(" " + row);
27
+ const title = `${GLYPH} tidepull` + (plain ? ` v${version}` : ` ${paint(theme.dim, `v${version}`)}`);
28
+ const shownTitle = visible(title) > inner - 4 ? `${GLYPH} tidepull` : title;
29
+ const dash = "\u2500";
30
+ const fill = Math.max(1, inner - visible(shownTitle) - 4);
31
+ lines.push(accent("\u250c\u2500" + " ") + shownTitle + " " + accent(" " + dash.repeat(fill) + "\u2510"));
32
+ for (const [key, value] of rows) {
33
+ const pad = Math.max(0, inner - 2 - LABEL - visible(value));
34
+ lines.push(accent("\u2502") + " " + dim(key.padEnd(LABEL)) + value + " ".repeat(pad) + " " + accent("\u2502"));
88
35
  }
89
- const tag = plain ? "" : theme.tag;
90
- const span = layout === "side" ? logoWidth + 4 + infoWidths[0] : logoWidth;
91
- const waves = Math.max(6, Math.min(30, span - 1));
92
- lines.push(paint(tag, " " + "≈".repeat(waves)));
36
+ lines.push(accent("\u2514" + dash.repeat(inner) + "\u2518"));
93
37
  return lines.join("\n");
94
38
  }
39
+ export const _visibleWidth = visible;
40
+ export { termWidth };
package/dist/ui/render.js CHANGED
@@ -56,6 +56,9 @@ export function humanRenderer(log, o) {
56
56
  case "merge":
57
57
  log.tag("merger", `Merging formats into "${e.output}"`);
58
58
  break;
59
+ case "extract-audio":
60
+ log.tag("audio", `Extracting audio to "${e.output}"`);
61
+ break;
59
62
  case "remux":
60
63
  log.tag("remux", `Remuxing to "${e.output}"`);
61
64
  break;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@boy-offi9-inc/tidepull",
3
- "version": "0.7.7",
3
+ "version": "0.8.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",
@@ -25,7 +25,7 @@
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=52",
29
29
  "lint:imports": "node scripts/lint-imports.mjs"
30
30
  },
31
31
  "devDependencies": {