tt-help-cli-ycl 1.3.33 → 1.3.34

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 (59) hide show
  1. package/README.md +17 -17
  2. package/cli.js +9 -9
  3. package/package.json +47 -47
  4. package/scripts/run-explore copy.bat +101 -101
  5. package/scripts/run-explore.bat +132 -127
  6. package/scripts/run-explore.ps1 +157 -153
  7. package/scripts/run-explore.sh +119 -113
  8. package/src/cli/attach.js +180 -180
  9. package/src/cli/auto.js +240 -240
  10. package/src/cli/config.js +152 -152
  11. package/src/cli/explore.js +488 -481
  12. package/src/cli/info.js +88 -88
  13. package/src/cli/open.js +111 -111
  14. package/src/cli/progress.js +111 -111
  15. package/src/cli/refresh.js +216 -216
  16. package/src/cli/scrape.js +47 -47
  17. package/src/cli/utils.js +18 -18
  18. package/src/cli/videos.js +41 -41
  19. package/src/cli/watch.js +31 -31
  20. package/src/lib/api-interceptor.js +43 -202
  21. package/src/lib/args.js +722 -722
  22. package/src/lib/browser/anti-detect.js +23 -23
  23. package/src/lib/browser/cdp.js +261 -261
  24. package/src/lib/browser/health-checker.js +114 -114
  25. package/src/lib/browser/launch.js +43 -43
  26. package/src/lib/browser/page.js +183 -183
  27. package/src/lib/constants.js +216 -213
  28. package/src/lib/delay.js +54 -54
  29. package/src/lib/explore-fetch.js +118 -118
  30. package/src/lib/fetcher.js +45 -45
  31. package/src/lib/filter.js +66 -66
  32. package/src/lib/io.js +54 -54
  33. package/src/lib/output.js +80 -80
  34. package/src/lib/page-error-detector.js +105 -105
  35. package/src/lib/parse-ssr.mjs +69 -69
  36. package/src/lib/parser.js +47 -47
  37. package/src/lib/retry.js +45 -45
  38. package/src/lib/scrape.js +89 -89
  39. package/src/lib/tiktok-scraper.mjs +194 -194
  40. package/src/lib/url.js +52 -52
  41. package/src/main.js +48 -48
  42. package/src/scraper/auto-core.js +203 -203
  43. package/src/scraper/core.js +211 -211
  44. package/src/scraper/explore-core.js +167 -167
  45. package/src/scraper/modules/captcha-handler.js +114 -114
  46. package/src/scraper/modules/follow-extractor.js +194 -194
  47. package/src/scraper/modules/guess-extractor.js +51 -51
  48. package/src/scraper/modules/page-helpers.js +48 -48
  49. package/src/scraper/refresh-core.js +179 -179
  50. package/src/videos/core.js +125 -125
  51. package/src/watch/data-store.js +1030 -1030
  52. package/src/watch/public/index.html +753 -753
  53. package/src/watch/server.js +933 -933
  54. package/scripts/test-captcha-lib.mjs +0 -68
  55. package/scripts/test-captcha.mjs +0 -81
  56. package/scripts/test-incognito-lib.mjs +0 -36
  57. package/scripts/test-login-state.mjs +0 -128
  58. package/scripts/test-safe-click.mjs +0 -45
  59. package/src/results/user-videos-bar.lar.lar.moeta.json +0 -37
