tt-help-cli-ycl 1.3.25 → 1.3.26

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 (59) hide show
  1. package/README.md +17 -17
  2. package/cli.js +9 -9
  3. package/package.json +47 -47
  4. package/scripts/run-explore copy.bat +68 -68
  5. package/scripts/run-explore.bat +68 -68
  6. package/scripts/run-explore.ps1 +81 -81
  7. package/scripts/run-explore.sh +73 -73
  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/src/cli/attach.js +180 -180
  14. package/src/cli/auto.js +240 -186
  15. package/src/cli/config.js +152 -152
  16. package/src/cli/explore.js +439 -296
  17. package/src/cli/info.js +88 -88
  18. package/src/cli/progress.js +111 -111
  19. package/src/cli/refresh.js +216 -216
  20. package/src/cli/scrape.js +47 -47
  21. package/src/cli/utils.js +18 -18
  22. package/src/cli/videos.js +41 -41
  23. package/src/cli/watch.js +31 -31
  24. package/src/lib/api-interceptor.js +191 -191
  25. package/src/lib/args.js +551 -551
  26. package/src/lib/browser/anti-detect.js +23 -23
  27. package/src/lib/browser/cdp.js +236 -236
  28. package/src/lib/browser/health-checker.js +43 -4
  29. package/src/lib/browser/launch.js +43 -43
  30. package/src/lib/browser/page.js +156 -156
  31. package/src/lib/constants.js +206 -206
  32. package/src/lib/delay.js +54 -54
  33. package/src/lib/explore-fetch.js +118 -118
  34. package/src/lib/fetcher.js +45 -45
  35. package/src/lib/filter.js +66 -66
  36. package/src/lib/io.js +54 -54
  37. package/src/lib/output.js +80 -80
  38. package/src/lib/page-error-detector.js +71 -71
  39. package/src/lib/parse-ssr.mjs +69 -69
  40. package/src/lib/parser.js +47 -47
  41. package/src/lib/retry.js +45 -45
  42. package/src/lib/scrape.js +89 -89
  43. package/src/lib/tiktok-scraper.mjs +194 -194
  44. package/src/lib/url.js +52 -52
  45. package/src/main.js +44 -44
  46. package/src/results/user-videos-bar.lar.lar.moeta.json +37 -0
  47. package/src/scraper/auto-core.js +203 -203
  48. package/src/scraper/core.js +211 -211
  49. package/src/scraper/explore-core.js +201 -198
  50. package/src/scraper/modules/captcha-handler.js +114 -114
  51. package/src/scraper/modules/comment-extractor.js +74 -74
  52. package/src/scraper/modules/follow-extractor.js +118 -118
  53. package/src/scraper/modules/guess-extractor.js +51 -51
  54. package/src/scraper/modules/page-helpers.js +48 -48
  55. package/src/scraper/refresh-core.js +179 -179
  56. package/src/videos/core.js +101 -101
  57. package/src/watch/data-store.js +828 -828
  58. package/src/watch/public/index.html +753 -753
  59. package/src/watch/server.js +705 -705
