@kadaliao/geektime-downloader 1.0.0 → 1.0.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 +21 -0
- package/download.js +21 -4
- 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
|
-
|
|
889
|
-
|
|
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;
|
|
@@ -996,7 +1013,7 @@ async function main(options) {
|
|
|
996
1013
|
program
|
|
997
1014
|
.name('geektime-dl')
|
|
998
1015
|
.description('批量下载极客时间专栏文章为PDF')
|
|
999
|
-
.version('1.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')
|
package/package.json
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kadaliao/geektime-downloader",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "极客时间专栏文章批量下载工具 - 支持一键下载整个专栏为PDF",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "download.js",
|
|
7
7
|
"bin": {
|
|
8
|
-
"geektime-dl": "
|
|
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/
|
|
26
|
+
"url": "git+https://github.com/kadaliao/geektime-downloader.git"
|
|
26
27
|
},
|
|
27
28
|
"engines": {
|
|
28
29
|
"node": ">=16.0.0"
|