tt-help-cli-ycl 1.3.48 → 1.3.50

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 (64) hide show
  1. package/README.md +33 -33
  2. package/cli.js +9 -9
  3. package/package.json +52 -52
  4. package/scripts/run-explore copy.bat +101 -101
  5. package/scripts/run-explore.bat +134 -134
  6. package/scripts/run-explore.ps1 +159 -159
  7. package/scripts/run-explore.sh +121 -121
  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 +331 -331
  15. package/src/cli/auto.js +265 -265
  16. package/src/cli/comments.js +620 -620
  17. package/src/cli/config.js +170 -170
  18. package/src/cli/db-import.js +51 -51
  19. package/src/cli/explore.js +555 -555
  20. package/src/cli/open.js +109 -111
  21. package/src/cli/progress.js +111 -111
  22. package/src/cli/refresh.js +288 -288
  23. package/src/cli/scrape.js +47 -47
  24. package/src/cli/utils.js +18 -18
  25. package/src/cli/videos.js +41 -41
  26. package/src/cli/videostats.js +196 -196
  27. package/src/cli/watch.js +30 -30
  28. package/src/lib/api-interceptor.js +161 -161
  29. package/src/lib/args.js +809 -809
  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 +184 -184
  35. package/src/lib/constants.js +297 -297
  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 +109 -109
  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 +90 -90
  47. package/src/lib/target-locations.js +61 -61
  48. package/src/lib/tiktok-scraper.mjs +98 -61
  49. package/src/lib/url.js +52 -52
  50. package/src/main.js +73 -73
  51. package/src/npm-main.js +70 -70
  52. package/src/results/user-videos-bar.lar.lar.moeta.json +37 -0
  53. package/src/scraper/auto-core.js +203 -203
  54. package/src/scraper/core.js +255 -255
  55. package/src/scraper/explore-core.js +208 -208
  56. package/src/scraper/modules/captcha-handler.js +114 -114
  57. package/src/scraper/modules/follow-extractor.js +250 -250
  58. package/src/scraper/modules/guess-extractor.js +51 -51
  59. package/src/scraper/modules/page-helpers.js +48 -48
  60. package/src/scraper/refresh-core.js +213 -213
  61. package/src/videos/core.js +143 -143
  62. package/src/watch/data-store.js +2980 -2980
  63. package/src/watch/public/index.html +2355 -2355
  64. package/src/watch/server.js +727 -727
