tt-help-cli-ycl 1.3.12 → 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 (50) hide show
  1. package/README.md +17 -17
  2. package/cli.js +9 -9
  3. package/package.json +45 -45
  4. package/scripts/run-explore.bat +68 -68
  5. package/scripts/run-explore.ps1 +81 -81
  6. package/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/explore.js +227 -193
  14. package/src/cli/progress.js +111 -111
  15. package/src/cli/refresh.js +216 -0
  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/args.js +456 -402
  21. package/src/lib/browser/anti-detect.js +23 -23
  22. package/src/lib/browser/cdp.js +52 -10
  23. package/src/lib/browser/launch.js +43 -43
  24. package/src/lib/browser/page.js +146 -87
  25. package/src/lib/constants.js +119 -115
  26. package/src/lib/delay.js +54 -54
  27. package/src/lib/explore-fetch.js +118 -118
  28. package/src/lib/fetcher.js +45 -45
  29. package/src/lib/filter.js +66 -66
  30. package/src/lib/io.js +54 -54
  31. package/src/lib/output.js +80 -80
  32. package/src/lib/parser.js +47 -47
  33. package/src/lib/retry.js +45 -45
  34. package/src/lib/scrape.js +40 -40
  35. package/src/lib/url.js +52 -52
  36. package/src/main.js +2 -0
  37. package/src/results/user-videos-bar.lar.lar.moeta.json +37 -0
  38. package/src/scraper/auto-core.js +203 -194
  39. package/src/scraper/core.js +211 -190
  40. package/src/scraper/explore-core.js +180 -171
  41. package/src/scraper/modules/captcha-handler.js +114 -114
  42. package/src/scraper/modules/comment-extractor.js +74 -69
  43. package/src/scraper/modules/follow-extractor.js +121 -121
  44. package/src/scraper/modules/guess-extractor.js +51 -51
  45. package/src/scraper/modules/page-helpers.js +48 -48
  46. package/src/scraper/refresh-core.js +179 -0
  47. package/src/videos/core.js +126 -126
  48. package/src/watch/data-store.js +431 -302
  49. package/src/watch/public/index.html +721 -701
  50. package/src/watch/server.js +483 -359
