tt-help-cli-ycl 1.3.11 → 1.3.13

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 (61) hide show
  1. package/README.md +17 -17
  2. package/cli.js +9 -9
  3. package/package.json +45 -46
  4. package/{bat → scripts}/run-explore.bat +68 -68
  5. package/{bat → scripts}/run-explore.ps1 +81 -81
  6. package/{bat → scripts}/run-explore.sh +73 -73
  7. package/scripts/test-captcha-lib.mjs +68 -0
  8. package/scripts/test-captcha.mjs +81 -0
  9. package/scripts/test-incognito-lib.mjs +36 -0
  10. package/scripts/test-login-state.mjs +128 -0
  11. package/scripts/test-safe-click.mjs +45 -0
  12. package/src/cli/auto.js +186 -157
  13. package/src/cli/config.js +116 -0
  14. package/src/cli/explore-default.js +83 -0
  15. package/src/cli/explore.js +227 -181
  16. package/src/cli/progress.js +111 -111
  17. package/src/cli/refresh.js +216 -0
  18. package/src/cli/scrape.js +47 -47
  19. package/src/cli/utils.js +18 -18
  20. package/src/cli/videos.js +41 -41
  21. package/src/cli/watch.js +31 -31
  22. package/src/lib/args.js +456 -391
  23. package/src/lib/browser/anti-detect.js +23 -23
  24. package/src/lib/browser/cdp.js +194 -142
  25. package/src/lib/browser/launch.js +43 -43
  26. package/src/lib/browser/page.js +146 -87
  27. package/src/lib/constants.js +119 -119
  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/{scraper/modules/page-error-detector.mjs → lib/page-error-detector.js} +70 -70
  35. package/src/lib/parser.js +47 -47
  36. package/src/lib/retry.js +45 -45
  37. package/src/lib/scrape.js +40 -40
  38. package/src/{scraper/modules/scroll-collector.mjs → lib/scroll-collector.js} +231 -189
  39. package/src/lib/url.js +52 -52
  40. package/src/main.js +48 -0
  41. package/src/results/user-videos-bar.lar.lar.moeta.json +37 -0
  42. package/src/scraper/{auto-core.mjs → auto-core.js} +203 -194
  43. package/src/scraper/{core.mjs → core.js} +211 -190
  44. package/src/scraper/{explore-core.mjs → explore-core.js} +180 -171
  45. package/src/scraper/modules/{captcha-handler.mjs → captcha-handler.js} +114 -114
  46. package/src/scraper/modules/{comment-extractor.mjs → comment-extractor.js} +74 -69
  47. package/src/scraper/modules/{follow-extractor.mjs → follow-extractor.js} +121 -121
  48. package/src/scraper/modules/{guess-extractor.mjs → guess-extractor.js} +51 -51
  49. package/src/scraper/modules/page-error-detector.js +1 -0
  50. package/src/scraper/modules/{page-helpers.mjs → page-helpers.js} +48 -48
  51. package/src/scraper/modules/scroll-collector.js +8 -0
  52. package/src/scraper/refresh-core.js +179 -0
  53. package/src/videos/{core.mjs → core.js} +126 -126
  54. package/src/watch/data-store.js +431 -0
  55. package/src/watch/public/index.html +721 -690
  56. package/src/watch/{server.mjs → server.js} +484 -349
  57. package/src/main.mjs +0 -234
  58. package/src/test-auto-follow.cjs +0 -109
  59. package/src/test-extractors.cjs +0 -75
  60. package/src/test-follow.cjs +0 -41
  61. package/src/watch/data-store.mjs +0 -274
