tt-help-cli-ycl 1.3.12 → 1.3.14

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 (55) hide show
  1. package/README.md +17 -17
  2. package/cli.js +9 -9
  3. package/package.json +47 -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/attach.js +160 -0
  13. package/src/cli/auto.js +186 -157
  14. package/src/cli/config.js +39 -3
  15. package/src/cli/explore.js +234 -193
  16. package/src/cli/info.js +88 -0
  17. package/src/cli/progress.js +111 -111
  18. package/src/cli/refresh.js +216 -0
  19. package/src/cli/scrape.js +47 -47
  20. package/src/cli/utils.js +18 -18
  21. package/src/cli/videos.js +41 -41
  22. package/src/cli/watch.js +31 -31
  23. package/src/lib/args.js +517 -402
  24. package/src/lib/browser/anti-detect.js +23 -23
  25. package/src/lib/browser/cdp.js +52 -10
  26. package/src/lib/browser/launch.js +43 -43
  27. package/src/lib/browser/page.js +146 -87
  28. package/src/lib/constants.js +199 -115
  29. package/src/lib/delay.js +54 -54
  30. package/src/lib/explore-fetch.js +118 -118
  31. package/src/lib/fetcher.js +45 -45
  32. package/src/lib/filter.js +66 -66
  33. package/src/lib/io.js +54 -54
  34. package/src/lib/output.js +80 -80
  35. package/src/lib/parse-ssr.mjs +69 -0
  36. package/src/lib/parser.js +47 -47
  37. package/src/lib/retry.js +45 -45
  38. package/src/lib/scrape.js +89 -40
  39. package/src/lib/tiktok-scraper.mjs +176 -0
  40. package/src/lib/url.js +52 -52
  41. package/src/main.js +12 -16
  42. package/src/results/user-videos-bar.lar.lar.moeta.json +37 -0
  43. package/src/scraper/auto-core.js +203 -194
  44. package/src/scraper/core.js +211 -190
  45. package/src/scraper/explore-core.js +162 -171
  46. package/src/scraper/modules/captcha-handler.js +114 -114
  47. package/src/scraper/modules/comment-extractor.js +74 -69
  48. package/src/scraper/modules/follow-extractor.js +121 -121
  49. package/src/scraper/modules/guess-extractor.js +51 -51
  50. package/src/scraper/modules/page-helpers.js +48 -48
  51. package/src/scraper/refresh-core.js +179 -0
  52. package/src/videos/core.js +126 -126
  53. package/src/watch/data-store.js +536 -302
  54. package/src/watch/public/index.html +721 -701
  55. package/src/watch/server.js +527 -359
package/src/lib/args.js CHANGED
@@ -1,403 +1,518 @@
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
+ let exploreMaxVideos = 1;
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]) || 5;
188
+ } else if (arg === '--max-followers') {
189
+ exploreMaxFollowers = parseInt(args[++i]) || 5;
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]) || 1;
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
+ export function parseArgs() {
430
+ const args = process.argv.slice(2);
431
+
432
+ if (args.includes('-h') || args.includes('--help')) {
433
+ 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 };
434
+ }
435
+ if (args.includes('--version')) {
436
+ 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 };
437
+ }
438
+
439
+ if (args.length > 0 && args[0] === 'explore') {
440
+ return parseExploreArgs(args.slice(1));
441
+ }
442
+
443
+ if (args.length > 0 && args[0] === 'info') {
444
+ return parseInfoArgs(args.slice(1));
445
+ }
446
+
447
+ if (args.length > 0 && args[0] === 'watch') {
448
+ return parseWatchArgs(args.slice(1));
449
+ }
450
+
451
+ if (args.length > 0 && args[0] === 'attach') {
452
+ return parseAttachArgs(args.slice(1));
453
+ }
454
+
455
+ const urls = [];
456
+ let inputFile = null;
457
+ let outputFile = null;
458
+ let outputFormat = 'json';
459
+ let exploreCount = 0;
460
+ let showConfig = false;
461
+ let showHelp = false;
462
+ let showVersion = false;
463
+ let customProxy = null;
464
+ let configAction = null;
465
+ let configKey = null;
466
+ let configValue = null;
467
+ let pipeMode = false;
468
+ let filterStr = null;
469
+
470
+ for (let i = 0; i < args.length; i++) {
471
+ const arg = args[i];
472
+
473
+ if (arg === '--explore') {
474
+ exploreCount = args[i + 1] && !args[i + 1].startsWith('http')
475
+ ? parseInt(args[++i], 10)
476
+ : 100;
477
+ } else if (arg === '--proxy') {
478
+ customProxy = args[++i];
479
+ } else if (arg === '--filter') {
480
+ filterStr = args[++i];
481
+ } else if (arg === 'config') {
482
+ configAction = args[i + 1];
483
+ if (!configAction) {
484
+ configAction = 'show';
485
+ } else if (configAction === 'set' || configAction === 'set-proxy' || configAction === 'set-browser') {
486
+ configKey = args[i + 2];
487
+ configValue = args[i + 3];
488
+ i += 3;
489
+ } else {
490
+ i++;
491
+ }
492
+ } else if (arg === '--pipe') {
493
+ pipeMode = true;
494
+ } else if (arg === '-i' || arg === '--input') {
495
+ inputFile = args[++i];
496
+ } else if (arg === '-o' || arg === '--output') {
497
+ outputFile = args[++i];
498
+ } else if (arg === '-f' || arg === '--format') {
499
+ outputFormat = args[++i];
500
+ } else if (arg === '-c' || arg === '--config') {
501
+ showConfig = true;
502
+ } else if (arg === '-h' || arg === '--help') {
503
+ showHelp = true;
504
+ } else if (arg === '--version') {
505
+ showVersion = true;
506
+ } else if (arg.startsWith('http')) {
507
+ urls.push(arg);
508
+ }
509
+ }
510
+
511
+ if (inputFile) {
512
+ const content = readFileSync(inputFile, 'utf-8');
513
+ const lines = content.split(/\r?\n/).map(l => l.trim()).filter(l => l.startsWith('http'));
514
+ urls.push(...lines);
515
+ }
516
+
517
+ return { urls, outputFile, outputFormat, exploreCount, showConfig, showHelp, showVersion, customProxy, configAction, configKey, configValue, pipeMode, filterStr };
403
518
  }