@kadaliao/geektime-downloader 1.0.0 → 1.0.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 +21 -0
  2. package/download.js +23 -6
  3. package/package.json +5 -4
package/README.md CHANGED
@@ -186,6 +186,27 @@ npx @kadaliao/geektime-downloader \
186
186
 
187
187
  ## 🐛 常见问题
188
188
 
189
+ ### Playwright 浏览器未安装?
190
+
191
+ 如果遇到 "Executable doesn't exist" 错误,说明 Playwright 浏览器未安装。
192
+
193
+ **方式一:自动安装(推荐)**
194
+ ```bash
195
+ # 全局安装会自动安装浏览器
196
+ npm install -g @kadaliao/geektime-downloader
197
+ ```
198
+
199
+ **方式二:手动安装浏览器**
200
+ ```bash
201
+ # 只安装 Chromium
202
+ npx playwright install chromium
203
+
204
+ # 或安装浏览器及系统依赖(Linux/Mac)
205
+ npx playwright install chromium --with-deps
206
+ ```
207
+
208
+ **注意**:使用 `npx` 直接运行时,可能需要先手动安装浏览器。为了更好的体验,建议全局安装。
209
+
189
210
  ### Cookie 和 URL 必须通过命令行传吗?
190
211
 
191
212
  不是。三种方式任选:
package/download.js CHANGED
@@ -885,9 +885,26 @@ async function main(options) {
885
885
  console.log(chalk.gray(`📁 输出目录: ${outputDir}\n`));
886
886
 
887
887
  // 启动浏览器
888
- const browser = await chromium.launch({
889
- headless: options.headless !== false
890
- });
888
+ let browser;
889
+ try {
890
+ browser = await chromium.launch({
891
+ headless: options.headless !== false
892
+ });
893
+ } catch (error) {
894
+ // 检查是否是浏览器未安装的错误
895
+ if (error.message.includes("Executable doesn't exist") || error.message.includes('browsers')) {
896
+ console.error(chalk.red('\n❌ Playwright 浏览器未安装!\n'));
897
+ console.log(chalk.yellow('请运行以下命令安装浏览器:'));
898
+ console.log(chalk.cyan(' npx playwright install chromium\n'));
899
+ console.log(chalk.gray('或者使用 --with-deps 参数安装系统依赖:'));
900
+ console.log(chalk.gray(' npx playwright install chromium --with-deps\n'));
901
+ console.log(chalk.gray('提示:如果你是通过 npx 运行的,建议先全局安装:'));
902
+ console.log(chalk.gray(' npm install -g @kadaliao/geektime-downloader\n'));
903
+ process.exit(1);
904
+ }
905
+ // 其他错误直接抛出
906
+ throw error;
907
+ }
891
908
 
892
909
  // 保存到全局变量,用于信号处理
893
910
  globalBrowser = browser;
@@ -933,7 +950,7 @@ async function main(options) {
933
950
  }
934
951
 
935
952
  // 并发下载
936
- const concurrency = parseInt(options.concurrency) || 3;
953
+ const concurrency = parseInt(options.concurrency) || 5;
937
954
  if (concurrency > 1) {
938
955
  console.log(chalk.gray(`📊 并发数: ${concurrency}\n`));
939
956
  }
@@ -996,13 +1013,13 @@ async function main(options) {
996
1013
  program
997
1014
  .name('geektime-dl')
998
1015
  .description('批量下载极客时间专栏文章为PDF')
999
- .version('1.0.0')
1016
+ .version('1.0.1')
1000
1017
  .option('-u, --url <url>', '专栏文章URL(任意一篇)')
1001
1018
  .option('-c, --cookie <cookie>', 'Cookie字符串(用于认证)')
1002
1019
  .option('-o, --output <dir>', '输出目录', './downloads')
1003
1020
  .option('--headless <boolean>', '无头模式', true)
1004
1021
  .option('--delay <ms>', '每篇文章之间的延迟(ms)', '2000')
1005
- .option('--concurrency <number>', '并发下载数量', '3')
1022
+ .option('--concurrency <number>', '并发下载数量', '5')
1006
1023
  .option('--dry-run', '预览模式,只显示文章列表')
1007
1024
  .option('--limit <number>', '限制下载数量(用于测试)')
1008
1025
  .option('--no-merge', '禁用PDF合并(默认会合并所有文章为一个PDF)')
package/package.json CHANGED
@@ -1,15 +1,16 @@
1
1
  {
2
2
  "name": "@kadaliao/geektime-downloader",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "极客时间专栏文章批量下载工具 - 支持一键下载整个专栏为PDF",
5
5
  "type": "module",
6
6
  "main": "download.js",
7
7
  "bin": {
8
- "geektime-dl": "./download.js"
8
+ "geektime-dl": "download.js"
9
9
  },
10
10
  "scripts": {
11
11
  "start": "node download.js",
12
- "test": "node download.js --dry-run"
12
+ "test": "node download.js --dry-run",
13
+ "postinstall": "npx playwright install chromium --with-deps || echo '⚠️ Playwright安装失败,请手动运行: npx playwright install chromium'"
13
14
  },
14
15
  "keywords": [
15
16
  "geektime",
@@ -22,7 +23,7 @@
22
23
  "license": "MIT",
23
24
  "repository": {
24
25
  "type": "git",
25
- "url": "https://github.com/yourusername/geektime-downloader.git"
26
+ "url": "git+https://github.com/kadaliao/geektime-downloader.git"
26
27
  },
27
28
  "engines": {
28
29
  "node": ">=16.0.0"