@cloud411716/fancy-webnovel 0.1.50 → 0.1.52
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/package.json
CHANGED
|
@@ -178,11 +178,16 @@ function spawnScraper(platform, length, outDir) {
|
|
|
178
178
|
const args = scraperArgs(platform, length, outDir);
|
|
179
179
|
const ports = ['9222', '9223'];
|
|
180
180
|
let portIdx = 0;
|
|
181
|
+
let dots = 0;
|
|
182
|
+
const interval = setInterval(() => {
|
|
183
|
+
dots++;
|
|
184
|
+
process.stderr.write('.');
|
|
185
|
+
}, 3000);
|
|
181
186
|
|
|
182
187
|
function tryPort(port) {
|
|
188
|
+
process.stderr.write(`\n → 端口 ${port} ...`);
|
|
183
189
|
const scraperScript = join(dirname(fileURLToPath(import.meta.url)), 'scrapers', args.script);
|
|
184
190
|
const fullArgs = ['--port', port, ...args.extra];
|
|
185
|
-
// stderr 透传到父进程 stderr,用户实时看到进度
|
|
186
191
|
const p = spawn('node', [scraperScript, ...fullArgs], {
|
|
187
192
|
timeout: 120000,
|
|
188
193
|
stdio: ['ignore', 'pipe', 'inherit'],
|
|
@@ -190,50 +195,56 @@ function spawnScraper(platform, length, outDir) {
|
|
|
190
195
|
let out = '';
|
|
191
196
|
p.stdout.on('data', d => { out += d.toString(); });
|
|
192
197
|
p.on('close', (code) => {
|
|
198
|
+
clearInterval(interval);
|
|
193
199
|
if (code === 0 && out.trim()) {
|
|
194
200
|
resolve({ ok: true, output: out, stderr: '' });
|
|
195
201
|
} else if (portIdx < ports.length - 1) {
|
|
196
202
|
portIdx++;
|
|
203
|
+
process.stderr.write(` (失败)\n`);
|
|
197
204
|
tryPort(ports[portIdx]);
|
|
198
205
|
} else {
|
|
199
|
-
|
|
206
|
+
process.stderr.write(` (失败)\n`);
|
|
200
207
|
const errTail = out.trimEnd().slice(-300);
|
|
201
208
|
resolve({ ok: false, output: out, error: errTail || `exit ${code}` });
|
|
202
209
|
}
|
|
203
210
|
});
|
|
204
211
|
p.on('error', (e) => {
|
|
205
|
-
|
|
206
|
-
|
|
212
|
+
clearInterval(interval);
|
|
213
|
+
if (portIdx < ports.length - 1) {
|
|
214
|
+
portIdx++;
|
|
215
|
+
tryPort(ports[portIdx]);
|
|
216
|
+
} else {
|
|
217
|
+
resolve({ ok: false, output: '', error: e.message });
|
|
218
|
+
}
|
|
207
219
|
});
|
|
208
220
|
}
|
|
209
221
|
tryPort(ports[portIdx]);
|
|
210
222
|
});
|
|
211
223
|
}
|
|
212
224
|
|
|
213
|
-
function scraperArgs(platform, length) {
|
|
225
|
+
function scraperArgs(platform, length, outDir) {
|
|
214
226
|
switch (platform) {
|
|
215
227
|
case 'fanqie':
|
|
216
228
|
return {
|
|
217
229
|
script: 'fanqie-rank-scraper.cjs',
|
|
218
|
-
extra: ['--channel', 'all', '--top', '20'],
|
|
230
|
+
extra: ['--channel', 'all', '--top', '20', '--outdir', outDir],
|
|
219
231
|
};
|
|
220
232
|
case 'jinjiang':
|
|
221
233
|
return {
|
|
222
234
|
script: 'jjwxc-rank-scraper.cjs',
|
|
223
|
-
extra: ['--type', '12'],
|
|
235
|
+
extra: ['--type', '12', '--outdir', outDir],
|
|
224
236
|
};
|
|
225
237
|
case 'zhihu':
|
|
226
238
|
return {
|
|
227
239
|
script: 'zhihu-rank-scraper.cjs',
|
|
228
|
-
extra: ['--length', length === 'short' ? 'short' : 'long'],
|
|
240
|
+
extra: ['--length', length === 'short' ? 'short' : 'long', '--outdir', outDir],
|
|
229
241
|
};
|
|
230
242
|
case 'qimao':
|
|
231
243
|
return {
|
|
232
244
|
script: 'qimao-rank-scraper.cjs',
|
|
233
|
-
extra: ['--channel', length === 'short' ? 'female' : 'male', '--type', 'hot'],
|
|
245
|
+
extra: ['--channel', length === 'short' ? 'female' : 'male', '--type', 'hot', '--outdir', outDir],
|
|
234
246
|
};
|
|
235
247
|
case 'dianzhong':
|
|
236
|
-
// 点众没有 scraper,降级为 browser stub
|
|
237
248
|
return { script: null, extra: [] };
|
|
238
249
|
default:
|
|
239
250
|
return { script: null, extra: [] };
|
|
@@ -387,7 +398,7 @@ async function main() {
|
|
|
387
398
|
scanFiles = scrapeFiles.map(f => f.file);
|
|
388
399
|
} else {
|
|
389
400
|
// 其他平台:spawn scraper 进程
|
|
390
|
-
const cfg = scraperArgs(platform, length);
|
|
401
|
+
const cfg = scraperArgs(platform, length, scanDir);
|
|
391
402
|
if (!cfg.script) {
|
|
392
403
|
console.error(` ❌ 平台 ${platform} 暂不支持采集`);
|
|
393
404
|
process.exit(1);
|