@@ -1,255 +1,255 @@
1
- import {
2
- closeCommentPanel,
3
- delay,
4
- ensureBrowserReady,
5
- ensureTikTokPage,
6
- setDelayConfig,
7
- getDelayConfig,
8
- retryWithBackoff,
9
- assertPageUrl,
10
- } from "./modules/page-helpers.js";
11
- import { extractCommentAuthors } from "./modules/comment-extractor.js";
12
- import { extractGuessVideos } from "./modules/guess-extractor.js";
13
- import {
14
- DEFAULT_TARGET_LOCATIONS_CSV,
15
- isLocationInList,
16
- normalizeLocationList,
17
- } from "../lib/target-locations.js";
18
-
19
- async function scrapeSingleVideo(
20
- page,
21
- maxComments,
22
- maxGuess,
23
- log,
24
- location = DEFAULT_TARGET_LOCATIONS_CSV,
25
- ) {
26
- const config = getDelayConfig();
27
-
28
- await page
29
- .waitForSelector('[class*="VideoMeta"]', { timeout: 10000 })
30
- .catch(() => {});
31
- await delay(Math.round(config.commentMax * 0.3), config.commentMax);
32
-
33
- const userData = await page.evaluate(() => {
34
- const result = {};
35
- const m = window.location.href.match(/\/@([^/]+)\/video/);
36
- if (m) result.uniqueId = m[1];
37
- const authorEls = document.querySelectorAll('[class*="Author"]');
38
- for (const el of authorEls) {
39
- const text = (el.textContent || "").trim();
40
- if (text && !text.includes("TikTok") && !text.includes("Share")) {
41
- result.nickname = text;
42
- break;
43
- }
44
- }
45
- const html = document.documentElement.outerHTML;
46
- const locMatch = html.match(/"locationCreated":"([^"]*)/);
47
- if (locMatch) result.locationCreated = locMatch[1];
48
- return result;
49
- });
50
-
51
- const videoAuthor = userData.uniqueId ? "@" + userData.uniqueId : null;
52
- if (!videoAuthor) throw new Error("无法获取视频作者");
53
-
54
- let guessVideos = [];
55
- let commentUsers = [];
56
- let captchaDetected = false;
57
- let captchaStage = "";
58
- let captchaMessage = "";
59
-
60
- const locationList = normalizeLocationList(location);
61
- if (isLocationInList(userData.locationCreated, locationList)) {
62
- if (maxGuess > 0) {
63
- guessVideos = await extractGuessVideos(page, maxGuess);
64
- }
65
- if (maxComments > 0) {
66
- const commentResult = await extractCommentAuthors(page, maxComments);
67
- commentUsers = commentResult.authors || [];
68
- if (commentResult.captchaDetected) {
69
- captchaDetected = true;
70
- captchaStage = "comment";
71
- captchaMessage = "评论阶段出现验证码";
72
- }
73
- }
74
- await closeCommentPanel(page);
75
- if (maxGuess > 0 || maxComments > 0) {
76
- await delay(Math.round(config.commentMax * 0.3), config.commentMax);
77
- }
78
- }
79
-
80
- return {
81
- videoAuthor,
82
- uniqueId: userData.uniqueId,
83
- nickname: userData.nickname,
84
- locationCreated: userData.locationCreated,
85
- commentUsers: [...new Set(commentUsers)],
86
- guessVideos,
87
- captchaDetected,
88
- captchaStage,
89
- captchaMessage,
90
- };
91
- }
92
-
93
- async function runScrape(options) {
94
- const {
95
- videoUrl,
96
- maxVideos = 20,
97
- maxComments = 999,
98
- maxGuess = 10,
99
- preset = null,
100
- switchMax = null,
101
- commentMax = null,
102
- log = console.error,
103
- browser: externalBrowser = null,
104
- page: externalPage = null,
105
- } = options;
106
-
107
- if (preset) {
108
- setDelayConfig(preset);
109
- } else if (switchMax || commentMax) {
110
- setDelayConfig({
111
- switchMax: switchMax || 5000,
112
- commentMax: commentMax || 3000,
113
- });
114
- }
115
-
116
- const config = getDelayConfig();
117
- let browser, page;
118
- const isExternal = !!(externalBrowser && externalPage);
119
-
120
- if (!isExternal) {
121
- log(`视频地址: ${videoUrl}`);
122
- log(
123
- `视频数: ${maxVideos}, 评论数: ${maxComments}, 猜你喜欢: ${maxGuess}, 切换延迟: ${config.switchMax}ms, 评论延迟: ${config.commentMax}ms`,
124
- );
125
- }
126
-
127
- if (isExternal) {
128
- browser = externalBrowser;
129
- page = externalPage;
130
- } else {
131
- browser = await ensureBrowserReady();
132
- try {
133
- page = await ensureTikTokPage(browser, videoUrl);
134
- } catch (e) {
135
- await browser.close().catch(() => {});
136
- throw e;
137
- }
138
- }
139
-
140
- await retryWithBackoff(
141
- () => page.goto(videoUrl, { waitUntil: "load", timeout: 30000 }),
142
- { log },
143
- );
144
- assertPageUrl(page, videoUrl.split("/video/")[0]);
145
- await delay(Math.round(config.switchMax * 0.5), config.switchMax);
146
- await closeCommentPanel(page);
147
- await delay(Math.round(config.commentMax * 0.5), config.commentMax);
148
-
149
- const allResults = [];
150
- let anyCaptchaDetected = false;
151
- let anyCaptchaStage = "";
152
- let anyCaptchaMessage = "";
153
- const videoAuthors = new Set();
154
- const commentUsers = new Set();
155
- const allCommentAuthorsList = [];
156
- const allGuessAuthors = new Set();
157
- const allGuessVideos = [];
158
-
159
- for (let i = 0; i < maxVideos; i++) {
160
- await delay(Math.round(config.commentMax * 0.3), config.commentMax);
161
-
162
- let result;
163
- try {
164
- result = await scrapeSingleVideo(page, maxComments, maxGuess, log);
165
- } catch (e) {
166
- log(`[${i + 1}/${maxVideos}] 跳过: ${e.message}`);
167
- if (i < maxVideos - 1) {
168
- await page.evaluate(() => {
169
- const container = document.querySelector(
170
- '[class*="ColumnListContainer"]',
171
- );
172
- if (container) container.scrollTop += 700;
173
- else window.scrollBy(0, 700);
174
- });
175
- await delay(Math.round(config.switchMax * 0.5), config.switchMax);
176
- }
177
- continue;
178
- }
179
-
180
- allResults.push(result);
181
- if (result.captchaDetected) {
182
- anyCaptchaDetected = true;
183
- anyCaptchaStage = result.captchaStage || "";
184
- anyCaptchaMessage = result.captchaMessage || "";
185
- }
186
- videoAuthors.add(result.videoAuthor);
187
- result.commentUsers.forEach((u) => commentUsers.add(u));
188
- allCommentAuthorsList.push(...result.commentUsers);
189
- if (result.guessVideos) {
190
- allGuessVideos.push(...result.guessVideos);
191
- result.guessVideos.forEach((v) => {
192
- if (v.author) allGuessAuthors.add(v.author);
193
- });
194
- }
195
-
196
- if ((i + 1) % 5 === 0 || i === 0) {
197
- log(
198
- `[${i + 1}/${maxVideos}] ${result.videoAuthor} | 昵称: ${result.nickname || "-"} | 评论用户: ${result.commentUsers.length} | 猜你喜欢: ${result.guessVideos ? result.guessVideos.length : 0}`,
199
- );
200
- }
201
-
202
- if (i < maxVideos - 1) {
203
- await page.evaluate(() => {
204
- const container = document.querySelector(
205
- '[class*="ColumnListContainer"]',
206
- );
207
- if (container) container.scrollTop += 700;
208
- });
209
- await delay(2000, config.switchMax);
210
- }
211
- }
212
-
213
- log(
214
- `\n结果: 视频作者 ${videoAuthors.size} | 评论用户 ${commentUsers.size} | 总评论 ${allCommentAuthorsList.length} | 猜你喜欢作者 ${allGuessAuthors.size} | 总猜中视频 ${allGuessVideos.length}`,
215
- );
216
-
217
- const videoDetails = {};
218
- for (const r of allResults) {
219
- const key = r.videoAuthor;
220
- if (!videoDetails[key]) {
221
- videoDetails[key] = {
222
- videoAuthor: r.videoAuthor,
223
- uniqueId: r.uniqueId,
224
- nickname: r.nickname,
225
- locationCreated: r.locationCreated,
226
- };
227
- }
228
- }
229
-
230
- const output = {
231
- videoDetails: Object.values(videoDetails),
232
- commentUsers: [...commentUsers].sort(),
233
- allCommentAuthorsList,
234
- guessVideos: allGuessVideos,
235
- guessAuthors: [...allGuessAuthors].sort(),
236
- stats: {
237
- totalVideos: allResults.length,
238
- uniqueVideoAuthors: videoAuthors.size,
239
- uniqueCommentAuthors: commentUsers.size,
240
- uniqueGuessAuthors: allGuessAuthors.size,
241
- totalGuessVideos: allGuessVideos.length,
242
- },
243
- };
244
-
245
- return {
246
- output,
247
- browser,
248
- isExternal,
249
- captchaDetected: anyCaptchaDetected,
250
- captchaStage: anyCaptchaStage,
251
- captchaMessage: anyCaptchaMessage,
252
- };
253
- }
254
-
255
- export { scrapeSingleVideo, runScrape };
1
+ import {
2
+ closeCommentPanel,
3
+ delay,
4
+ ensureBrowserReady,
5
+ ensureTikTokPage,
6
+ setDelayConfig,
7
+ getDelayConfig,
8
+ retryWithBackoff,
9
+ assertPageUrl,
10
+ } from "./modules/page-helpers.js";
11
+ import { extractCommentAuthors } from "./modules/comment-extractor.js";
12
+ import { extractGuessVideos } from "./modules/guess-extractor.js";
13
+ import {
14
+ DEFAULT_TARGET_LOCATIONS_CSV,
15
+ isLocationInList,
16
+ normalizeLocationList,
17
+ } from "../lib/target-locations.js";
18
+
19
+ async function scrapeSingleVideo(
20
+ page,
21
+ maxComments,
22
+ maxGuess,
23
+ log,
24
+ location = DEFAULT_TARGET_LOCATIONS_CSV,
25
+ ) {
26
+ const config = getDelayConfig();
27
+
28
+ await page
29
+ .waitForSelector('[class*="VideoMeta"]', { timeout: 10000 })
30
+ .catch(() => {});
31
+ await delay(Math.round(config.commentMax * 0.3), config.commentMax);
32
+
33
+ const userData = await page.evaluate(() => {
34
+ const result = {};
35
+ const m = window.location.href.match(/\/@([^/]+)\/video/);
36
+ if (m) result.uniqueId = m[1];
37
+ const authorEls = document.querySelectorAll('[class*="Author"]');
38
+ for (const el of authorEls) {
39
+ const text = (el.textContent || "").trim();
40
+ if (text && !text.includes("TikTok") && !text.includes("Share")) {
41
+ result.nickname = text;
42
+ break;
43
+ }
44
+ }
45
+ const html = document.documentElement.outerHTML;
46
+ const locMatch = html.match(/"locationCreated":"([^"]*)/);
47
+ if (locMatch) result.locationCreated = locMatch[1];
48
+ return result;
49
+ });
50
+
51
+ const videoAuthor = userData.uniqueId ? "@" + userData.uniqueId : null;
52
+ if (!videoAuthor) throw new Error("无法获取视频作者");
53
+
54
+ let guessVideos = [];
55
+ let commentUsers = [];
56
+ let captchaDetected = false;
57
+ let captchaStage = "";
58
+ let captchaMessage = "";
59
+
60
+ const locationList = normalizeLocationList(location);
61
+ if (isLocationInList(userData.locationCreated, locationList)) {
62
+ if (maxGuess > 0) {
63
+ guessVideos = await extractGuessVideos(page, maxGuess);
64
+ }
65
+ if (maxComments > 0) {
66
+ const commentResult = await extractCommentAuthors(page, maxComments);
67
+ commentUsers = commentResult.authors || [];
68
+ if (commentResult.captchaDetected) {
69
+ captchaDetected = true;
70
+ captchaStage = "comment";
71
+ captchaMessage = "评论阶段出现验证码";
72
+ }
73
+ }
74
+ await closeCommentPanel(page);
75
+ if (maxGuess > 0 || maxComments > 0) {
76
+ await delay(Math.round(config.commentMax * 0.3), config.commentMax);
77
+ }
78
+ }
79
+
80
+ return {
81
+ videoAuthor,
82
+ uniqueId: userData.uniqueId,
83
+ nickname: userData.nickname,
84
+ locationCreated: userData.locationCreated,
85
+ commentUsers: [...new Set(commentUsers)],
86
+ guessVideos,
87
+ captchaDetected,
88
+ captchaStage,
89
+ captchaMessage,
90
+ };
91
+ }
92
+
93
+ async function runScrape(options) {
94
+ const {
95
+ videoUrl,
96
+ maxVideos = 20,
97
+ maxComments = 999,
98
+ maxGuess = 10,
99
+ preset = null,
100
+ switchMax = null,
101
+ commentMax = null,
102
+ log = console.error,
103
+ browser: externalBrowser = null,
104
+ page: externalPage = null,
105
+ } = options;
106
+
107
+ if (preset) {
108
+ setDelayConfig(preset);
109
+ } else if (switchMax || commentMax) {
110
+ setDelayConfig({
111
+ switchMax: switchMax || 5000,
112
+ commentMax: commentMax || 3000,
113
+ });
114
+ }
115
+
116
+ const config = getDelayConfig();
117
+ let browser, page;
118
+ const isExternal = !!(externalBrowser && externalPage);
119
+
120
+ if (!isExternal) {
121
+ log(`视频地址: ${videoUrl}`);
122
+ log(
123
+ `视频数: ${maxVideos}, 评论数: ${maxComments}, 猜你喜欢: ${maxGuess}, 切换延迟: ${config.switchMax}ms, 评论延迟: ${config.commentMax}ms`,
124
+ );
125
+ }
126
+
127
+ if (isExternal) {
128
+ browser = externalBrowser;
129
+ page = externalPage;
130
+ } else {
131
+ browser = await ensureBrowserReady();
132
+ try {
133
+ page = await ensureTikTokPage(browser, videoUrl);
134
+ } catch (e) {
135
+ await browser.close().catch(() => {});
136
+ throw e;
137
+ }
138
+ }
139
+
140
+ await retryWithBackoff(
141
+ () => page.goto(videoUrl, { waitUntil: "load", timeout: 30000 }),
142
+ { log },
143
+ );
144
+ assertPageUrl(page, videoUrl.split("/video/")[0]);
145
+ await delay(Math.round(config.switchMax * 0.5), config.switchMax);
146
+ await closeCommentPanel(page);
147
+ await delay(Math.round(config.commentMax * 0.5), config.commentMax);
148
+
149
+ const allResults = [];
150
+ let anyCaptchaDetected = false;
151
+ let anyCaptchaStage = "";
152
+ let anyCaptchaMessage = "";
153
+ const videoAuthors = new Set();
154
+ const commentUsers = new Set();
155
+ const allCommentAuthorsList = [];
156
+ const allGuessAuthors = new Set();
157
+ const allGuessVideos = [];
158
+
159
+ for (let i = 0; i < maxVideos; i++) {
160
+ await delay(Math.round(config.commentMax * 0.3), config.commentMax);
161
+
162
+ let result;
163
+ try {
164
+ result = await scrapeSingleVideo(page, maxComments, maxGuess, log);
165
+ } catch (e) {
166
+ log(`[${i + 1}/${maxVideos}] 跳过: ${e.message}`);
167
+ if (i < maxVideos - 1) {
168
+ await page.evaluate(() => {
169
+ const container = document.querySelector(
170
+ '[class*="ColumnListContainer"]',
171
+ );
172
+ if (container) container.scrollTop += 700;
173
+ else window.scrollBy(0, 700);
174
+ });
175
+ await delay(Math.round(config.switchMax * 0.5), config.switchMax);
176
+ }
177
+ continue;
178
+ }
179
+
180
+ allResults.push(result);
181
+ if (result.captchaDetected) {
182
+ anyCaptchaDetected = true;
183
+ anyCaptchaStage = result.captchaStage || "";
184
+ anyCaptchaMessage = result.captchaMessage || "";
185
+ }
186
+ videoAuthors.add(result.videoAuthor);
187
+ result.commentUsers.forEach((u) => commentUsers.add(u));
188
+ allCommentAuthorsList.push(...result.commentUsers);
189
+ if (result.guessVideos) {
190
+ allGuessVideos.push(...result.guessVideos);
191
+ result.guessVideos.forEach((v) => {
192
+ if (v.author) allGuessAuthors.add(v.author);
193
+ });
194
+ }
195
+
196
+ if ((i + 1) % 5 === 0 || i === 0) {
197
+ log(
198
+ `[${i + 1}/${maxVideos}] ${result.videoAuthor} | 昵称: ${result.nickname || "-"} | 评论用户: ${result.commentUsers.length} | 猜你喜欢: ${result.guessVideos ? result.guessVideos.length : 0}`,
199
+ );
200
+ }
201
+
202
+ if (i < maxVideos - 1) {
203
+ await page.evaluate(() => {
204
+ const container = document.querySelector(
205
+ '[class*="ColumnListContainer"]',
206
+ );
207
+ if (container) container.scrollTop += 700;
208
+ });
209
+ await delay(2000, config.switchMax);
210
+ }
211
+ }
212
+
213
+ log(
214
+ `\n结果: 视频作者 ${videoAuthors.size} | 评论用户 ${commentUsers.size} | 总评论 ${allCommentAuthorsList.length} | 猜你喜欢作者 ${allGuessAuthors.size} | 总猜中视频 ${allGuessVideos.length}`,
215
+ );
216
+
217
+ const videoDetails = {};
218
+ for (const r of allResults) {
219
+ const key = r.videoAuthor;
220
+ if (!videoDetails[key]) {
221
+ videoDetails[key] = {
222
+ videoAuthor: r.videoAuthor,
223
+ uniqueId: r.uniqueId,
224
+ nickname: r.nickname,
225
+ locationCreated: r.locationCreated,
226
+ };
227
+ }
228
+ }
229
+
230
+ const output = {
231
+ videoDetails: Object.values(videoDetails),
232
+ commentUsers: [...commentUsers].sort(),
233
+ allCommentAuthorsList,
234
+ guessVideos: allGuessVideos,
235
+ guessAuthors: [...allGuessAuthors].sort(),
236
+ stats: {
237
+ totalVideos: allResults.length,
238
+ uniqueVideoAuthors: videoAuthors.size,
239
+ uniqueCommentAuthors: commentUsers.size,
240
+ uniqueGuessAuthors: allGuessAuthors.size,
241
+ totalGuessVideos: allGuessVideos.length,
242
+ },
243
+ };
244
+
245
+ return {
246
+ output,
247
+ browser,
248
+ isExternal,
249
+ captchaDetected: anyCaptchaDetected,
250
+ captchaStage: anyCaptchaStage,
251
+ captchaMessage: anyCaptchaMessage,
252
+ };
253
+ }
254
+
255
+ export { scrapeSingleVideo, runScrape };