@@ -1,190 +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.mjs';
11
- import { extractCommentAuthors } from './modules/comment-extractor.mjs';
12
- import { extractGuessVideos } from './modules/guess-extractor.mjs';
13
-
14
- async function scrapeSingleVideo(page, maxComments, maxGuess, log, location = 'ES') {
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
-
44
- if (userData.locationCreated === location) {
45
- if (maxGuess > 0) {
46
- guessVideos = await extractGuessVideos(page, maxGuess);
47
- }
48
- if (maxComments > 0) {
49
- commentUsers = await extractCommentAuthors(page, maxComments);
50
- }
51
- await closeCommentPanel(page);
52
- if (maxGuess > 0 || maxComments > 0) {
53
- await delay(Math.round(config.commentMax * 0.3), config.commentMax);
54
- }
55
- }
56
-
57
- return {
58
- videoAuthor,
59
- uniqueId: userData.uniqueId,
60
- nickname: userData.nickname,
61
- locationCreated: userData.locationCreated,
62
- commentUsers: [...new Set(commentUsers)],
63
- guessVideos,
64
- };
65
- }
66
-
67
- async function runScrape(options) {
68
- const {
69
- videoUrl, maxVideos = 20, maxComments = 999, maxGuess = 10,
70
- preset = null, switchMax = null, commentMax = null,
71
- log = console.error,
72
- browser: externalBrowser = null, page: externalPage = null,
73
- } = options;
74
-
75
- if (preset) {
76
- setDelayConfig(preset);
77
- } else if (switchMax || commentMax) {
78
- setDelayConfig({ switchMax: switchMax || 5000, commentMax: commentMax || 3000 });
79
- }
80
-
81
- const config = getDelayConfig();
82
- let browser, page;
83
- const isExternal = !!(externalBrowser && externalPage);
84
-
85
- if (!isExternal) {
86
- log(`视频地址: ${videoUrl}`);
87
- log(`视频数: ${maxVideos}, 评论数: ${maxComments}, 猜你喜欢: ${maxGuess}, 切换延迟: ${config.switchMax}ms, 评论延迟: ${config.commentMax}ms`);
88
- }
89
-
90
- if (isExternal) {
91
- browser = externalBrowser;
92
- page = externalPage;
93
- } else {
94
- browser = await ensureBrowserReady();
95
- try {
96
- page = await ensureTikTokPage(browser, videoUrl);
97
- } catch (e) {
98
- await browser.close().catch(() => {});
99
- throw e;
100
- }
101
- }
102
-
103
- await retryWithBackoff(() => page.goto(videoUrl, { waitUntil: 'load', timeout: 30000 }), { log });
104
- assertPageUrl(page, videoUrl.split('/video/')[0]);
105
- await delay(Math.round(config.switchMax * 0.5), config.switchMax);
106
- await closeCommentPanel(page);
107
- await delay(Math.round(config.commentMax * 0.5), config.commentMax);
108
-
109
- const allResults = [];
110
- const videoAuthors = new Set();
111
- const commentUsers = new Set();
112
- const allCommentAuthorsList = [];
113
- const allGuessAuthors = new Set();
114
- const allGuessVideos = [];
115
-
116
- for (let i = 0; i < maxVideos; i++) {
117
- await delay(Math.round(config.commentMax * 0.3), config.commentMax);
118
-
119
- let result;
120
- try {
121
- result = await scrapeSingleVideo(page, maxComments, maxGuess, log);
122
- } catch (e) {
123
- log(`[${i + 1}/${maxVideos}] 跳过: ${e.message}`);
124
- if (i < maxVideos - 1) {
125
- await page.evaluate(() => {
126
- const container = document.querySelector('[class*="ColumnListContainer"]');
127
- if (container) container.scrollTop += 700;
128
- else window.scrollBy(0, 700);
129
- });
130
- await delay(Math.round(config.switchMax * 0.5), config.switchMax);
131
- }
132
- continue;
133
- }
134
-
135
- allResults.push(result);
136
- videoAuthors.add(result.videoAuthor);
137
- result.commentUsers.forEach(u => commentUsers.add(u));
138
- allCommentAuthorsList.push(...result.commentUsers);
139
- if (result.guessVideos) {
140
- allGuessVideos.push(...result.guessVideos);
141
- result.guessVideos.forEach(v => { if (v.author) allGuessAuthors.add(v.author); });
142
- }
143
-
144
- if ((i + 1) % 5 === 0 || i === 0) {
145
- log(`[${i + 1}/${maxVideos}] ${result.videoAuthor} | 昵称: ${result.nickname || '-'} | 评论用户: ${result.commentUsers.length} | 猜你喜欢: ${result.guessVideos ? result.guessVideos.length : 0}`);
146
- }
147
-
148
- if (i < maxVideos - 1) {
149
- await page.evaluate(() => {
150
- const container = document.querySelector('[class*="ColumnListContainer"]');
151
- if (container) container.scrollTop += 700;
152
- });
153
- await delay(2000, config.switchMax);
154
- }
155
- }
156
-
157
- log(`\n结果: 视频作者 ${videoAuthors.size} | 评论用户 ${commentUsers.size} | 总评论 ${allCommentAuthorsList.length} | 猜你喜欢作者 ${allGuessAuthors.size} | 总猜中视频 ${allGuessVideos.length}`);
158
-
159
- const videoDetails = {};
160
- for (const r of allResults) {
161
- const key = r.videoAuthor;
162
- if (!videoDetails[key]) {
163
- videoDetails[key] = {
164
- videoAuthor: r.videoAuthor,
165
- uniqueId: r.uniqueId,
166
- nickname: r.nickname,
167
- locationCreated: r.locationCreated,
168
- };
169
- }
170
- }
171
-
172
- const output = {
173
- videoDetails: Object.values(videoDetails),
174
- commentUsers: [...commentUsers].sort(),
175
- allCommentAuthorsList,
176
- guessVideos: allGuessVideos,
177
- guessAuthors: [...allGuessAuthors].sort(),
178
- stats: {
179
- totalVideos: allResults.length,
180
- uniqueVideoAuthors: videoAuthors.size,
181
- uniqueCommentAuthors: commentUsers.size,
182
- uniqueGuessAuthors: allGuessAuthors.size,
183
- totalGuessVideos: allGuessVideos.length,
184
- },
185
- };
186
-
187
- return { output, browser, isExternal };
188
- }
189
-
190
- 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 };