tt-help-cli-ycl 1.3.12 → 1.3.13

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 (50) hide show
  1. package/README.md +17 -17
  2. package/cli.js +9 -9
  3. package/package.json +45 -45
  4. package/scripts/run-explore.bat +68 -68
  5. package/scripts/run-explore.ps1 +81 -81
  6. package/scripts/run-explore.sh +73 -73
  7. package/scripts/test-captcha-lib.mjs +68 -0
  8. package/scripts/test-captcha.mjs +81 -0
  9. package/scripts/test-incognito-lib.mjs +36 -0
  10. package/scripts/test-login-state.mjs +128 -0
  11. package/scripts/test-safe-click.mjs +45 -0
  12. package/src/cli/auto.js +186 -157
  13. package/src/cli/explore.js +227 -193
  14. package/src/cli/progress.js +111 -111
  15. package/src/cli/refresh.js +216 -0
  16. package/src/cli/scrape.js +47 -47
  17. package/src/cli/utils.js +18 -18
  18. package/src/cli/videos.js +41 -41
  19. package/src/cli/watch.js +31 -31
  20. package/src/lib/args.js +456 -402
  21. package/src/lib/browser/anti-detect.js +23 -23
  22. package/src/lib/browser/cdp.js +52 -10
  23. package/src/lib/browser/launch.js +43 -43
  24. package/src/lib/browser/page.js +146 -87
  25. package/src/lib/constants.js +119 -115
  26. package/src/lib/delay.js +54 -54
  27. package/src/lib/explore-fetch.js +118 -118
  28. package/src/lib/fetcher.js +45 -45
  29. package/src/lib/filter.js +66 -66
  30. package/src/lib/io.js +54 -54
  31. package/src/lib/output.js +80 -80
  32. package/src/lib/parser.js +47 -47
  33. package/src/lib/retry.js +45 -45
  34. package/src/lib/scrape.js +40 -40
  35. package/src/lib/url.js +52 -52
  36. package/src/main.js +2 -0
  37. package/src/results/user-videos-bar.lar.lar.moeta.json +37 -0
  38. package/src/scraper/auto-core.js +203 -194
  39. package/src/scraper/core.js +211 -190
  40. package/src/scraper/explore-core.js +180 -171
  41. package/src/scraper/modules/captcha-handler.js +114 -114
  42. package/src/scraper/modules/comment-extractor.js +74 -69
  43. package/src/scraper/modules/follow-extractor.js +121 -121
  44. package/src/scraper/modules/guess-extractor.js +51 -51
  45. package/src/scraper/modules/page-helpers.js +48 -48
  46. package/src/scraper/refresh-core.js +179 -0
  47. package/src/videos/core.js +126 -126
  48. package/src/watch/data-store.js +431 -302
  49. package/src/watch/public/index.html +721 -701
  50. package/src/watch/server.js +483 -359