package/src/lib/args.js CHANGED
@@ -1,552 +1,552 @@
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 (j < positional.length && !PRESETS.includes(positional[j]?.toLowerCase()) && isNaN(positional[j])) {
108
- usernames.push(positional[j].replace('@', ''));
109
- j++;
110
- }
111
-
112
- // preset
113
- if (j < positional.length && PRESETS.includes(positional[j].toLowerCase())) {
114
- autoPreset = positional[j].toLowerCase();
115
- j++;
116
- autoCollectMax = parseInt(positional[j]) || 1; j++;
117
- autoScrapeDepth = parseInt(positional[j]) || 50; j++;
118
- autoMaxComments = parseInt(positional[j]) || 200; j++;
119
- autoMaxGuess = parseInt(positional[j]) || 10; j++;
120
- } else if (usernames.length > 0) {
121
- autoCollectMax = parseInt(positional[j]) || 1; j++;
122
- autoScrapeDepth = parseInt(positional[j]) || 50; j++;
123
- autoMaxComments = parseInt(positional[j]) || 200; j++;
124
- autoMaxGuess = parseInt(positional[j]) || 10;
125
- }
126
-
127
- return {
128
- subcommand: 'auto',
129
- autoUsernames: usernames,
130
- autoCollectMax,
131
- autoScrapeDepth,
132
- autoMaxComments,
133
- autoMaxGuess,
134
- autoPreset,
135
- autoSwitchDelay,
136
- autoCommentDelay,
137
- serverUrl,
138
- autoEnableFollow,
139
- autoMaxFollowing,
140
- autoMaxFollowers,
141
- urls: [],
142
- outputFormat: 'json',
143
- exploreCount: 0,
144
- showConfig: false,
145
- showHelp: false,
146
- customProxy: null,
147
- configAction: null,
148
- configValue: null,
149
- pipeMode: false,
150
- filterStr: null,
151
- };
152
- }
153
-
154
- function parseExploreArgs(args) {
155
- let serverUrl = defaultServer;
156
- let explorePreset = 'normal';
157
- let exploreMaxComments = 10;
158
- let exploreMaxGuess = 0;
159
- let exploreEnableFollow = true;
160
- let exploreMaxFollowing = 50;
161
- let exploreMaxFollowers = 50;
162
- let exploreLocation = 'PL,NL,BE,DE,FR,IT,ES,IE';
163
- let exploreMaxUsers = 0;
164
- let explorePort = null;
165
- let exploreProfile = null;
166
- let exploreUserId = null;
167
- let exploreMaxVideos = 16;
168
-
169
- const positional = [];
170
- const PRESETS = ['fast', 'normal', 'slow', 'stealth'];
171
-
172
- for (let i = 0; i < args.length; i++) {
173
- const arg = args[i];
174
- if (arg === '--server') {
175
- serverUrl = args[++i];
176
- } else if (arg === '--max-comments') {
177
- exploreMaxComments = parseInt(args[++i]) || 0;
178
- } else if (arg === '--max-guess') {
179
- exploreMaxGuess = parseInt(args[++i]) || 0;
180
- } else if (arg === '--location') {
181
- exploreLocation = args[++i];
182
- } else if (arg === '--enable-follow') {
183
- exploreEnableFollow = true;
184
- } else if (arg === '--disable-follow') {
185
- exploreEnableFollow = false;
186
- } else if (arg === '--max-following') {
187
- exploreMaxFollowing = parseInt(args[++i]) || 50;
188
-
189
- exploreMaxFollowers = parseInt(args[++i]) || 50;
190
- } else if (arg === '--max-users') {
191
- exploreMaxUsers = parseInt(args[++i]) || 0;
192
- } else if (arg === '--port') {
193
- explorePort = parseInt(args[++i]) || 9222;
194
- } else if (arg === '--profile') {
195
- exploreProfile = args[++i];
196
- } else if (arg === '--user-id') {
197
- exploreUserId = args[++i];
198
- } else if (arg === '--max-videos') {
199
- exploreMaxVideos = parseInt(args[++i]) || 16;
200
- } else {
201
- positional.push(arg);
202
- }
203
- }
204
-
205
- const usernames = [];
206
- let j = 0;
207
- while (j < positional.length && !PRESETS.includes(positional[j]?.toLowerCase()) && isNaN(positional[j])) {
208
- usernames.push(positional[j].replace('@', ''));
209
- j++;
210
- }
211
-
212
- if (j < positional.length && PRESETS.includes(positional[j].toLowerCase())) {
213
- explorePreset = positional[j].toLowerCase();
214
- j++;
215
- }
216
-
217
- return {
218
- subcommand: 'explore',
219
- exploreUsernames: usernames,
220
- explorePreset,
221
- exploreMaxComments,
222
- exploreMaxGuess,
223
- exploreEnableFollow,
224
- exploreMaxFollowing,
225
- exploreMaxFollowers,
226
- exploreLocation,
227
- serverUrl,
228
- exploreMaxUsers,
229
- explorePort,
230
- exploreProfile,
231
- exploreUserId,
232
- exploreMaxVideos,
233
- urls: [],
234
- outputFormat: 'json',
235
- exploreCount: 0,
236
- showConfig: false,
237
- showHelp: false,
238
- customProxy: null,
239
- configAction: null,
240
- configValue: null,
241
- pipeMode: false,
242
- filterStr: null,
243
- };
244
- }
245
-
246
- function parseVideosArgs(args) {
247
- let videosUsername = null;
248
- let videosMax = 5;
249
- let outputFile = null;
250
-
251
- const positional = [];
252
-
253
- for (let i = 0; i < args.length; i++) {
254
- const arg = args[i];
255
- if (arg === '-o' || arg === '--output') {
256
- outputFile = args[++i];
257
- } else {
258
- positional.push(arg);
259
- }
260
- }
261
-
262
- videosUsername = positional[0] ? positional[0].replace('@', '') : null;
263
- videosMax = parseInt(positional[1]) || 5;
264
-
265
- return {
266
- subcommand: 'videos',
267
- videosUsername,
268
- videosMax,
269
- outputFile,
270
- urls: [],
271
- outputFormat: 'json',
272
- exploreCount: 0,
273
- showConfig: false,
274
- showHelp: false,
275
- customProxy: null,
276
- configAction: null,
277
- configValue: null,
278
- pipeMode: false,
279
- filterStr: null,
280
- };
281
- }
282
-
283
- function parseInfoArgs(args) {
284
- let onlyVideo = false;
285
- const urls = [];
286
-
287
- for (let i = 0; i < args.length; i++) {
288
- const arg = args[i];
289
- if (arg === '--onlyvideo') {
290
- onlyVideo = true;
291
- } else if (!arg.startsWith('--')) {
292
- urls.push(arg);
293
- }
294
- }
295
-
296
- return {
297
- subcommand: 'info',
298
- infoUrls: urls,
299
- infoOnlyVideo: onlyVideo,
300
- outputFile: null,
301
- outputFormat: 'json',
302
- exploreCount: 0,
303
- showConfig: false,
304
- showHelp: false,
305
- showVersion: false,
306
- customProxy: null,
307
- configAction: null,
308
- configKey: null,
309
- configValue: null,
310
- pipeMode: false,
311
- filterStr: null,
312
- };
313
- }
314
-
315
- function parseWatchArgs(args) {
316
- let outputFile = './result.json';
317
- let watchPort = 3001;
318
-
319
- for (let i = 0; i < args.length; i++) {
320
- const arg = args[i];
321
- if (arg === '-o' || arg === '--output') {
322
- outputFile = args[++i];
323
- } else if (arg === '-p') {
324
- watchPort = parseInt(args[++i]) || 3001;
325
- }
326
- }
327
-
328
- return {
329
- subcommand: 'watch',
330
- outputFile,
331
- watchPort,
332
- urls: [],
333
- outputFormat: 'json',
334
- exploreCount: 0,
335
- showConfig: false,
336
- showHelp: false,
337
- customProxy: null,
338
- configAction: null,
339
- configValue: null,
340
- pipeMode: false,
341
- filterStr: null,
342
- };
343
- }
344
-
345
- function parseRefreshArgs(args) {
346
- let serverUrl = defaultServer;
347
- let explorePreset = 'normal';
348
- let exploreMaxComments = 10;
349
- let exploreMaxGuess = 0;
350
- let explorePort = null;
351
- let exploreProfile = null;
352
- let exploreUserId = null;
353
-
354
- for (let i = 0; i < args.length; i++) {
355
- const arg = args[i];
356
- if (arg === '--server') {
357
- serverUrl = args[++i];
358
- } else if (arg === '--comments') {
359
- exploreMaxComments = parseInt(args[++i]) || 10;
360
- } else if (arg === '--guess') {
361
- exploreMaxGuess = parseInt(args[++i]) || 0;
362
- } else if (arg === '--preset') {
363
- explorePreset = args[++i];
364
- } else if (arg === '--port') {
365
- explorePort = parseInt(args[++i]) || 9222;
366
- } else if (arg === '--profile') {
367
- exploreProfile = args[++i];
368
- } else if (arg === '--user-id') {
369
- exploreUserId = args[++i];
370
- }
371
- }
372
-
373
- return {
374
- subcommand: 'refresh',
375
- explorePreset,
376
- exploreMaxComments,
377
- exploreMaxGuess,
378
- explorePort,
379
- exploreProfile,
380
- exploreUserId,
381
- serverUrl,
382
- urls: [],
383
- outputFormat: 'json',
384
- exploreCount: 0,
385
- showConfig: false,
386
- showHelp: false,
387
- customProxy: null,
388
- configAction: null,
389
- configValue: null,
390
- pipeMode: false,
391
- filterStr: null,
392
- };
393
- }
394
-
395
- function parseAttachArgs(args) {
396
- let parallel = 1;
397
- let interval = 10;
398
- let serverUrl = defaultServer;
399
-
400
- for (let i = 0; i < args.length; i++) {
401
- const arg = args[i];
402
- if (arg === '-p' || arg === '--parallel') {
403
- parallel = parseInt(args[++i], 10) || 1;
404
- } else if (arg === '-i' || arg === '--interval') {
405
- interval = parseInt(args[++i], 10) || 10;
406
- } else if (arg === '-s' || arg === '--server') {
407
- serverUrl = args[++i];
408
- }
409
- }
410
-
411
- return {
412
- subcommand: 'attach',
413
- attachParallel: parallel,
414
- attachInterval: interval,
415
- serverUrl,
416
- urls: [],
417
- outputFormat: 'json',
418
- exploreCount: 0,
419
- showConfig: false,
420
- showHelp: false,
421
- customProxy: null,
422
- configAction: null,
423
- configValue: null,
424
- pipeMode: false,
425
- filterStr: null,
426
- };
427
- }
428
-
429
- function parseOpenArgs(args) {
430
- let openPort = null;
431
- let openList = false;
432
-
433
- for (let i = 0; i < args.length; i++) {
434
- const arg = args[i];
435
- if (arg === '--list') {
436
- openList = true;
437
- } else if (!arg.startsWith('-')) {
438
- openPort = arg;
439
- }
440
- }
441
-
442
- return {
443
- subcommand: 'open',
444
- openPort,
445
- openList,
446
- urls: [],
447
- outputFormat: 'json',
448
- exploreCount: 0,
449
- showConfig: false,
450
- showHelp: false,
451
- customProxy: null,
452
- configAction: null,
453
- configValue: null,
454
- pipeMode: false,
455
- filterStr: null,
456
- };
457
- }
458
-
459
- export function parseArgs() {
460
- const args = process.argv.slice(2);
461
-
462
- if (args.includes('-h') || args.includes('--help')) {
463
- return { showHelp: true, showVersion: false, subcommand: null, urls: [], outputFile: null, outputFormat: 'json', exploreCount: 0, showConfig: false, customProxy: null, configAction: null, configValue: null, pipeMode: false, filterStr: null };
464
- }
465
- if (args.includes('--version')) {
466
- return { showHelp: false, showVersion: true, subcommand: null, urls: [], outputFile: null, outputFormat: 'json', exploreCount: 0, showConfig: false, customProxy: null, configAction: null, configValue: null, pipeMode: false, filterStr: null };
467
- }
468
-
469
- if (args.length > 0 && args[0] === 'explore') {
470
- return parseExploreArgs(args.slice(1));
471
- }
472
-
473
- if (args.length > 0 && args[0] === 'info') {
474
- return parseInfoArgs(args.slice(1));
475
- }
476
-
477
- if (args.length > 0 && args[0] === 'watch') {
478
- return parseWatchArgs(args.slice(1));
479
- }
480
-
481
- if (args.length > 0 && args[0] === 'attach') {
482
- return parseAttachArgs(args.slice(1));
483
- }
484
-
485
- if (args.length > 0 && args[0] === 'open') {
486
- return parseOpenArgs(args.slice(1));
487
- }
488
-
489
- const urls = [];
490
- let inputFile = null;
491
- let outputFile = null;
492
- let outputFormat = 'json';
493
- let exploreCount = 0;
494
- let showConfig = false;
495
- let showHelp = false;
496
- let showVersion = false;
497
- let customProxy = null;
498
- let configAction = null;
499
- let configKey = null;
500
- let configValue = null;
501
- let pipeMode = false;
502
- let filterStr = null;
503
-
504
- for (let i = 0; i < args.length; i++) {
505
- const arg = args[i];
506
-
507
- if (arg === '--explore') {
508
- exploreCount = args[i + 1] && !args[i + 1].startsWith('http')
509
- ? parseInt(args[++i], 10)
510
- : 100;
511
- } else if (arg === '--proxy') {
512
- customProxy = args[++i];
513
- } else if (arg === '--filter') {
514
- filterStr = args[++i];
515
- } else if (arg === 'config') {
516
- configAction = args[i + 1];
517
- if (!configAction) {
518
- configAction = 'show';
519
- } else if (configAction === 'set' || configAction === 'set-proxy' || configAction === 'set-browser') {
520
- configKey = args[i + 2];
521
- configValue = args[i + 3];
522
- i += 3;
523
- } else {
524
- i++;
525
- }
526
- } else if (arg === '--pipe') {
527
- pipeMode = true;
528
- } else if (arg === '-i' || arg === '--input') {
529
- inputFile = args[++i];
530
- } else if (arg === '-o' || arg === '--output') {
531
- outputFile = args[++i];
532
- } else if (arg === '-f' || arg === '--format') {
533
- outputFormat = args[++i];
534
- } else if (arg === '-c' || arg === '--config') {
535
- showConfig = true;
536
- } else if (arg === '-h' || arg === '--help') {
537
- showHelp = true;
538
- } else if (arg === '--version') {
539
- showVersion = true;
540
- } else if (arg.startsWith('http')) {
541
- urls.push(arg);
542
- }
543
- }
544
-
545
- if (inputFile) {
546
- const content = readFileSync(inputFile, 'utf-8');
547
- const lines = content.split(/\r?\n/).map(l => l.trim()).filter(l => l.startsWith('http'));
548
- urls.push(...lines);
549
- }
550
-
551
- return { urls, outputFile, outputFormat, exploreCount, showConfig, showHelp, showVersion, customProxy, configAction, configKey, configValue, pipeMode, filterStr };
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 (j < positional.length && !PRESETS.includes(positional[j]?.toLowerCase()) && isNaN(positional[j])) {
108
+ usernames.push(positional[j].replace('@', ''));
109
+ j++;
110
+ }
111
+
112
+ // preset
113
+ if (j < positional.length && PRESETS.includes(positional[j].toLowerCase())) {
114
+ autoPreset = positional[j].toLowerCase();
115
+ j++;
116
+ autoCollectMax = parseInt(positional[j]) || 1; j++;
117
+ autoScrapeDepth = parseInt(positional[j]) || 50; j++;
118
+ autoMaxComments = parseInt(positional[j]) || 200; j++;
119
+ autoMaxGuess = parseInt(positional[j]) || 10; j++;
120
+ } else if (usernames.length > 0) {
121
+ autoCollectMax = parseInt(positional[j]) || 1; j++;
122
+ autoScrapeDepth = parseInt(positional[j]) || 50; j++;
123
+ autoMaxComments = parseInt(positional[j]) || 200; j++;
124
+ autoMaxGuess = parseInt(positional[j]) || 10;
125
+ }
126
+
127
+ return {
128
+ subcommand: 'auto',
129
+ autoUsernames: usernames,
130
+ autoCollectMax,
131
+ autoScrapeDepth,
132
+ autoMaxComments,
133
+ autoMaxGuess,
134
+ autoPreset,
135
+ autoSwitchDelay,
136
+ autoCommentDelay,
137
+ serverUrl,
138
+ autoEnableFollow,
139
+ autoMaxFollowing,
140
+ autoMaxFollowers,
141
+ urls: [],
142
+ outputFormat: 'json',
143
+ exploreCount: 0,
144
+ showConfig: false,
145
+ showHelp: false,
146
+ customProxy: null,
147
+ configAction: null,
148
+ configValue: null,
149
+ pipeMode: false,
150
+ filterStr: null,
151
+ };
152
+ }
153
+
154
+ function parseExploreArgs(args) {
155
+ let serverUrl = defaultServer;
156
+ let explorePreset = 'normal';
157
+ let exploreMaxComments = 10;
158
+ let exploreMaxGuess = 0;
159
+ let exploreEnableFollow = true;
160
+ let exploreMaxFollowing = 50;
161
+ let exploreMaxFollowers = 50;
162
+ let exploreLocation = 'PL,NL,BE,DE,FR,IT,ES,IE';
163
+ let exploreMaxUsers = 0;
164
+ let explorePort = null;
165
+ let exploreProfile = null;
166
+ let exploreUserId = null;
167
+ let exploreMaxVideos = 16;
168
+
169
+ const positional = [];
170
+ const PRESETS = ['fast', 'normal', 'slow', 'stealth'];
171
+
172
+ for (let i = 0; i < args.length; i++) {
173
+ const arg = args[i];
174
+ if (arg === '--server') {
175
+ serverUrl = args[++i];
176
+ } else if (arg === '--max-comments') {
177
+ exploreMaxComments = parseInt(args[++i]) || 0;
178
+ } else if (arg === '--max-guess') {
179
+ exploreMaxGuess = parseInt(args[++i]) || 0;
180
+ } else if (arg === '--location') {
181
+ exploreLocation = args[++i];
182
+ } else if (arg === '--enable-follow') {
183
+ exploreEnableFollow = true;
184
+ } else if (arg === '--disable-follow') {
185
+ exploreEnableFollow = false;
186
+ } else if (arg === '--max-following') {
187
+ exploreMaxFollowing = parseInt(args[++i]) || 50;
188
+
189
+ exploreMaxFollowers = parseInt(args[++i]) || 50;
190
+ } else if (arg === '--max-users') {
191
+ exploreMaxUsers = parseInt(args[++i]) || 0;
192
+ } else if (arg === '--port') {
193
+ explorePort = parseInt(args[++i]) || 9222;
194
+ } else if (arg === '--profile') {
195
+ exploreProfile = args[++i];
196
+ } else if (arg === '--user-id') {
197
+ exploreUserId = args[++i];
198
+ } else if (arg === '--max-videos') {
199
+ exploreMaxVideos = parseInt(args[++i]) || 16;
200
+ } else {
201
+ positional.push(arg);
202
+ }
203
+ }
204
+
205
+ const usernames = [];
206
+ let j = 0;
207
+ while (j < positional.length && !PRESETS.includes(positional[j]?.toLowerCase()) && isNaN(positional[j])) {
208
+ usernames.push(positional[j].replace('@', ''));
209
+ j++;
210
+ }
211
+
212
+ if (j < positional.length && PRESETS.includes(positional[j].toLowerCase())) {
213
+ explorePreset = positional[j].toLowerCase();
214
+ j++;
215
+ }
216
+
217
+ return {
218
+ subcommand: 'explore',
219
+ exploreUsernames: usernames,
220
+ explorePreset,
221
+ exploreMaxComments,
222
+ exploreMaxGuess,
223
+ exploreEnableFollow,
224
+ exploreMaxFollowing,
225
+ exploreMaxFollowers,
226
+ exploreLocation,
227
+ serverUrl,
228
+ exploreMaxUsers,
229
+ explorePort,
230
+ exploreProfile,
231
+ exploreUserId,
232
+ exploreMaxVideos,
233
+ urls: [],
234
+ outputFormat: 'json',
235
+ exploreCount: 0,
236
+ showConfig: false,
237
+ showHelp: false,
238
+ customProxy: null,
239
+ configAction: null,
240
+ configValue: null,
241
+ pipeMode: false,
242
+ filterStr: null,
243
+ };
244
+ }
245
+
246
+ function parseVideosArgs(args) {
247
+ let videosUsername = null;
248
+ let videosMax = 5;
249
+ let outputFile = null;
250
+
251
+ const positional = [];
252
+
253
+ for (let i = 0; i < args.length; i++) {
254
+ const arg = args[i];
255
+ if (arg === '-o' || arg === '--output') {
256
+ outputFile = args[++i];
257
+ } else {
258
+ positional.push(arg);
259
+ }
260
+ }
261
+
262
+ videosUsername = positional[0] ? positional[0].replace('@', '') : null;
263
+ videosMax = parseInt(positional[1]) || 5;
264
+
265
+ return {
266
+ subcommand: 'videos',
267
+ videosUsername,
268
+ videosMax,
269
+ outputFile,
270
+ urls: [],
271
+ outputFormat: 'json',
272
+ exploreCount: 0,
273
+ showConfig: false,
274
+ showHelp: false,
275
+ customProxy: null,
276
+ configAction: null,
277
+ configValue: null,
278
+ pipeMode: false,
279
+ filterStr: null,
280
+ };
281
+ }
282
+
283
+ function parseInfoArgs(args) {
284
+ let onlyVideo = false;
285
+ const urls = [];
286
+
287
+ for (let i = 0; i < args.length; i++) {
288
+ const arg = args[i];
289
+ if (arg === '--onlyvideo') {
290
+ onlyVideo = true;
291
+ } else if (!arg.startsWith('--')) {
292
+ urls.push(arg);
293
+ }
294
+ }
295
+
296
+ return {
297
+ subcommand: 'info',
298
+ infoUrls: urls,
299
+ infoOnlyVideo: onlyVideo,
300
+ outputFile: null,
301
+ outputFormat: 'json',
302
+ exploreCount: 0,
303
+ showConfig: false,
304
+ showHelp: false,
305
+ showVersion: false,
306
+ customProxy: null,
307
+ configAction: null,
308
+ configKey: null,
309
+ configValue: null,
310
+ pipeMode: false,
311
+ filterStr: null,
312
+ };
313
+ }
314
+
315
+ function parseWatchArgs(args) {
316
+ let outputFile = './result.json';
317
+ let watchPort = 3001;
318
+
319
+ for (let i = 0; i < args.length; i++) {
320
+ const arg = args[i];
321
+ if (arg === '-o' || arg === '--output') {
322
+ outputFile = args[++i];
323
+ } else if (arg === '-p') {
324
+ watchPort = parseInt(args[++i]) || 3001;
325
+ }
326
+ }
327
+
328
+ return {
329
+ subcommand: 'watch',
330
+ outputFile,
331
+ watchPort,
332
+ urls: [],
333
+ outputFormat: 'json',
334
+ exploreCount: 0,
335
+ showConfig: false,
336
+ showHelp: false,
337
+ customProxy: null,
338
+ configAction: null,
339
+ configValue: null,
340
+ pipeMode: false,
341
+ filterStr: null,
342
+ };
343
+ }
344
+
345
+ function parseRefreshArgs(args) {
346
+ let serverUrl = defaultServer;
347
+ let explorePreset = 'normal';
348
+ let exploreMaxComments = 10;
349
+ let exploreMaxGuess = 0;
350
+ let explorePort = null;
351
+ let exploreProfile = null;
352
+ let exploreUserId = null;
353
+
354
+ for (let i = 0; i < args.length; i++) {
355
+ const arg = args[i];
356
+ if (arg === '--server') {
357
+ serverUrl = args[++i];
358
+ } else if (arg === '--comments') {
359
+ exploreMaxComments = parseInt(args[++i]) || 10;
360
+ } else if (arg === '--guess') {
361
+ exploreMaxGuess = parseInt(args[++i]) || 0;
362
+ } else if (arg === '--preset') {
363
+ explorePreset = args[++i];
364
+ } else if (arg === '--port') {
365
+ explorePort = parseInt(args[++i]) || 9222;
366
+ } else if (arg === '--profile') {
367
+ exploreProfile = args[++i];
368
+ } else if (arg === '--user-id') {
369
+ exploreUserId = args[++i];
370
+ }
371
+ }
372
+
373
+ return {
374
+ subcommand: 'refresh',
375
+ explorePreset,
376
+ exploreMaxComments,
377
+ exploreMaxGuess,
378
+ explorePort,
379
+ exploreProfile,
380
+ exploreUserId,
381
+ serverUrl,
382
+ urls: [],
383
+ outputFormat: 'json',
384
+ exploreCount: 0,
385
+ showConfig: false,
386
+ showHelp: false,
387
+ customProxy: null,
388
+ configAction: null,
389
+ configValue: null,
390
+ pipeMode: false,
391
+ filterStr: null,
392
+ };
393
+ }
394
+
395
+ function parseAttachArgs(args) {
396
+ let parallel = 1;
397
+ let interval = 10;
398
+ let serverUrl = defaultServer;
399
+
400
+ for (let i = 0; i < args.length; i++) {
401
+ const arg = args[i];
402
+ if (arg === '-p' || arg === '--parallel') {
403
+ parallel = parseInt(args[++i], 10) || 1;
404
+ } else if (arg === '-i' || arg === '--interval') {
405
+ interval = parseInt(args[++i], 10) || 10;
406
+ } else if (arg === '-s' || arg === '--server') {
407
+ serverUrl = args[++i];
408
+ }
409
+ }
410
+
411
+ return {
412
+ subcommand: 'attach',
413
+ attachParallel: parallel,
414
+ attachInterval: interval,
415
+ serverUrl,
416
+ urls: [],
417
+ outputFormat: 'json',
418
+ exploreCount: 0,
419
+ showConfig: false,
420
+ showHelp: false,
421
+ customProxy: null,
422
+ configAction: null,
423
+ configValue: null,
424
+ pipeMode: false,
425
+ filterStr: null,
426
+ };
427
+ }
428
+
429
+ function parseOpenArgs(args) {
430
+ let openPort = null;
431
+ let openList = false;
432
+
433
+ for (let i = 0; i < args.length; i++) {
434
+ const arg = args[i];
435
+ if (arg === '--list') {
436
+ openList = true;
437
+ } else if (!arg.startsWith('-')) {
438
+ openPort = arg;
439
+ }
440
+ }
441
+
442
+ return {
443
+ subcommand: 'open',
444
+ openPort,
445
+ openList,
446
+ urls: [],
447
+ outputFormat: 'json',
448
+ exploreCount: 0,
449
+ showConfig: false,
450
+ showHelp: false,
451
+ customProxy: null,
452
+ configAction: null,
453
+ configValue: null,
454
+ pipeMode: false,
455
+ filterStr: null,
456
+ };
457
+ }
458
+
459
+ export function parseArgs() {
460
+ const args = process.argv.slice(2);
461
+
462
+ if (args.includes('-h') || args.includes('--help')) {
463
+ return { showHelp: true, showVersion: false, subcommand: null, urls: [], outputFile: null, outputFormat: 'json', exploreCount: 0, showConfig: false, customProxy: null, configAction: null, configValue: null, pipeMode: false, filterStr: null };
464
+ }
465
+ if (args.includes('--version')) {
466
+ return { showHelp: false, showVersion: true, subcommand: null, urls: [], outputFile: null, outputFormat: 'json', exploreCount: 0, showConfig: false, customProxy: null, configAction: null, configValue: null, pipeMode: false, filterStr: null };
467
+ }
468
+
469
+ if (args.length > 0 && args[0] === 'explore') {
470
+ return parseExploreArgs(args.slice(1));
471
+ }
472
+
473
+ if (args.length > 0 && args[0] === 'info') {
474
+ return parseInfoArgs(args.slice(1));
475
+ }
476
+
477
+ if (args.length > 0 && args[0] === 'watch') {
478
+ return parseWatchArgs(args.slice(1));
479
+ }
480
+
481
+ if (args.length > 0 && args[0] === 'attach') {
482
+ return parseAttachArgs(args.slice(1));
483
+ }
484
+
485
+ if (args.length > 0 && args[0] === 'open') {
486
+ return parseOpenArgs(args.slice(1));
487
+ }
488
+
489
+ const urls = [];
490
+ let inputFile = null;
491
+ let outputFile = null;
492
+ let outputFormat = 'json';
493
+ let exploreCount = 0;
494
+ let showConfig = false;
495
+ let showHelp = false;
496
+ let showVersion = false;
497
+ let customProxy = null;
498
+ let configAction = null;
499
+ let configKey = null;
500
+ let configValue = null;
501
+ let pipeMode = false;
502
+ let filterStr = null;
503
+
504
+ for (let i = 0; i < args.length; i++) {
505
+ const arg = args[i];
506
+
507
+ if (arg === '--explore') {
508
+ exploreCount = args[i + 1] && !args[i + 1].startsWith('http')
509
+ ? parseInt(args[++i], 10)
510
+ : 100;
511
+ } else if (arg === '--proxy') {
512
+ customProxy = args[++i];
513
+ } else if (arg === '--filter') {
514
+ filterStr = args[++i];
515
+ } else if (arg === 'config') {
516
+ configAction = args[i + 1];
517
+ if (!configAction) {
518
+ configAction = 'show';
519
+ } else if (configAction === 'set' || configAction === 'set-proxy' || configAction === 'set-browser') {
520
+ configKey = args[i + 2];
521
+ configValue = args[i + 3];
522
+ i += 3;
523
+ } else {
524
+ i++;
525
+ }
526
+ } else if (arg === '--pipe') {
527
+ pipeMode = true;
528
+ } else if (arg === '-i' || arg === '--input') {
529
+ inputFile = args[++i];
530
+ } else if (arg === '-o' || arg === '--output') {
531
+ outputFile = args[++i];
532
+ } else if (arg === '-f' || arg === '--format') {
533
+ outputFormat = args[++i];
534
+ } else if (arg === '-c' || arg === '--config') {
535
+ showConfig = true;
536
+ } else if (arg === '-h' || arg === '--help') {
537
+ showHelp = true;
538
+ } else if (arg === '--version') {
539
+ showVersion = true;
540
+ } else if (arg.startsWith('http')) {
541
+ urls.push(arg);
542
+ }
543
+ }
544
+
545
+ if (inputFile) {
546
+ const content = readFileSync(inputFile, 'utf-8');
547
+ const lines = content.split(/\r?\n/).map(l => l.trim()).filter(l => l.startsWith('http'));
548
+ urls.push(...lines);
549
+ }
550
+
551
+ return { urls, outputFile, outputFormat, exploreCount, showConfig, showHelp, showVersion, customProxy, configAction, configKey, configValue, pipeMode, filterStr };
552
552
  }