tt-help-cli-ycl 1.3.2 → 1.3.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tt-help-cli-ycl",
3
- "version": "1.3.2",
3
+ "version": "1.3.3",
4
4
  "description": "TikTok user & video data scraper - extract ttSeller, verified, locationCreated from HTML source",
5
5
  "type": "module",
6
6
  "bin": {
@@ -39,6 +39,7 @@
39
39
  "homepage": "https://github.com/jsjhycl/tt-help-cli#readme",
40
40
  "dependencies": {
41
41
  "playwright": "^1.59.1",
42
+ "tt-help-cli-ycl": "^1.3.2",
42
43
  "undici": "^8.1.0"
43
44
  }
44
45
  }
@@ -27,8 +27,7 @@ export async function handleExplore(options) {
27
27
  try {
28
28
  await apiGet(`${serverUrl}/api/stats`);
29
29
  } catch {
30
- console.error(`无法连接服务端: ${serverUrl}`);
31
- console.error('请先启动服务端: tt-help watch -o <数据文件>');
30
+ console.error(`无法连接服务端: ${serverUrl},退出`);
32
31
  process.exit(1);
33
32
  }
34
33
 
package/src/lib/args.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { readFileSync } from 'fs';
2
+ import { server as defaultServer } from './constants.js';
2
3
  import { proxy } from './constants.js';
3
4
 
4
5
  const PRESETS = ['fast', 'normal', 'slow', 'stealth'];
@@ -74,7 +75,7 @@ function parseAutoArgs(args) {
74
75
  let autoPreset = 'fast';
75
76
  let autoSwitchDelay = null;
76
77
  let autoCommentDelay = null;
77
- let serverUrl = 'http://127.0.0.1:3000';
78
+ let serverUrl = defaultServer;
78
79
  let autoEnableFollow = false;
79
80
  let autoMaxFollowing = 200;
80
81
  let autoMaxFollowers = 200;
@@ -152,7 +153,7 @@ function parseAutoArgs(args) {
152
153
  }
153
154
 
154
155
  function parseExploreArgs(args) {
155
- let serverUrl = 'http://127.0.0.1:3000';
156
+ let serverUrl = defaultServer;
156
157
  let explorePreset = 'normal';
157
158
  let exploreMaxComments = 10;
158
159
  let exploreMaxGuess = 0;
@@ -266,14 +267,14 @@ function parseVideosArgs(args) {
266
267
 
267
268
  function parseWatchArgs(args) {
268
269
  let outputFile = './result.json';
269
- let watchPort = 3000;
270
+ let watchPort = 3001;
270
271
 
271
272
  for (let i = 0; i < args.length; i++) {
272
273
  const arg = args[i];
273
274
  if (arg === '-o' || arg === '--output') {
274
275
  outputFile = args[++i];
275
276
  } else if (arg === '-p') {
276
- watchPort = parseInt(args[++i]) || 3000;
277
+ watchPort = parseInt(args[++i]) || 3001;
277
278
  }
278
279
  }
279
280
 
@@ -335,6 +336,7 @@ export function parseArgs() {
335
336
  let showVersion = false;
336
337
  let customProxy = null;
337
338
  let configAction = null;
339
+ let configKey = null;
338
340
  let configValue = null;
339
341
  let pipeMode = false;
340
342
  let filterStr = null;
@@ -352,9 +354,12 @@ export function parseArgs() {
352
354
  filterStr = args[++i];
353
355
  } else if (arg === 'config') {
354
356
  configAction = args[i + 1];
355
- if (configAction === 'set' || configAction === 'set-proxy' || configAction === 'set-browser') {
356
- configValue = args[i + 2];
357
- i += 2;
357
+ if (!configAction) {
358
+ configAction = 'show';
359
+ } else if (configAction === 'set' || configAction === 'set-proxy' || configAction === 'set-browser') {
360
+ configKey = args[i + 2];
361
+ configValue = args[i + 3];
362
+ i += 3;
358
363
  } else {
359
364
  i++;
360
365
  }
@@ -383,5 +388,5 @@ export function parseArgs() {
383
388
  urls.push(...lines);
384
389
  }
385
390
 
386
- return { urls, outputFile, outputFormat, exploreCount, showConfig, showHelp, showVersion, customProxy, configAction, configValue, pipeMode, filterStr };
391
+ return { urls, outputFile, outputFormat, exploreCount, showConfig, showHelp, showVersion, customProxy, configAction, configKey, configValue, pipeMode, filterStr };
387
392
  }
@@ -12,6 +12,7 @@ const DEFAULT_PROXY = 'http://127.0.0.1:7897';
12
12
  const DEFAULT_OUTPUT = 'tiktok_data.json';
13
13
 
14
14
  let proxy = DEFAULT_PROXY;
15
+ let server = 'http://127.0.0.1:3001';
15
16
  let configFile = null;
16
17
  let browser = null;
17
18
 
@@ -21,6 +22,9 @@ try {
21
22
  if (cfg.proxy) {
22
23
  proxy = cfg.proxy;
23
24
  }
25
+ if (cfg.server) {
26
+ server = cfg.server;
27
+ }
24
28
  if (cfg.browser) {
25
29
  browser = cfg.browser;
26
30
  }
@@ -41,10 +45,10 @@ function saveBrowser(path) {
41
45
  const HELP_TEXT = [
42
46
  '用法: tt-help explore <用户名> [preset] [选项]',
43
47
  '',
44
- ' 支持多个用户名: tt-help explore @user1 @user2 --server http://127.0.0.1:3000',
48
+ ' 支持多个用户名: tt-help explore @user1 @user2 --server http://127.0.0.1:3001',
45
49
  ' 预设: fast, normal(默认), slow, stealth',
46
50
  ' 选项:',
47
- ' --server <URL> 服务端地址,默认 http://127.0.0.1:3000',
51
+ ' --server <URL> 服务端地址,默认 http://127.0.0.1:3001',
48
52
  ' --location <国家代码> 国家筛选,默认 ES',
49
53
  ' --max-comments <数量> 每视频最大评论数,默认 10',
50
54
  ' --max-guess <数量> 每视频最大猜你喜欢数,默认 0',
@@ -54,10 +58,14 @@ const HELP_TEXT = [
54
58
  ' --max-followers <数量> 最大获取粉丝数,默认 5',
55
59
  ' --max-users <数量> 最大处理用户数,默认无限制',
56
60
  ' 全局选项:',
61
+ ' config 查看当前配置',
62
+ ' config set <key> <value> 设置配置(key: proxy, server, browser)',
63
+ ' config reset 重置代理为默认',
57
64
  ' -h, --help 显示帮助',
58
65
  ' --version 显示版本号',
59
66
  '',
60
67
  ' 示例: tt-help explore qiqi23280 fast --location ES --max-comments 50',
68
+ ' tt-help config set server http://127.0.0.1:3001',
61
69
  ];
62
70
 
63
71
  const CONFIG_TEXT = [
@@ -65,6 +73,7 @@ const CONFIG_TEXT = [
65
73
  '',
66
74
  '配置:',
67
75
  ` 代理: ${proxy}`,
76
+ ` 服务端: ${server}`,
68
77
  ` 浏览器: ${browser || '未配置(将自动探测或回退)'}`,
69
78
  ` 输出格式: json`,
70
79
  ` 默认输出: ${DEFAULT_OUTPUT}`,
@@ -73,6 +82,7 @@ const CONFIG_TEXT = [
73
82
 
74
83
  export {
75
84
  proxy,
85
+ server,
76
86
  configFile,
77
87
  configPath,
78
88
  DEFAULT_PROXY,
package/src/main.mjs CHANGED
@@ -29,29 +29,50 @@ function showUsage() {
29
29
  process.exit(0);
30
30
  }
31
31
 
32
- function handleConfig(action, value) {
32
+ function handleConfig(action, key, value) {
33
33
  if (action === 'show' || action === null) {
34
34
  showConfig([], null);
35
35
  return;
36
36
  }
37
37
  if (action === 'set' || action === 'set-proxy') {
38
+ if (!key) {
39
+ console.error('用法: tt-help config set <key> <value>');
40
+ console.error(' 可用 key: proxy, server, browser');
41
+ process.exit(1);
42
+ }
43
+ if (!value && key.startsWith('http://')) {
44
+ // 兼容旧用法: config set <代理地址>(key 实际是 value)
45
+ const cfg = existsSync(configPath) ? JSON.parse(readFileSync(configPath, 'utf-8')) : {};
46
+ cfg.proxy = key;
47
+ writeFileSync(configPath, JSON.stringify(cfg, null, 2), 'utf-8');
48
+ console.log(`代理已设置为: ${key}`);
49
+ console.log(`配置文件: ${configPath}`);
50
+ return;
51
+ }
38
52
  if (!value) {
39
- console.error('用法: tt-help config set <代理地址>');
53
+ console.error(`请提供 ${key} 的值`);
40
54
  process.exit(1);
41
55
  }
42
56
  const cfg = existsSync(configPath) ? JSON.parse(readFileSync(configPath, 'utf-8')) : {};
43
- cfg.proxy = value;
57
+ if (key === 'proxy') cfg.proxy = value;
58
+ else if (key === 'server') cfg.server = value;
59
+ else if (key === 'browser') cfg.browser = value;
60
+ else {
61
+ console.error(`未知配置项: ${key}`);
62
+ console.error(' 可用 key: proxy, server, browser');
63
+ process.exit(1);
64
+ }
44
65
  writeFileSync(configPath, JSON.stringify(cfg, null, 2), 'utf-8');
45
- console.log(`代理已设置为: ${value}`);
66
+ console.log(`${key} 已设置为: ${value}`);
46
67
  console.log(`配置文件: ${configPath}`);
47
68
  return;
48
69
  }
49
70
  if (action === 'set-browser') {
50
- if (!value) {
71
+ if (!key) {
51
72
  console.error('用法: tt-help config set-browser <浏览器路径 或 auto>');
52
73
  process.exit(1);
53
74
  }
54
- if (value === 'auto') {
75
+ if (key === 'auto') {
55
76
  if (existsSync(configPath)) {
56
77
  const cfg = JSON.parse(readFileSync(configPath, 'utf-8'));
57
78
  delete cfg.browser;
@@ -59,8 +80,8 @@ function handleConfig(action, value) {
59
80
  }
60
81
  console.log('已切换为自动探测浏览器模式');
61
82
  } else {
62
- saveBrowser(value);
63
- console.log(`浏览器已设置为: ${value}`);
83
+ saveBrowser(key);
84
+ console.log(`浏览器已设置为: ${key}`);
64
85
  }
65
86
  console.log(`配置文件: ${configPath}`);
66
87
  return;
@@ -174,7 +195,7 @@ async function main() {
174
195
  case 'watch': return handleWatch(parsed);
175
196
  }
176
197
 
177
- const { urls, outputFile, outputFormat, exploreCount, showConfig: showCfg, showHelp, showVersion, customProxy, configAction, configValue, pipeMode, filterStr } = parsed;
198
+ const { urls, outputFile, outputFormat, exploreCount, showConfig: showCfg, showHelp, showVersion, customProxy, configAction, configKey, configValue, pipeMode, filterStr } = parsed;
178
199
  const proxyUrl = customProxy || proxy;
179
200
  const filter = parseFilter(filterStr);
180
201
 
@@ -183,7 +204,7 @@ async function main() {
183
204
  process.exit(0);
184
205
  }
185
206
  if (showHelp) return showUsage();
186
- if (configAction) return handleConfig(configAction, configValue);
207
+ if (configAction) return handleConfig(configAction, configKey, configValue);
187
208
  if (showCfg) return showConfig(urls, outputFile);
188
209
  if (urls.length === 0 && exploreCount === 0) return showUsage();
189
210