bilisum 1.13.1 → 1.13.2

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.
Files changed (3) hide show
  1. package/README.md +3 -3
  2. package/bin/bilisum.js +184 -60
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -1,11 +1,11 @@
1
1
  # BiliSum
2
2
 
3
- `bilisum` is the npx helper for BiliSum, an AI video summarizer and knowledge-base tool for Bilibili, YouTube, and local videos.
3
+ `bilisum` starts BiliSum from npx with the official Docker image.
4
4
 
5
5
  ```bash
6
6
  npx bilisum
7
- npx bilisum release
7
+ npx bilisum start --port 3839 --pull
8
8
  npx bilisum docker
9
9
  ```
10
10
 
11
- The desktop app is distributed through GitHub Releases. The npx package stays small and points users to the latest release or Docker quick start.
11
+ Docker Desktop is required. The desktop app is still distributed through GitHub Releases.
package/bin/bilisum.js CHANGED
@@ -1,12 +1,13 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- const { execFileSync, spawn } = require("node:child_process");
3
+ const { execFileSync, spawn, spawnSync } = require("node:child_process");
4
4
  const { existsSync, readFileSync } = require("node:fs");
5
5
  const { join } = require("node:path");
6
6
 
7
7
  const RELEASES_URL = "https://github.com/lycohana/BiliSum/releases/latest";
8
8
  const REPO_URL = "https://github.com/lycohana/BiliSum";
9
- const DOCKER_IMAGE = "lycohana/bilisum:latest";
9
+ const DEFAULT_IMAGE = "lycohana/bilisum:latest";
10
+ const DEFAULT_PORT = "3838";
10
11
 
