tt-help-cli-ycl 1.3.34 → 1.3.36

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 (62) hide show
  1. package/README.md +33 -17
  2. package/cli.js +9 -9
  3. package/package.json +49 -47
  4. package/scripts/run-explore copy.bat +101 -101
  5. package/scripts/run-explore.bat +132 -132
  6. package/scripts/run-explore.ps1 +157 -157
  7. package/scripts/run-explore.sh +119 -119
  8. package/scripts/test-captcha-lib.mjs +68 -0
  9. package/scripts/test-captcha.mjs +81 -0
  10. package/scripts/test-incognito-lib.mjs +36 -0
  11. package/scripts/test-login-state.mjs +128 -0
  12. package/scripts/test-safe-click.mjs +45 -0
  13. package/scripts/test-watch-db-smoke.mjs +246 -0
  14. package/src/cli/attach.js +240 -180
  15. package/src/cli/auto.js +265 -240
  16. package/src/cli/comments.js +301 -210
  17. package/src/cli/config.js +170 -152
  18. package/src/cli/db-import.js +51 -0
  19. package/src/cli/explore.js +519 -488
  20. package/src/cli/info.js +88 -88
  21. package/src/cli/open.js +111 -111
  22. package/src/cli/progress.js +111 -111
  23. package/src/cli/refresh.js +288 -216
  24. package/src/cli/scrape.js +47 -47
  25. package/src/cli/utils.js +18 -18
  26. package/src/cli/videos.js +41 -41
  27. package/src/cli/videostats.js +140 -25
  28. package/src/cli/watch.js +30 -31
  29. package/src/lib/args.js +766 -722
  30. package/src/lib/browser/anti-detect.js +23 -23
  31. package/src/lib/browser/cdp.js +261 -261
  32. package/src/lib/browser/health-checker.js +114 -114
  33. package/src/lib/browser/launch.js +43 -43
  34. package/src/lib/browser/page.js +183 -183
  35. package/src/lib/constants.js +238 -216
  36. package/src/lib/delay.js +54 -54
  37. package/src/lib/explore-fetch.js +118 -118
  38. package/src/lib/fetcher.js +45 -45
  39. package/src/lib/filter.js +66 -66
  40. package/src/lib/io.js +54 -54
  41. package/src/lib/output.js +80 -80
  42. package/src/lib/page-error-detector.js +105 -105
  43. package/src/lib/parse-ssr.mjs +69 -69
  44. package/src/lib/parser.js +47 -47
  45. package/src/lib/retry.js +45 -45
  46. package/src/lib/scrape.js +89 -89
  47. package/src/lib/tiktok-scraper.mjs +232 -194
  48. package/src/lib/url.js +52 -52
  49. package/src/main.js +70 -48
  50. package/src/results/user-videos-bar.lar.lar.moeta.json +37 -0
  51. package/src/scraper/auto-core.js +203 -203
  52. package/src/scraper/core.js +211 -211
  53. package/src/scraper/explore-core.js +177 -167
  54. package/src/scraper/modules/captcha-handler.js +114 -114
  55. package/src/scraper/modules/follow-extractor.js +194 -194
  56. package/src/scraper/modules/guess-extractor.js +51 -51
  57. package/src/scraper/modules/page-helpers.js +48 -48
  58. package/src/scraper/refresh-core.js +179 -179
  59. package/src/videos/core.js +125 -125
  60. package/src/watch/data-store.js +2364 -1030
  61. package/src/watch/public/index.html +1494 -753
  62. package/src/watch/server.js +628 -933
