@boy-offi9-inc/tidepull 0.14.0 → 0.16.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
@@ -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
 
@@ -263,8 +276,27 @@ export async function main(argv) {
263
276
  : "";
264
277
  if (bannerText)
265
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
+ }
266
287
  if (!urls.length && !values["list-extractors"]) {
267
- log.error("No URL given. Quick start: tidepull <url> ('tidepull --help' for everything)");
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>");
268
300
  return 2;
269
301
  }
270
302
  const tp = createTidepull({
package/dist/plugins.d.ts CHANGED
@@ -4,5 +4,7 @@ export interface TidepullPlugin {
4
4
  name: string;
5
5
  apiVersion: number;
6
6
  extractors?: Extractor[];
7
+ version?: string;
8
+ npmPackage?: string;
7
9
  }
8
10
  export declare const definePlugin: (p: TidepullPlugin) => TidepullPlugin;
package/dist/ui/banner.js CHANGED
@@ -3,19 +3,17 @@ function termWidth() {
3
3
  return process.stdout.columns ?? 80;
4
4
  }
5
5
  const ART_WIDE = [
6
- "___________________ ___________",
7
- "__ /___(_)_____ /________________ ____ /__ /",
8
- "_ __/_ /_ __ /_ _ \\__ __ \\ / / /_ /__ / ",
9
- "/ /_ _ / / /_/ / / __/_ /_/ / /_/ /_ / _ / ",
10
- "\\__/ /_/ \\__,_/ \\___/_ .___/\\__,_/ /_/ /_/ ",
11
- " /_/ ",
6
+ "_____________________ ________ ___________",
7
+ "___ __/__(_)_____ /_______ __ \\___ ____ /__ /",
8
+ "__ / __ /_ __ /_ _ \\_ /_/ / / / /_ /__ / ",
9
+ "_ / _ / / /_/ / / __/ ____// /_/ /_ / _ / ",
10
+ "/_/ /_/ \\__,_/ \\___//_/ \\__,_/ /_/ /_/ ",
12
11
  ];
13
12
  const ART_MID = [
14
- " __ _ __ ____",
15
- " / /_(_)__/ /__ ___ __ __/ / /",
16
- "/ __/ / _ / -_) _ \\/ // / / / ",
17
- "\\__/_/\\_,_/\\__/ .__/\\_,_/_/_/ ",
18
- " /_/ ",
13
+ " _______ __ ___ ____",
14
+ "/_ __(_)__/ /__ / _ \\__ __/ / /",
15
+ " / / / / _ / -_) ___/ // / / / ",
16
+ "/_/ /_/\\_,_/\\__/_/ \\_,_/_/_/ ",
19
17
  ];
20
18
  const COMMANDS = [
21
19
  ["tidepull <url>", "pull best video + audio"],
@@ -75,7 +73,7 @@ export function renderBanner(version, theme, color = true, plugins = [], width)
75
73
  lines.push(" " + accent("tidepull") + dim(" <url> --help for more"));
76
74
  return lines.join("\n");
77
75
  }
78
- const title = `tidepull v${version}`;
76
+ const title = `TidePull v${version}`;
79
77
  return [accent(title), dim("see --help")].join("\n");
80
78
  }
81
79
  export const _visibleWidth = visible;
@@ -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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@boy-offi9-inc/tidepull",
3
- "version": "0.14.0",
3
+ "version": "0.16.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",