11
12
  function readVersion() {
12
13
  const packagePath = join(__dirname, "..", "package.json");
@@ -23,89 +24,212 @@ function printHelp() {
23
24
  console.log("AI 视频总结与知识库工具,深度优化 B 站体验,同时支持 YouTube 和本地视频。");
24
25
  console.log("");
25
26
  console.log("Usage:");
26
- console.log(" npx bilisum Show this help");
27
- console.log(" npx bilisum --version Print package version");
28
- console.log(" npx bilisum release Open the latest GitHub release");
29
- console.log(" npx bilisum docker Print a Docker quick-start command");
27
+ console.log(" npx bilisum Start BiliSum with Docker");
28
+ console.log(" npx bilisum start [options] Start BiliSum with Docker");
29
+ console.log(" npx bilisum --version Print package version");
30
+ console.log(" npx bilisum release Open the latest GitHub release");
31
+ console.log(" npx bilisum docker Print the Docker command");
32
+ console.log("");
33
+ console.log("Options:");
34
+ console.log(" --port <port> Host port, default 3838");
35
+ console.log(" --image <image> Docker image, default lycohana/bilisum:latest");
36
+ console.log(" --name <name> Container name, default bilisum");
37
+ console.log(" --data <volume-or-path> Data volume/path, default bilisum-data");
38
+ console.log(" --env KEY=VALUE Pass an environment variable");
39
+ console.log(" --pull Pull the image before starting");
40
+ console.log(" --detach, -d Run container in background");
41
+ console.log(" --no-open Do not open the browser");
30
42
  console.log("");
31
43
  console.log(`Latest release: ${RELEASES_URL}`);
32
44
  console.log(`Repository: ${REPO_URL}`);
33
45
  }
34
46
 
35
- function printDockerCommand() {
36
- console.log("Docker quick start:");
47
+ function parseStartOptions(args) {
48
+ const options = {
49
+ port: process.env.BILISUM_PORT || DEFAULT_PORT,
50
+ image: process.env.BILISUM_DOCKER_IMAGE || DEFAULT_IMAGE,
51
+ name: process.env.BILISUM_CONTAINER_NAME || "bilisum",
52
+ data: process.env.BILISUM_DATA || "bilisum-data",
53
+ env: [],
54
+ pull: false,
55
+ detach: false,
56
+ open: true,
57
+ };
58
+
59
+ for (let index = 0; index < args.length; index += 1) {
60
+ const arg = args[index];
61
+ if (arg === "--port" || arg === "-p") {
62
+ options.port = readOptionValue(args, ++index, arg);
63
+ } else if (arg === "--image") {
64
+ options.image = readOptionValue(args, ++index, arg);
65
+ } else if (arg === "--name") {
66
+ options.name = readOptionValue(args, ++index, arg);
67
+ } else if (arg === "--data") {
68
+ options.data = readOptionValue(args, ++index, arg);
69
+ } else if (arg === "--env" || arg === "-e") {
70
+ options.env.push(readOptionValue(args, ++index, arg));
71
+ } else if (arg === "--pull") {
72
+ options.pull = true;
73
+ } else if (arg === "--detach" || arg === "-d") {
74
+ options.detach = true;
75
+ } else if (arg === "--no-open") {
76
+ options.open = false;
77
+ } else {
78
+ throw new Error(`Unknown option: ${arg}`);
79
+ }
80
+ }
81
+
82
+ return options;
83
+ }
84
+
85
+ function readOptionValue(args, index, option) {
86
+ const value = args[index];
87
+ if (!value || value.startsWith("--")) {
88
+ throw new Error(`${option} requires a value`);
89
+ }
90
+ return value;
91
+ }
92
+
93
+ function dockerCommand(options) {
94
+ const args = ["run", "--rm"];
95
+ if (options.detach) {
96
+ args.push("-d");
97
+ } else {
98
+ args.push("-it");
99
+ }
100
+
101
+ args.push("--name", options.name);
102
+ args.push("-p", `${options.port}:3838`);
103
+ args.push("-v", `${options.data}:/data`);
104
+
105
+ const envKeys = [
106
+ "VIDEO_SUM_LLM_ENABLED",
107
+ "VIDEO_SUM_LLM_BASE_URL",
108
+ "VIDEO_SUM_LLM_MODEL",
109
+ "VIDEO_SUM_LLM_API_KEY",
110
+ "VIDEO_SUM_TRANSCRIPTION_PROVIDER",
111
+ "VIDEO_SUM_SILICONFLOW_ASR_BASE_URL",
112
+ "VIDEO_SUM_SILICONFLOW_ASR_MODEL",
113
+ "VIDEO_SUM_SILICONFLOW_ASR_API_KEY",
114
+ "VIDEO_SUM_YTDLP_COOKIES_FILE",
115
+ ];
116
+ for (const key of envKeys) {
117
+ if (process.env[key]) {
118
+ args.push("-e", `${key}=${process.env[key]}`);
119
+ }
120
+ }
121
+ for (const value of options.env) {
122
+ args.push("-e", value);
123
+ }
124
+
125
+ args.push(options.image);
126
+ return args;
127
+ }
128
+
129
+ function printDockerCommand(options = parseStartOptions([])) {
130
+ console.log(["docker", ...dockerCommand(options)].join(" "));
131
+ }
132
+
133
+ function ensureDocker() {
134
+ const result = spawnSync("docker", ["--version"], { stdio: "ignore", windowsHide: true });
135
+ if (result.status !== 0) {
136
+ throw new Error("Docker was not detected. Install Docker Desktop, then run npx bilisum again.");
137
+ }
138
+ }
139
+
140
+ function startService(args) {
141
+ const options = parseStartOptions(args);
142
+ ensureDocker();
143
+
144
+ if (options.pull) {
145
+ execFileSync("docker", ["pull", options.image], { stdio: "inherit" });
146
+ }
147
+
148
+ const url = `http://127.0.0.1:${options.port}`;
149
+ console.log(`Starting BiliSum at ${url}`);
37
150
  console.log("");
38
- console.log(`docker run --rm -it -p 3838:3838 -v bilisum-data:/data ${DOCKER_IMAGE}`);
151
+ printDockerCommand(options);
39
152
  console.log("");
40
- console.log("Then open http://127.0.0.1:3838");
153
+
154
+ const child = spawn("docker", dockerCommand(options), {
155
+ stdio: "inherit",
156
+ windowsHide: false,
157
+ });
158
+
159
+ if (options.open) {
160
+ setTimeout(() => openUrl(url), 1800);
161
+ }
162
+
163
+ child.on("exit", (code, signal) => {
164
+ if (signal) {
165
+ process.kill(process.pid, signal);
166
+ return;
167
+ }
168
+ process.exitCode = code || 0;
169
+ });
41
170
  }
42
171
 
43
172
  function openUrl(url) {
44
173
  const platform = process.platform;
45
174
  const command = platform === "win32" ? "cmd" : platform === "darwin" ? "open" : "xdg-open";
46
175
  const args = platform === "win32" ? ["/c", "start", "", url] : [url];
47
-
48
- try {
49
- const child = spawn(command, args, {
50
- detached: true,
51
- stdio: "ignore",
52
- windowsHide: true,
53
- });
54
- child.on("error", () => {
55
- console.log(url);
56
- });
57
- child.unref();
58
- console.log(`Opened ${url}`);
59
- } catch {
176
+ const child = spawn(command, args, {
177
+ detached: true,
178
+ stdio: "ignore",
179
+ windowsHide: true,
180
+ });
181
+ child.on("error", () => {
60
182
  console.log(url);
61
- }
183
+ });
184
+ child.unref();
62
185
  }
63
186
 
64
- function isDockerAvailable() {
187
+ function main() {
188
+ const [command, ...args] = process.argv.slice(2);
189
+
65
190
  try {
66
- execFileSync("docker", ["--version"], { stdio: "ignore" });
67
- return true;
68
- } catch {
69
- return false;
70
- }
71
- }
191
+ if (!command) {
192
+ startService([]);
193
+ return;
194
+ }
72
195
 
73
- function main() {
74
- const [command] = process.argv.slice(2);
196
+ if (command === "start" || command === "serve") {
197
+ startService(args);
198
+ return;
199
+ }
75
200
 
76
- if (!command || command === "help" || command === "-h" || command === "--help") {
77
- printHelp();
78
- return;
79
- }
201
+ if (command === "help" || command === "-h" || command === "--help") {
202
+ printHelp();
203
+ return;
204
+ }
80
205
 
81
- if (command === "version" || command === "-v" || command === "--version") {
82
- console.log(readVersion());
83
- return;
84
- }
206
+ if (command === "version" || command === "-v" || command === "--version") {
207
+ console.log(readVersion());
208
+ return;
209
+ }
85
210
 
86
- if (command === "release" || command === "releases" || command === "download") {
87
- openUrl(RELEASES_URL);
88
- return;
89
- }
211
+ if (command === "release" || command === "releases" || command === "download") {
212
+ openUrl(RELEASES_URL);
213
+ return;
214
+ }
90
215
 
91
- if (command === "repo" || command === "github") {
92
- openUrl(REPO_URL);
93
- return;
94
- }
216
+ if (command === "repo" || command === "github") {
217
+ openUrl(REPO_URL);
218
+ return;
219
+ }
95
220
 
96
- if (command === "docker") {
97
- printDockerCommand();
98
- if (!isDockerAvailable()) {
99
- console.log("");
100
- console.log("Docker was not detected on this machine.");
221
+ if (command === "docker") {
222
+ printDockerCommand(parseStartOptions(args));
223
+ return;
101
224
  }
102
- return;
103
- }
104
225
 
105
- console.error(`Unknown command: ${command}`);
106
- console.error("");
107
- printHelp();
108
- process.exitCode = 1;
226
+ throw new Error(`Unknown command: ${command}`);
227
+ } catch (error) {
228
+ console.error(error instanceof Error ? error.message : String(error));
229
+ console.error("");
230
+ printHelp();
231
+ process.exitCode = 1;
232
+ }
109
233
  }
110
234
 
111
235
  main();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bilisum",
3
- "version": "1.13.1",
4
- "description": "BiliSum npx launcher for release downloads and Docker usage.",
3
+ "version": "1.13.2",
4
+ "description": "Start BiliSum from npx with the official Docker image.",
5
5
  "bin": {
6
6
  "bilisum": "bin/bilisum.js"
7
7
  },