package/src/lib/args.js CHANGED
@@ -1,403 +1,457 @@
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 = 5;
161
- let exploreMaxFollowers = 5;
162
- let exploreLocation = 'ES';
163
- let exploreMaxUsers = 0;
164
- let explorePort = null;
165
- let exploreProfile = null;
166
- let exploreUserId = null;
167
-
168
- const positional = [];
169
- const PRESETS = ['fast', 'normal', 'slow', 'stealth'];
170
-
171
- for (let i = 0; i < args.length; i++) {
172
- const arg = args[i];
173
- if (arg === '--server') {
174
- serverUrl = args[++i];
175
- } else if (arg === '--max-comments') {
176
- exploreMaxComments = parseInt(args[++i]) || 0;
177
- } else if (arg === '--max-guess') {
178
- exploreMaxGuess = parseInt(args[++i]) || 0;
179
- } else if (arg === '--location') {
180
- exploreLocation = args[++i];
181
- } else if (arg === '--enable-follow') {
182
- exploreEnableFollow = true;
183
- } else if (arg === '--disable-follow') {
184
- exploreEnableFollow = false;
185
- } else if (arg === '--max-following') {
186
- exploreMaxFollowing = parseInt(args[++i]) || 5;
187
- } else if (arg === '--max-followers') {
188
- exploreMaxFollowers = parseInt(args[++i]) || 5;
189
- } else if (arg === '--max-users') {
190
- exploreMaxUsers = parseInt(args[++i]) || 0;
191
- } else if (arg === '--port') {
192
- explorePort = parseInt(args[++i]) || 9222;
193
- } else if (arg === '--profile') {
194
- exploreProfile = args[++i];
195
- } else if (arg === '--user-id') {
196
- exploreUserId = args[++i];
197
- } else {
198
- positional.push(arg);
199
- }
200
- }
201
-
202
- const usernames = [];
203
- let j = 0;
204
- while (j < positional.length && !PRESETS.includes(positional[j]?.toLowerCase()) && isNaN(positional[j])) {
205
- usernames.push(positional[j].replace('@', ''));
206
- j++;
207
- }
208
-
209
- if (j < positional.length && PRESETS.includes(positional[j].toLowerCase())) {
210
- explorePreset = positional[j].toLowerCase();
211
- j++;
212
- }
213
-
214
- return {
215
- subcommand: 'explore',
216
- exploreUsernames: usernames,
217
- explorePreset,
218
- exploreMaxComments,
219
- exploreMaxGuess,
220
- exploreEnableFollow,
221
- exploreMaxFollowing,
222
- exploreMaxFollowers,
223
- exploreLocation,
224
- serverUrl,
225
- exploreMaxUsers,
226
- explorePort,
227
- exploreProfile,
228
- exploreUserId,
229
- urls: [],
230
- outputFormat: 'json',
231
- exploreCount: 0,
232
- showConfig: false,
233
- showHelp: false,
234
- customProxy: null,
235
- configAction: null,
236
- configValue: null,
237
- pipeMode: false,
238
- filterStr: null,
239
- };
240
- }
241
-
242
- function parseVideosArgs(args) {
243
- let videosUsername = null;
244
- let videosMax = 5;
245
- let outputFile = null;
246
-
247
- const positional = [];
248
-
249
- for (let i = 0; i < args.length; i++) {
250
- const arg = args[i];
251
- if (arg === '-o' || arg === '--output') {
252
- outputFile = args[++i];
253
- } else {
254
- positional.push(arg);
255
- }
256
- }
257
-
258
- videosUsername = positional[0] ? positional[0].replace('@', '') : null;
259
- videosMax = parseInt(positional[1]) || 5;
260
-
261
- return {
262
- subcommand: 'videos',
263
- videosUsername,
264
- videosMax,
265
- outputFile,
266
- urls: [],
267
- outputFormat: 'json',
268
- exploreCount: 0,
269
- showConfig: false,
270
- showHelp: false,
271
- customProxy: null,
272
- configAction: null,
273
- configValue: null,
274
- pipeMode: false,
275
- filterStr: null,
276
- };
277
- }
278
-
279
- function parseWatchArgs(args) {
280
- let outputFile = './result.json';
281
- let watchPort = 3001;
282
-
283
- for (let i = 0; i < args.length; i++) {
284
- const arg = args[i];
285
- if (arg === '-o' || arg === '--output') {
286
- outputFile = args[++i];
287
- } else if (arg === '-p') {
288
- watchPort = parseInt(args[++i]) || 3001;
289
- }
290
- }
291
-
292
- return {
293
- subcommand: 'watch',
294
- outputFile,
295
- watchPort,
296
- urls: [],
297
- outputFormat: 'json',
298
- exploreCount: 0,
299
- showConfig: false,
300
- showHelp: false,
301
- customProxy: null,
302
- configAction: null,
303
- configValue: null,
304
- pipeMode: false,
305
- filterStr: null,
306
- };
307
- }
308
-
309
- export function parseArgs() {
310
- const args = process.argv.slice(2);
311
-
312
- // Global flags take precedence over subcommands
313
- if (args.includes('-h') || args.includes('--help')) {
314
- 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 };
315
- }
316
- if (args.includes('--version')) {
317
- 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 };
318
- }
319
-
320
- if (args.length > 0 && args[0] === 'scrape') {
321
- return parseScrapeArgs(args.slice(1));
322
- }
323
-
324
- if (args.length > 0 && args[0] === 'videos') {
325
- return parseVideosArgs(args.slice(1));
326
- }
327
-
328
- if (args.length > 0 && args[0] === 'auto') {
329
- return parseAutoArgs(args.slice(1));
330
- }
331
-
332
- if (args.length > 0 && args[0] === 'explore') {
333
- return parseExploreArgs(args.slice(1));
334
- }
335
-
336
- if (args.length > 0 && args[0] === 'watch') {
337
- return parseWatchArgs(args.slice(1));
338
- }
339
-
340
- const urls = [];
341
- let inputFile = null;
342
- let outputFile = null;
343
- let outputFormat = 'json';
344
- let exploreCount = 0;
345
- let showConfig = false;
346
- let showHelp = false;
347
- let showVersion = false;
348
- let customProxy = null;
349
- let configAction = null;
350
- let configKey = null;
351
- let configValue = null;
352
- let pipeMode = false;
353
- let filterStr = null;
354
-
355
- for (let i = 0; i < args.length; i++) {
356
- const arg = args[i];
357
-
358
- if (arg === '--explore') {
359
- exploreCount = args[i + 1] && !args[i + 1].startsWith('http')
360
- ? parseInt(args[++i], 10)
361
- : 100;
362
- } else if (arg === '--proxy') {
363
- customProxy = args[++i];
364
- } else if (arg === '--filter') {
365
- filterStr = args[++i];
366
- } else if (arg === 'config') {
367
- configAction = args[i + 1];
368
- if (!configAction) {
369
- configAction = 'show';
370
- } else if (configAction === 'set' || configAction === 'set-proxy' || configAction === 'set-browser') {
371
- configKey = args[i + 2];
372
- configValue = args[i + 3];
373
- i += 3;
374
- } else {
375
- i++;
376
- }
377
- } else if (arg === '--pipe') {
378
- pipeMode = true;
379
- } else if (arg === '-i' || arg === '--input') {
380
- inputFile = args[++i];
381
- } else if (arg === '-o' || arg === '--output') {
382
- outputFile = args[++i];
383
- } else if (arg === '-f' || arg === '--format') {
384
- outputFormat = args[++i];
385
- } else if (arg === '-c' || arg === '--config') {
386
- showConfig = true;
387
- } else if (arg === '-h' || arg === '--help') {
388
- showHelp = true;
389
- } else if (arg === '--version') {
390
- showVersion = true;
391
- } else if (arg.startsWith('http')) {
392
- urls.push(arg);
393
- }
394
- }
395
-
396
- if (inputFile) {
397
- const content = readFileSync(inputFile, 'utf-8');
398
- const lines = content.split(/\r?\n/).map(l => l.trim()).filter(l => l.startsWith('http'));
399
- urls.push(...lines);
400
- }
401
-
402
- 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 = 5;
161
+ let exploreMaxFollowers = 5;
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
+
168
+ const positional = [];
169
+ const PRESETS = ['fast', 'normal', 'slow', 'stealth'];
170
+
171
+ for (let i = 0; i < args.length; i++) {
172
+ const arg = args[i];
173
+ if (arg === '--server') {
174
+ serverUrl = args[++i];
175
+ } else if (arg === '--max-comments') {
176
+ exploreMaxComments = parseInt(args[++i]) || 0;
177
+ } else if (arg === '--max-guess') {
178
+ exploreMaxGuess = parseInt(args[++i]) || 0;
179
+ } else if (arg === '--location') {
180
+ exploreLocation = args[++i];
181
+ } else if (arg === '--enable-follow') {
182
+ exploreEnableFollow = true;
183
+ } else if (arg === '--disable-follow') {
184
+ exploreEnableFollow = false;
185
+ } else if (arg === '--max-following') {
186
+ exploreMaxFollowing = parseInt(args[++i]) || 5;
187
+ } else if (arg === '--max-followers') {
188
+ exploreMaxFollowers = parseInt(args[++i]) || 5;
189
+ } else if (arg === '--max-users') {
190
+ exploreMaxUsers = parseInt(args[++i]) || 0;
191
+ } else if (arg === '--port') {
192
+ explorePort = parseInt(args[++i]) || 9222;
193
+ } else if (arg === '--profile') {
194
+ exploreProfile = args[++i];
195
+ } else if (arg === '--user-id') {
196
+ exploreUserId = args[++i];
197
+ } else {
198
+ positional.push(arg);
199
+ }
200
+ }
201
+
202
+ const usernames = [];
203
+ let j = 0;
204
+ while (j < positional.length && !PRESETS.includes(positional[j]?.toLowerCase()) && isNaN(positional[j])) {
205
+ usernames.push(positional[j].replace('@', ''));
206
+ j++;
207
+ }
208
+
209
+ if (j < positional.length && PRESETS.includes(positional[j].toLowerCase())) {
210
+ explorePreset = positional[j].toLowerCase();
211
+ j++;
212
+ }
213
+
214
+ return {
215
+ subcommand: 'explore',
216
+ exploreUsernames: usernames,
217
+ explorePreset,
218
+ exploreMaxComments,
219
+ exploreMaxGuess,
220
+ exploreEnableFollow,
221
+ exploreMaxFollowing,
222
+ exploreMaxFollowers,
223
+ exploreLocation,
224
+ serverUrl,
225
+ exploreMaxUsers,
226
+ explorePort,
227
+ exploreProfile,
228
+ exploreUserId,
229
+ urls: [],
230
+ outputFormat: 'json',
231
+ exploreCount: 0,
232
+ showConfig: false,
233
+ showHelp: false,
234
+ customProxy: null,
235
+ configAction: null,
236
+ configValue: null,
237
+ pipeMode: false,
238
+ filterStr: null,
239
+ };
240
+ }
241
+
242
+ function parseVideosArgs(args) {
243
+ let videosUsername = null;
244
+ let videosMax = 5;
245
+ let outputFile = null;
246
+
247
+ const positional = [];
248
+
249
+ for (let i = 0; i < args.length; i++) {
250
+ const arg = args[i];
251
+ if (arg === '-o' || arg === '--output') {
252
+ outputFile = args[++i];
253
+ } else {
254
+ positional.push(arg);
255
+ }
256
+ }
257
+
258
+ videosUsername = positional[0] ? positional[0].replace('@', '') : null;
259
+ videosMax = parseInt(positional[1]) || 5;
260
+
261
+ return {
262
+ subcommand: 'videos',
263
+ videosUsername,
264
+ videosMax,
265
+ outputFile,
266
+ urls: [],
267
+ outputFormat: 'json',
268
+ exploreCount: 0,
269
+ showConfig: false,
270
+ showHelp: false,
271
+ customProxy: null,
272
+ configAction: null,
273
+ configValue: null,
274
+ pipeMode: false,
275
+ filterStr: null,
276
+ };
277
+ }
278
+
279
+ function parseWatchArgs(args) {
280
+ let outputFile = './result.json';
281
+ let watchPort = 3001;
282
+
283
+ for (let i = 0; i < args.length; i++) {
284
+ const arg = args[i];
285
+ if (arg === '-o' || arg === '--output') {
286
+ outputFile = args[++i];
287
+ } else if (arg === '-p') {
288
+ watchPort = parseInt(args[++i]) || 3001;
289
+ }
290
+ }
291
+
292
+ return {
293
+ subcommand: 'watch',
294
+ outputFile,
295
+ watchPort,
296
+ urls: [],
297
+ outputFormat: 'json',
298
+ exploreCount: 0,
299
+ showConfig: false,
300
+ showHelp: false,
301
+ customProxy: null,
302
+ configAction: null,
303
+ configValue: null,
304
+ pipeMode: false,
305
+ filterStr: null,
306
+ };
307
+ }
308
+
309
+ function parseRefreshArgs(args) {
310
+ let serverUrl = defaultServer;
311
+ let explorePreset = 'normal';
312
+ let exploreMaxComments = 10;
313
+ let exploreMaxGuess = 0;
314
+ let explorePort = null;
315
+ let exploreProfile = null;
316
+ let exploreUserId = null;
317
+
318
+ for (let i = 0; i < args.length; i++) {
319
+ const arg = args[i];
320
+ if (arg === '--server') {
321
+ serverUrl = args[++i];
322
+ } else if (arg === '--comments') {
323
+ exploreMaxComments = parseInt(args[++i]) || 10;
324
+ } else if (arg === '--guess') {
325
+ exploreMaxGuess = parseInt(args[++i]) || 0;
326
+ } else if (arg === '--preset') {
327
+ explorePreset = args[++i];
328
+ } else if (arg === '--port') {
329
+ explorePort = parseInt(args[++i]) || 9222;
330
+ } else if (arg === '--profile') {
331
+ exploreProfile = args[++i];
332
+ } else if (arg === '--user-id') {
333
+ exploreUserId = args[++i];
334
+ }
335
+ }
336
+
337
+ return {
338
+ subcommand: 'refresh',
339
+ explorePreset,
340
+ exploreMaxComments,
341
+ exploreMaxGuess,
342
+ explorePort,
343
+ exploreProfile,
344
+ exploreUserId,
345
+ serverUrl,
346
+ urls: [],
347
+ outputFormat: 'json',
348
+ exploreCount: 0,
349
+ showConfig: false,
350
+ showHelp: false,
351
+ customProxy: null,
352
+ configAction: null,
353
+ configValue: null,
354
+ pipeMode: false,
355
+ filterStr: null,
356
+ };
357
+ }
358
+
359
+ export function parseArgs() {
360
+ const args = process.argv.slice(2);
361
+
362
+ // Global flags take precedence over subcommands
363
+ if (args.includes('-h') || args.includes('--help')) {
364
+ 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 };
365
+ }
366
+ if (args.includes('--version')) {
367
+ 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 };
368
+ }
369
+
370
+ if (args.length > 0 && args[0] === 'scrape') {
371
+ return parseScrapeArgs(args.slice(1));
372
+ }
373
+
374
+ if (args.length > 0 && args[0] === 'videos') {
375
+ return parseVideosArgs(args.slice(1));
376
+ }
377
+
378
+ if (args.length > 0 && args[0] === 'auto') {
379
+ return parseAutoArgs(args.slice(1));
380
+ }
381
+
382
+ if (args.length > 0 && args[0] === 'explore') {
383
+ return parseExploreArgs(args.slice(1));
384
+ }
385
+
386
+ if (args.length > 0 && args[0] === 'refresh') {
387
+ return parseRefreshArgs(args.slice(1));
388
+ }
389
+
390
+ if (args.length > 0 && args[0] === 'watch') {
391
+ return parseWatchArgs(args.slice(1));
392
+ }
393
+
394
+ const urls = [];
395
+ let inputFile = null;
396
+ let outputFile = null;
397
+ let outputFormat = 'json';
398
+ let exploreCount = 0;
399
+ let showConfig = false;
400
+ let showHelp = false;
401
+ let showVersion = false;
402
+ let customProxy = null;
403
+ let configAction = null;
404
+ let configKey = null;
405
+ let configValue = null;
406
+ let pipeMode = false;
407
+ let filterStr = null;
408
+
409
+ for (let i = 0; i < args.length; i++) {
410
+ const arg = args[i];
411
+
412
+ if (arg === '--explore') {
413
+ exploreCount = args[i + 1] && !args[i + 1].startsWith('http')
414
+ ? parseInt(args[++i], 10)
415
+ : 100;
416
+ } else if (arg === '--proxy') {
417
+ customProxy = args[++i];
418
+ } else if (arg === '--filter') {
419
+ filterStr = args[++i];
420
+ } else if (arg === 'config') {
421
+ configAction = args[i + 1];
422
+ if (!configAction) {
423
+ configAction = 'show';
424
+ } else if (configAction === 'set' || configAction === 'set-proxy' || configAction === 'set-browser') {
425
+ configKey = args[i + 2];
426
+ configValue = args[i + 3];
427
+ i += 3;
428
+ } else {
429
+ i++;
430
+ }
431
+ } else if (arg === '--pipe') {
432
+ pipeMode = true;
433
+ } else if (arg === '-i' || arg === '--input') {
434
+ inputFile = args[++i];
435
+ } else if (arg === '-o' || arg === '--output') {
436
+ outputFile = args[++i];
437
+ } else if (arg === '-f' || arg === '--format') {
438
+ outputFormat = args[++i];
439
+ } else if (arg === '-c' || arg === '--config') {
440
+ showConfig = true;
441
+ } else if (arg === '-h' || arg === '--help') {
442
+ showHelp = true;
443
+ } else if (arg === '--version') {
444
+ showVersion = true;
445
+ } else if (arg.startsWith('http')) {
446
+ urls.push(arg);
447
+ }
448
+ }
449
+
450
+ if (inputFile) {
451
+ const content = readFileSync(inputFile, 'utf-8');
452
+ const lines = content.split(/\r?\n/).map(l => l.trim()).filter(l => l.startsWith('http'));
453
+ urls.push(...lines);
454
+ }
455
+
456
+ return { urls, outputFile, outputFormat, exploreCount, showConfig, showHelp, showVersion, customProxy, configAction, configKey, configValue, pipeMode, filterStr };
403
457
  }