tt-help-cli-ycl 1.0.2 → 1.0.4

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/README.md CHANGED
@@ -1,17 +1,17 @@
1
- # tt-help
2
-
3
- TikTok user & video data scraper — extract ttSeller, verified, locationCreated from HTML source.
4
-
5
- ## Install
6
-
7
- ```bash
8
- npm i -g tt-help
9
- ```
10
-
11
- ## Usage
12
-
13
- ```bash
14
- tt-help [options] <urls...>
15
- ```
16
-
17
- 示例、代理配置、和更多用法请查看仓库或 `src/main.mjs` 中的帮助文本。
1
+ # tt-help
2
+
3
+ TikTok user & video data scraper — extract ttSeller, verified, locationCreated from HTML source.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm i -g tt-help
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```bash
14
+ tt-help [options] <urls...>
15
+ ```
16
+
17
+ 示例、代理配置、和更多用法请查看仓库或 `src/main.mjs` 中的帮助文本。
package/cli.js CHANGED
@@ -1,9 +1,9 @@
1
- #!/usr/bin/env node
2
- import { fileURLToPath } from 'url';
3
- import { dirname, resolve } from 'path';
4
-
5
- const __filename = fileURLToPath(import.meta.url);
6
- const __dirname = dirname(__filename);
7
-
8
- const mainPath = resolve(__dirname, 'src', 'main.mjs');
9
- await import(`file://${mainPath}`);
1
+ #!/usr/bin/env node
2
+ import { fileURLToPath } from 'url';
3
+ import { dirname, resolve } from 'path';
4
+
5
+ const __filename = fileURLToPath(import.meta.url);
6
+ const __dirname = dirname(__filename);
7
+
8
+ const mainPath = resolve(__dirname, 'src', 'main.mjs');
9
+ await import(`file://${mainPath}`);
package/package.json CHANGED
@@ -1,44 +1,44 @@
1
- {
2
- "name": "tt-help-cli-ycl",
3
- "version": "1.0.2",
4
- "description": "TikTok user & video data scraper - extract ttSeller, verified, locationCreated from HTML source",
5
- "type": "module",
6
- "bin": {
7
- "tt-help": "cli.js"
8
- },
9
- "main": "src/main.mjs",
10
- "files": [
11
- "cli.js",
12
- "src/"
13
- ],
14
- "scripts": {
15
- "start": "node src/main.mjs"
16
- },
17
- "keywords": [
18
- "tiktok",
19
- "scraper",
20
- "cli",
21
- "seller",
22
- "ttSeller"
23
- ],
24
- "author": "jsjhycl",
25
- "license": "ISC",
26
- "engines": {
27
- "node": ">=18"
28
- },
29
- "publishConfig": {
30
- "access": "public"
31
- },
32
- "repository": {
33
- "type": "git",
34
- "url": "https://github.com/jsjhycl/tt-help-cli.git"
35
- },
36
- "bugs": {
37
- "url": "https://github.com/jsjhycl/tt-help-cli/issues"
38
- },
39
- "homepage": "https://github.com/jsjhycl/tt-help-cli#readme",
40
- "dependencies": {
41
- "playwright": "^1.59.1",
42
- "undici": "^8.1.0"
43
- }
44
- }
1
+ {
2
+ "name": "tt-help-cli-ycl",
3
+ "version": "1.0.4",
4
+ "description": "TikTok user & video data scraper - extract ttSeller, verified, locationCreated from HTML source",
5
+ "type": "module",
6
+ "bin": {
7
+ "tt-help": "cli.js"
8
+ },
9
+ "main": "src/main.mjs",
10
+ "files": [
11
+ "cli.js",
12
+ "src/"
13
+ ],
14
+ "scripts": {
15
+ "start": "node src/main.mjs"
16
+ },
17
+ "keywords": [
18
+ "tiktok",
19
+ "scraper",
20
+ "cli",
21
+ "seller",
22
+ "ttSeller"
23
+ ],
24
+ "author": "jsjhycl",
25
+ "license": "ISC",
26
+ "engines": {
27
+ "node": ">=18"
28
+ },
29
+ "publishConfig": {
30
+ "access": "public"
31
+ },
32
+ "repository": {
33
+ "type": "git",
34
+ "url": "git+https://github.com/jsjhycl/tt-help-cli.git"
35
+ },
36
+ "bugs": {
37
+ "url": "https://github.com/jsjhycl/tt-help-cli/issues"
38
+ },
39
+ "homepage": "https://github.com/jsjhycl/tt-help-cli#readme",
40
+ "dependencies": {
41
+ "playwright": "^1.59.1",
42
+ "undici": "^8.1.0"
43
+ }
44
+ }
package/src/lib/args.js CHANGED
@@ -1,59 +1,62 @@
1
- import { readFileSync } from 'fs';
2
- import { proxy } from './constants.js';
3
-
4
- export function parseArgs() {
5
- const args = process.argv.slice(2);
6
- const urls = [];
7
- let inputFile = null;
8
- let outputFile = null;
9
- let outputFormat = 'json';
10
- let exploreCount = 0;
11
- let showConfig = false;
12
- let showHelp = false;
13
- let customProxy = null;
14
- let configAction = null;
15
- let configValue = null;
16
- let pipeMode = false;
17
-
18
- for (let i = 0; i < args.length; i++) {
19
- const arg = args[i];
20
-
21
- if (arg === '--explore') {
22
- exploreCount = args[i + 1] && !args[i + 1].startsWith('http')
23
- ? parseInt(args[++i], 10)
24
- : 100;
25
- } else if (arg === '--proxy') {
26
- customProxy = args[++i];
27
- } else if (arg === 'config') {
28
- configAction = args[i + 1];
29
- if (configAction === 'set' || configAction === 'set-proxy') {
30
- configValue = args[i + 2];
31
- i += 2;
32
- } else {
33
- i++;
34
- }
35
- } else if (arg === '--pipe') {
36
- pipeMode = true;
37
- } else if (arg === '-i' || arg === '--input') {
38
- inputFile = args[++i];
39
- } else if (arg === '-o' || arg === '--output') {
40
- outputFile = args[++i];
41
- } else if (arg === '-f' || arg === '--format') {
42
- outputFormat = args[++i];
43
- } else if (arg === '-c' || arg === '--config') {
44
- showConfig = true;
45
- } else if (arg === '-h' || arg === '--help') {
46
- showHelp = true;
47
- } else if (arg.startsWith('http')) {
48
- urls.push(arg);
49
- }
50
- }
51
-
52
- if (inputFile) {
53
- const content = readFileSync(inputFile, 'utf-8');
54
- const lines = content.split(/\r?\n/).map(l => l.trim()).filter(l => l.startsWith('http'));
55
- urls.push(...lines);
56
- }
57
-
58
- return { urls, outputFile, outputFormat, exploreCount, showConfig, showHelp, customProxy, configAction, configValue, pipeMode };
59
- }
1
+ import { readFileSync } from 'fs';
2
+ import { proxy } from './constants.js';
3
+
4
+ export function parseArgs() {
5
+ const args = process.argv.slice(2);
6
+ const urls = [];
7
+ let inputFile = null;
8
+ let outputFile = null;
9
+ let outputFormat = 'json';
10
+ let exploreCount = 0;
11
+ let showConfig = false;
12
+ let showHelp = false;
13
+ let customProxy = null;
14
+ let configAction = null;
15
+ let configValue = null;
16
+ let pipeMode = false;
17
+ let filterStr = null;
18
+
19
+ for (let i = 0; i < args.length; i++) {
20
+ const arg = args[i];
21
+
22
+ if (arg === '--explore') {
23
+ exploreCount = args[i + 1] && !args[i + 1].startsWith('http')
24
+ ? parseInt(args[++i], 10)
25
+ : 100;
26
+ } else if (arg === '--proxy') {
27
+ customProxy = args[++i];
28
+ } else if (arg === '--filter') {
29
+ filterStr = args[++i];
30
+ } else if (arg === 'config') {
31
+ configAction = args[i + 1];
32
+ if (configAction === 'set' || configAction === 'set-proxy' || configAction === 'set-browser') {
33
+ configValue = args[i + 2];
34
+ i += 2;
35
+ } else {
36
+ i++;
37
+ }
38
+ } else if (arg === '--pipe') {
39
+ pipeMode = true;
40
+ } else if (arg === '-i' || arg === '--input') {
41
+ inputFile = args[++i];
42
+ } else if (arg === '-o' || arg === '--output') {
43
+ outputFile = args[++i];
44
+ } else if (arg === '-f' || arg === '--format') {
45
+ outputFormat = args[++i];
46
+ } else if (arg === '-c' || arg === '--config') {
47
+ showConfig = true;
48
+ } else if (arg === '-h' || arg === '--help') {
49
+ showHelp = true;
50
+ } else if (arg.startsWith('http')) {
51
+ urls.push(arg);
52
+ }
53
+ }
54
+
55
+ if (inputFile) {
56
+ const content = readFileSync(inputFile, 'utf-8');
57
+ const lines = content.split(/\r?\n/).map(l => l.trim()).filter(l => l.startsWith('http'));
58
+ urls.push(...lines);
59
+ }
60
+
61
+ return { urls, outputFile, outputFormat, exploreCount, showConfig, showHelp, customProxy, configAction, configValue, pipeMode, filterStr };
62
+ }
@@ -1,76 +1,102 @@
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
-
17
- try {
18
- if (existsSync(configPath)) {
19
- const cfg = JSON.parse(readFileSync(configPath, 'utf-8'));
20
- if (cfg.proxy) {
21
- proxy = cfg.proxy;
22
- configFile = configPath;
23
- }
24
- }
25
- } catch {
26
- // no config file
27
- }
28
-
29
- const HELP_TEXT = [
30
- '用法: tt-help [选项]',
31
- '',
32
- '参数:',
33
- ' --explore [count] 从 Explore 页面获取视频列表(默认: 100)',
34
- ' --pipe 将 Explore 结果自动传给 URL 爬取',
35
- ' --proxy <地址> 临时指定代理地址',
36
- ' -i, --input <file> 从文件读取 URL 列表(每行一个)',
37
- ' -o, --output <file> 指定输出文件(默认: tiktok_data.json)',
38
- ' -f, --format <fmt> 输出格式: json(默认), table, raw',
39
- ' -c, --config 显示当前配置',
40
- ' -h, --help 显示帮助',
41
- '',
42
- '配置代理:',
43
- ' tt-help config set http://127.0.0.1:7890 设置代理',
44
- ' tt-help config show 查看配置',
45
- ' tt-help config reset 恢复默认',
46
- '',
47
- '示例:',
48
- ' tt-help --explore 200 # 先预览 Explore 结果',
49
- ' tt-help --explore 50 --pipe -o result.json # 自动抓取用户数据',
50
- ' tt-help --explore -f raw # 仅输出 URL 列表',
51
- ' tt-help --explore -f raw -o urls.txt # 保存 URL 到文件',
52
- ' tt-help -i urls.txt -o result.json # 再爬取这些 URL',
53
- ' tt-help config set http://127.0.0.1:7890',
54
- ' tt-help https://www.tiktok.com/@username',
55
- ];
56
-
57
- const CONFIG_TEXT = [
58
- 'tt-help v1.0.1',
59
- '',
60
- '配置:',
61
- ` 代理: ${proxy}`,
62
- ` 输出格式: json`,
63
- ` 默认输出: ${DEFAULT_OUTPUT}`,
64
- ` 配置文件: ${configFile || '无(使用默认值)'}`,
65
- ];
66
-
67
- export {
68
- proxy,
69
- configFile,
70
- configPath,
71
- DEFAULT_PROXY,
72
- DEFAULT_OUTPUT,
73
- USER_SECTION_SIZE,
74
- HELP_TEXT,
75
- CONFIG_TEXT,
76
- };
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
+ '',
44
+ '参数:',
45
+ ' --explore [count] 从 Explore 页面获取视频列表(默认: 100)',
46
+ ' --pipe 将 Explore 结果自动传给 URL 爬取',
47
+ ' --proxy <地址> 临时指定代理地址',
48
+ ' --filter <条件> 过滤结果(格式: key=value&key2=value2)',
49
+ ' -i, --input <file> 从文件读取 URL 列表(每行一个)',
50
+ ' -o, --output <file> 指定输出文件(默认: tiktok_data.json)',
51
+ ' -f, --format <fmt> 输出格式: json(默认), table, raw',
52
+ ' -c, --config 显示当前配置',
53
+ ' -h, --help 显示帮助',
54
+ '',
55
+ '过滤示例:',
56
+ ' --filter "ttSeller=true&verified=false" 过滤卖家且未认证',
57
+ ' --filter "locationCreated=DE,ES" 过滤指定地区',
58
+ ' --filter "ttSeller=true&locationCreated=US" 组合条件',
59
+ '',
60
+ '配置代理:',
61
+ ' tt-help config set http://127.0.0.1:7890 设置代理',
62
+ ' tt-help config show 查看配置',
63
+ ' tt-help config reset 恢复默认',
64
+ '',
65
+ '配置浏览器:',
66
+ ' tt-help config set-browser /path/to/chrome 手动指定浏览器路径',
67
+ ' tt-help config set-browser auto 自动探测浏览器',
68
+ '',
69
+ '示例:',
70
+ ' tt-help --explore 200 # 先预览 Explore 结果',
71
+ ' tt-help --explore 50 --pipe -o result.json # 自动抓取用户数据',
72
+ ' tt-help --explore -f raw # 仅输出 URL 列表',
73
+ ' tt-help --explore -f raw -o urls.txt # 保存 URL 到文件',
74
+ ' tt-help -i urls.txt -o result.json # 再爬取这些 URL',
75
+ ' tt-help config set http://127.0.0.1:7890',
76
+ ' tt-help https://www.tiktok.com/@username',
77
+ ' tt-help https://... --filter "ttSeller=true&locationCreated=DE"',
78
+ ];
79
+
80
+ const CONFIG_TEXT = [
81
+ 'tt-help v1.0.1',
82
+ '',
83
+ '配置:',
84
+ ` 代理: ${proxy}`,
85
+ ` 浏览器: ${browser || '未配置(将自动探测或回退)'}`,
86
+ ` 输出格式: json`,
87
+ ` 默认输出: ${DEFAULT_OUTPUT}`,
88
+ ` 配置文件: ${configFile || '无(使用默认值)'}`,
89
+ ];
90
+
91
+ export {
92
+ proxy,
93
+ configFile,
94
+ configPath,
95
+ DEFAULT_PROXY,
96
+ DEFAULT_OUTPUT,
97
+ USER_SECTION_SIZE,
98
+ HELP_TEXT,
99
+ CONFIG_TEXT,
100
+ browser,
101
+ saveBrowser,
102
+ };