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
@@ -1,211 +1,211 @@
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
-
14
- async function scrapeSingleVideo(page, maxComments, maxGuess, log, location = 'PL,NL,BE,DE,FR,IT,ES,IE') {
15
- const config = getDelayConfig();
16
-
17
- await page.waitForSelector('[class*="VideoMeta"]', { timeout: 10000 }).catch(() => {});
18
- await delay(Math.round(config.commentMax * 0.3), config.commentMax);
19
-
20
- const userData = await page.evaluate(() => {
21
- const result = {};
22
- const m = window.location.href.match(/\/@([^/]+)\/video/);
23
- if (m) result.uniqueId = m[1];
24
- const authorEls = document.querySelectorAll('[class*="Author"]');
25
- for (const el of authorEls) {
26
- const text = (el.textContent || '').trim();
27
- if (text && !text.includes('TikTok') && !text.includes('Share')) {
28
- result.nickname = text;
29
- break;
30
- }
31
- }
32
- const html = document.documentElement.outerHTML;
33
- const locMatch = html.match(/"locationCreated":"([^"]*)/);
34
- if (locMatch) result.locationCreated = locMatch[1];
35
- return result;
36
- });
37
-
38
- const videoAuthor = userData.uniqueId ? '@' + userData.uniqueId : null;
39
- if (!videoAuthor) throw new Error('无法获取视频作者');
40
-
41
- let guessVideos = [];
42
- let commentUsers = [];
43
- let captchaDetected = false;
44
- let captchaStage = '';
45
- let captchaMessage = '';
46
-
47
- const locationList = (location || 'ES').split(',').map(s => s.trim().toUpperCase());
48
- if (locationList.includes(userData.locationCreated?.toUpperCase?.() || userData.locationCreated)) {
49
- if (maxGuess > 0) {
50
- guessVideos = await extractGuessVideos(page, maxGuess);
51
- }
52
- if (maxComments > 0) {
53
- const commentResult = await extractCommentAuthors(page, maxComments);
54
- commentUsers = commentResult.authors || [];
55
- if (commentResult.captchaDetected) {
56
- captchaDetected = true;
57
- captchaStage = 'comment';
58
- captchaMessage = '评论阶段出现验证码';
59
- }
60
- }
61
- await closeCommentPanel(page);
62
- if (maxGuess > 0 || maxComments > 0) {
63
- await delay(Math.round(config.commentMax * 0.3), config.commentMax);
64
- }
65
- }
66
-
67
- return {
68
- videoAuthor,
69
- uniqueId: userData.uniqueId,
70
- nickname: userData.nickname,
71
- locationCreated: userData.locationCreated,
72
- commentUsers: [...new Set(commentUsers)],
73
- guessVideos,
74
- captchaDetected,
75
- captchaStage,
76
- captchaMessage,
77
- };
78
- }
79
-
80
- async function runScrape(options) {
81
- const {
82
- videoUrl, maxVideos = 20, maxComments = 999, maxGuess = 10,
83
- preset = null, switchMax = null, commentMax = null,
84
- log = console.error,
85
- browser: externalBrowser = null, page: externalPage = null,
86
- } = options;
87
-
88
- if (preset) {
89
- setDelayConfig(preset);
90
- } else if (switchMax || commentMax) {
91
- setDelayConfig({ switchMax: switchMax || 5000, commentMax: commentMax || 3000 });
92
- }
93
-
94
- const config = getDelayConfig();
95
- let browser, page;
96
- const isExternal = !!(externalBrowser && externalPage);
97
-
98
- if (!isExternal) {
99
- log(`视频地址: ${videoUrl}`);
100
- log(`视频数: ${maxVideos}, 评论数: ${maxComments}, 猜你喜欢: ${maxGuess}, 切换延迟: ${config.switchMax}ms, 评论延迟: ${config.commentMax}ms`);
101
- }
102
-
103
- if (isExternal) {
104
- browser = externalBrowser;
105
- page = externalPage;
106
- } else {
107
- browser = await ensureBrowserReady();
108
- try {
109
- page = await ensureTikTokPage(browser, videoUrl);
110
- } catch (e) {
111
- await browser.close().catch(() => {});
112
- throw e;
113
- }
114
- }
115
-
116
- await retryWithBackoff(() => page.goto(videoUrl, { waitUntil: 'load', timeout: 30000 }), { log });
117
- assertPageUrl(page, videoUrl.split('/video/')[0]);
118
- await delay(Math.round(config.switchMax * 0.5), config.switchMax);
119
- await closeCommentPanel(page);
120
- await delay(Math.round(config.commentMax * 0.5), config.commentMax);
121
-
122
- const allResults = [];
123
- let anyCaptchaDetected = false;
124
- let anyCaptchaStage = '';
125
- let anyCaptchaMessage = '';
126
- const videoAuthors = new Set();
127
- const commentUsers = new Set();
128
- const allCommentAuthorsList = [];
129
- const allGuessAuthors = new Set();
130
- const allGuessVideos = [];
131
-
132
- for (let i = 0; i < maxVideos; i++) {
133
- await delay(Math.round(config.commentMax * 0.3), config.commentMax);
134
-
135
- let result;
136
- try {
137
- result = await scrapeSingleVideo(page, maxComments, maxGuess, log);
138
- } catch (e) {
139
- log(`[${i + 1}/${maxVideos}] 跳过: ${e.message}`);
140
- if (i < maxVideos - 1) {
141
- await page.evaluate(() => {
142
- const container = document.querySelector('[class*="ColumnListContainer"]');
143
- if (container) container.scrollTop += 700;
144
- else window.scrollBy(0, 700);
145
- });
146
- await delay(Math.round(config.switchMax * 0.5), config.switchMax);
147
- }
148
- continue;
149
- }
150
-
151
- allResults.push(result);
152
- if (result.captchaDetected) {
153
- anyCaptchaDetected = true;
154
- anyCaptchaStage = result.captchaStage || '';
155
- anyCaptchaMessage = result.captchaMessage || '';
156
- }
157
- videoAuthors.add(result.videoAuthor);
158
- result.commentUsers.forEach(u => commentUsers.add(u));
159
- allCommentAuthorsList.push(...result.commentUsers);
160
- if (result.guessVideos) {
161
- allGuessVideos.push(...result.guessVideos);
162
- result.guessVideos.forEach(v => { if (v.author) allGuessAuthors.add(v.author); });
163
- }
164
-
165
- if ((i + 1) % 5 === 0 || i === 0) {
166
- log(`[${i + 1}/${maxVideos}] ${result.videoAuthor} | 昵称: ${result.nickname || '-'} | 评论用户: ${result.commentUsers.length} | 猜你喜欢: ${result.guessVideos ? result.guessVideos.length : 0}`);
167
- }
168
-
169
- if (i < maxVideos - 1) {
170
- await page.evaluate(() => {
171
- const container = document.querySelector('[class*="ColumnListContainer"]');
172
- if (container) container.scrollTop += 700;
173
- });
174
- await delay(2000, config.switchMax);
175
- }
176
- }
177
-
178
- log(`\n结果: 视频作者 ${videoAuthors.size} | 评论用户 ${commentUsers.size} | 总评论 ${allCommentAuthorsList.length} | 猜你喜欢作者 ${allGuessAuthors.size} | 总猜中视频 ${allGuessVideos.length}`);
179
-
180
- const videoDetails = {};
181
- for (const r of allResults) {
182
- const key = r.videoAuthor;
183
- if (!videoDetails[key]) {
184
- videoDetails[key] = {
185
- videoAuthor: r.videoAuthor,
186
- uniqueId: r.uniqueId,
187
- nickname: r.nickname,
188
- locationCreated: r.locationCreated,
189
- };
190
- }
191
- }
192
-
193
- const output = {
194
- videoDetails: Object.values(videoDetails),
195
- commentUsers: [...commentUsers].sort(),
196
- allCommentAuthorsList,
197
- guessVideos: allGuessVideos,
198
- guessAuthors: [...allGuessAuthors].sort(),
199
- stats: {
200
- totalVideos: allResults.length,
201
- uniqueVideoAuthors: videoAuthors.size,
202
- uniqueCommentAuthors: commentUsers.size,
203
- uniqueGuessAuthors: allGuessAuthors.size,
204
- totalGuessVideos: allGuessVideos.length,
205
- },
206
- };
207
-
208
- return { output, browser, isExternal, captchaDetected: anyCaptchaDetected, captchaStage: anyCaptchaStage, captchaMessage: anyCaptchaMessage };
209
- }
210
-
211
- 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
+
14
+ async function scrapeSingleVideo(page, maxComments, maxGuess, log, location = 'PL,NL,BE,DE,FR,IT,ES,IE') {
15
+ const config = getDelayConfig();
16
+
17
+ await page.waitForSelector('[class*="VideoMeta"]', { timeout: 10000 }).catch(() => {});
18
+ await delay(Math.round(config.commentMax * 0.3), config.commentMax);
19
+
20
+ const userData = await page.evaluate(() => {
21
+ const result = {};
22
+ const m = window.location.href.match(/\/@([^/]+)\/video/);
23
+ if (m) result.uniqueId = m[1];
24
+ const authorEls = document.querySelectorAll('[class*="Author"]');
25
+ for (const el of authorEls) {
26
+ const text = (el.textContent || '').trim();
27
+ if (text && !text.includes('TikTok') && !text.includes('Share')) {
28
+ result.nickname = text;
29
+ break;
30
+ }
31
+ }
32
+ const html = document.documentElement.outerHTML;
33
+ const locMatch = html.match(/"locationCreated":"([^"]*)/);
34
+ if (locMatch) result.locationCreated = locMatch[1];
35
+ return result;
36
+ });
37
+
38
+ const videoAuthor = userData.uniqueId ? '@' + userData.uniqueId : null;
39
+ if (!videoAuthor) throw new Error('无法获取视频作者');
40
+
41
+ let guessVideos = [];
42
+ let commentUsers = [];
43
+ let captchaDetected = false;
44
+ let captchaStage = '';
45
+ let captchaMessage = '';
46
+
47
+ const locationList = (location || 'ES').split(',').map(s => s.trim().toUpperCase());
48
+ if (locationList.includes(userData.locationCreated?.toUpperCase?.() || userData.locationCreated)) {
49
+ if (maxGuess > 0) {
50
+ guessVideos = await extractGuessVideos(page, maxGuess);
51
+ }
52
+ if (maxComments > 0) {
53
+ const commentResult = await extractCommentAuthors(page, maxComments);
54
+ commentUsers = commentResult.authors || [];
55
+ if (commentResult.captchaDetected) {
56
+ captchaDetected = true;
57
+ captchaStage = 'comment';
58
+ captchaMessage = '评论阶段出现验证码';
59
+ }
60
+ }
61
+ await closeCommentPanel(page);
62
+ if (maxGuess > 0 || maxComments > 0) {
63
+ await delay(Math.round(config.commentMax * 0.3), config.commentMax);
64
+ }
65
+ }
66
+
67
+ return {
68
+ videoAuthor,
69
+ uniqueId: userData.uniqueId,
70
+ nickname: userData.nickname,
71
+ locationCreated: userData.locationCreated,
72
+ commentUsers: [...new Set(commentUsers)],
73
+ guessVideos,
74
+ captchaDetected,
75
+ captchaStage,
76
+ captchaMessage,
77
+ };
78
+ }
79
+
80
+ async function runScrape(options) {
81
+ const {
82
+ videoUrl, maxVideos = 20, maxComments = 999, maxGuess = 10,
83
+ preset = null, switchMax = null, commentMax = null,
84
+ log = console.error,
85
+ browser: externalBrowser = null, page: externalPage = null,
86
+ } = options;
87
+
88
+ if (preset) {
89
+ setDelayConfig(preset);
90
+ } else if (switchMax || commentMax) {
91
+ setDelayConfig({ switchMax: switchMax || 5000, commentMax: commentMax || 3000 });
92
+ }
93
+
94
+ const config = getDelayConfig();
95
+ let browser, page;
96
+ const isExternal = !!(externalBrowser && externalPage);
97
+
98
+ if (!isExternal) {
99
+ log(`视频地址: ${videoUrl}`);
100
+ log(`视频数: ${maxVideos}, 评论数: ${maxComments}, 猜你喜欢: ${maxGuess}, 切换延迟: ${config.switchMax}ms, 评论延迟: ${config.commentMax}ms`);
101
+ }
102
+
103
+ if (isExternal) {
104
+ browser = externalBrowser;
105
+ page = externalPage;
106
+ } else {
107
+ browser = await ensureBrowserReady();
108
+ try {
109
+ page = await ensureTikTokPage(browser, videoUrl);
110
+ } catch (e) {
111
+ await browser.close().catch(() => {});
112
+ throw e;
113
+ }
114
+ }
115
+
116
+ await retryWithBackoff(() => page.goto(videoUrl, { waitUntil: 'load', timeout: 30000 }), { log });
117
+ assertPageUrl(page, videoUrl.split('/video/')[0]);
118
+ await delay(Math.round(config.switchMax * 0.5), config.switchMax);
119
+ await closeCommentPanel(page);
120
+ await delay(Math.round(config.commentMax * 0.5), config.commentMax);
121
+
122
+ const allResults = [];
123
+ let anyCaptchaDetected = false;
124
+ let anyCaptchaStage = '';
125
+ let anyCaptchaMessage = '';
126
+ const videoAuthors = new Set();
127
+ const commentUsers = new Set();
128
+ const allCommentAuthorsList = [];
129
+ const allGuessAuthors = new Set();
130
+ const allGuessVideos = [];
131
+
132
+ for (let i = 0; i < maxVideos; i++) {
133
+ await delay(Math.round(config.commentMax * 0.3), config.commentMax);
134
+
135
+ let result;
136
+ try {
137
+ result = await scrapeSingleVideo(page, maxComments, maxGuess, log);
138
+ } catch (e) {
139
+ log(`[${i + 1}/${maxVideos}] 跳过: ${e.message}`);
140
+ if (i < maxVideos - 1) {
141
+ await page.evaluate(() => {
142
+ const container = document.querySelector('[class*="ColumnListContainer"]');
143
+ if (container) container.scrollTop += 700;
144
+ else window.scrollBy(0, 700);
145
+ });
146
+ await delay(Math.round(config.switchMax * 0.5), config.switchMax);
147
+ }
148
+ continue;
149
+ }
150
+
151
+ allResults.push(result);
152
+ if (result.captchaDetected) {
153
+ anyCaptchaDetected = true;
154
+ anyCaptchaStage = result.captchaStage || '';
155
+ anyCaptchaMessage = result.captchaMessage || '';
156
+ }
157
+ videoAuthors.add(result.videoAuthor);
158
+ result.commentUsers.forEach(u => commentUsers.add(u));
159
+ allCommentAuthorsList.push(...result.commentUsers);
160
+ if (result.guessVideos) {
161
+ allGuessVideos.push(...result.guessVideos);
162
+ result.guessVideos.forEach(v => { if (v.author) allGuessAuthors.add(v.author); });
163
+ }
164
+
165
+ if ((i + 1) % 5 === 0 || i === 0) {
166
+ log(`[${i + 1}/${maxVideos}] ${result.videoAuthor} | 昵称: ${result.nickname || '-'} | 评论用户: ${result.commentUsers.length} | 猜你喜欢: ${result.guessVideos ? result.guessVideos.length : 0}`);
167
+ }
168
+
169
+ if (i < maxVideos - 1) {
170
+ await page.evaluate(() => {
171
+ const container = document.querySelector('[class*="ColumnListContainer"]');
172
+ if (container) container.scrollTop += 700;
173
+ });
174
+ await delay(2000, config.switchMax);
175
+ }
176
+ }
177
+
178
+ log(`\n结果: 视频作者 ${videoAuthors.size} | 评论用户 ${commentUsers.size} | 总评论 ${allCommentAuthorsList.length} | 猜你喜欢作者 ${allGuessAuthors.size} | 总猜中视频 ${allGuessVideos.length}`);
179
+
180
+ const videoDetails = {};
181
+ for (const r of allResults) {
182
+ const key = r.videoAuthor;
183
+ if (!videoDetails[key]) {
184
+ videoDetails[key] = {
185
+ videoAuthor: r.videoAuthor,
186
+ uniqueId: r.uniqueId,
187
+ nickname: r.nickname,
188
+ locationCreated: r.locationCreated,
189
+ };
190
+ }
191
+ }
192
+
193
+ const output = {
194
+ videoDetails: Object.values(videoDetails),
195
+ commentUsers: [...commentUsers].sort(),
196
+ allCommentAuthorsList,
197
+ guessVideos: allGuessVideos,
198
+ guessAuthors: [...allGuessAuthors].sort(),
199
+ stats: {
200
+ totalVideos: allResults.length,
201
+ uniqueVideoAuthors: videoAuthors.size,
202
+ uniqueCommentAuthors: commentUsers.size,
203
+ uniqueGuessAuthors: allGuessAuthors.size,
204
+ totalGuessVideos: allGuessVideos.length,
205
+ },
206
+ };
207
+
208
+ return { output, browser, isExternal, captchaDetected: anyCaptchaDetected, captchaStage: anyCaptchaStage, captchaMessage: anyCaptchaMessage };
209
+ }
210
+
211
+ export { scrapeSingleVideo, runScrape };