package/src/lib/args.js CHANGED
@@ -1,722 +1,766 @@
1
- import { readFileSync } from "fs";
2
- import { server as defaultServer } from "./constants.js";
3
-
4
- const PRESETS = ["fast", "normal", "slow", "stealth"];
5
-
6
- function parseScrapeArgs(args) {
7
- let scrapeUrl = null;
8
- let scrapePreset = null;
9
- let scrapeMaxVideos = 20;
10
- let scrapeMaxComments = 999;
11
- let scrapeMaxGuess = 10;
12
- let scrapeSwitchDelay = null;
13
- let scrapeCommentDelay = null;
14
- let outputFile = null;
15
-
16
- const positional = [];
17
-
18
- for (let i = 0; i < args.length; i++) {
19
- const arg = args[i];
20
- if (arg === "-o" || arg === "--output") {
21
- outputFile = args[++i];
22
- } else if (arg === "--switch-delay") {
23
- scrapeSwitchDelay = parseInt(args[++i]) || null;
24
- } else if (arg === "--comment-delay") {
25
- scrapeCommentDelay = parseInt(args[++i]) || null;
26
- } else {
27
- positional.push(arg);
28
- }
29
- }
30
-
31
- scrapeUrl = positional[0] || null;
32
-
33
- if (positional[1]) {
34
- if (PRESETS.includes(positional[1].toLowerCase())) {
35
- scrapePreset = positional[1].toLowerCase();
36
- scrapeMaxVideos = parseInt(positional[2]) || 20;
37
- scrapeMaxComments = parseInt(positional[3]) || 999;
38
- scrapeMaxGuess = parseInt(positional[4]) || 10;
39
- } else {
40
- scrapeMaxVideos = parseInt(positional[1]) || 20;
41
- scrapeMaxComments = parseInt(positional[2]) || 999;
42
- scrapeMaxGuess = parseInt(positional[3]) || 10;
43
- }
44
- }
45
-
46
- return {
47
- subcommand: "scrape",
48
- scrapeUrl,
49
- scrapePreset,
50
- scrapeMaxVideos,
51
- scrapeMaxComments,
52
- scrapeMaxGuess,
53
- scrapeSwitchDelay,
54
- scrapeCommentDelay,
55
- outputFile,
56
- urls: [],
57
- outputFormat: "json",
58
- exploreCount: 0,
59
- showConfig: false,
60
- showHelp: false,
61
- customProxy: null,
62
- configAction: null,
63
- configValue: null,
64
- pipeMode: false,
65
- filterStr: null,
66
- };
67
- }
68
-
69
- function parseAutoArgs(args) {
70
- let autoCollectMax = 1;
71
- let autoScrapeDepth = 50;
72
- let autoMaxComments = 200;
73
- let autoMaxGuess = 10;
74
- let autoPreset = "fast";
75
- let autoSwitchDelay = null;
76
- let autoCommentDelay = null;
77
- let serverUrl = defaultServer;
78
- let autoEnableFollow = false;
79
- let autoMaxFollowing = 200;
80
- let autoMaxFollowers = 200;
81
-
82
- const positional = [];
83
- const PRESETS = ["fast", "normal", "slow", "stealth"];
84
-
85
- for (let i = 0; i < args.length; i++) {
86
- const arg = args[i];
87
- if (arg === "--server") {
88
- serverUrl = args[++i];
89
- } else if (arg === "--switch-delay") {
90
- autoSwitchDelay = parseInt(args[++i]) || null;
91
- } else if (arg === "--comment-delay") {
92
- autoCommentDelay = parseInt(args[++i]) || null;
93
- } else if (arg === "--enable-follow") {
94
- autoEnableFollow = true;
95
- } else if (arg === "--max-following") {
96
- autoMaxFollowing = parseInt(args[++i]) || 200;
97
- } else if (arg === "--max-followers") {
98
- autoMaxFollowers = parseInt(args[++i]) || 200;
99
- } else {
100
- positional.push(arg);
101
- }
102
- }
103
-
104
- // 收集用户名(非 preset、非数字的都是用户名)
105
- const usernames = [];
106
- let j = 0;
107
- while (
108
- j < positional.length &&
109
- !PRESETS.includes(positional[j]?.toLowerCase()) &&
110
- isNaN(positional[j])
111
- ) {
112
- usernames.push(positional[j].replace("@", ""));
113
- j++;
114
- }
115
-
116
- // preset
117
- if (j < positional.length && PRESETS.includes(positional[j].toLowerCase())) {
118
- autoPreset = positional[j].toLowerCase();
119
- j++;
120
- autoCollectMax = parseInt(positional[j]) || 1;
121
- j++;
122
- autoScrapeDepth = parseInt(positional[j]) || 50;
123
- j++;
124
- autoMaxComments = parseInt(positional[j]) || 200;
125
- j++;
126
- autoMaxGuess = parseInt(positional[j]) || 10;
127
- j++;
128
- } else if (usernames.length > 0) {
129
- autoCollectMax = parseInt(positional[j]) || 1;
130
- j++;
131
- autoScrapeDepth = parseInt(positional[j]) || 50;
132
- j++;
133
- autoMaxComments = parseInt(positional[j]) || 200;
134
- j++;
135
- autoMaxGuess = parseInt(positional[j]) || 10;
136
- }
137
-
138
- return {
139
- subcommand: "auto",
140
- autoUsernames: usernames,
141
- autoCollectMax,
142
- autoScrapeDepth,
143
- autoMaxComments,
144
- autoMaxGuess,
145
- autoPreset,
146
- autoSwitchDelay,
147
- autoCommentDelay,
148
- serverUrl,
149
- autoEnableFollow,
150
- autoMaxFollowing,
151
- autoMaxFollowers,
152
- urls: [],
153
- outputFormat: "json",
154
- exploreCount: 0,
155
- showConfig: false,
156
- showHelp: false,
157
- customProxy: null,
158
- configAction: null,
159
- configValue: null,
160
- pipeMode: false,
161
- filterStr: null,
162
- };
163
- }
164
-
165
- function parseExploreArgs(args) {
166
- let serverUrl = defaultServer;
167
- let explorePreset = "normal";
168
- let exploreMaxComments = 10;
169
- let exploreMaxGuess = 0;
170
- let exploreEnableFollow = true;
171
- let exploreMaxFollowing = 50;
172
- let exploreMaxFollowers = 50;
173
- let exploreLocation = "PL,NL,BE,DE,FR,IT,ES,IE,AT";
174
- let exploreJobLocations = null;
175
- let exploreMaxUsers = 0;
176
- let explorePort = null;
177
- let exploreBasePort = null;
178
- let explorePortCount = null;
179
- let exploreUserId = null;
180
- let exploreMaxVideos = 16;
181
-
182
- const positional = [];
183
- const PRESETS = ["fast", "normal", "slow", "stealth"];
184
-
185
- for (let i = 0; i < args.length; i++) {
186
- const arg = args[i];
187
- if (arg === "--server") {
188
- serverUrl = args[++i];
189
- } else if (arg === "--max-comments") {
190
- exploreMaxComments = parseInt(args[++i]) || 0;
191
- } else if (arg === "--max-guess") {
192
- exploreMaxGuess = parseInt(args[++i]) || 0;
193
- } else if (arg === "--location") {
194
- exploreLocation = args[++i];
195
- } else if (arg === "--job-locations") {
196
- exploreJobLocations = args[++i];
197
- } else if (arg === "--enable-follow") {
198
- exploreEnableFollow = true;
199
- } else if (arg === "--disable-follow") {
200
- exploreEnableFollow = false;
201
- } else if (arg === "--max-following") {
202
- exploreMaxFollowing = parseInt(args[++i]) || 50;
203
-
204
- exploreMaxFollowers = parseInt(args[++i]) || 50;
205
- } else if (arg === "--max-users") {
206
- exploreMaxUsers = parseInt(args[++i]) || 0;
207
- } else if (arg === "--port") {
208
- explorePort = parseInt(args[++i]) || 9222;
209
- } else if (arg === "--base-port") {
210
- exploreBasePort = parseInt(args[++i]) || 9222;
211
- } else if (arg === "--port-count") {
212
- explorePortCount = parseInt(args[++i]) || 10;
213
- } else if (arg === "--user-id") {
214
- exploreUserId = args[++i];
215
- } else if (arg === "--max-videos") {
216
- exploreMaxVideos = parseInt(args[++i]) || 16;
217
- } else {
218
- positional.push(arg);
219
- }
220
- }
221
-
222
- const usernames = [];
223
- let j = 0;
224
- while (
225
- j < positional.length &&
226
- !PRESETS.includes(positional[j]?.toLowerCase()) &&
227
- isNaN(positional[j])
228
- ) {
229
- usernames.push(positional[j].replace("@", ""));
230
- j++;
231
- }
232
-
233
- if (j < positional.length && PRESETS.includes(positional[j].toLowerCase())) {
234
- explorePreset = positional[j].toLowerCase();
235
- j++;
236
- }
237
-
238
- return {
239
- subcommand: "explore",
240
- exploreUsernames: usernames,
241
- explorePreset,
242
- exploreMaxComments,
243
- exploreMaxGuess,
244
- exploreEnableFollow,
245
- exploreMaxFollowing,
246
- exploreMaxFollowers,
247
- exploreLocation,
248
- exploreJobLocations,
249
- serverUrl,
250
- exploreMaxUsers,
251
- explorePort,
252
- exploreBasePort,
253
- explorePortCount,
254
- exploreUserId,
255
- exploreMaxVideos,
256
- urls: [],
257
- outputFormat: "json",
258
- exploreCount: 0,
259
- showConfig: false,
260
- showHelp: false,
261
- customProxy: null,
262
- configAction: null,
263
- configValue: null,
264
- pipeMode: false,
265
- filterStr: null,
266
- };
267
- }
268
-
269
- function parseVideosArgs(args) {
270
- let videosUsername = null;
271
- let videosMax = 5;
272
- let outputFile = null;
273
-
274
- const positional = [];
275
-
276
- for (let i = 0; i < args.length; i++) {
277
- const arg = args[i];
278
- if (arg === "-o" || arg === "--output") {
279
- outputFile = args[++i];
280
- } else {
281
- positional.push(arg);
282
- }
283
- }
284
-
285
- videosUsername = positional[0] ? positional[0].replace("@", "") : null;
286
- videosMax = parseInt(positional[1]) || 5;
287
-
288
- return {
289
- subcommand: "videos",
290
- videosUsername,
291
- videosMax,
292
- outputFile,
293
- urls: [],
294
- outputFormat: "json",
295
- exploreCount: 0,
296
- showConfig: false,
297
- showHelp: false,
298
- customProxy: null,
299
- configAction: null,
300
- configValue: null,
301
- pipeMode: false,
302
- filterStr: null,
303
- };
304
- }
305
-
306
- function parseInfoArgs(args) {
307
- let onlyVideo = false;
308
- const urls = [];
309
-
310
- for (let i = 0; i < args.length; i++) {
311
- const arg = args[i];
312
- if (arg === "--onlyvideo") {
313
- onlyVideo = true;
314
- } else if (!arg.startsWith("--")) {
315
- urls.push(arg);
316
- }
317
- }
318
-
319
- return {
320
- subcommand: "info",
321
- infoUrls: urls,
322
- infoOnlyVideo: onlyVideo,
323
- outputFile: null,
324
- outputFormat: "json",
325
- exploreCount: 0,
326
- showConfig: false,
327
- showHelp: false,
328
- showVersion: false,
329
- customProxy: null,
330
- configAction: null,
331
- configKey: null,
332
- configValue: null,
333
- pipeMode: false,
334
- filterStr: null,
335
- };
336
- }
337
-
338
- function parseWatchArgs(args) {
339
- let outputFile = "./result.json";
340
- let watchPort = 3001;
341
-
342
- for (let i = 0; i < args.length; i++) {
343
- const arg = args[i];
344
- if (arg === "-o" || arg === "--output") {
345
- outputFile = args[++i];
346
- } else if (arg === "-p") {
347
- watchPort = parseInt(args[++i]) || 3001;
348
- }
349
- }
350
-
351
- return {
352
- subcommand: "watch",
353
- outputFile,
354
- watchPort,
355
- urls: [],
356
- outputFormat: "json",
357
- exploreCount: 0,
358
- showConfig: false,
359
- showHelp: false,
360
- customProxy: null,
361
- configAction: null,
362
- configValue: null,
363
- pipeMode: false,
364
- filterStr: null,
365
- };
366
- }
367
-
368
- function parseRefreshArgs(args) {
369
- let serverUrl = defaultServer;
370
- let explorePreset = "normal";
371
- let exploreMaxComments = 10;
372
- let exploreMaxGuess = 0;
373
- let explorePort = null;
374
- let exploreProfile = null;
375
- let exploreUserId = null;
376
-
377
- for (let i = 0; i < args.length; i++) {
378
- const arg = args[i];
379
- if (arg === "--server") {
380
- serverUrl = args[++i];
381
- } else if (arg === "--comments") {
382
- exploreMaxComments = parseInt(args[++i]) || 10;
383
- } else if (arg === "--guess") {
384
- exploreMaxGuess = parseInt(args[++i]) || 0;
385
- } else if (arg === "--preset") {
386
- explorePreset = args[++i];
387
- } else if (arg === "--port") {
388
- explorePort = parseInt(args[++i]) || 9222;
389
- } else if (arg === "--profile") {
390
- exploreProfile = args[++i];
391
- } else if (arg === "--user-id") {
392
- exploreUserId = args[++i];
393
- }
394
- }
395
-
396
- return {
397
- subcommand: "refresh",
398
- explorePreset,
399
- exploreMaxComments,
400
- exploreMaxGuess,
401
- explorePort,
402
- exploreProfile,
403
- exploreUserId,
404
- serverUrl,
405
- urls: [],
406
- outputFormat: "json",
407
- exploreCount: 0,
408
- showConfig: false,
409
- showHelp: false,
410
- customProxy: null,
411
- configAction: null,
412
- configValue: null,
413
- pipeMode: false,
414
- filterStr: null,
415
- };
416
- }
417
-
418
- function parseAttachArgs(args) {
419
- let parallel = 1;
420
- let interval = 10;
421
- let serverUrl = defaultServer;
422
-
423
- for (let i = 0; i < args.length; i++) {
424
- const arg = args[i];
425
- if (arg === "-p" || arg === "--parallel") {
426
- parallel = parseInt(args[++i], 10) || 1;
427
- } else if (arg === "-i" || arg === "--interval") {
428
- interval = parseInt(args[++i], 10) || 10;
429
- } else if (arg === "-s" || arg === "--server") {
430
- serverUrl = args[++i];
431
- }
432
- }
433
-
434
- return {
435
- subcommand: "attach",
436
- attachParallel: parallel,
437
- attachInterval: interval,
438
- serverUrl,
439
- urls: [],
440
- outputFormat: "json",
441
- exploreCount: 0,
442
- showConfig: false,
443
- showHelp: false,
444
- customProxy: null,
445
- configAction: null,
446
- configValue: null,
447
- pipeMode: false,
448
- filterStr: null,
449
- };
450
- }
451
-
452
- function parseOpenArgs(args) {
453
- let openPort = null;
454
- let openList = false;
455
-
456
- for (let i = 0; i < args.length; i++) {
457
- const arg = args[i];
458
- if (arg === "--list") {
459
- openList = true;
460
- } else if (!arg.startsWith("-")) {
461
- openPort = arg;
462
- }
463
- }
464
-
465
- return {
466
- subcommand: "open",
467
- openPort,
468
- openList,
469
- urls: [],
470
- outputFormat: "json",
471
- exploreCount: 0,
472
- showConfig: false,
473
- showHelp: false,
474
- customProxy: null,
475
- configAction: null,
476
- configValue: null,
477
- pipeMode: false,
478
- filterStr: null,
479
- };
480
- }
481
-
482
- function parseVideoStatsArgs(args) {
483
- let statsFile = null;
484
- let statsParallel = 3;
485
-
486
- for (let i = 0; i < args.length; i++) {
487
- const arg = args[i];
488
- if (arg === "-p" || arg === "--parallel") {
489
- statsParallel = parseInt(args[++i]) || 3;
490
- } else if (!arg.startsWith("-")) {
491
- statsFile = args[i] || null;
492
- }
493
- }
494
-
495
- return {
496
- subcommand: "videostats",
497
- statsFile,
498
- statsParallel,
499
- commentsUrl: null,
500
- commentsMax: 20,
501
- commentsSave: false,
502
- commentsParallel: 1,
503
- commentsInterval: 10,
504
- commentsServer: defaultServer,
505
- urls: [],
506
- outputFormat: "json",
507
- exploreCount: 0,
508
- showConfig: false,
509
- showHelp: false,
510
- customProxy: null,
511
- configAction: null,
512
- configValue: null,
513
- pipeMode: false,
514
- filterStr: null,
515
- };
516
- }
517
-
518
- function parseCommentsArgs(args) {
519
- let commentsUrl = null;
520
- let commentsMax = 20;
521
- let commentsSave = false;
522
- let commentsParallel = 1;
523
- let commentsInterval = 10;
524
- let commentsServer = defaultServer;
525
-
526
- const positional = [];
527
-
528
- for (let i = 0; i < args.length; i++) {
529
- const arg = args[i];
530
- if (arg === "--save") {
531
- commentsSave = true;
532
- } else if (arg === "-p" || arg === "--parallel") {
533
- commentsParallel = parseInt(args[++i]) || 1;
534
- } else if (arg === "-i" || arg === "--interval") {
535
- commentsInterval = parseInt(args[++i]) || 10;
536
- } else if (arg === "-s" || arg === "--server") {
537
- commentsServer = args[++i];
538
- } else if (arg === "-m" || arg === "--max-comments") {
539
- commentsMax = parseInt(args[++i]) || 20;
540
- } else {
541
- positional.push(arg);
542
- }
543
- }
544
-
545
- commentsUrl = positional[0] || null;
546
- if (positional[1]) {
547
- commentsMax = parseInt(positional[1]) || 20;
548
- }
549
-
550
- return {
551
- subcommand: "comments",
552
- commentsUrl,
553
- commentsMax,
554
- commentsSave,
555
- commentsParallel,
556
- commentsInterval,
557
- commentsServer,
558
- urls: [],
559
- outputFormat: "json",
560
- exploreCount: 0,
561
- showConfig: false,
562
- showHelp: false,
563
- customProxy: null,
564
- configAction: null,
565
- configValue: null,
566
- pipeMode: false,
567
- filterStr: null,
568
- };
569
- }
570
-
571
- export function parseArgs() {
572
- const args = process.argv.slice(2);
573
-
574
- if (args.includes("-h") || args.includes("--help")) {
575
- return {
576
- showHelp: true,
577
- showVersion: false,
578
- subcommand: null,
579
- urls: [],
580
- outputFile: null,
581
- outputFormat: "json",
582
- exploreCount: 0,
583
- showConfig: false,
584
- customProxy: null,
585
- configAction: null,
586
- configValue: null,
587
- pipeMode: false,
588
- filterStr: null,
589
- };
590
- }
591
- if (args.includes("--version")) {
592
- return {
593
- showHelp: false,
594
- showVersion: true,
595
- subcommand: null,
596
- urls: [],
597
- outputFile: null,
598
- outputFormat: "json",
599
- exploreCount: 0,
600
- showConfig: false,
601
- customProxy: null,
602
- configAction: null,
603
- configValue: null,
604
- pipeMode: false,
605
- filterStr: null,
606
- };
607
- }
608
-
609
- if (args.length > 0 && args[0] === "explore") {
610
- return parseExploreArgs(args.slice(1));
611
- }
612
-
613
- if (args.length > 0 && args[0] === "info") {
614
- return parseInfoArgs(args.slice(1));
615
- }
616
-
617
- if (args.length > 0 && args[0] === "watch") {
618
- return parseWatchArgs(args.slice(1));
619
- }
620
-
621
- if (args.length > 0 && args[0] === "attach") {
622
- return parseAttachArgs(args.slice(1));
623
- }
624
-
625
- if (args.length > 0 && args[0] === "open") {
626
- return parseOpenArgs(args.slice(1));
627
- }
628
-
629
- if (args.length > 0 && args[0] === "comments") {
630
- return parseCommentsArgs(args.slice(1));
631
- }
632
-
633
- if (args.length > 0 && args[0] === "videostats") {
634
- return parseVideoStatsArgs(args.slice(1));
635
- }
636
-
637
- const urls = [];
638
- let inputFile = null;
639
- let outputFile = null;
640
- let outputFormat = "json";
641
- let exploreCount = 0;
642
- let showConfig = false;
643
- let showHelp = false;
644
- let showVersion = false;
645
- let customProxy = null;
646
- let configAction = null;
647
- let configKey = null;
648
- let configValue = null;
649
- let pipeMode = false;
650
- let filterStr = null;
651
-
652
- for (let i = 0; i < args.length; i++) {
653
- const arg = args[i];
654
-
655
- if (arg === "--explore") {
656
- exploreCount =
657
- args[i + 1] && !args[i + 1].startsWith("http")
658
- ? parseInt(args[++i], 10)
659
- : 100;
660
- } else if (arg === "--proxy") {
661
- customProxy = args[++i];
662
- } else if (arg === "--filter") {
663
- filterStr = args[++i];
664
- } else if (arg === "config") {
665
- configAction = args[i + 1];
666
- if (!configAction) {
667
- configAction = "show";
668
- } else if (
669
- configAction === "set" ||
670
- configAction === "set-proxy" ||
671
- configAction === "set-browser"
672
- ) {
673
- configKey = args[i + 2];
674
- configValue = args[i + 3];
675
- i += 3;
676
- } else {
677
- i++;
678
- }
679
- } else if (arg === "--pipe") {
680
- pipeMode = true;
681
- } else if (arg === "-i" || arg === "--input") {
682
- inputFile = args[++i];
683
- } else if (arg === "-o" || arg === "--output") {
684
- outputFile = args[++i];
685
- } else if (arg === "-f" || arg === "--format") {
686
- outputFormat = args[++i];
687
- } else if (arg === "-c" || arg === "--config") {
688
- showConfig = true;
689
- } else if (arg === "-h" || arg === "--help") {
690
- showHelp = true;
691
- } else if (arg === "--version") {
692
- showVersion = true;
693
- } else if (arg.startsWith("http")) {
694
- urls.push(arg);
695
- }
696
- }
697
-
698
- if (inputFile) {
699
- const content = readFileSync(inputFile, "utf-8");
700
- const lines = content
701
- .split(/\r?\n/)
702
- .map((l) => l.trim())
703
- .filter((l) => l.startsWith("http"));
704
- urls.push(...lines);
705
- }
706
-
707
- return {
708
- urls,
709
- outputFile,
710
- outputFormat,
711
- exploreCount,
712
- showConfig,
713
- showHelp,
714
- showVersion,
715
- customProxy,
716
- configAction,
717
- configKey,
718
- configValue,
719
- pipeMode,
720
- filterStr,
721
- };
722
- }
1
+ import { readFileSync } from "fs";
2
+ import { server as defaultServer } from "./constants.js";
3
+
4
+ const PRESETS = ["fast", "normal", "slow", "stealth"];
5
+
6
+ function parseScrapeArgs(args) {
7
+ let scrapeUrl = null;
8
+ let scrapePreset = null;
9
+ let scrapeMaxVideos = 20;
10
+ let scrapeMaxComments = 999;
11
+ let scrapeMaxGuess = 10;
12
+ let scrapeSwitchDelay = null;
13
+ let scrapeCommentDelay = null;
14
+ let outputFile = null;
15
+
16
+ const positional = [];
17
+
18
+ for (let i = 0; i < args.length; i++) {
19
+ const arg = args[i];
20
+ if (arg === "-o" || arg === "--output") {
21
+ outputFile = args[++i];
22
+ } else if (arg === "--switch-delay") {
23
+ scrapeSwitchDelay = parseInt(args[++i]) || null;
24
+ } else if (arg === "--comment-delay") {
25
+ scrapeCommentDelay = parseInt(args[++i]) || null;
26
+ } else {
27
+ positional.push(arg);
28
+ }
29
+ }
30
+
31
+ scrapeUrl = positional[0] || null;
32
+
33
+ if (positional[1]) {
34
+ if (PRESETS.includes(positional[1].toLowerCase())) {
35
+ scrapePreset = positional[1].toLowerCase();
36
+ scrapeMaxVideos = parseInt(positional[2]) || 20;
37
+ scrapeMaxComments = parseInt(positional[3]) || 999;
38
+ scrapeMaxGuess = parseInt(positional[4]) || 10;
39
+ } else {
40
+ scrapeMaxVideos = parseInt(positional[1]) || 20;
41
+ scrapeMaxComments = parseInt(positional[2]) || 999;
42
+ scrapeMaxGuess = parseInt(positional[3]) || 10;
43
+ }
44
+ }
45
+
46
+ return {
47
+ subcommand: "scrape",
48
+ scrapeUrl,
49
+ scrapePreset,
50
+ scrapeMaxVideos,
51
+ scrapeMaxComments,
52
+ scrapeMaxGuess,
53
+ scrapeSwitchDelay,
54
+ scrapeCommentDelay,
55
+ outputFile,
56
+ urls: [],
57
+ outputFormat: "json",
58
+ exploreCount: 0,
59
+ showConfig: false,
60
+ showHelp: false,
61
+ customProxy: null,
62
+ configAction: null,
63
+ configValue: null,
64
+ pipeMode: false,
65
+ filterStr: null,
66
+ };
67
+ }
68
+
69
+ function parseAutoArgs(args) {
70
+ let autoCollectMax = 1;
71
+ let autoScrapeDepth = 50;
72
+ let autoMaxComments = 200;
73
+ let autoMaxGuess = 10;
74
+ let autoPreset = "fast";
75
+ let autoSwitchDelay = null;
76
+ let autoCommentDelay = null;
77
+ let serverUrl = defaultServer;
78
+ let autoEnableFollow = false;
79
+ let autoMaxFollowing = 200;
80
+ let autoMaxFollowers = 200;
81
+
82
+ const positional = [];
83
+ const PRESETS = ["fast", "normal", "slow", "stealth"];
84
+
85
+ for (let i = 0; i < args.length; i++) {
86
+ const arg = args[i];
87
+ if (arg === "--server") {
88
+ serverUrl = args[++i];
89
+ } else if (arg === "--switch-delay") {
90
+ autoSwitchDelay = parseInt(args[++i]) || null;
91
+ } else if (arg === "--comment-delay") {
92
+ autoCommentDelay = parseInt(args[++i]) || null;
93
+ } else if (arg === "--enable-follow") {
94
+ autoEnableFollow = true;
95
+ } else if (arg === "--max-following") {
96
+ autoMaxFollowing = parseInt(args[++i]) || 200;
97
+ } else if (arg === "--max-followers") {
98
+ autoMaxFollowers = parseInt(args[++i]) || 200;
99
+ } else {
100
+ positional.push(arg);
101
+ }
102
+ }
103
+
104
+ // 收集用户名(非 preset、非数字的都是用户名)
105
+ const usernames = [];
106
+ let j = 0;
107
+ while (
108
+ j < positional.length &&
109
+ !PRESETS.includes(positional[j]?.toLowerCase()) &&
110
+ isNaN(positional[j])
111
+ ) {
112
+ usernames.push(positional[j].replace("@", ""));
113
+ j++;
114
+ }
115
+
116
+ // preset
117
+ if (j < positional.length && PRESETS.includes(positional[j].toLowerCase())) {
118
+ autoPreset = positional[j].toLowerCase();
119
+ j++;
120
+ autoCollectMax = parseInt(positional[j]) || 1;
121
+ j++;
122
+ autoScrapeDepth = parseInt(positional[j]) || 50;
123
+ j++;
124
+ autoMaxComments = parseInt(positional[j]) || 200;
125
+ j++;
126
+ autoMaxGuess = parseInt(positional[j]) || 10;
127
+ j++;
128
+ } else if (usernames.length > 0) {
129
+ autoCollectMax = parseInt(positional[j]) || 1;
130
+ j++;
131
+ autoScrapeDepth = parseInt(positional[j]) || 50;
132
+ j++;
133
+ autoMaxComments = parseInt(positional[j]) || 200;
134
+ j++;
135
+ autoMaxGuess = parseInt(positional[j]) || 10;
136
+ }
137
+
138
+ return {
139
+ subcommand: "auto",
140
+ autoUsernames: usernames,
141
+ autoCollectMax,
142
+ autoScrapeDepth,
143
+ autoMaxComments,
144
+ autoMaxGuess,
145
+ autoPreset,
146
+ autoSwitchDelay,
147
+ autoCommentDelay,
148
+ serverUrl,
149
+ autoEnableFollow,
150
+ autoMaxFollowing,
151
+ autoMaxFollowers,
152
+ urls: [],
153
+ outputFormat: "json",
154
+ exploreCount: 0,
155
+ showConfig: false,
156
+ showHelp: false,
157
+ customProxy: null,
158
+ configAction: null,
159
+ configValue: null,
160
+ pipeMode: false,
161
+ filterStr: null,
162
+ };
163
+ }
164
+
165
+ function parseExploreArgs(args) {
166
+ let serverUrl = defaultServer;
167
+ let explorePreset = "normal";
168
+ let exploreMaxComments = 10;
169
+ let exploreMaxGuess = 0;
170
+ let exploreEnableFollow = true;
171
+ let exploreMaxFollowing = 50;
172
+ let exploreMaxFollowers = 50;
173
+ let exploreLocation = "PL,NL,BE,DE,FR,IT,ES,IE,AT";
174
+ let exploreJobLocations = null;
175
+ let exploreMaxUsers = 0;
176
+ let explorePort = null;
177
+ let exploreBasePort = null;
178
+ let explorePortCount = null;
179
+ let exploreUserId = null;
180
+ let exploreMaxVideos = 16;
181
+
182
+ const positional = [];
183
+ const PRESETS = ["fast", "normal", "slow", "stealth"];
184
+
185
+ for (let i = 0; i < args.length; i++) {
186
+ const arg = args[i];
187
+ if (arg === "--server") {
188
+ serverUrl = args[++i];
189
+ } else if (arg === "--max-comments") {
190
+ exploreMaxComments = parseInt(args[++i]) || 0;
191
+ } else if (arg === "--max-guess") {
192
+ exploreMaxGuess = parseInt(args[++i]) || 0;
193
+ } else if (arg === "--location") {
194
+ exploreLocation = args[++i];
195
+ } else if (arg === "--job-locations") {
196
+ exploreJobLocations = args[++i];
197
+ } else if (arg === "--enable-follow") {
198
+ exploreEnableFollow = true;
199
+ } else if (arg === "--disable-follow") {
200
+ exploreEnableFollow = false;
201
+ } else if (arg === "--max-following") {
202
+ exploreMaxFollowing = parseInt(args[++i]) || 50;
203
+
204
+ exploreMaxFollowers = parseInt(args[++i]) || 50;
205
+ } else if (arg === "--max-users") {
206
+ exploreMaxUsers = parseInt(args[++i]) || 0;
207
+ } else if (arg === "--port") {
208
+ explorePort = parseInt(args[++i]) || 9222;
209
+ } else if (arg === "--base-port") {
210
+ exploreBasePort = parseInt(args[++i]) || 9222;
211
+ } else if (arg === "--port-count") {
212
+ explorePortCount = parseInt(args[++i]) || 10;
213
+ } else if (arg === "--user-id") {
214
+ exploreUserId = args[++i];
215
+ } else if (arg === "--max-videos") {
216
+ exploreMaxVideos = parseInt(args[++i]) || 16;
217
+ } else {
218
+ positional.push(arg);
219
+ }
220
+ }
221
+
222
+ const usernames = [];
223
+ let j = 0;
224
+ while (
225
+ j < positional.length &&
226
+ !PRESETS.includes(positional[j]?.toLowerCase()) &&
227
+ isNaN(positional[j])
228
+ ) {
229
+ usernames.push(positional[j].replace("@", ""));
230
+ j++;
231
+ }
232
+
233
+ if (j < positional.length && PRESETS.includes(positional[j].toLowerCase())) {
234
+ explorePreset = positional[j].toLowerCase();
235
+ j++;
236
+ }
237
+
238
+ return {
239
+ subcommand: "explore",
240
+ exploreUsernames: usernames,
241
+ explorePreset,
242
+ exploreMaxComments,
243
+ exploreMaxGuess,
244
+ exploreEnableFollow,
245
+ exploreMaxFollowing,
246
+ exploreMaxFollowers,
247
+ exploreLocation,
248
+ exploreJobLocations,
249
+ serverUrl,
250
+ exploreMaxUsers,
251
+ explorePort,
252
+ exploreBasePort,
253
+ explorePortCount,
254
+ exploreUserId,
255
+ exploreMaxVideos,
256
+ urls: [],
257
+ outputFormat: "json",
258
+ exploreCount: 0,
259
+ showConfig: false,
260
+ showHelp: false,
261
+ customProxy: null,
262
+ configAction: null,
263
+ configValue: null,
264
+ pipeMode: false,
265
+ filterStr: null,
266
+ };
267
+ }
268
+
269
+ function parseVideosArgs(args) {
270
+ let videosUsername = null;
271
+ let videosMax = 5;
272
+ let outputFile = null;
273
+
274
+ const positional = [];
275
+
276
+ for (let i = 0; i < args.length; i++) {
277
+ const arg = args[i];
278
+ if (arg === "-o" || arg === "--output") {
279
+ outputFile = args[++i];
280
+ } else {
281
+ positional.push(arg);
282
+ }
283
+ }
284
+
285
+ videosUsername = positional[0] ? positional[0].replace("@", "") : null;
286
+ videosMax = parseInt(positional[1]) || 5;
287
+
288
+ return {
289
+ subcommand: "videos",
290
+ videosUsername,
291
+ videosMax,
292
+ outputFile,
293
+ urls: [],
294
+ outputFormat: "json",
295
+ exploreCount: 0,
296
+ showConfig: false,
297
+ showHelp: false,
298
+ customProxy: null,
299
+ configAction: null,
300
+ configValue: null,
301
+ pipeMode: false,
302
+ filterStr: null,
303
+ };
304
+ }
305
+
306
+ function parseInfoArgs(args) {
307
+ let onlyVideo = false;
308
+ const urls = [];
309
+
310
+ for (let i = 0; i < args.length; i++) {
311
+ const arg = args[i];
312
+ if (arg === "--onlyvideo") {
313
+ onlyVideo = true;
314
+ } else if (!arg.startsWith("--")) {
315
+ urls.push(arg);
316
+ }
317
+ }
318
+
319
+ return {
320
+ subcommand: "info",
321
+ infoUrls: urls,
322
+ infoOnlyVideo: onlyVideo,
323
+ outputFile: null,
324
+ outputFormat: "json",
325
+ exploreCount: 0,
326
+ showConfig: false,
327
+ showHelp: false,
328
+ showVersion: false,
329
+ customProxy: null,
330
+ configAction: null,
331
+ configKey: null,
332
+ configValue: null,
333
+ pipeMode: false,
334
+ filterStr: null,
335
+ };
336
+ }
337
+
338
+ function parseWatchArgs(args) {
339
+ let dataAnchor = "./result.db";
340
+ let watchPort = 3001;
341
+
342
+ for (let i = 0; i < args.length; i++) {
343
+ const arg = args[i];
344
+ if (arg === "-o" || arg === "--output") {
345
+ dataAnchor = args[++i];
346
+ } else if (arg === "-p") {
347
+ watchPort = parseInt(args[++i]) || 3001;
348
+ }
349
+ }
350
+
351
+ return {
352
+ subcommand: "watch",
353
+ outputFile: dataAnchor,
354
+ dataAnchor,
355
+ watchPort,
356
+ urls: [],
357
+ outputFormat: "json",
358
+ exploreCount: 0,
359
+ showConfig: false,
360
+ showHelp: false,
361
+ customProxy: null,
362
+ configAction: null,
363
+ configValue: null,
364
+ pipeMode: false,
365
+ filterStr: null,
366
+ };
367
+ }
368
+
369
+ function parseDbImportArgs(args) {
370
+ let dbPath = "./result.db";
371
+ let usersFilePath = null;
372
+ let doneFilePath = null;
373
+ let videosFilePath = null;
374
+
375
+ for (let i = 0; i < args.length; i++) {
376
+ const arg = args[i];
377
+ if (arg === "--db") {
378
+ dbPath = args[++i] || dbPath;
379
+ } else if (arg === "--users") {
380
+ usersFilePath = args[++i] || null;
381
+ } else if (arg === "--done") {
382
+ doneFilePath = args[++i] || null;
383
+ } else if (arg === "--videos") {
384
+ videosFilePath = args[++i] || null;
385
+ }
386
+ }
387
+
388
+ return {
389
+ subcommand: "db-import",
390
+ dbPath,
391
+ usersFilePath,
392
+ doneFilePath,
393
+ videosFilePath,
394
+ urls: [],
395
+ outputFormat: "json",
396
+ exploreCount: 0,
397
+ showConfig: false,
398
+ showHelp: false,
399
+ customProxy: null,
400
+ configAction: null,
401
+ configValue: null,
402
+ pipeMode: false,
403
+ filterStr: null,
404
+ };
405
+ }
406
+
407
+ function parseRefreshArgs(args) {
408
+ let serverUrl = defaultServer;
409
+ let explorePreset = "normal";
410
+ let exploreMaxComments = 10;
411
+ let exploreMaxGuess = 0;
412
+ let explorePort = null;
413
+ let exploreProfile = null;
414
+ let exploreUserId = null;
415
+
416
+ for (let i = 0; i < args.length; i++) {
417
+ const arg = args[i];
418
+ if (arg === "--server") {
419
+ serverUrl = args[++i];
420
+ } else if (arg === "--comments") {
421
+ exploreMaxComments = parseInt(args[++i]) || 10;
422
+ } else if (arg === "--guess") {
423
+ exploreMaxGuess = parseInt(args[++i]) || 0;
424
+ } else if (arg === "--preset") {
425
+ explorePreset = args[++i];
426
+ } else if (arg === "--port") {
427
+ explorePort = parseInt(args[++i]) || 9222;
428
+ } else if (arg === "--profile") {
429
+ exploreProfile = args[++i];
430
+ } else if (arg === "--user-id") {
431
+ exploreUserId = args[++i];
432
+ }
433
+ }
434
+
435
+ return {
436
+ subcommand: "refresh",
437
+ explorePreset,
438
+ exploreMaxComments,
439
+ exploreMaxGuess,
440
+ explorePort,
441
+ exploreProfile,
442
+ exploreUserId,
443
+ serverUrl,
444
+ urls: [],
445
+ outputFormat: "json",
446
+ exploreCount: 0,
447
+ showConfig: false,
448
+ showHelp: false,
449
+ customProxy: null,
450
+ configAction: null,
451
+ configValue: null,
452
+ pipeMode: false,
453
+ filterStr: null,
454
+ };
455
+ }
456
+
457
+ function parseAttachArgs(args) {
458
+ let parallel = 1;
459
+ let interval = 10;
460
+ let serverUrl = defaultServer;
461
+
462
+ for (let i = 0; i < args.length; i++) {
463
+ const arg = args[i];
464
+ if (arg === "-p" || arg === "--parallel") {
465
+ parallel = parseInt(args[++i], 10) || 1;
466
+ } else if (arg === "-i" || arg === "--interval") {
467
+ interval = parseInt(args[++i], 10) || 10;
468
+ } else if (arg === "-s" || arg === "--server") {
469
+ serverUrl = args[++i];
470
+ }
471
+ }
472
+
473
+ return {
474
+ subcommand: "attach",
475
+ attachParallel: parallel,
476
+ attachInterval: interval,
477
+ serverUrl,
478
+ urls: [],
479
+ outputFormat: "json",
480
+ exploreCount: 0,
481
+ showConfig: false,
482
+ showHelp: false,
483
+ customProxy: null,
484
+ configAction: null,
485
+ configValue: null,
486
+ pipeMode: false,
487
+ filterStr: null,
488
+ };
489
+ }
490
+
491
+ function parseOpenArgs(args) {
492
+ let openPort = null;
493
+ let openList = false;
494
+
495
+ for (let i = 0; i < args.length; i++) {
496
+ const arg = args[i];
497
+ if (arg === "--list") {
498
+ openList = true;
499
+ } else if (!arg.startsWith("-")) {
500
+ openPort = arg;
501
+ }
502
+ }
503
+
504
+ return {
505
+ subcommand: "open",
506
+ openPort,
507
+ openList,
508
+ urls: [],
509
+ outputFormat: "json",
510
+ exploreCount: 0,
511
+ showConfig: false,
512
+ showHelp: false,
513
+ customProxy: null,
514
+ configAction: null,
515
+ configValue: null,
516
+ pipeMode: false,
517
+ filterStr: null,
518
+ };
519
+ }
520
+
521
+ function parseVideoStatsArgs(args) {
522
+ let statsSource = null;
523
+ let statsParallel = 3;
524
+
525
+ for (let i = 0; i < args.length; i++) {
526
+ const arg = args[i];
527
+ if (arg === "-p" || arg === "--parallel") {
528
+ statsParallel = parseInt(args[++i]) || 3;
529
+ } else if (!arg.startsWith("-")) {
530
+ statsSource = args[i] || null;
531
+ }
532
+ }
533
+
534
+ return {
535
+ subcommand: "videostats",
536
+ statsFile: statsSource,
537
+ statsSource,
538
+ statsParallel,
539
+ commentsUrl: null,
540
+ commentsMax: 20,
541
+ commentsSave: false,
542
+ commentsParallel: 1,
543
+ commentsInterval: 10,
544
+ commentsServer: defaultServer,
545
+ urls: [],
546
+ outputFormat: "json",
547
+ exploreCount: 0,
548
+ showConfig: false,
549
+ showHelp: false,
550
+ customProxy: null,
551
+ configAction: null,
552
+ configValue: null,
553
+ pipeMode: false,
554
+ filterStr: null,
555
+ };
556
+ }
557
+
558
+ function parseCommentsArgs(args) {
559
+ let commentsUrl = null;
560
+ let commentsMax = 20;
561
+ let commentsSave = false;
562
+ let commentsParallel = 1;
563
+ let commentsInterval = 10;
564
+ let commentsServer = defaultServer;
565
+
566
+ const positional = [];
567
+
568
+ for (let i = 0; i < args.length; i++) {
569
+ const arg = args[i];
570
+ if (arg === "--save") {
571
+ commentsSave = true;
572
+ } else if (arg === "-p" || arg === "--parallel") {
573
+ commentsParallel = parseInt(args[++i]) || 1;
574
+ } else if (arg === "-i" || arg === "--interval") {
575
+ commentsInterval = parseInt(args[++i]) || 10;
576
+ } else if (arg === "-s" || arg === "--server") {
577
+ commentsServer = args[++i];
578
+ } else if (arg === "-m" || arg === "--max-comments") {
579
+ commentsMax = parseInt(args[++i]) || 20;
580
+ } else {
581
+ positional.push(arg);
582
+ }
583
+ }
584
+
585
+ commentsUrl = positional[0] || null;
586
+ if (positional[1]) {
587
+ commentsMax = parseInt(positional[1]) || 20;
588
+ }
589
+
590
+ return {
591
+ subcommand: "comments",
592
+ commentsUrl,
593
+ commentsMax,
594
+ commentsSave,
595
+ commentsParallel,
596
+ commentsInterval,
597
+ commentsServer,
598
+ urls: [],
599
+ outputFormat: "json",
600
+ exploreCount: 0,
601
+ showConfig: false,
602
+ showHelp: false,
603
+ customProxy: null,
604
+ configAction: null,
605
+ configValue: null,
606
+ pipeMode: false,
607
+ filterStr: null,
608
+ };
609
+ }
610
+
611
+ export function parseArgs() {
612
+ const args = process.argv.slice(2);
613
+
614
+ if (args.includes("-h") || args.includes("--help")) {
615
+ return {
616
+ showHelp: true,
617
+ showVersion: false,
618
+ subcommand: null,
619
+ urls: [],
620
+ outputFile: null,
621
+ outputFormat: "json",
622
+ exploreCount: 0,
623
+ showConfig: false,
624
+ customProxy: null,
625
+ configAction: null,
626
+ configValue: null,
627
+ pipeMode: false,
628
+ filterStr: null,
629
+ };
630
+ }
631
+ if (args.includes("--version")) {
632
+ return {
633
+ showHelp: false,
634
+ showVersion: true,
635
+ subcommand: null,
636
+ urls: [],
637
+ outputFile: null,
638
+ outputFormat: "json",
639
+ exploreCount: 0,
640
+ showConfig: false,
641
+ customProxy: null,
642
+ configAction: null,
643
+ configValue: null,
644
+ pipeMode: false,
645
+ filterStr: null,
646
+ };
647
+ }
648
+
649
+ if (args.length > 0 && args[0] === "explore") {
650
+ return parseExploreArgs(args.slice(1));
651
+ }
652
+
653
+ if (args.length > 0 && args[0] === "info") {
654
+ return parseInfoArgs(args.slice(1));
655
+ }
656
+
657
+ if (args.length > 0 && args[0] === "watch") {
658
+ return parseWatchArgs(args.slice(1));
659
+ }
660
+
661
+ if (args.length > 0 && args[0] === "attach") {
662
+ return parseAttachArgs(args.slice(1));
663
+ }
664
+
665
+ if (args.length > 0 && args[0] === "open") {
666
+ return parseOpenArgs(args.slice(1));
667
+ }
668
+
669
+ if (args.length > 0 && args[0] === "comments") {
670
+ return parseCommentsArgs(args.slice(1));
671
+ }
672
+
673
+ if (args.length > 0 && args[0] === "videostats") {
674
+ return parseVideoStatsArgs(args.slice(1));
675
+ }
676
+
677
+ if (args.length > 0 && args[0] === "db-import") {
678
+ return parseDbImportArgs(args.slice(1));
679
+ }
680
+
681
+ const urls = [];
682
+ let inputFile = null;
683
+ let outputFile = null;
684
+ let outputFormat = "json";
685
+ let exploreCount = 0;
686
+ let showConfig = false;
687
+ let showHelp = false;
688
+ let showVersion = false;
689
+ let customProxy = null;
690
+ let configAction = null;
691
+ let configKey = null;
692
+ let configValue = null;
693
+ let pipeMode = false;
694
+ let filterStr = null;
695
+
696
+ for (let i = 0; i < args.length; i++) {
697
+ const arg = args[i];
698
+
699
+ if (arg === "--explore") {
700
+ exploreCount =
701
+ args[i + 1] && !args[i + 1].startsWith("http")
702
+ ? parseInt(args[++i], 10)
703
+ : 100;
704
+ } else if (arg === "--proxy") {
705
+ customProxy = args[++i];
706
+ } else if (arg === "--filter") {
707
+ filterStr = args[++i];
708
+ } else if (arg === "config") {
709
+ configAction = args[i + 1];
710
+ if (!configAction) {
711
+ configAction = "show";
712
+ } else if (
713
+ configAction === "set" ||
714
+ configAction === "set-proxy" ||
715
+ configAction === "set-browser"
716
+ ) {
717
+ configKey = args[i + 2];
718
+ configValue = args[i + 3];
719
+ i += 3;
720
+ } else {
721
+ i++;
722
+ }
723
+ } else if (arg === "--pipe") {
724
+ pipeMode = true;
725
+ } else if (arg === "-i" || arg === "--input") {
726
+ inputFile = args[++i];
727
+ } else if (arg === "-o" || arg === "--output") {
728
+ outputFile = args[++i];
729
+ } else if (arg === "-f" || arg === "--format") {
730
+ outputFormat = args[++i];
731
+ } else if (arg === "-c" || arg === "--config") {
732
+ showConfig = true;
733
+ } else if (arg === "-h" || arg === "--help") {
734
+ showHelp = true;
735
+ } else if (arg === "--version") {
736
+ showVersion = true;
737
+ } else if (arg.startsWith("http")) {
738
+ urls.push(arg);
739
+ }
740
+ }
741
+
742
+ if (inputFile) {
743
+ const content = readFileSync(inputFile, "utf-8");
744
+ const lines = content
745
+ .split(/\r?\n/)
746
+ .map((l) => l.trim())
747
+ .filter((l) => l.startsWith("http"));
748
+ urls.push(...lines);
749
+ }
750
+
751
+ return {
752
+ urls,
753
+ outputFile,
754
+ outputFormat,
755
+ exploreCount,
756
+ showConfig,
757
+ showHelp,
758
+ showVersion,
759
+ customProxy,
760
+ configAction,
761
+ configKey,
762
+ configValue,
763
+ pipeMode,
764
+ filterStr,
765
+ };
766
+ }