tt-help-cli-ycl 1.0.7 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/lib/args.js CHANGED
@@ -1,288 +1,398 @@
1
- import { readFileSync } from 'fs';
2
- import { proxy } 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 scrapeSwitchDelay = null;
12
- let scrapeCommentDelay = null;
13
- let outputFile = null;
14
-
15
- const positional = [];
16
-
17
- for (let i = 0; i < args.length; i++) {
18
- const arg = args[i];
19
- if (arg === '-o' || arg === '--output') {
20
- outputFile = args[++i];
21
- } else if (arg === '--switch-delay') {
22
- scrapeSwitchDelay = parseInt(args[++i]) || null;
23
- } else if (arg === '--comment-delay') {
24
- scrapeCommentDelay = parseInt(args[++i]) || null;
25
- } else {
26
- positional.push(arg);
27
- }
28
- }
29
-
30
- scrapeUrl = positional[0] || null;
31
-
32
- if (positional[1]) {
33
- if (PRESETS.includes(positional[1].toLowerCase())) {
34
- scrapePreset = positional[1].toLowerCase();
35
- scrapeMaxVideos = parseInt(positional[2]) || 20;
36
- scrapeMaxComments = parseInt(positional[3]) || 999;
37
- } else {
38
- scrapeMaxVideos = parseInt(positional[1]) || 20;
39
- scrapeMaxComments = parseInt(positional[2]) || 999;
40
- }
41
- }
42
-
43
- return {
44
- subcommand: 'scrape',
45
- scrapeUrl,
46
- scrapePreset,
47
- scrapeMaxVideos,
48
- scrapeMaxComments,
49
- scrapeSwitchDelay,
50
- scrapeCommentDelay,
51
- outputFile,
52
- urls: [],
53
- outputFormat: 'json',
54
- exploreCount: 0,
55
- showConfig: false,
56
- showHelp: false,
57
- customProxy: null,
58
- configAction: null,
59
- configValue: null,
60
- pipeMode: false,
61
- filterStr: null,
62
- };
63
- }
64
-
65
- function parseAutoArgs(args) {
66
- let autoCollectMax = 1;
67
- let autoScrapeDepth = 50;
68
- let autoMaxComments = 200;
69
- let autoPreset = 'fast';
70
- let autoSwitchDelay = null;
71
- let autoCommentDelay = null;
72
- let outputFile = null;
73
- let autoWatch = false;
74
- let autoWatchPort = 3000;
75
-
76
- const positional = [];
77
- const PRESETS = ['fast', 'normal', 'slow', 'stealth'];
78
-
79
- for (let i = 0; i < args.length; i++) {
80
- const arg = args[i];
81
- if (arg === '-o' || arg === '--output') {
82
- outputFile = args[++i];
83
- } else if (arg === '--switch-delay') {
84
- autoSwitchDelay = parseInt(args[++i]) || null;
85
- } else if (arg === '--comment-delay') {
86
- autoCommentDelay = parseInt(args[++i]) || null;
87
- } else if (arg === '--watch') {
88
- autoWatch = true;
89
- if (args[i + 1] === '-p') {
90
- autoWatchPort = parseInt(args[i + 2]) || 3000;
91
- i += 2;
92
- }
93
- } else if (arg === '-p' && autoWatch) {
94
- autoWatchPort = parseInt(args[++i]) || 3000;
95
- } else {
96
- positional.push(arg);
97
- }
98
- }
99
-
100
- // 收集用户名(非 preset、非数字的都是用户名)
101
- const usernames = [];
102
- let j = 0;
103
- while (j < positional.length && !PRESETS.includes(positional[j]?.toLowerCase()) && isNaN(positional[j])) {
104
- usernames.push(positional[j].replace('@', ''));
105
- j++;
106
- }
107
-
108
- // preset
109
- if (j < positional.length && PRESETS.includes(positional[j].toLowerCase())) {
110
- autoPreset = positional[j].toLowerCase();
111
- j++;
112
- autoCollectMax = parseInt(positional[j]) || 1; j++;
113
- autoScrapeDepth = parseInt(positional[j]) || 50; j++;
114
- autoMaxComments = parseInt(positional[j]) || 200; j++;
115
- } else if (usernames.length > 0) {
116
- autoCollectMax = parseInt(positional[j]) || 1; j++;
117
- autoScrapeDepth = parseInt(positional[j]) || 50; j++;
118
- autoMaxComments = parseInt(positional[j]) || 200;
119
- }
120
-
121
- return {
122
- subcommand: 'auto',
123
- autoUsernames: usernames,
124
- autoCollectMax,
125
- autoScrapeDepth,
126
- autoMaxComments,
127
- autoPreset,
128
- autoSwitchDelay,
129
- autoCommentDelay,
130
- outputFile,
131
- autoWatch,
132
- autoWatchPort,
133
- urls: [],
134
- outputFormat: 'json',
135
- exploreCount: 0,
136
- showConfig: false,
137
- showHelp: false,
138
- customProxy: null,
139
- configAction: null,
140
- configValue: null,
141
- pipeMode: false,
142
- filterStr: null,
143
- };
144
- }
145
-
146
- function parseVideosArgs(args) {
147
- let videosUsername = null;
148
- let videosMax = 5;
149
- let outputFile = null;
150
-
151
- const positional = [];
152
-
153
- for (let i = 0; i < args.length; i++) {
154
- const arg = args[i];
155
- if (arg === '-o' || arg === '--output') {
156
- outputFile = args[++i];
157
- } else {
158
- positional.push(arg);
159
- }
160
- }
161
-
162
- videosUsername = positional[0] ? positional[0].replace('@', '') : null;
163
- videosMax = parseInt(positional[1]) || 5;
164
-
165
- return {
166
- subcommand: 'videos',
167
- videosUsername,
168
- videosMax,
169
- outputFile,
170
- urls: [],
171
- outputFormat: 'json',
172
- exploreCount: 0,
173
- showConfig: false,
174
- showHelp: false,
175
- customProxy: null,
176
- configAction: null,
177
- configValue: null,
178
- pipeMode: false,
179
- filterStr: null,
180
- };
181
- }
182
-
183
- function parseWatchArgs(args) {
184
- let outputFile = null;
185
- let watchPort = 3000;
186
-
187
- for (let i = 0; i < args.length; i++) {
188
- const arg = args[i];
189
- if (arg === '-o' || arg === '--output') {
190
- outputFile = args[++i];
191
- } else if (arg === '-p') {
192
- watchPort = parseInt(args[++i]) || 3000;
193
- }
194
- }
195
-
196
- return {
197
- subcommand: 'watch',
198
- outputFile,
199
- watchPort,
200
- urls: [],
201
- outputFormat: 'json',
202
- exploreCount: 0,
203
- showConfig: false,
204
- showHelp: false,
205
- customProxy: null,
206
- configAction: null,
207
- configValue: null,
208
- pipeMode: false,
209
- filterStr: null,
210
- };
211
- }
212
-
213
- export function parseArgs() {
214
- const args = process.argv.slice(2);
215
-
216
- if (args.length > 0 && args[0] === 'scrape') {
217
- return parseScrapeArgs(args.slice(1));
218
- }
219
-
220
- if (args.length > 0 && args[0] === 'videos') {
221
- return parseVideosArgs(args.slice(1));
222
- }
223
-
224
- if (args.length > 0 && args[0] === 'auto') {
225
- return parseAutoArgs(args.slice(1));
226
- }
227
-
228
- if (args.length > 0 && args[0] === 'watch') {
229
- return parseWatchArgs(args.slice(1));
230
- }
231
-
232
- const urls = [];
233
- let inputFile = null;
234
- let outputFile = null;
235
- let outputFormat = 'json';
236
- let exploreCount = 0;
237
- let showConfig = false;
238
- let showHelp = false;
239
- let customProxy = null;
240
- let configAction = null;
241
- let configValue = null;
242
- let pipeMode = false;
243
- let filterStr = null;
244
-
245
- for (let i = 0; i < args.length; i++) {
246
- const arg = args[i];
247
-
248
- if (arg === '--explore') {
249
- exploreCount = args[i + 1] && !args[i + 1].startsWith('http')
250
- ? parseInt(args[++i], 10)
251
- : 100;
252
- } else if (arg === '--proxy') {
253
- customProxy = args[++i];
254
- } else if (arg === '--filter') {
255
- filterStr = args[++i];
256
- } else if (arg === 'config') {
257
- configAction = args[i + 1];
258
- if (configAction === 'set' || configAction === 'set-proxy' || configAction === 'set-browser') {
259
- configValue = args[i + 2];
260
- i += 2;
261
- } else {
262
- i++;
263
- }
264
- } else if (arg === '--pipe') {
265
- pipeMode = true;
266
- } else if (arg === '-i' || arg === '--input') {
267
- inputFile = args[++i];
268
- } else if (arg === '-o' || arg === '--output') {
269
- outputFile = args[++i];
270
- } else if (arg === '-f' || arg === '--format') {
271
- outputFormat = args[++i];
272
- } else if (arg === '-c' || arg === '--config') {
273
- showConfig = true;
274
- } else if (arg === '-h' || arg === '--help') {
275
- showHelp = true;
276
- } else if (arg.startsWith('http')) {
277
- urls.push(arg);
278
- }
279
- }
280
-
281
- if (inputFile) {
282
- const content = readFileSync(inputFile, 'utf-8');
283
- const lines = content.split(/\r?\n/).map(l => l.trim()).filter(l => l.startsWith('http'));
284
- urls.push(...lines);
285
- }
286
-
287
- return { urls, outputFile, outputFormat, exploreCount, showConfig, showHelp, customProxy, configAction, configValue, pipeMode, filterStr };
1
+ import { readFileSync } from 'fs';
2
+ import { proxy } 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 outputFile = null;
78
+ let autoWatch = false;
79
+ let autoWatchPort = 3000;
80
+ let autoEnableFollow = false;
81
+ let autoMaxFollowing = 200;
82
+ let autoMaxFollowers = 200;
83
+
84
+ const positional = [];
85
+ const PRESETS = ['fast', 'normal', 'slow', 'stealth'];
86
+
87
+ for (let i = 0; i < args.length; i++) {
88
+ const arg = args[i];
89
+ if (arg === '-o' || arg === '--output') {
90
+ outputFile = args[++i];
91
+ } else if (arg === '--switch-delay') {
92
+ autoSwitchDelay = parseInt(args[++i]) || null;
93
+ } else if (arg === '--comment-delay') {
94
+ autoCommentDelay = parseInt(args[++i]) || null;
95
+ } else if (arg === '--watch') {
96
+ autoWatch = true;
97
+ if (args[i + 1] === '-p') {
98
+ autoWatchPort = parseInt(args[i + 2]) || 3000;
99
+ i += 2;
100
+ }
101
+ } else if (arg === '-p' && autoWatch) {
102
+ autoWatchPort = parseInt(args[++i]) || 3000;
103
+ } else if (arg === '--enable-follow') {
104
+ autoEnableFollow = true;
105
+ } else if (arg === '--max-following') {
106
+ autoMaxFollowing = parseInt(args[++i]) || 200;
107
+ } else if (arg === '--max-followers') {
108
+ autoMaxFollowers = parseInt(args[++i]) || 200;
109
+ } else {
110
+ positional.push(arg);
111
+ }
112
+ }
113
+
114
+ // 收集用户名(非 preset、非数字的都是用户名)
115
+ const usernames = [];
116
+ let j = 0;
117
+ while (j < positional.length && !PRESETS.includes(positional[j]?.toLowerCase()) && isNaN(positional[j])) {
118
+ usernames.push(positional[j].replace('@', ''));
119
+ j++;
120
+ }
121
+
122
+ // preset
123
+ if (j < positional.length && PRESETS.includes(positional[j].toLowerCase())) {
124
+ autoPreset = positional[j].toLowerCase();
125
+ j++;
126
+ autoCollectMax = parseInt(positional[j]) || 1; j++;
127
+ autoScrapeDepth = parseInt(positional[j]) || 50; j++;
128
+ autoMaxComments = parseInt(positional[j]) || 200; j++;
129
+ autoMaxGuess = parseInt(positional[j]) || 10; j++;
130
+ } else if (usernames.length > 0) {
131
+ autoCollectMax = parseInt(positional[j]) || 1; j++;
132
+ autoScrapeDepth = parseInt(positional[j]) || 50; j++;
133
+ autoMaxComments = parseInt(positional[j]) || 200; j++;
134
+ autoMaxGuess = parseInt(positional[j]) || 10;
135
+ }
136
+
137
+ return {
138
+ subcommand: 'auto',
139
+ autoUsernames: usernames,
140
+ autoCollectMax,
141
+ autoScrapeDepth,
142
+ autoMaxComments,
143
+ autoMaxGuess,
144
+ autoPreset,
145
+ autoSwitchDelay,
146
+ autoCommentDelay,
147
+ outputFile,
148
+ autoWatch,
149
+ autoWatchPort,
150
+ autoEnableFollow,
151
+ autoMaxFollowing,
152
+ autoMaxFollowers,
153
+ urls: [],
154
+ outputFormat: 'json',
155
+ exploreCount: 0,
156
+ showConfig: false,
157
+ showHelp: false,
158
+ customProxy: null,
159
+ configAction: null,
160
+ configValue: null,
161
+ pipeMode: false,
162
+ filterStr: null,
163
+ };
164
+ }
165
+
166
+ function parseExploreArgs(args) {
167
+ let outputFile = null;
168
+ let explorePreset = 'normal';
169
+ let exploreMaxComments = 100;
170
+ let exploreMaxGuess = 0;
171
+ let exploreEnableFollow = true;
172
+ let exploreMaxFollowing = 200;
173
+ let exploreMaxFollowers = 200;
174
+ let exploreLocation = 'ES';
175
+ let exploreWatch = false;
176
+ let exploreWatchPort = 3000;
177
+ let exploreMaxUsers = 0;
178
+
179
+ const positional = [];
180
+ const PRESETS = ['fast', 'normal', 'slow', 'stealth'];
181
+
182
+ for (let i = 0; i < args.length; i++) {
183
+ const arg = args[i];
184
+ if (arg === '-o' || arg === '--output') {
185
+ outputFile = args[++i];
186
+ } else if (arg === '--max-comments') {
187
+ exploreMaxComments = parseInt(args[++i]) || 0;
188
+ } else if (arg === '--max-guess') {
189
+ exploreMaxGuess = parseInt(args[++i]) || 0;
190
+ } else if (arg === '--location') {
191
+ exploreLocation = args[++i];
192
+ } else if (arg === '--enable-follow') {
193
+ exploreEnableFollow = true;
194
+ } else if (arg === '--disable-follow') {
195
+ exploreEnableFollow = false;
196
+ } else if (arg === '--max-following') {
197
+ exploreMaxFollowing = parseInt(args[++i]) || 200;
198
+ } else if (arg === '--max-followers') {
199
+ exploreMaxFollowers = parseInt(args[++i]) || 200;
200
+ } else if (arg === '--max-users') {
201
+ exploreMaxUsers = parseInt(args[++i]) || 0;
202
+ } else if (arg === '--watch') {
203
+ exploreWatch = true;
204
+ if (args[i + 1] === '-p') {
205
+ exploreWatchPort = parseInt(args[i + 2]) || 3000;
206
+ i += 2;
207
+ }
208
+ } else {
209
+ positional.push(arg);
210
+ }
211
+ }
212
+
213
+ const usernames = [];
214
+ let j = 0;
215
+ while (j < positional.length && !PRESETS.includes(positional[j]?.toLowerCase()) && isNaN(positional[j])) {
216
+ usernames.push(positional[j].replace('@', ''));
217
+ j++;
218
+ }
219
+
220
+ if (j < positional.length && PRESETS.includes(positional[j].toLowerCase())) {
221
+ explorePreset = positional[j].toLowerCase();
222
+ j++;
223
+ }
224
+
225
+ return {
226
+ subcommand: 'explore',
227
+ exploreUsernames: usernames,
228
+ explorePreset,
229
+ exploreMaxComments,
230
+ exploreMaxGuess,
231
+ exploreEnableFollow,
232
+ exploreMaxFollowing,
233
+ exploreMaxFollowers,
234
+ exploreLocation,
235
+ exploreWatch,
236
+ exploreWatchPort,
237
+ exploreMaxUsers,
238
+ outputFile,
239
+ urls: [],
240
+ outputFormat: 'json',
241
+ exploreCount: 0,
242
+ showConfig: false,
243
+ showHelp: false,
244
+ customProxy: null,
245
+ configAction: null,
246
+ configValue: null,
247
+ pipeMode: false,
248
+ filterStr: null,
249
+ };
250
+ }
251
+
252
+ function parseVideosArgs(args) {
253
+ let videosUsername = null;
254
+ let videosMax = 5;
255
+ let outputFile = null;
256
+
257
+ const positional = [];
258
+
259
+ for (let i = 0; i < args.length; i++) {
260
+ const arg = args[i];
261
+ if (arg === '-o' || arg === '--output') {
262
+ outputFile = args[++i];
263
+ } else {
264
+ positional.push(arg);
265
+ }
266
+ }
267
+
268
+ videosUsername = positional[0] ? positional[0].replace('@', '') : null;
269
+ videosMax = parseInt(positional[1]) || 5;
270
+
271
+ return {
272
+ subcommand: 'videos',
273
+ videosUsername,
274
+ videosMax,
275
+ outputFile,
276
+ urls: [],
277
+ outputFormat: 'json',
278
+ exploreCount: 0,
279
+ showConfig: false,
280
+ showHelp: false,
281
+ customProxy: null,
282
+ configAction: null,
283
+ configValue: null,
284
+ pipeMode: false,
285
+ filterStr: null,
286
+ };
287
+ }
288
+
289
+ function parseWatchArgs(args) {
290
+ let outputFile = null;
291
+ let watchPort = 3000;
292
+
293
+ for (let i = 0; i < args.length; i++) {
294
+ const arg = args[i];
295
+ if (arg === '-o' || arg === '--output') {
296
+ outputFile = args[++i];
297
+ } else if (arg === '-p') {
298
+ watchPort = parseInt(args[++i]) || 3000;
299
+ }
300
+ }
301
+
302
+ return {
303
+ subcommand: 'watch',
304
+ outputFile,
305
+ watchPort,
306
+ urls: [],
307
+ outputFormat: 'json',
308
+ exploreCount: 0,
309
+ showConfig: false,
310
+ showHelp: false,
311
+ customProxy: null,
312
+ configAction: null,
313
+ configValue: null,
314
+ pipeMode: false,
315
+ filterStr: null,
316
+ };
317
+ }
318
+
319
+ export function parseArgs() {
320
+ const args = process.argv.slice(2);
321
+
322
+ if (args.length > 0 && args[0] === 'scrape') {
323
+ return parseScrapeArgs(args.slice(1));
324
+ }
325
+
326
+ if (args.length > 0 && args[0] === 'videos') {
327
+ return parseVideosArgs(args.slice(1));
328
+ }
329
+
330
+ if (args.length > 0 && args[0] === 'auto') {
331
+ return parseAutoArgs(args.slice(1));
332
+ }
333
+
334
+ if (args.length > 0 && args[0] === 'explore') {
335
+ return parseExploreArgs(args.slice(1));
336
+ }
337
+
338
+ if (args.length > 0 && args[0] === 'watch') {
339
+ return parseWatchArgs(args.slice(1));
340
+ }
341
+
342
+ const urls = [];
343
+ let inputFile = null;
344
+ let outputFile = null;
345
+ let outputFormat = 'json';
346
+ let exploreCount = 0;
347
+ let showConfig = false;
348
+ let showHelp = false;
349
+ let customProxy = null;
350
+ let configAction = 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 === 'set' || configAction === 'set-proxy' || configAction === 'set-browser') {
369
+ configValue = args[i + 2];
370
+ i += 2;
371
+ } else {
372
+ i++;
373
+ }
374
+ } else if (arg === '--pipe') {
375
+ pipeMode = true;
376
+ } else if (arg === '-i' || arg === '--input') {
377
+ inputFile = args[++i];
378
+ } else if (arg === '-o' || arg === '--output') {
379
+ outputFile = args[++i];
380
+ } else if (arg === '-f' || arg === '--format') {
381
+ outputFormat = args[++i];
382
+ } else if (arg === '-c' || arg === '--config') {
383
+ showConfig = true;
384
+ } else if (arg === '-h' || arg === '--help') {
385
+ showHelp = true;
386
+ } else if (arg.startsWith('http')) {
387
+ urls.push(arg);
388
+ }
389
+ }
390
+
391
+ if (inputFile) {
392
+ const content = readFileSync(inputFile, 'utf-8');
393
+ const lines = content.split(/\r?\n/).map(l => l.trim()).filter(l => l.startsWith('http'));
394
+ urls.push(...lines);
395
+ }
396
+
397
+ return { urls, outputFile, outputFormat, exploreCount, showConfig, showHelp, customProxy, configAction, configValue, pipeMode, filterStr };
288
398
  }