@boy-offi9-inc/tidepull 0.13.0 → 0.15.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 +1 -1
- package/dist/main.js +40 -7
- package/dist/plugins.d.ts +2 -0
- package/dist/ui/banner.js +67 -59
- package/dist/updatecheck.d.ts +11 -0
- package/dist/updatecheck.js +67 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -109,7 +109,7 @@ export default definePlugin({
|
|
|
109
109
|
}],
|
|
110
110
|
});
|
|
111
111
|
```
|
|
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`.
|
|
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). Plugins may declare `version` and `npmPackage`; the CLI then checks npm (24h cache, `TIDEPULL_NO_UPDATE_CHECK=1` to disable) and highlights available plugin upgrades next to the core one. 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`.
|
|
113
113
|
|
|
114
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
115
|
|
package/dist/main.js
CHANGED
|
@@ -2,6 +2,7 @@ import { parseArgs } from "node:util";
|
|
|
2
2
|
import { DEFAULT_FORMAT, selectFormats } from "./core/selector.js";
|
|
3
3
|
import { TidepullError, errMsg } from "./core/errors.js";
|
|
4
4
|
import { existsSync, readFileSync } from "node:fs";
|
|
5
|
+
import { spawnSync } from "node:child_process";
|
|
5
6
|
import { isPlaylist } from "./core/pipeline.js";
|
|
6
7
|
import { Archive, configArgs, parseRate, readUrlList } from "./cliutil.js";
|
|
7
8
|
import { cookieJar, loadCookieFile } from "./cookies.js";
|
|
@@ -16,6 +17,18 @@ import { humanRenderer, jsonRenderer } from "./ui/render.js";
|
|
|
16
17
|
import { renderBanner } from "./ui/banner.js";
|
|
17
18
|
import { pickTheme, THEME_NAMES } from "./ui/theme.js";
|
|
18
19
|
import { Spinner } from "./ui/spinner.js";
|
|
20
|
+
import { checkUpdates, renderNotices } from "./updatecheck.js";
|
|
21
|
+
function ffmpegProbe() {
|
|
22
|
+
try {
|
|
23
|
+
const r = spawnSync("ffmpeg", ["-version"], { timeout: 2000, encoding: "utf8" });
|
|
24
|
+
if (r.status !== 0 || !r.stdout)
|
|
25
|
+
return "ffmpeg: not found (merge and -x disabled)";
|
|
26
|
+
return "ffmpeg " + (/ffmpeg version (\S+)/.exec(r.stdout)?.[1] ?? "(unknown version)");
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return "ffmpeg: not found (merge and -x disabled)";
|
|
30
|
+
}
|
|
31
|
+
}
|
|
19
32
|
export const VERSION = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8")).version;
|
|
20
33
|
const HELP = `tidepull ${VERSION}: a minimal media downloader
|
|
21
34
|
|
|
@@ -235,10 +248,6 @@ export async function main(argv) {
|
|
|
235
248
|
log.error(errMsg(e));
|
|
236
249
|
return e instanceof TidepullError ? e.exitCode : 1;
|
|
237
250
|
}
|
|
238
|
-
if (!urls.length && !values["list-extractors"]) {
|
|
239
|
-
log.error("You must provide at least one URL. Try 'tidepull --help'.");
|
|
240
|
-
return 2;
|
|
241
|
-
}
|
|
242
251
|
const headers = {};
|
|
243
252
|
for (const h of values.header ?? []) {
|
|
244
253
|
const i = h.indexOf(":");
|
|
@@ -262,9 +271,33 @@ export async function main(argv) {
|
|
|
262
271
|
return e instanceof TidepullError ? e.exitCode : 1;
|
|
263
272
|
}
|
|
264
273
|
showBanner = interactiveStdout && !values["list-extractors"];
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
274
|
+
const bannerText = showBanner
|
|
275
|
+
? renderBanner(VERSION, theme, !values["no-color"] && shouldUseColor(), plugins.map((p) => p.name)) + "\n"
|
|
276
|
+
: "";
|
|
277
|
+
if (bannerText)
|
|
278
|
+
process.stderr.write(bannerText);
|
|
279
|
+
if (!machineMode && !values.quiet && !process.env.TIDEPULL_NO_UPDATE_CHECK) {
|
|
280
|
+
try {
|
|
281
|
+
const notices = await checkUpdates(VERSION, plugins);
|
|
282
|
+
for (const line of renderNotices(notices))
|
|
283
|
+
log.tag("update", line);
|
|
284
|
+
}
|
|
285
|
+
catch { }
|
|
286
|
+
}
|
|
287
|
+
if (!urls.length && !values["list-extractors"]) {
|
|
288
|
+
const plain = !log.color || theme.name === "mono";
|
|
289
|
+
const paint = (c, s) => (plain ? s : c + s + theme.reset);
|
|
290
|
+
const dim = (s) => paint(theme.dim, s);
|
|
291
|
+
const ok = (s) => paint(theme.success, s);
|
|
292
|
+
const ff = ffmpegProbe();
|
|
293
|
+
process.stderr.write([
|
|
294
|
+
"",
|
|
295
|
+
dim("environment") + " " + ok(ff) + " " + dim(`plugins dir: ${defDir}`) + ` ` + dim(`(${plugins.length} loaded)`),
|
|
296
|
+
dim("more") + " " + dim("'tidepull --help' for every option · github.com/boy-offi9-inc/Tidepull"),
|
|
297
|
+
"",
|
|
298
|
+
].join("\n"));
|
|
299
|
+
log.error("No URL given. Quick start: tidepull <url>");
|
|
300
|
+
return 2;
|
|
268
301
|
}
|
|
269
302
|
const tp = createTidepull({
|
|
270
303
|
http: { headers, headerHosts: values["header-host"] ?? [], userAgent: values["user-agent"], retries: num(values.retries, 3), cookies },
|
package/dist/plugins.d.ts
CHANGED
package/dist/ui/banner.js
CHANGED
|
@@ -1,74 +1,82 @@
|
|
|
1
|
-
const GLYPH = "\u2b22";
|
|
2
1
|
const visible = (s) => s.replace(/\x1b\[[0-9;]*m/g, "").length;
|
|
3
2
|
function termWidth() {
|
|
4
3
|
return process.stdout.columns ?? 80;
|
|
5
4
|
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
}
|
|
37
|
-
return rows;
|
|
5
|
+
const ART_WIDE = [
|
|
6
|
+
"___________________ ___________",
|
|
7
|
+
"__ /___(_)_____ /________________ ____ /__ /",
|
|
8
|
+
"_ __/_ /_ __ /_ _ \\__ __ \\ / / /_ /__ / ",
|
|
9
|
+
"/ /_ _ / / /_/ / / __/_ /_/ / /_/ /_ / _ / ",
|
|
10
|
+
"\\__/ /_/ \\__,_/ \\___/_ .___/\\__,_/ /_/ /_/ ",
|
|
11
|
+
" /_/ ",
|
|
12
|
+
];
|
|
13
|
+
const ART_MID = [
|
|
14
|
+
" __ _ __ ____",
|
|
15
|
+
" / /_(_)__/ /__ ___ __ __/ / /",
|
|
16
|
+
"/ __/ / _ / -_) _ \\/ // / / / ",
|
|
17
|
+
"\\__/_/\\_,_/\\__/ .__/\\_,_/_/_/ ",
|
|
18
|
+
" /_/ ",
|
|
19
|
+
];
|
|
20
|
+
const COMMANDS = [
|
|
21
|
+
["tidepull <url>", "pull best video + audio"],
|
|
22
|
+
["tidepull -F <url>", "list available formats"],
|
|
23
|
+
["tidepull -x <url>", "extract the audio track"],
|
|
24
|
+
["tidepull --live <url>", "record a live stream"],
|
|
25
|
+
];
|
|
26
|
+
const CMD_PAD = 24;
|
|
27
|
+
function pad(s, n) {
|
|
28
|
+
return s + " ".repeat(Math.max(1, n - visible(s)));
|
|
38
29
|
}
|
|
39
30
|
export function renderBanner(version, theme, color = true, plugins = [], width) {
|
|
40
31
|
const plain = !color || !!process.env.NO_COLOR || theme.name === "mono";
|
|
41
32
|
const paint = (c, s) => (plain ? s : c + s + theme.reset);
|
|
42
33
|
const accent = (s) => paint(theme.accent, s);
|
|
43
34
|
const dim = (s) => paint(theme.dim, s);
|
|
44
|
-
const
|
|
45
|
-
const
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
const
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
35
|
+
const ok = (s) => paint(theme.success, s);
|
|
36
|
+
const w = width ?? termWidth();
|
|
37
|
+
const commandBlock = (colWidth, rows = COMMANDS) => rows.map(([cmd, desc]) => {
|
|
38
|
+
const space = cmd.indexOf(" ");
|
|
39
|
+
const name = space < 0 ? cmd : cmd.slice(0, space);
|
|
40
|
+
const rest = space < 0 ? "" : cmd.slice(space);
|
|
41
|
+
return " " + accent(name) + pad(dim(rest), colWidth - visible(name)) + dim(desc);
|
|
42
|
+
});
|
|
43
|
+
const PLUGIN_LABEL = "plugins: ";
|
|
44
|
+
let pluginValue = plugins.length ? plugins.join(", ") : "none";
|
|
45
|
+
const room = w - 2 - visible(`v${version}`) - 2 - PLUGIN_LABEL.length;
|
|
46
|
+
if (visible(pluginValue) > room) {
|
|
47
|
+
let names = plugins;
|
|
48
|
+
while (names.length > 1) {
|
|
49
|
+
names = names.slice(0, -1);
|
|
50
|
+
const body = names.join(", ") + ` +${plugins.length - names.length}`;
|
|
51
|
+
if (visible(body) <= room) {
|
|
52
|
+
pluginValue = body;
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (visible(pluginValue) > room)
|
|
57
|
+
pluginValue = pluginValue.slice(0, Math.max(1, room - 1)) + "\u2026";
|
|
58
|
+
}
|
|
59
|
+
const pluginLine = dim(PLUGIN_LABEL) + (plugins.length ? ok(pluginValue) : dim(pluginValue));
|
|
60
|
+
if (w >= 54) {
|
|
61
|
+
const lines = ART_WIDE.map((l) => accent(l));
|
|
62
|
+
lines.push("");
|
|
63
|
+
lines.push(" " + dim("media downloader") + " " + ok(`v${version}`));
|
|
64
|
+
lines.push(" " + pluginLine);
|
|
65
|
+
lines.push("");
|
|
66
|
+
lines.push(...commandBlock(CMD_PAD));
|
|
67
|
+
lines.push("");
|
|
68
|
+
lines.push(" " + dim("tidepull --help for everything else"));
|
|
69
|
+
return lines.join("\n");
|
|
58
70
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
lines.push(accent("\u250c\u2500" + " ") + shownTitle + " " + accent(" " + dash.repeat(fill) + "\u2510"));
|
|
66
|
-
for (const [key, value] of rows) {
|
|
67
|
-
const pad = Math.max(0, inner - 2 - LABEL - visible(value));
|
|
68
|
-
lines.push(accent("\u2502") + " " + dim(key.padEnd(LABEL)) + value + " ".repeat(pad) + " " + accent("\u2502"));
|
|
71
|
+
if (w >= 34) {
|
|
72
|
+
const lines = ART_MID.map((l) => accent(" " + l));
|
|
73
|
+
lines.push("");
|
|
74
|
+
lines.push(" " + ok(`v${version}`) + " " + pluginLine);
|
|
75
|
+
lines.push(" " + accent("tidepull") + dim(" <url> --help for more"));
|
|
76
|
+
return lines.join("\n");
|
|
69
77
|
}
|
|
70
|
-
|
|
71
|
-
return
|
|
78
|
+
const title = `tidepull v${version}`;
|
|
79
|
+
return [accent(title), dim("see --help")].join("\n");
|
|
72
80
|
}
|
|
73
81
|
export const _visibleWidth = visible;
|
|
74
82
|
export { termWidth };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { TidepullPlugin } from "./plugins.js";
|
|
2
|
+
export declare function cachePath(env?: NodeJS.ProcessEnv): string;
|
|
3
|
+
export declare function isNewer(a: string, b: string): boolean;
|
|
4
|
+
export interface UpdateNotice {
|
|
5
|
+
pkg: string;
|
|
6
|
+
from: string;
|
|
7
|
+
to: string;
|
|
8
|
+
install: string;
|
|
9
|
+
}
|
|
10
|
+
export declare function checkUpdates(current: string, plugins: TidepullPlugin[], env?: NodeJS.ProcessEnv): Promise<UpdateNotice[]>;
|
|
11
|
+
export declare function renderNotices(notices: UpdateNotice[]): string[];
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
const REG = "https://registry.npmjs.org";
|
|
5
|
+
const TTL = 24 * 60 * 60 * 1000;
|
|
6
|
+
export function cachePath(env = process.env) {
|
|
7
|
+
return path.join(env.XDG_CACHE_HOME ?? path.join(os.homedir(), ".cache"), "tidepull", "update-check.json");
|
|
8
|
+
}
|
|
9
|
+
export function isNewer(a, b) {
|
|
10
|
+
const num = (v) => v.split("-")[0].split(".").map(Number);
|
|
11
|
+
const pa = num(a), pb = num(b);
|
|
12
|
+
for (let i = 0; i < 3; i++)
|
|
13
|
+
if ((pa[i] || 0) !== (pb[i] || 0))
|
|
14
|
+
return (pa[i] || 0) > (pb[i] || 0);
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
async function latest(pkg, signal) {
|
|
18
|
+
const res = await fetch(`${REG}/${encodeURIComponent(pkg)}/latest`, { signal });
|
|
19
|
+
if (!res.ok)
|
|
20
|
+
return undefined;
|
|
21
|
+
return (await res.json()).version;
|
|
22
|
+
}
|
|
23
|
+
export async function checkUpdates(current, plugins, env = process.env) {
|
|
24
|
+
if (env.TIDEPULL_NO_UPDATE_CHECK)
|
|
25
|
+
return [];
|
|
26
|
+
const targets = plugins.filter((p) => typeof p.npmPackage === "string" && typeof p.version === "string");
|
|
27
|
+
let cache = {};
|
|
28
|
+
try {
|
|
29
|
+
cache = JSON.parse(readFileSync(cachePath(env), "utf8"));
|
|
30
|
+
}
|
|
31
|
+
catch { }
|
|
32
|
+
const fresh = typeof cache.t === "number" && Date.now() - cache.t < TTL;
|
|
33
|
+
if (!fresh) {
|
|
34
|
+
const ac = new AbortController();
|
|
35
|
+
const timer = setTimeout(() => ac.abort(), 1500);
|
|
36
|
+
try {
|
|
37
|
+
const pkgs = ["@boy-offi9-inc/tidepull", ...targets.map((p) => p.npmPackage)];
|
|
38
|
+
const results = await Promise.all(pkgs.map((p) => latest(p, ac.signal)));
|
|
39
|
+
cache = { t: Date.now(), core: results[0], plugins: {} };
|
|
40
|
+
targets.forEach((p, i) => { if (results[i + 1])
|
|
41
|
+
cache.plugins[p.npmPackage] = results[i + 1]; });
|
|
42
|
+
try {
|
|
43
|
+
mkdirSync(path.dirname(cachePath(env)), { recursive: true });
|
|
44
|
+
writeFileSync(cachePath(env), JSON.stringify(cache));
|
|
45
|
+
}
|
|
46
|
+
catch { }
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
return [];
|
|
50
|
+
}
|
|
51
|
+
finally {
|
|
52
|
+
clearTimeout(timer);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
const out = [];
|
|
56
|
+
if (cache.core && isNewer(cache.core, current))
|
|
57
|
+
out.push({ pkg: "tidepull", from: current, to: cache.core, install: "npm i -g @boy-offi9-inc/tidepull" });
|
|
58
|
+
for (const p of targets) {
|
|
59
|
+
const to = cache.plugins?.[p.npmPackage];
|
|
60
|
+
if (to && isNewer(to, p.version))
|
|
61
|
+
out.push({ pkg: p.npmPackage, from: p.version, to, install: `npm i ${p.npmPackage}` });
|
|
62
|
+
}
|
|
63
|
+
return out;
|
|
64
|
+
}
|
|
65
|
+
export function renderNotices(notices) {
|
|
66
|
+
return notices.map((u) => `update available: ${u.pkg} ${u.to} (you have ${u.from}) — run: ${u.install}`);
|
|
67
|
+
}
|
package/package.json
CHANGED