tt-help-cli-ycl 1.3.34 → 1.3.36

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 (62) hide show
  1. package/README.md +33 -17
  2. package/cli.js +9 -9
  3. package/package.json +49 -47
  4. package/scripts/run-explore copy.bat +101 -101
  5. package/scripts/run-explore.bat +132 -132
  6. package/scripts/run-explore.ps1 +157 -157
  7. package/scripts/run-explore.sh +119 -119
  8. package/scripts/test-captcha-lib.mjs +68 -0
  9. package/scripts/test-captcha.mjs +81 -0
  10. package/scripts/test-incognito-lib.mjs +36 -0
  11. package/scripts/test-login-state.mjs +128 -0
  12. package/scripts/test-safe-click.mjs +45 -0
  13. package/scripts/test-watch-db-smoke.mjs +246 -0
  14. package/src/cli/attach.js +240 -180
  15. package/src/cli/auto.js +265 -240
  16. package/src/cli/comments.js +301 -210
  17. package/src/cli/config.js +170 -152
  18. package/src/cli/db-import.js +51 -0
  19. package/src/cli/explore.js +519 -488
  20. package/src/cli/info.js +88 -88
  21. package/src/cli/open.js +111 -111
  22. package/src/cli/progress.js +111 -111
  23. package/src/cli/refresh.js +288 -216
  24. package/src/cli/scrape.js +47 -47
  25. package/src/cli/utils.js +18 -18
  26. package/src/cli/videos.js +41 -41
  27. package/src/cli/videostats.js +140 -25
  28. package/src/cli/watch.js +30 -31
  29. package/src/lib/args.js +766 -722
  30. package/src/lib/browser/anti-detect.js +23 -23
  31. package/src/lib/browser/cdp.js +261 -261
  32. package/src/lib/browser/health-checker.js +114 -114
  33. package/src/lib/browser/launch.js +43 -43
  34. package/src/lib/browser/page.js +183 -183
  35. package/src/lib/constants.js +238 -216
  36. package/src/lib/delay.js +54 -54
  37. package/src/lib/explore-fetch.js +118 -118
  38. package/src/lib/fetcher.js +45 -45
  39. package/src/lib/filter.js +66 -66
  40. package/src/lib/io.js +54 -54
  41. package/src/lib/output.js +80 -80
  42. package/src/lib/page-error-detector.js +105 -105
  43. package/src/lib/parse-ssr.mjs +69 -69
  44. package/src/lib/parser.js +47 -47
  45. package/src/lib/retry.js +45 -45
  46. package/src/lib/scrape.js +89 -89
  47. package/src/lib/tiktok-scraper.mjs +232 -194
  48. package/src/lib/url.js +52 -52
  49. package/src/main.js +70 -48
  50. package/src/results/user-videos-bar.lar.lar.moeta.json +37 -0
  51. package/src/scraper/auto-core.js +203 -203
  52. package/src/scraper/core.js +211 -211
  53. package/src/scraper/explore-core.js +177 -167
  54. package/src/scraper/modules/captcha-handler.js +114 -114
  55. package/src/scraper/modules/follow-extractor.js +194 -194
  56. package/src/scraper/modules/guess-extractor.js +51 -51
  57. package/src/scraper/modules/page-helpers.js +48 -48
  58. package/src/scraper/refresh-core.js +179 -179
  59. package/src/videos/core.js +125 -125
  60. package/src/watch/data-store.js +2364 -1030
  61. package/src/watch/public/index.html +1494 -753
  62. package/src/watch/server.js +628 -933