@@ -1,194 +1,203 @@
1
- import {
2
- delay,
3
- ensureBrowserReady,
4
- ensureTikTokPage,
5
- setDelayConfig,
6
- getDelayConfig,
7
- closeCommentPanel,
8
- retryWithBackoff,
9
- detectPageError,
10
- isLoggedIn,
11
- assertPageUrl,
12
- } from './modules/page-helpers.js';
13
- import { detectCaptcha } from './modules/captcha-handler.js';
14
- export { ensureBrowserReady };
15
- import {
16
- getUserInfo,
17
- collectVideos,
18
- } from '../videos/core.js';
19
- import { runScrape } from './core.js';
20
- import { extractFollowAndFollowers } from './modules/follow-extractor.js';
21
-
22
- function mergeUserInfo(existing, incoming, source) {
23
- const merged = { ...existing };
24
- for (const [key, value] of Object.entries(incoming)) {
25
- if (key === '_sources') continue;
26
- if (value === undefined || value === null || value === '') continue;
27
- if (typeof value === 'number' && typeof merged[key] === 'number') {
28
- merged[key] = Math.max(merged[key], value);
29
- } else if (merged[key] === undefined || merged[key] === null || merged[key] === '') {
30
- merged[key] = value;
31
- }
32
- }
33
- if (source) {
34
- if (!merged._sources) merged._sources = [];
35
- if (!merged._sources.includes(source)) merged._sources.push(source);
36
- }
37
- return merged;
38
- }
39
-
40
- async function processUser(page, username, options, log) {
41
- const {
42
- collectMax = 1,
43
- scrapeDepth = 50,
44
- maxComments = 200,
45
- maxGuess = 10,
46
- preset = 'fast',
47
- switchMax = null,
48
- commentMax = null,
49
- enableFollow = false,
50
- maxFollowing = 200,
51
- maxFollowers = 200,
52
- browser = null,
53
- } = options;
54
-
55
- const result = {
56
- userInfo: null,
57
- collectedVideos: [],
58
- discoveredVideoAuthors: [],
59
- discoveredCommentAuthors: [],
60
- discoveredGuessAuthors: [],
61
- discoveredFollowing: [],
62
- discoveredFollowers: [],
63
- error: null,
64
- };
65
-
66
- try {
67
- log(`\n[processUser] 访问 @${username}...`);
68
- await retryWithBackoff(async () => {
69
- await page.goto(`https://www.tiktok.com/@${username}`, {
70
- waitUntil: 'load', timeout: 30000,
71
- });
72
- assertPageUrl(page, `@${username}`);
73
- }, { log });
74
- await page.waitForSelector('[class*="DivVideoList"]', { timeout: 10000 }).catch(() => {});
75
- await delay(1000, 2000);
76
-
77
- const info = await getUserInfo(page);
78
- result.userInfo = info;
79
- if (!info.uniqueId) info.uniqueId = username;
80
- log(` 昵称: ${info.nickname || '-'} | 粉丝: ${info.followerCount || 0}`);
81
-
82
- if (options.enableFollow) {
83
- const loggedIn = await isLoggedIn(page);
84
- if (!loggedIn) {
85
- log(' [跳过] 提取关注/粉丝:未登录,请先登录 TikTok');
86
- result.discoveredFollowing = [];
87
- result.discoveredFollowers = [];
88
- } else {
89
- try {
90
- log(' 提取关注/粉丝列表...');
91
- const { following, followers } = await extractFollowAndFollowers(page, {
92
- maxFollowing: options.maxFollowing || 200,
93
- maxFollowers: options.maxFollowers || 200,
94
- log,
95
- });
96
- result.discoveredFollowing = following;
97
- result.discoveredFollowers = followers;
98
- log(` 关注: ${following.length} | 粉丝: ${followers.length}`);
99
- } catch (e) {
100
- log(` 关注/粉丝提取失败: ${e.message}`);
101
- result.discoveredFollowing = [];
102
- result.discoveredFollowers = [];
103
- }
104
- }
105
- }
106
-
107
- const captcha = await detectCaptcha(page);
108
- if (captcha && captcha.visible) {
109
- log(`[验证码] @${username} 页面出现验证码`);
110
- result.captchaDetected = true;
111
- }
112
-
113
- const videos = await collectVideos(page, username, collectMax, log);
114
- const videoList = Array.from(videos.values()).slice(0, collectMax);
115
- result.collectedVideos = videoList.map(v => ({
116
- videoId: v.id,
117
- videoUrl: v.href,
118
- }));
119
-
120
- if (videoList.length > 0) {
121
- const allVideoAuthors = new Map();
122
- const allCommentAuthors = new Set();
123
- const allGuessAuthors = new Set();
124
-
125
- for (let i = 0; i < videoList.length; i++) {
126
- const video = videoList[i];
127
- const videoUrl = video.href.startsWith('http')
128
- ? video.href
129
- : `https://www.tiktok.com${video.href}`;
130
- log(` [${i + 1}/${videoList.length}] 开始 scrape: ${videoUrl} (深度 ${scrapeDepth})`);
131
-
132
- const scrapeResult = await runScrape({
133
- videoUrl,
134
- maxVideos: scrapeDepth,
135
- maxComments,
136
- maxGuess,
137
- preset,
138
- switchMax,
139
- commentMax,
140
- browser,
141
- page,
142
- log,
143
- });
144
-
145
- const scrapeOutput = scrapeResult.output;
146
-
147
- if (scrapeOutput && scrapeOutput.videoDetails) {
148
- for (const vd of scrapeOutput.videoDetails) {
149
- if (!allVideoAuthors.has(vd.uniqueId)) {
150
- allVideoAuthors.set(vd.uniqueId, {
151
- uniqueId: vd.uniqueId,
152
- nickname: vd.nickname,
153
- locationCreated: vd.locationCreated,
154
- });
155
- }
156
- }
157
- }
158
-
159
- if (scrapeOutput && scrapeOutput.commentUsers) {
160
- for (const cu of scrapeOutput.commentUsers) {
161
- allCommentAuthors.add(cu);
162
- }
163
- }
164
-
165
- if (scrapeOutput && scrapeOutput.guessAuthors) {
166
- for (const ga of scrapeOutput.guessAuthors) {
167
- allGuessAuthors.add(ga);
168
- }
169
- }
170
- }
171
-
172
- result.discoveredVideoAuthors = [...allVideoAuthors.values()];
173
- result.discoveredCommentAuthors = [...allCommentAuthors];
174
- result.discoveredGuessAuthors = [...allGuessAuthors];
175
-
176
- log(` 发现: ${result.discoveredVideoAuthors.length} 个视频作者, ${result.discoveredCommentAuthors.length} 个评论作者, ${result.discoveredGuessAuthors.length} 个猜你喜欢作者`);
177
- } else {
178
- const pageError = await detectPageError(page);
179
- result.restricted = !!pageError;
180
- if (pageError) {
181
- log(` @${username} 页面受限(${pageError}),标记跳过`);
182
- } else {
183
- log(` @${username} 没有视频,跳过 scrape`);
184
- }
185
- }
186
- } catch (e) {
187
- result.error = e.message;
188
- log(` [错误] ${e.message}`);
189
- }
190
-
191
- return result;
192
- }
193
-
194
- export { processUser, mergeUserInfo };
1
+ import {
2
+ delay,
3
+ ensureBrowserReady,
4
+ ensureTikTokPage,
5
+ setDelayConfig,
6
+ getDelayConfig,
7
+ closeCommentPanel,
8
+ retryWithBackoff,
9
+ detectPageError,
10
+ isLoggedIn,
11
+ assertPageUrl,
12
+ } from './modules/page-helpers.js';
13
+ import { detectCaptcha } from './modules/captcha-handler.js';
14
+ export { ensureBrowserReady };
15
+ import {
16
+ getUserInfo,
17
+ collectVideos,
18
+ } from '../videos/core.js';
19
+ import { runScrape } from './core.js';
20
+ import { extractFollowAndFollowers } from './modules/follow-extractor.js';
21
+
22
+ function mergeUserInfo(existing, incoming, source) {
23
+ const merged = { ...existing };
24
+ for (const [key, value] of Object.entries(incoming)) {
25
+ if (key === '_sources') continue;
26
+ if (value === undefined || value === null || value === '') continue;
27
+ if (typeof value === 'number' && typeof merged[key] === 'number') {
28
+ merged[key] = Math.max(merged[key], value);
29
+ } else if (merged[key] === undefined || merged[key] === null || merged[key] === '') {
30
+ merged[key] = value;
31
+ }
32
+ }
33
+ if (source) {
34
+ if (!merged._sources) merged._sources = [];
35
+ if (!merged._sources.includes(source)) merged._sources.push(source);
36
+ }
37
+ return merged;
38
+ }
39
+
40
+ async function processUser(page, username, options, log) {
41
+ const {
42
+ collectMax = 1,
43
+ scrapeDepth = 50,
44
+ maxComments = 200,
45
+ maxGuess = 10,
46
+ preset = 'fast',
47
+ switchMax = null,
48
+ commentMax = null,
49
+ enableFollow = false,
50
+ maxFollowing = 200,
51
+ maxFollowers = 200,
52
+ browser = null,
53
+ } = options;
54
+
55
+ const result = {
56
+ userInfo: null,
57
+ collectedVideos: [],
58
+ discoveredVideoAuthors: [],
59
+ discoveredCommentAuthors: [],
60
+ discoveredGuessAuthors: [],
61
+ discoveredFollowing: [],
62
+ discoveredFollowers: [],
63
+ error: null,
64
+ };
65
+
66
+ try {
67
+ log(`\n[processUser] 访问 @${username}...`);
68
+ await retryWithBackoff(async () => {
69
+ await page.goto(`https://www.tiktok.com/@${username}`, {
70
+ waitUntil: 'load', timeout: 30000,
71
+ });
72
+ assertPageUrl(page, `@${username}`);
73
+ }, { log });
74
+ await page.waitForSelector('[class*="DivVideoList"]', { timeout: 10000 }).catch(() => {});
75
+ await delay(1000, 2000);
76
+
77
+ const info = await getUserInfo(page);
78
+ result.userInfo = info;
79
+ if (!info.uniqueId) info.uniqueId = username;
80
+ log(` 昵称: ${info.nickname || '-'} | 粉丝: ${info.followerCount || 0}`);
81
+
82
+ if (options.enableFollow) {
83
+ const loggedIn = await isLoggedIn(page);
84
+ if (!loggedIn) {
85
+ log(' [跳过] 提取关注/粉丝:未登录,请先登录 TikTok');
86
+ result.discoveredFollowing = [];
87
+ result.discoveredFollowers = [];
88
+ } else {
89
+ try {
90
+ log(' 提取关注/粉丝列表...');
91
+ const { following, followers } = await extractFollowAndFollowers(page, {
92
+ maxFollowing: options.maxFollowing || 200,
93
+ maxFollowers: options.maxFollowers || 200,
94
+ log,
95
+ });
96
+ result.discoveredFollowing = following;
97
+ result.discoveredFollowers = followers;
98
+ log(` 关注: ${following.length} | 粉丝: ${followers.length}`);
99
+ } catch (e) {
100
+ log(` 关注/粉丝提取失败: ${e.message}`);
101
+ result.discoveredFollowing = [];
102
+ result.discoveredFollowers = [];
103
+ }
104
+ }
105
+ }
106
+
107
+ const captcha = await detectCaptcha(page);
108
+ if (captcha && captcha.visible) {
109
+ log(`[验证码] @${username} 页面出现验证码`);
110
+ result.captchaDetected = true;
111
+ result.captchaStage = result.captchaStage || 'video-page';
112
+ result.captchaMessage = result.captchaMessage || '视频页出现验证码';
113
+ }
114
+
115
+ const videos = await collectVideos(page, username, collectMax, log);
116
+ const videoList = Array.from(videos.values()).slice(0, collectMax);
117
+ result.collectedVideos = videoList.map(v => ({
118
+ videoId: v.id,
119
+ videoUrl: v.href,
120
+ }));
121
+
122
+ if (videoList.length > 0) {
123
+ const allVideoAuthors = new Map();
124
+ const allCommentAuthors = new Set();
125
+ const allGuessAuthors = new Set();
126
+
127
+ for (let i = 0; i < videoList.length; i++) {
128
+ const video = videoList[i];
129
+ const videoUrl = video.href.startsWith('http')
130
+ ? video.href
131
+ : `https://www.tiktok.com${video.href}`;
132
+ log(` [${i + 1}/${videoList.length}] 开始 scrape: ${videoUrl} (深度 ${scrapeDepth})`);
133
+
134
+ const scrapeResult = await runScrape({
135
+ videoUrl,
136
+ maxVideos: scrapeDepth,
137
+ maxComments,
138
+ maxGuess,
139
+ preset,
140
+ switchMax,
141
+ commentMax,
142
+ browser,
143
+ page,
144
+ log,
145
+ });
146
+
147
+ if (scrapeResult.captchaDetected) {
148
+ result.captchaDetected = true;
149
+ result.captchaStage = scrapeResult.captchaStage || 'scrape';
150
+ result.captchaMessage = scrapeResult.captchaMessage || 'scrape阶段出现验证码';
151
+ }
152
+
153
+ const scrapeOutput = scrapeResult.output;
154
+
155
+ if (scrapeOutput && scrapeOutput.videoDetails) {
156
+ for (const vd of scrapeOutput.videoDetails) {
157
+ if (!allVideoAuthors.has(vd.uniqueId)) {
158
+ allVideoAuthors.set(vd.uniqueId, {
159
+ uniqueId: vd.uniqueId,
160
+ nickname: vd.nickname,
161
+ locationCreated: vd.locationCreated,
162
+ });
163
+ }
164
+ }
165
+ }
166
+
167
+ if (scrapeOutput && scrapeOutput.commentUsers) {
168
+ for (const cu of scrapeOutput.commentUsers) {
169
+ allCommentAuthors.add(cu);
170
+ }
171
+ }
172
+
173
+ if (scrapeOutput && scrapeOutput.guessAuthors) {
174
+ for (const ga of scrapeOutput.guessAuthors) {
175
+ allGuessAuthors.add(ga);
176
+ }
177
+ }
178
+ }
179
+
180
+ result.discoveredVideoAuthors = [...allVideoAuthors.values()];
181
+ result.discoveredCommentAuthors = [...allCommentAuthors];
182
+ result.discoveredGuessAuthors = [...allGuessAuthors];
183
+
184
+ log(` 发现: ${result.discoveredVideoAuthors.length} 个视频作者, ${result.discoveredCommentAuthors.length} 个评论作者, ${result.discoveredGuessAuthors.length} 个猜你喜欢作者`);
185
+ } else {
186
+ const pageError = await detectPageError(page);
187
+ result.restricted = !!pageError;
188
+ if (pageError) {
189
+ log(` @${username} 页面受限(${pageError}),标记跳过`);
190
+ } else {
191
+ log(` @${username} 没有视频,跳过 scrape`);
192
+ }
193
+ }
194
+ } catch (e) {
195
+ result.error = e.message;
196
+ result.errorStack = e.stack || '';
197
+ log(` [错误] ${e.message}`);
198
+ }
199
+
200
+ return result;
201
+ }
202
+
203
+ export { processUser, mergeUserInfo };