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.
@@ -1,11 +1,13 @@
1
- import { createRequire } from 'module';
2
-
3
- const require = createRequire(import.meta.url);
4
- const core = require('../auto-core.cjs');
5
- const helpers = require('../scraper/modules/page-helpers.cjs');
6
-
7
- export const runAuto = core.runAuto;
8
- export const processUser = core.processUser;
9
- export const ensureBrowserReady = helpers.ensureBrowserReady;
10
- export const ensureTikTokPage = helpers.ensureTikTokPage;
1
+ import { createRequire } from 'module';
2
+
3
+ const require = createRequire(import.meta.url);
4
+ const core = require('../auto-core.cjs');
5
+ const exploreCore = require('../explore-core.cjs');
6
+ const helpers = require('../scraper/modules/page-helpers.cjs');
7
+
8
+ export const runAuto = core.runAuto;
9
+ export const processUser = core.processUser;
10
+ export const processExplore = exploreCore.processExplore;
11
+ export const ensureBrowserReady = helpers.ensureBrowserReady;
12
+ export const ensureTikTokPage = helpers.ensureTikTokPage;
11
13
  export const closeCommentPanel = helpers.closeCommentPanel;
@@ -1,148 +1,151 @@
1
- import { join, dirname } from 'path';
2
- import { readFileSync, writeFileSync, existsSync } from 'fs';
3
- import { fileURLToPath } from 'url';
4
-
5
- const __filename = fileURLToPath(import.meta.url);
6
- const __dirname = dirname(__filename);
7
- const homeDir = process.env.HOME || process.env.USERPROFILE || '';
8
- const configPath = join(homeDir, '.tt-help.json');
9
-
10
- const DEFAULT_PROXY = 'http://127.0.0.1:7897';
11
- const DEFAULT_OUTPUT = 'tiktok_data.json';
12
- const USER_SECTION_SIZE = 12000;
13
-
14
- let proxy = DEFAULT_PROXY;
15
- let configFile = null;
16
- let browser = null;
17
-
18
- try {
19
- if (existsSync(configPath)) {
20
- const cfg = JSON.parse(readFileSync(configPath, 'utf-8'));
21
- if (cfg.proxy) {
22
- proxy = cfg.proxy;
23
- }
24
- if (cfg.browser) {
25
- browser = cfg.browser;
26
- }
27
- configFile = configPath;
28
- }
29
- } catch {
30
- // no config file
31
- }
32
-
33
- function saveBrowser(path) {
34
- const cfg = existsSync(configPath) ? JSON.parse(readFileSync(configPath, 'utf-8')) : {};
35
- cfg.browser = path;
36
- writeFileSync(configPath, JSON.stringify(cfg, null, 2), 'utf-8');
37
- browser = path;
38
- configFile = configPath;
39
- }
40
-
41
- const HELP_TEXT = [
42
- '用法: tt-help [选项]',
43
- ' tt-help scrape <URL> [预设] [选项]',
44
- ' tt-help videos <用户名> [最大视频数] [选项]',
45
- ' tt-help auto <用户名> [preset] [收集数] [切换数] [每视频评论数] [选项]',
46
- '',
47
- '参数:',
48
- ' --explore [count] 从 Explore 页面获取视频列表(默认: 100)',
49
- ' --pipe 将 Explore 结果自动传给 URL 爬取',
50
- ' --proxy <地址> 临时指定代理地址',
51
- ' --filter <条件> 过滤结果(格式: key=value&key2=value2)',
52
- ' -i, --input <file> 从文件读取 URL 列表(每行一个)',
53
- ' -o, --output <file> 指定输出文件(默认: tiktok_data.json)',
54
- ' -f, --format <fmt> 输出格式: json(默认), table, raw',
55
- ' -c, --config 显示当前配置',
56
- ' -h, --help 显示帮助',
57
- '',
58
- '浏览器抓取模式 (scrape):',
59
- ' tt-help scrape <URL> [preset] [最大视频数] [最大评论数] [-o 输出路径]',
60
- ' tt-help scrape <URL> [最大视频数] [最大评论数] [--switch-delay ms] [--comment-delay ms]',
61
- ' 预设: fast(600ms/400ms), normal(1.5s/800ms), slow(3s/2s), stealth(5s/3.5s)',
62
- ' 不指定 -o 则输出到 stdout(可 pipe)',
63
- '',
64
- '用户视频模式 (videos):',
65
- ' tt-help videos <用户名> [最大视频数] [-o 输出路径]',
66
- ' 获取用户信息和视频列表(浏览器模式)',
67
- ' 不指定 -o 则输出到 stdout(可 pipe)',
68
- '',
69
- '自动探索模式 (auto):',
70
- ' tt-help auto [用户名...] [preset] [收集数] [切换数] [每视频评论数] [选项]',
71
- ' 支持多个用户名: tt-help auto @user1 @user2 -o data.json',
72
- ' 不指定用户名: 从 -o 数据源中读取未处理的用户继续探索',
73
- ' 收集数: 从种子用户收集的种子视频数(默认 1)',
74
- ' 切换数: 每个种子作者主页下切换视频的次数(默认 50)',
75
- ' 每视频评论数: 每个视频抓取评论数(默认 200)',
76
- ' 预设: fast(默认), normal, slow, stealth',
77
- ' 选项: -o <路径> 数据源文件(不指定则输出到 stdout)',
78
- ' --switch-delay <ms> 视频切换延迟(毫秒)',
79
- ' --comment-delay <ms> 评论滚动延迟(毫秒)',
80
- ' --watch [-p 3000] 启动 Web 监控页面实时查看数据',
81
- ' 返回: 纯用户数组,按 uniqueId 去重',
82
- ' 示例: tt-help auto username -o result.json',
83
- ' tt-help auto @a @b fast 1 30 100 -o data.json',
84
- ' tt-help auto -o data.json # 续跑',
85
- ' tt-help auto username --watch -o data.json # 带监控页面',
86
- '',
87
- '实时监控模式 (watch):',
88
- ' tt-help watch -o <数据文件> [-p 端口]',
89
- ' 启动 Web 监控页面,实时查看采集数据',
90
- ' 支持在 auto 模式中通过 --watch 参数同时启动',
91
- ' 示例: tt-help watch -o data.json',
92
- ' tt-help watch -o data.json -p 8080',
93
- '',
94
- '过滤示例:',
95
- ' --filter "ttSeller=true&verified=false" 过滤卖家且未认证',
96
- ' --filter "locationCreated=DE,ES" 过滤指定地区',
97
- ' --filter "ttSeller=true&locationCreated=US" 组合条件',
98
- '',
99
- '配置代理:',
100
- ' tt-help config set http://127.0.0.1:7890 设置代理',
101
- ' tt-help config show 查看配置',
102
- ' tt-help config reset 恢复默认',
103
- '',
104
- '配置浏览器:',
105
- ' tt-help config set-browser /path/to/chrome 手动指定浏览器路径',
106
- ' tt-help config set-browser auto 自动探测浏览器',
107
- '',
108
- '示例:',
109
- ' tt-help --explore 200 # 先预览 Explore 结果',
110
- ' tt-help --explore 50 --pipe -o result.json # 自动抓取用户数据',
111
- ' tt-help --explore -f raw # 仅输出 URL 列表',
112
- ' tt-help --explore -f raw -o urls.txt # 保存 URL 到文件',
113
- ' tt-help -i urls.txt -o result.json # 再爬取这些 URL',
114
- ' tt-help scrape <URL> fast 50 999 # 浏览器抓取(快速预设)',
115
- ' tt-help scrape <URL> slow -o out.json # 慢速预设,输出到文件',
116
- ' tt-help scrape <URL> 20 999 | jq . # 输出到 stdout 可 pipe',
117
- ' tt-help videos username 100 # 获取用户 100 个视频',
118
- ' tt-help videos username 50 -o out.json # 输出到文件',
119
- ' tt-help auto username -o out.json # 自动探索(默认 fast/1/50/200)',
120
- ' tt-help auto username slow 1 30 100 -o out.json # 慢速探索',
121
- ' tt-help config set http://127.0.0.1:7890',
122
- ' tt-help https://www.tiktok.com/@username',
123
- ' tt-help https://... --filter "ttSeller=true&locationCreated=DE"',
124
- ];
125
-
126
- const CONFIG_TEXT = [
127
- 'tt-help v1.0.1',
128
- '',
129
- '配置:',
130
- ` 代理: ${proxy}`,
131
- ` 浏览器: ${browser || '未配置(将自动探测或回退)'}`,
132
- ` 输出格式: json`,
133
- ` 默认输出: ${DEFAULT_OUTPUT}`,
134
- ` 配置文件: ${configFile || '无(使用默认值)'}`,
135
- ];
136
-
137
- export {
138
- proxy,
139
- configFile,
140
- configPath,
141
- DEFAULT_PROXY,
142
- DEFAULT_OUTPUT,
143
- USER_SECTION_SIZE,
144
- HELP_TEXT,
145
- CONFIG_TEXT,
146
- browser,
147
- saveBrowser,
148
- };
1
+ import { join, dirname } from 'path';
2
+ import { readFileSync, writeFileSync, existsSync } from 'fs';
3
+ import { fileURLToPath } from 'url';
4
+
5
+ const __filename = fileURLToPath(import.meta.url);
6
+ const __dirname = dirname(__filename);
7
+ const homeDir = process.env.HOME || process.env.USERPROFILE || '';
8
+ const configPath = join(homeDir, '.tt-help.json');
9
+
10
+ const DEFAULT_PROXY = 'http://127.0.0.1:7897';
11
+ const DEFAULT_OUTPUT = 'tiktok_data.json';
12
+ const USER_SECTION_SIZE = 12000;
13
+
14
+ let proxy = DEFAULT_PROXY;
15
+ let configFile = null;
16
+ let browser = null;
17
+
18
+ try {
19
+ if (existsSync(configPath)) {
20
+ const cfg = JSON.parse(readFileSync(configPath, 'utf-8'));
21
+ if (cfg.proxy) {
22
+ proxy = cfg.proxy;
23
+ }
24
+ if (cfg.browser) {
25
+ browser = cfg.browser;
26
+ }
27
+ configFile = configPath;
28
+ }
29
+ } catch {
30
+ // no config file
31
+ }
32
+
33
+ function saveBrowser(path) {
34
+ const cfg = existsSync(configPath) ? JSON.parse(readFileSync(configPath, 'utf-8')) : {};
35
+ cfg.browser = path;
36
+ writeFileSync(configPath, JSON.stringify(cfg, null, 2), 'utf-8');
37
+ browser = path;
38
+ configFile = configPath;
39
+ }
40
+
41
+ const HELP_TEXT = [
42
+ '用法: tt-help [选项]',
43
+ ' tt-help scrape <URL> [预设] [选项]',
44
+ ' tt-help videos <用户名> [最大视频数] [选项]',
45
+ ' tt-help auto <用户名> [preset] [收集数] [切换数] [每视频评论数] [选项]',
46
+ '',
47
+ '参数:',
48
+ ' --explore [count] 从 Explore 页面获取视频列表(默认: 100)',
49
+ ' --pipe 将 Explore 结果自动传给 URL 爬取',
50
+ ' --proxy <地址> 临时指定代理地址',
51
+ ' --filter <条件> 过滤结果(格式: key=value&key2=value2)',
52
+ ' -i, --input <file> 从文件读取 URL 列表(每行一个)',
53
+ ' -o, --output <file> 指定输出文件(默认: tiktok_data.json)',
54
+ ' -f, --format <fmt> 输出格式: json(默认), table, raw',
55
+ ' -c, --config 显示当前配置',
56
+ ' -h, --help 显示帮助',
57
+ '',
58
+ '浏览器抓取模式 (scrape):',
59
+ ' tt-help scrape <URL> [preset] [最大视频数] [最大评论数] [-o 输出路径]',
60
+ ' tt-help scrape <URL> [最大视频数] [最大评论数] [--switch-delay ms] [--comment-delay ms]',
61
+ ' 预设: fast(600ms/400ms), normal(1.5s/800ms), slow(3s/2s), stealth(5s/3.5s)',
62
+ ' 不指定 -o 则输出到 stdout(可 pipe)',
63
+ '',
64
+ '用户视频模式 (videos):',
65
+ ' tt-help videos <用户名> [最大视频数] [-o 输出路径]',
66
+ ' 获取用户信息和视频列表(浏览器模式)',
67
+ ' 不指定 -o 则输出到 stdout(可 pipe)',
68
+ '',
69
+ '自动探索模式 (auto):',
70
+ ' tt-help auto [用户名...] [preset] [收集数] [切换数] [每视频评论数] [选项]',
71
+ ' 支持多个用户名: tt-help auto @user1 @user2 -o data.json',
72
+ ' 不指定用户名: 从 -o 数据源中读取未处理的用户继续探索',
73
+ ' 收集数: 从种子用户收集的种子视频数(默认 1)',
74
+ ' 切换数: 每个种子作者主页下切换视频的次数(默认 50)',
75
+ ' 每视频评论数: 每个视频抓取评论数(默认 200)',
76
+ ' 预设: fast(默认), normal, slow, stealth',
77
+ ' 选项: -o <路径> 数据源文件(不指定则输出到 stdout)',
78
+ ' --switch-delay <ms> 视频切换延迟(毫秒)',
79
+ ' --comment-delay <ms> 评论滚动延迟(毫秒)',
80
+ ' --watch [-p 3000] 启动 Web 监控页面实时查看数据',
81
+ ' --enable-follow 启用关注/粉丝列表提取(需已登录)',
82
+ ' --max-following <n> 关注列表最大提取数(默认 200)',
83
+ ' --max-followers <n> 粉丝列表最大提取数(默认 200)',
84
+ ' 返回: 纯用户数组,按 uniqueId 去重',
85
+ ' 示例: tt-help auto username -o result.json',
86
+ ' tt-help auto @a @b fast 1 30 100 -o data.json',
87
+ ' tt-help auto -o data.json # 续跑',
88
+ ' tt-help auto username --watch -o data.json # 带监控页面',
89
+ '',
90
+ '实时监控模式 (watch):',
91
+ ' tt-help watch -o <数据文件> [-p 端口]',
92
+ ' 启动 Web 监控页面,实时查看采集数据',
93
+ ' 支持在 auto 模式中通过 --watch 参数同时启动',
94
+ ' 示例: tt-help watch -o data.json',
95
+ ' tt-help watch -o data.json -p 8080',
96
+ '',
97
+ '过滤示例:',
98
+ ' --filter "ttSeller=true&verified=false" 过滤卖家且未认证',
99
+ ' --filter "locationCreated=DE,ES" 过滤指定地区',
100
+ ' --filter "ttSeller=true&locationCreated=US" 组合条件',
101
+ '',
102
+ '配置代理:',
103
+ ' tt-help config set http://127.0.0.1:7890 设置代理',
104
+ ' tt-help config show 查看配置',
105
+ ' tt-help config reset 恢复默认',
106
+ '',
107
+ '配置浏览器:',
108
+ ' tt-help config set-browser /path/to/chrome 手动指定浏览器路径',
109
+ ' tt-help config set-browser auto 自动探测浏览器',
110
+ '',
111
+ '示例:',
112
+ ' tt-help --explore 200 # 先预览 Explore 结果',
113
+ ' tt-help --explore 50 --pipe -o result.json # 自动抓取用户数据',
114
+ ' tt-help --explore -f raw # 仅输出 URL 列表',
115
+ ' tt-help --explore -f raw -o urls.txt # 保存 URL 到文件',
116
+ ' tt-help -i urls.txt -o result.json # 再爬取这些 URL',
117
+ ' tt-help scrape <URL> fast 50 999 # 浏览器抓取(快速预设)',
118
+ ' tt-help scrape <URL> slow -o out.json # 慢速预设,输出到文件',
119
+ ' tt-help scrape <URL> 20 999 | jq . # 输出到 stdout 可 pipe',
120
+ ' tt-help videos username 100 # 获取用户 100 个视频',
121
+ ' tt-help videos username 50 -o out.json # 输出到文件',
122
+ ' tt-help auto username -o out.json # 自动探索(默认 fast/1/50/200)',
123
+ ' tt-help auto username slow 1 30 100 -o out.json # 慢速探索',
124
+ ' tt-help config set http://127.0.0.1:7890',
125
+ ' tt-help https://www.tiktok.com/@username',
126
+ ' tt-help https://... --filter "ttSeller=true&locationCreated=DE"',
127
+ ];
128
+
129
+ const CONFIG_TEXT = [
130
+ 'tt-help v1.0.1',
131
+ '',
132
+ '配置:',
133
+ ` 代理: ${proxy}`,
134
+ ` 浏览器: ${browser || '未配置(将自动探测或回退)'}`,
135
+ ` 输出格式: json`,
136
+ ` 默认输出: ${DEFAULT_OUTPUT}`,
137
+ ` 配置文件: ${configFile || '无(使用默认值)'}`,
138
+ ];
139
+
140
+ export {
141
+ proxy,
142
+ configFile,
143
+ configPath,
144
+ DEFAULT_PROXY,
145
+ DEFAULT_OUTPUT,
146
+ USER_SECTION_SIZE,
147
+ HELP_TEXT,
148
+ CONFIG_TEXT,
149
+ browser,
150
+ saveBrowser,
151
+ };