package/src/cli/config.js CHANGED
@@ -1,152 +1,170 @@
1
- import { HELP_TEXT, configPath, saveBrowser, saveUserId, saveMaxFollowing, saveMaxFollowers, saveMaxVideos, saveMaxComments, getConfigText } from '../lib/constants.js';
2
- import { readFileSync, writeFileSync, existsSync } from 'fs';
3
- import { fileURLToPath } from 'url';
4
- import { dirname, join } from 'path';
5
-
6
- const __dirname = dirname(fileURLToPath(import.meta.url));
7
- const pkgPath = join(__dirname, '..', '..', 'package.json');
8
- const { version } = JSON.parse(readFileSync(pkgPath, 'utf-8'));
9
-
10
- function showConfig(urls, outputFile) {
11
- const configLines = getConfigText();
12
- if (urls.length > 0) {
13
- configLines.push(`\n URL数量: ${urls.length}`);
14
- }
15
- if (outputFile) {
16
- configLines.push(` 输出文件: ${outputFile}`);
17
- }
18
- console.error(configLines.join('\n'));
19
- }
20
-
21
- function showUsage() {
22
- console.error(HELP_TEXT.join('\n'));
23
- process.exit(0);
24
- }
25
-
26
- function handleConfig(action, key, value) {
27
- switch (action) {
28
- case 'show': {
29
- const configLines = getConfigText();
30
- console.error(configLines.join('\n'));
31
- break;
32
- }
33
-
34
- case 'set': {
35
- if (!key) {
36
- console.error('用法: tt-help config set <key> <value>');
37
- console.error(' 可用 key: proxy, server, browser, userId, maxFollowing, maxFollowers, maxVideos, maxComments');
38
- return;
39
- }
40
-
41
- switch (key) {
42
- case 'proxy':
43
- if (!value) {
44
- console.error('请提供 proxy 的值');
45
- console.error('用法: tt-help config set proxy <代理地址>');
46
- return;
47
- }
48
- saveProxy(value);
49
- console.error(`代理已更新: ${value}`);
50
- break;
51
-
52
- case 'server':
53
- if (!value) {
54
- console.error('请提供 server 的值');
55
- return;
56
- }
57
- saveServer(value);
58
- console.error(`服务器已更新: ${value}`);
59
- break;
60
-
61
- case 'browser':
62
- if (!value) {
63
- console.error('请提供 browser 的值');
64
- console.error('用法: tt-help config set browser <浏览器路径>');
65
- console.error(' 或: tt-help config set-browser <浏览器路径>');
66
- return;
67
- }
68
- saveBrowser(value);
69
- console.error(`浏览器路径已更新: ${value}`);
70
- break;
71
-
72
- case 'userId':
73
- if (!value) {
74
- console.error('请提供 userId 的值');
75
- return;
76
- }
77
- saveUserId(value);
78
- console.error(`用户号已更新: ${value}`);
79
- break;
80
-
81
- case 'maxFollowing':
82
- if (!value) {
83
- console.error('请提供 maxFollowing 的值');
84
- return;
85
- }
86
- saveMaxFollowing(value);
87
- console.error(`商家关注采集数已更新: ${value}`);
88
- break;
89
-
90
- case 'maxFollowers':
91
- if (!value) {
92
- console.error('请提供 maxFollowers 的值');
93
- return;
94
- }
95
- saveMaxFollowers(value);
96
- console.error(`粉丝采集数已更新: ${value}`);
97
- break;
98
-
99
- case 'maxVideos':
100
- if (!value) {
101
- console.error('请提供 maxVideos 的值');
102
- return;
103
- }
104
- saveMaxVideos(value);
105
- console.error(`视频采集数已更新: ${value}`);
106
- break;
107
-
108
- case 'maxComments':
109
- if (!value) {
110
- console.error('请提供 maxComments 的值');
111
- return;
112
- }
113
- saveMaxComments(value);
114
- console.error(`评论采集数已更新: ${value}`);
115
- break;
116
-
117
- default:
118
- console.error(`未知配置项: ${key}`);
119
- console.error(' 可用 key: proxy, server, browser, userId, maxFollowing, maxFollowers, maxVideos, maxComments');
120
- }
121
- break;
122
- }
123
-
124
- case 'reset': {
125
- if (existsSync(configPath)) {
126
- writeFileSync(configPath, '{}', 'utf-8');
127
- console.error('配置已重置为默认');
128
- } else {
129
- console.error('配置文件不存在或已是默认状态');
130
- }
131
- break;
132
- }
133
-
134
- default:
135
- console.error(`未知配置命令: ${action}`);
136
- console.error('用法: tt-help config [show|set|reset]');
137
- }
138
- }
139
-
140
- function saveProxy(newProxy) {
141
- const cfg = existsSync(configPath) ? JSON.parse(readFileSync(configPath, 'utf-8')) : {};
142
- cfg.proxy = newProxy;
143
- writeFileSync(configPath, JSON.stringify(cfg, null, 2), 'utf-8');
144
- }
145
-
146
- function saveServer(newServer) {
147
- const cfg = existsSync(configPath) ? JSON.parse(readFileSync(configPath, 'utf-8')) : {};
148
- cfg.server = newServer;
149
- writeFileSync(configPath, JSON.stringify(cfg, null, 2), 'utf-8');
150
- }
151
-
152
- export { handleConfig, showConfig, showUsage, version };
1
+ import {
2
+ HELP_TEXT,
3
+ configPath,
4
+ saveBrowser,
5
+ saveUserId,
6
+ saveMaxFollowing,
7
+ saveMaxFollowers,
8
+ saveMaxVideos,
9
+ saveMaxComments,
10
+ getConfigText,
11
+ } from "../lib/constants.js";
12
+ import { readFileSync, writeFileSync, existsSync } from "fs";
13
+ import { fileURLToPath } from "url";
14
+ import { dirname, join } from "path";
15
+
16
+ const __dirname = dirname(fileURLToPath(import.meta.url));
17
+ const pkgPath = join(__dirname, "..", "..", "package.json");
18
+ const { version } = JSON.parse(readFileSync(pkgPath, "utf-8"));
19
+
20
+ function showConfig(urls, outputFile) {
21
+ const configLines = getConfigText();
22
+ if (urls.length > 0) {
23
+ configLines.push(`\n URL数量: ${urls.length}`);
24
+ }
25
+ if (outputFile) {
26
+ configLines.push(` 输出/锚点路径: ${outputFile}`);
27
+ }
28
+ console.error(configLines.join("\n"));
29
+ }
30
+
31
+ function showUsage() {
32
+ console.error(HELP_TEXT.join("\n"));
33
+ process.exit(0);
34
+ }
35
+
36
+ function handleConfig(action, key, value) {
37
+ switch (action) {
38
+ case "show": {
39
+ const configLines = getConfigText();
40
+ console.error(configLines.join("\n"));
41
+ break;
42
+ }
43
+
44
+ case "set": {
45
+ if (!key) {
46
+ console.error("用法: tt-help config set <key> <value>");
47
+ console.error(
48
+ " 可用 key: proxy, server, browser, userId, maxFollowing, maxFollowers, maxVideos, maxComments",
49
+ );
50
+ return;
51
+ }
52
+
53
+ switch (key) {
54
+ case "proxy":
55
+ if (!value) {
56
+ console.error("请提供 proxy 的值");
57
+ console.error("用法: tt-help config set proxy <代理地址>");
58
+ return;
59
+ }
60
+ saveProxy(value);
61
+ console.error(`代理已更新: ${value}`);
62
+ break;
63
+
64
+ case "server":
65
+ if (!value) {
66
+ console.error("请提供 server 的值");
67
+ return;
68
+ }
69
+ saveServer(value);
70
+ console.error(`服务器已更新: ${value}`);
71
+ break;
72
+
73
+ case "browser":
74
+ if (!value) {
75
+ console.error("请提供 browser 的值");
76
+ console.error("用法: tt-help config set browser <浏览器路径>");
77
+ console.error(" 或: tt-help config set-browser <浏览器路径>");
78
+ return;
79
+ }
80
+ saveBrowser(value);
81
+ console.error(`浏览器路径已更新: ${value}`);
82
+ break;
83
+
84
+ case "userId":
85
+ if (!value) {
86
+ console.error("请提供 userId 的值");
87
+ return;
88
+ }
89
+ saveUserId(value);
90
+ console.error(`用户号已更新: ${value}`);
91
+ break;
92
+
93
+ case "maxFollowing":
94
+ if (!value) {
95
+ console.error("请提供 maxFollowing 的值");
96
+ return;
97
+ }
98
+ saveMaxFollowing(value);
99
+ console.error(`商家关注采集数已更新: ${value}`);
100
+ break;
101
+
102
+ case "maxFollowers":
103
+ if (!value) {
104
+ console.error("请提供 maxFollowers 的值");
105
+ return;
106
+ }
107
+ saveMaxFollowers(value);
108
+ console.error(`粉丝采集数已更新: ${value}`);
109
+ break;
110
+
111
+ case "maxVideos":
112
+ if (!value) {
113
+ console.error("请提供 maxVideos 的值");
114
+ return;
115
+ }
116
+ saveMaxVideos(value);
117
+ console.error(`视频采集数已更新: ${value}`);
118
+ break;
119
+
120
+ case "maxComments":
121
+ if (!value) {
122
+ console.error("请提供 maxComments 的值");
123
+ return;
124
+ }
125
+ saveMaxComments(value);
126
+ console.error(`评论采集数已更新: ${value}`);
127
+ break;
128
+
129
+ default:
130
+ console.error(`未知配置项: ${key}`);
131
+ console.error(
132
+ " 可用 key: proxy, server, browser, userId, maxFollowing, maxFollowers, maxVideos, maxComments",
133
+ );
134
+ }
135
+ break;
136
+ }
137
+
138
+ case "reset": {
139
+ if (existsSync(configPath)) {
140
+ writeFileSync(configPath, "{}", "utf-8");
141
+ console.error("配置已重置为默认");
142
+ } else {
143
+ console.error("配置文件不存在或已是默认状态");
144
+ }
145
+ break;
146
+ }
147
+
148
+ default:
149
+ console.error(`未知配置命令: ${action}`);
150
+ console.error("用法: tt-help config [show|set|reset]");
151
+ }
152
+ }
153
+
154
+ function saveProxy(newProxy) {
155
+ const cfg = existsSync(configPath)
156
+ ? JSON.parse(readFileSync(configPath, "utf-8"))
157
+ : {};
158
+ cfg.proxy = newProxy;
159
+ writeFileSync(configPath, JSON.stringify(cfg, null, 2), "utf-8");
160
+ }
161
+
162
+ function saveServer(newServer) {
163
+ const cfg = existsSync(configPath)
164
+ ? JSON.parse(readFileSync(configPath, "utf-8"))
165
+ : {};
166
+ cfg.server = newServer;
167
+ writeFileSync(configPath, JSON.stringify(cfg, null, 2), "utf-8");
168
+ }
169
+
170
+ export { handleConfig, showConfig, showUsage, version };
@@ -0,0 +1,51 @@
1
+ import { closeStoreDb, importLegacyJsonToDb } from "../watch/data-store.js";
2
+
3
+ export async function handleDbImport(options) {
4
+ const { dbPath, usersFilePath, doneFilePath, videosFilePath, showHelp } =
5
+ options;
6
+
7
+ if (showHelp) {
8
+ console.error(
9
+ "用法: tt-help db-import --db <db路径> [--users users.json] [--done done.json] [--videos videos.json]",
10
+ );
11
+ console.error("");
12
+ console.error("示例:");
13
+ console.error(
14
+ " tt-help db-import --db data/result.db --users data/result.json --done data/result-done.json --videos data/result-videos.json",
15
+ );
16
+ return;
17
+ }
18
+
19
+ if (!dbPath) {
20
+ console.error("请提供 --db <db路径>");
21
+ process.exit(1);
22
+ }
23
+
24
+ if (!usersFilePath && !doneFilePath && !videosFilePath) {
25
+ console.error("至少提供一个导入源:--users / --done / --videos");
26
+ process.exit(1);
27
+ }
28
+
29
+ try {
30
+ const result = importLegacyJsonToDb({
31
+ dbFilePath: dbPath,
32
+ usersFilePath,
33
+ doneFilePath,
34
+ videosFilePath,
35
+ });
36
+
37
+ console.error("[db-import] 导入完成");
38
+ console.error(`[db-import] 数据库: ${result.dbPath}`);
39
+ console.error(
40
+ `[db-import] 新增 users: ${result.usersImported}, 总数: ${result.totalUsers}`,
41
+ );
42
+ console.error(
43
+ `[db-import] 新增 jobs: ${result.jobsImported}, 总数: ${result.totalJobs}`,
44
+ );
45
+ console.error(
46
+ `[db-import] 新增 videos: ${result.videosImported}, 总数: ${result.totalVideos}`,
47
+ );
48
+ } finally {
49
+ closeStoreDb();
50
+ }
51
+ }