@boy-offi9-inc/tidepull 0.7.8 → 0.8.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 +2 -1
- package/dist/core/events.d.ts +3 -0
- package/dist/core/ffmpeg.d.ts +1 -0
- package/dist/core/ffmpeg.js +10 -0
- package/dist/core/pipeline.d.ts +1 -0
- package/dist/core/pipeline.js +11 -1
- package/dist/main.js +20 -5
- package/dist/ui/banner.js +39 -5
- package/dist/ui/render.js +3 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -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 |
|
|
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) |
|
package/dist/core/events.d.ts
CHANGED
package/dist/core/ffmpeg.d.ts
CHANGED
|
@@ -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>;
|
package/dist/core/ffmpeg.js
CHANGED
|
@@ -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
|
+
}
|
package/dist/core/pipeline.d.ts
CHANGED
package/dist/core/pipeline.js
CHANGED
|
@@ -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):
|
|
@@ -105,6 +107,16 @@ function listEntries(p) {
|
|
|
105
107
|
p.entries.forEach((e, i) => rows.push([String(i + 1), e.title ?? "", e.url]));
|
|
106
108
|
return table(rows);
|
|
107
109
|
}
|
|
110
|
+
function renderHelp(theme, color) {
|
|
111
|
+
const plain = !color || !!process.env.NO_COLOR || theme.name === "mono";
|
|
112
|
+
const accent = (s) => (plain ? s : theme.accent + s + theme.reset);
|
|
113
|
+
const lines = HELP.split("\n");
|
|
114
|
+
return [
|
|
115
|
+
renderBanner(VERSION, theme, color),
|
|
116
|
+
"",
|
|
117
|
+
...lines.map((l) => (l.startsWith("Usage:") ? accent(l) : l)),
|
|
118
|
+
].join("\n");
|
|
119
|
+
}
|
|
108
120
|
export async function main(argv) {
|
|
109
121
|
let values;
|
|
110
122
|
let positionals;
|
|
@@ -121,6 +133,8 @@ export async function main(argv) {
|
|
|
121
133
|
"no-continue": { type: "boolean" },
|
|
122
134
|
"merge-output-format": { type: "string" },
|
|
123
135
|
"remux-video": { type: "string" },
|
|
136
|
+
"extract-audio": { type: "boolean", short: "x" },
|
|
137
|
+
"audio-format": { type: "string" },
|
|
124
138
|
"ffmpeg-location": { type: "string" },
|
|
125
139
|
"dump-json": { type: "boolean", short: "j" },
|
|
126
140
|
"get-url": { type: "boolean", short: "g" },
|
|
@@ -169,7 +183,7 @@ export async function main(argv) {
|
|
|
169
183
|
return 2;
|
|
170
184
|
}
|
|
171
185
|
if (values.help)
|
|
172
|
-
return void process.stdout.write(
|
|
186
|
+
return void process.stdout.write(renderHelp(pickTheme(values.theme), !values["no-color"] && shouldUseColor()) + "\n"), 0;
|
|
173
187
|
if (values.version)
|
|
174
188
|
return void process.stdout.write(VERSION + "\n"), 0;
|
|
175
189
|
let theme;
|
|
@@ -181,8 +195,8 @@ export async function main(argv) {
|
|
|
181
195
|
return 2;
|
|
182
196
|
}
|
|
183
197
|
const machineMode = values.quiet || values["dump-json"] || values["get-url"] || values.simulate || values["progress-json"];
|
|
184
|
-
const interactiveStdout = process.stdout.isTTY && !machineMode
|
|
185
|
-
let showBanner =
|
|
198
|
+
const interactiveStdout = process.stdout.isTTY && !machineMode;
|
|
199
|
+
let showBanner = interactiveStdout;
|
|
186
200
|
const log = new Logger({
|
|
187
201
|
quiet: values.quiet,
|
|
188
202
|
verbose: values.verbose,
|
|
@@ -237,7 +251,7 @@ export async function main(argv) {
|
|
|
237
251
|
log.error(errMsg(e));
|
|
238
252
|
return e instanceof TidepullError ? e.exitCode : 1;
|
|
239
253
|
}
|
|
240
|
-
showBanner = interactiveStdout &&
|
|
254
|
+
showBanner = interactiveStdout && !values["list-extractors"];
|
|
241
255
|
if (showBanner) {
|
|
242
256
|
const pluginNames = plugins.map((p) => p.name);
|
|
243
257
|
process.stderr.write(renderBanner(VERSION, theme, !values["no-color"] && shouldUseColor(), pluginNames) + "\n");
|
|
@@ -255,7 +269,7 @@ export async function main(argv) {
|
|
|
255
269
|
return 0;
|
|
256
270
|
}
|
|
257
271
|
const opts = {
|
|
258
|
-
format: values.format ?? DEFAULT_FORMAT,
|
|
272
|
+
format: values.format ?? (values["extract-audio"] ? "ba/b" : DEFAULT_FORMAT),
|
|
259
273
|
output: values.output,
|
|
260
274
|
paths: values.paths,
|
|
261
275
|
resume: !values["no-continue"],
|
|
@@ -263,6 +277,7 @@ export async function main(argv) {
|
|
|
263
277
|
concurrency: Math.max(1, num(values["concurrent-fragments"], 4)),
|
|
264
278
|
mergeFormat: values["merge-output-format"],
|
|
265
279
|
remuxVideo: values["remux-video"],
|
|
280
|
+
extractAudio: values["extract-audio"] ? (values["audio-format"] ?? "best") : undefined,
|
|
266
281
|
headers,
|
|
267
282
|
limitRate,
|
|
268
283
|
writeSubs: !!values["write-subs"],
|
package/dist/ui/banner.js
CHANGED
|
@@ -3,15 +3,37 @@ const visible = (s) => s.replace(/\x1b\[[0-9;]*m/g, "").length;
|
|
|
3
3
|
function termWidth() {
|
|
4
4
|
return process.stdout.columns ?? 80;
|
|
5
5
|
}
|
|
6
|
-
function infoRows(version, theme, plain, plugins) {
|
|
6
|
+
function infoRows(version, theme, plain, plugins, valueRoom) {
|
|
7
7
|
const dim = (s) => (plain ? s : theme.dim + s + theme.reset);
|
|
8
8
|
const ok = (s) => (plain ? s : theme.success + s + theme.reset);
|
|
9
9
|
const tag = (s) => (plain ? s : theme.tag + s + theme.reset);
|
|
10
|
+
const fit = (s, plain_s) => {
|
|
11
|
+
if (visible(plain_s) <= valueRoom)
|
|
12
|
+
return s;
|
|
13
|
+
if (plugins.length > 1 && plain_s === plugins.join(", ")) {
|
|
14
|
+
let names = plugins;
|
|
15
|
+
do {
|
|
16
|
+
names = names.slice(0, -1);
|
|
17
|
+
const body = names.join(", ") + ` +${plugins.length - names.length}`;
|
|
18
|
+
if (visible(body) <= valueRoom)
|
|
19
|
+
return tag(body);
|
|
20
|
+
} while (names.length > 1);
|
|
21
|
+
const one = plugins[0].slice(0, Math.max(1, valueRoom - 1)) + "\u2026";
|
|
22
|
+
return tag(one);
|
|
23
|
+
}
|
|
24
|
+
return s;
|
|
25
|
+
};
|
|
10
26
|
const rows = [
|
|
11
27
|
["media downloader", ok(`v${version}`)],
|
|
12
28
|
["stdout", ok("data only")],
|
|
13
29
|
];
|
|
14
|
-
|
|
30
|
+
const pluginValue = plugins.length ? plugins.join(", ") : "";
|
|
31
|
+
if (plugins.length) {
|
|
32
|
+
rows.push(["plugins", fit(tag(pluginValue), pluginValue)]);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
rows.push(["plugins", dim("none")]);
|
|
36
|
+
}
|
|
15
37
|
return rows;
|
|
16
38
|
}
|
|
17
39
|
export function renderBanner(version, theme, color = true, plugins = [], width) {
|
|
@@ -19,10 +41,22 @@ export function renderBanner(version, theme, color = true, plugins = [], width)
|
|
|
19
41
|
const paint = (c, s) => (plain ? s : c + s + theme.reset);
|
|
20
42
|
const accent = (s) => paint(theme.accent, s);
|
|
21
43
|
const dim = (s) => paint(theme.dim, s);
|
|
22
|
-
const w = Math.
|
|
23
|
-
const rows = infoRows(version, theme, plain, plugins);
|
|
24
|
-
const LABEL = Math.max(...rows.map(([k]) => k.length)) + 2;
|
|
44
|
+
const w = Math.min(width ?? termWidth(), 60);
|
|
25
45
|
const inner = w - 2;
|
|
46
|
+
const LABEL = 17;
|
|
47
|
+
if (inner - 2 - LABEL < 10) {
|
|
48
|
+
const full = `${GLYPH} tidepull ${version}`;
|
|
49
|
+
const title = visible(full) > inner - 5
|
|
50
|
+
? full.slice(0, Math.max(1, inner - 6)) + "\u2026"
|
|
51
|
+
: full;
|
|
52
|
+
const dash = "\u2500";
|
|
53
|
+
const fill = Math.max(1, inner - visible(title) - 4);
|
|
54
|
+
return [
|
|
55
|
+
accent("\u250c\u2500" + " ") + title + " " + accent(" " + dash.repeat(fill) + "\u2510"),
|
|
56
|
+
accent("\u2514" + dash.repeat(inner) + "\u2518"),
|
|
57
|
+
].join("\n");
|
|
58
|
+
}
|
|
59
|
+
const rows = infoRows(version, theme, plain, plugins, inner - 2 - LABEL);
|
|
26
60
|
const lines = [];
|
|
27
61
|
const title = `${GLYPH} tidepull` + (plain ? ` v${version}` : ` ${paint(theme.dim, `v${version}`)}`);
|
|
28
62
|
const shownTitle = visible(title) > inner - 4 ? `${GLYPH} tidepull` : title;
|
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.
|
|
3
|
+
"version": "0.8.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,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=
|
|
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": {
|