package/src/cli/auto.js CHANGED
@@ -1,240 +1,240 @@
1
- import {
2
- getOrCreatePage,
3
- isBrowserClosedError,
4
- relaunchBrowser,
5
- } from "../lib/browser/page.js";
6
- import { userId as configuredUserId, saveUserId } from "../lib/constants.js";
7
- import { getMacOrUuid } from "../lib/mac-or-uuid.js";
8
- import { ensureBrowserReady as ensureBrowserReadyCDP } from "../lib/browser/cdp.js";
9
-
10
- const MAX_RETRY_WAIT = 5 * 60 * 1000;
11
-
12
- async function withRetry(label, fn) {
13
- let backoff = 1000;
14
- while (true) {
15
- try {
16
- return await fn();
17
- } catch (err) {
18
- console.error(
19
- `[连接] ${label} 失败: ${err.message},${backoff / 1000}秒后重试...`,
20
- );
21
- await new Promise((r) => setTimeout(r, backoff));
22
- if (backoff < MAX_RETRY_WAIT) backoff *= 2;
23
- }
24
- }
25
- }
26
-
27
- async function apiPost(url, body) {
28
- return withRetry(`POST ${url}`, async () => {
29
- const res = await fetch(url, {
30
- method: "POST",
31
- headers: { "Content-Type": "application/json" },
32
- body: JSON.stringify(body),
33
- });
34
- return res.json();
35
- });
36
- }
37
-
38
- async function apiGet(url) {
39
- return withRetry(`GET ${url}`, async () => {
40
- const res = await fetch(url);
41
- return res.json();
42
- });
43
- }
44
-
45
- export async function handleAuto(options) {
46
- const {
47
- autoUsernames,
48
- autoCollectMax,
49
- autoScrapeDepth,
50
- autoMaxComments,
51
- autoMaxGuess,
52
- autoPreset,
53
- autoSwitchDelay,
54
- autoCommentDelay,
55
- serverUrl,
56
- autoEnableFollow,
57
- autoMaxFollowing,
58
- autoMaxFollowers,
59
- } = options;
60
-
61
- let userId = configuredUserId;
62
- if (!userId) {
63
- userId = await getMacOrUuid();
64
- saveUserId(userId);
65
- console.error(`[初始化] 未检测到本地用户编号,已生成并使用: ${userId}`);
66
- }
67
-
68
- const runOptions = {
69
- collectMax: autoCollectMax,
70
- scrapeDepth: autoScrapeDepth,
71
- maxComments: autoMaxComments,
72
- maxGuess: autoMaxGuess,
73
- preset: autoPreset,
74
- switchMax: autoSwitchDelay,
75
- commentMax: autoCommentDelay,
76
- enableFollow: autoEnableFollow,
77
- maxFollowing: autoMaxFollowing,
78
- maxFollowers: autoMaxFollowers,
79
- userId,
80
- };
81
-
82
- await apiGet(`${serverUrl}/api/stats`);
83
-
84
- if (autoUsernames.length > 0) {
85
- const { added, skipped } = await apiPost(`${serverUrl}/api/users`, {
86
- usernames: autoUsernames,
87
- });
88
- console.error(`种子用户: ${added} 个新增, ${skipped} 个已存在`);
89
- }
90
-
91
- console.error(`服务器: ${serverUrl}(断开会自动重连)`);
92
-
93
- const { ensureBrowserReady, processUser } =
94
- await import("../scraper/auto-core.js");
95
- let browser = await ensureBrowserReady();
96
-
97
- const page = await getOrCreatePage(browser);
98
-
99
- let processedCount = 0;
100
- let errorCount = 0;
101
- let consecutiveNetworkErrors = 0;
102
- let captchaCount = 0; // 验证码累计计数
103
-
104
- while (true) {
105
- const job = await apiGet(
106
- `${serverUrl}/api/job?userId=${encodeURIComponent(userId)}`,
107
- );
108
- if (!job.hasJob) break;
109
-
110
- const username = job.user.uniqueId;
111
- processedCount++;
112
-
113
- if (consecutiveNetworkErrors > 0) {
114
- const waitTime =
115
- consecutiveNetworkErrors <= 2
116
- ? 0
117
- : consecutiveNetworkErrors <= 5
118
- ? 30000
119
- : 300000;
120
- if (waitTime > 0) {
121
- console.error(
122
- ` [网络] 连续 ${consecutiveNetworkErrors} 次网络异常,等待 ${waitTime / 1000}s 后重试...`,
123
- );
124
- await new Promise((r) => setTimeout(r, waitTime));
125
- }
126
- }
127
-
128
- console.error(`\n[${processedCount}] 处理 @${username}...`);
129
-
130
- const result = await processUser(
131
- page,
132
- username,
133
- { ...runOptions, browser },
134
- console.error,
135
- );
136
-
137
- if (result.restricted) {
138
- consecutiveNetworkErrors = 0;
139
- await apiPost(`${serverUrl}/api/job/${username}`, result);
140
- continue;
141
- }
142
-
143
- if (result.error) {
144
- // 浏览器关闭检测
145
- if (isBrowserClosedError(new Error(result.error))) {
146
- const newBrowser = await relaunchBrowser({}, 9222);
147
- browser = newBrowser;
148
- const newPage = await getOrCreatePage(browser);
149
- Object.assign(page, newPage);
150
- // 重试当前用户
151
- const retryResult = await processUser(
152
- page,
153
- username,
154
- { ...runOptions, browser },
155
- console.error,
156
- );
157
- Object.assign(result, retryResult);
158
- // 继续下方逻辑
159
- } else {
160
- consecutiveNetworkErrors++;
161
- errorCount++;
162
- await apiPost(`${serverUrl}/api/job/${username}`, result);
163
- const errorType = consecutiveNetworkErrors > 1 ? "network" : "other";
164
- await withRetry("report error", () =>
165
- apiPost(`${serverUrl}/api/error-report`, {
166
- userId,
167
- username,
168
- errorType,
169
- errorMessage: result.error,
170
- stage: "process",
171
- errorStack: result.errorStack || "",
172
- }),
173
- ).catch(() => {});
174
- continue;
175
- }
176
- }
177
-
178
- if (result.captchaDetected) {
179
- captchaCount++;
180
- console.error(` [验证码] 累计 ${captchaCount} 次`);
181
-
182
- await withRetry("report captcha", () =>
183
- apiPost(`${serverUrl}/api/error-report`, {
184
- userId,
185
- username,
186
- errorType: "captcha",
187
- errorMessage: result.captchaMessage || "页面出现验证码",
188
- stage: result.captchaStage || "video-page",
189
- errorStack: "",
190
- }),
191
- ).catch(() => {});
192
-
193
- // 累计2次验证码,标记异常(auto模式暂不支持账户切换)
194
- if (captchaCount >= 2) {
195
- console.error(
196
- ` [警告] 验证码累计 ${captchaCount} 次,建议检查账户状态`,
197
- );
198
- captchaCount = 0;
199
- }
200
- }
201
-
202
- consecutiveNetworkErrors = 0;
203
-
204
- const guessedLocation = result.locationCreated || null;
205
-
206
- const payload = {
207
- userInfo: result.userInfo || {},
208
- discoveredVideoAuthors: (result.discoveredVideoAuthors || []).map(
209
- (item) =>
210
- typeof item === "object" ? { ...item, guessedLocation } : item,
211
- ),
212
- discoveredCommentAuthors: (result.discoveredCommentAuthors || []).map(
213
- (author) => ({ author, guessedLocation }),
214
- ),
215
- discoveredGuessAuthors: (result.discoveredGuessAuthors || []).map(
216
- (author) => ({ author, guessedLocation }),
217
- ),
218
- discoveredFollowing: (result.discoveredFollowing || []).map((f) => ({
219
- handle: Array.isArray(f) ? f[0] : f,
220
- displayName: Array.isArray(f) ? f[1] : null,
221
- guessedLocation,
222
- })),
223
- discoveredFollowers: (result.discoveredFollowers || []).map((f) => ({
224
- handle: Array.isArray(f) ? f[0] : f,
225
- displayName: Array.isArray(f) ? f[1] : null,
226
- guessedLocation,
227
- })),
228
- };
229
- await apiPost(`${serverUrl}/api/job/${username}`, payload);
230
- console.error(" 已提交");
231
- }
232
-
233
- const stats = await apiGet(`${serverUrl}/api/stats`);
234
- console.error(`\n完成: ${processedCount} 个用户处理, ${errorCount} 个出错`);
235
- console.error(
236
- ` 总用户: ${stats.totalUsers}, 已完成: ${stats.processedUsers}, 待处理: ${stats.pendingUsers}, 错误: ${stats.errorUsers}`,
237
- );
238
-
239
- await browser.close().catch(() => {});
240
- }
1
+ import {
2
+ getOrCreatePage,
3
+ isBrowserClosedError,
4
+ relaunchBrowser,
5
+ } from "../lib/browser/page.js";
6
+ import { userId as configuredUserId, saveUserId } from "../lib/constants.js";
7
+ import { getMacOrUuid } from "../lib/mac-or-uuid.js";
8
+ import { ensureBrowserReady as ensureBrowserReadyCDP } from "../lib/browser/cdp.js";
9
+
10
+ const MAX_RETRY_WAIT = 5 * 60 * 1000;
11
+
12
+ async function withRetry(label, fn) {
13
+ let backoff = 1000;
14
+ while (true) {
15
+ try {
16
+ return await fn();
17
+ } catch (err) {
18
+ console.error(
19
+ `[连接] ${label} 失败: ${err.message},${backoff / 1000}秒后重试...`,
20
+ );
21
+ await new Promise((r) => setTimeout(r, backoff));
22
+ if (backoff < MAX_RETRY_WAIT) backoff *= 2;
23
+ }
24
+ }
25
+ }
26
+
27
+ async function apiPost(url, body) {
28
+ return withRetry(`POST ${url}`, async () => {
29
+ const res = await fetch(url, {
30
+ method: "POST",
31
+ headers: { "Content-Type": "application/json" },
32
+ body: JSON.stringify(body),
33
+ });
34
+ return res.json();
35
+ });
36
+ }
37
+
38
+ async function apiGet(url) {
39
+ return withRetry(`GET ${url}`, async () => {
40
+ const res = await fetch(url);
41
+ return res.json();
42
+ });
43
+ }
44
+
45
+ export async function handleAuto(options) {
46
+ const {
47
+ autoUsernames,
48
+ autoCollectMax,
49
+ autoScrapeDepth,
50
+ autoMaxComments,
51
+ autoMaxGuess,
52
+ autoPreset,
53
+ autoSwitchDelay,
54
+ autoCommentDelay,
55
+ serverUrl,
56
+ autoEnableFollow,
57
+ autoMaxFollowing,
58
+ autoMaxFollowers,
59
+ } = options;
60
+
61
+ let userId = configuredUserId;
62
+ if (!userId) {
63
+ userId = await getMacOrUuid();
64
+ saveUserId(userId);
65
+ console.error(`[初始化] 未检测到本地用户编号,已生成并使用: ${userId}`);
66
+ }
67
+
68
+ const runOptions = {
69
+ collectMax: autoCollectMax,
70
+ scrapeDepth: autoScrapeDepth,
71
+ maxComments: autoMaxComments,
72
+ maxGuess: autoMaxGuess,
73
+ preset: autoPreset,
74
+ switchMax: autoSwitchDelay,
75
+ commentMax: autoCommentDelay,
76
+ enableFollow: autoEnableFollow,
77
+ maxFollowing: autoMaxFollowing,
78
+ maxFollowers: autoMaxFollowers,
79
+ userId,
80
+ };
81
+
82
+ await apiGet(`${serverUrl}/api/stats`);
83
+
84
+ if (autoUsernames.length > 0) {
85
+ const { added, skipped } = await apiPost(`${serverUrl}/api/users`, {
86
+ usernames: autoUsernames,
87
+ });
88
+ console.error(`种子用户: ${added} 个新增, ${skipped} 个已存在`);
89
+ }
90
+
91
+ console.error(`服务器: ${serverUrl}(断开会自动重连)`);
92
+
93
+ const { ensureBrowserReady, processUser } =
94
+ await import("../scraper/auto-core.js");
95
+ let browser = await ensureBrowserReady();
96
+
97
+ const page = await getOrCreatePage(browser);
98
+
99
+ let processedCount = 0;
100
+ let errorCount = 0;
101
+ let consecutiveNetworkErrors = 0;
102
+ let captchaCount = 0; // 验证码累计计数
103
+
104
+ while (true) {
105
+ const job = await apiGet(
106
+ `${serverUrl}/api/job?userId=${encodeURIComponent(userId)}`,
107
+ );
108
+ if (!job.hasJob) break;
109
+
110
+ const username = job.user.uniqueId;
111
+ processedCount++;
112
+
113
+ if (consecutiveNetworkErrors > 0) {
114
+ const waitTime =
115
+ consecutiveNetworkErrors <= 2
116
+ ? 0
117
+ : consecutiveNetworkErrors <= 5
118
+ ? 30000
119
+ : 300000;
120
+ if (waitTime > 0) {
121
+ console.error(
122
+ ` [网络] 连续 ${consecutiveNetworkErrors} 次网络异常,等待 ${waitTime / 1000}s 后重试...`,
123
+ );
124
+ await new Promise((r) => setTimeout(r, waitTime));
125
+ }
126
+ }
127
+
128
+ console.error(`\n[${processedCount}] 处理 @${username}...`);
129
+
130
+ const result = await processUser(
131
+ page,
132
+ username,
133
+ { ...runOptions, browser },
134
+ console.error,
135
+ );
136
+
137
+ if (result.restricted) {
138
+ consecutiveNetworkErrors = 0;
139
+ await apiPost(`${serverUrl}/api/job/${username}`, result);
140
+ continue;
141
+ }
142
+
143
+ if (result.error) {
144
+ // 浏览器关闭检测
145
+ if (isBrowserClosedError(new Error(result.error))) {
146
+ const newBrowser = await relaunchBrowser({}, 9222);
147
+ browser = newBrowser;
148
+ const newPage = await getOrCreatePage(browser);
149
+ Object.assign(page, newPage);
150
+ // 重试当前用户
151
+ const retryResult = await processUser(
152
+ page,
153
+ username,
154
+ { ...runOptions, browser },
155
+ console.error,
156
+ );
157
+ Object.assign(result, retryResult);
158
+ // 继续下方逻辑
159
+ } else {
160
+ consecutiveNetworkErrors++;
161
+ errorCount++;
162
+ await apiPost(`${serverUrl}/api/job/${username}`, result);
163
+ const errorType = consecutiveNetworkErrors > 1 ? "network" : "other";
164
+ await withRetry("report error", () =>
165
+ apiPost(`${serverUrl}/api/error-report`, {
166
+ userId,
167
+ username,
168
+ errorType,
169
+ errorMessage: result.error,
170
+ stage: "process",
171
+ errorStack: result.errorStack || "",
172
+ }),
173
+ ).catch(() => {});
174
+ continue;
175
+ }
176
+ }
177
+
178
+ if (result.captchaDetected) {
179
+ captchaCount++;
180
+ console.error(` [验证码] 累计 ${captchaCount} 次`);
181
+
182
+ await withRetry("report captcha", () =>
183
+ apiPost(`${serverUrl}/api/error-report`, {
184
+ userId,
185
+ username,
186
+ errorType: "captcha",
187
+ errorMessage: result.captchaMessage || "页面出现验证码",
188
+ stage: result.captchaStage || "video-page",
189
+ errorStack: "",
190
+ }),
191
+ ).catch(() => {});
192
+
193
+ // 累计2次验证码,标记异常(auto模式暂不支持账户切换)
194
+ if (captchaCount >= 2) {
195
+ console.error(
196
+ ` [警告] 验证码累计 ${captchaCount} 次,建议检查账户状态`,
197
+ );
198
+ captchaCount = 0;
199
+ }
200
+ }
201
+
202
+ consecutiveNetworkErrors = 0;
203
+
204
+ const guessedLocation = result.locationCreated || null;
205
+
206
+ const payload = {
207
+ userInfo: result.userInfo || {},
208
+ discoveredVideoAuthors: (result.discoveredVideoAuthors || []).map(
209
+ (item) =>
210
+ typeof item === "object" ? { ...item, guessedLocation } : item,
211
+ ),
212
+ discoveredCommentAuthors: (result.discoveredCommentAuthors || []).map(
213
+ (author) => ({ author, guessedLocation }),
214
+ ),
215
+ discoveredGuessAuthors: (result.discoveredGuessAuthors || []).map(
216
+ (author) => ({ author, guessedLocation }),
217
+ ),
218
+ discoveredFollowing: (result.discoveredFollowing || []).map((f) => ({
219
+ handle: Array.isArray(f) ? f[0] : f,
220
+ displayName: Array.isArray(f) ? f[1] : null,
221
+ guessedLocation,
222
+ })),
223
+ discoveredFollowers: (result.discoveredFollowers || []).map((f) => ({
224
+ handle: Array.isArray(f) ? f[0] : f,
225
+ displayName: Array.isArray(f) ? f[1] : null,
226
+ guessedLocation,
227
+ })),
228
+ };
229
+ await apiPost(`${serverUrl}/api/job/${username}`, payload);
230
+ console.error(" 已提交");
231
+ }
232
+
233
+ const stats = await apiGet(`${serverUrl}/api/stats`);
234
+ console.error(`\n完成: ${processedCount} 个用户处理, ${errorCount} 个出错`);
235
+ console.error(
236
+ ` 总用户: ${stats.totalUsers}, 已完成: ${stats.processedUsers}, 待处理: ${stats.pendingUsers}, 错误: ${stats.errorUsers}`,
237
+ );
238
+
239
+ await browser.close().catch(() => {});
240
+ }