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,48 +1,48 @@
1
- import {
2
- delay,
3
- getDelayConfig,
4
- setDelayConfig,
5
- listDelayPresets,
6
- DELAY_PRESETS,
7
- } from '../../lib/delay.js';
8
- import { ensureBrowserReady } from '../../lib/browser/cdp.js';
9
- import {
10
- ensureTikTokPage,
11
- closeCommentPanel,
12
- findTikTokPage,
13
- getOrCreatePage,
14
- isLoggedIn,
15
- assertPageUrl,
16
- } from '../../lib/browser/page.js';
17
- import { retryWithBackoff, isRetryableError } from '../../lib/retry.js';
18
- import {
19
- extractUserSection,
20
- parseUserSection,
21
- extractLocationCreated,
22
- USER_SECTION_SIZE,
23
- } from '../../lib/parser.js';
24
- import { detectPageError } from './page-error-detector.js';
25
-
26
- export {
27
- delay,
28
- setDelayConfig,
29
- getDelayConfig,
30
- listDelayPresets,
31
- DELAY_PRESETS,
32
- ensureBrowserReady,
33
- ensureTikTokPage,
34
- closeCommentPanel,
35
- findTikTokPage,
36
- getOrCreatePage,
37
- isLoggedIn,
38
- assertPageUrl,
39
- retryWithBackoff,
40
- isRetryableError,
41
- extractUserSection,
42
- parseUserSection,
43
- extractLocationCreated,
44
- USER_SECTION_SIZE,
45
- detectPageError,
46
- };
47
-
48
- export const CDP_PORT = 9222;
1
+ import {
2
+ delay,
3
+ getDelayConfig,
4
+ setDelayConfig,
5
+ listDelayPresets,
6
+ DELAY_PRESETS,
7
+ } from '../../lib/delay.js';
8
+ import { ensureBrowserReady } from '../../lib/browser/cdp.js';
9
+ import {
10
+ ensureTikTokPage,
11
+ closeCommentPanel,
12
+ findTikTokPage,
13
+ getOrCreatePage,
14
+ isLoggedIn,
15
+ assertPageUrl,
16
+ } from '../../lib/browser/page.js';
17
+ import { retryWithBackoff, isRetryableError } from '../../lib/retry.js';
18
+ import {
19
+ extractUserSection,
20
+ parseUserSection,
21
+ extractLocationCreated,
22
+ USER_SECTION_SIZE,
23
+ } from '../../lib/parser.js';
24
+ import { detectPageError } from './page-error-detector.js';
25
+
26
+ export {
27
+ delay,
28
+ setDelayConfig,
29
+ getDelayConfig,
30
+ listDelayPresets,
31
+ DELAY_PRESETS,
32
+ ensureBrowserReady,
33
+ ensureTikTokPage,
34
+ closeCommentPanel,
35
+ findTikTokPage,
36
+ getOrCreatePage,
37
+ isLoggedIn,
38
+ assertPageUrl,
39
+ retryWithBackoff,
40
+ isRetryableError,
41
+ extractUserSection,
42
+ parseUserSection,
43
+ extractLocationCreated,
44
+ USER_SECTION_SIZE,
45
+ detectPageError,
46
+ };
47
+
48
+ export const CDP_PORT = 9222;
@@ -1,213 +1,213 @@
1
- import {
2
- delay,
3
- retryWithBackoff,
4
- detectPageError,
5
- assertPageUrl,
6
- } from "./modules/page-helpers.js";
7
- import { detectCaptcha } from "./modules/captcha-handler.js";
8
- import { getUserInfo, collectVideos } from "../videos/core.js";
9
- import { extractFollowAndFollowers } from "./modules/follow-extractor.js";
10
- import { processExplore } from "./explore-core.js";
11
- import { DEFAULT_TARGET_LOCATIONS_CSV } from "../lib/target-locations.js";
12
-
13
- export async function processRefresh(page, username, serverUrl, options, log) {
14
- const { maxFollowing = 100, maxFollowers = 100, maxVideos = 100 } = options;
15
-
16
- const result = {
17
- userInfo: null,
18
- discoveredVideoAuthors: [],
19
- discoveredFollowing: [],
20
- discoveredFollowers: [],
21
- newUsersAdded: 0,
22
- collectedVideos: 0,
23
- error: null,
24
- };
25
-
26
- try {
27
- log(` 访问 @${username} 主页...`);
28
- const homeUrl = `https://www.tiktok.com/@${username}`;
29
- await retryWithBackoff(
30
- async () => {
31
- await page.goto(homeUrl, {
32
- waitUntil: "domcontentloaded",
33
- timeout: 30000,
34
- });
35
- assertPageUrl(page, `@${username}`);
36
- },
37
- { log },
38
- );
39
- await page
40
- .waitForSelector('[class*="DivVideoList"]', { timeout: 10000 })
41
- .catch(() => {});
42
- await delay(1000, 2000);
43
-
44
- log(" 获取用户信息...");
45
- const info = await getUserInfo(page);
46
- if (info) {
47
- result.userInfo = info;
48
- log(
49
- ` 用户: ${info.nickname || username} | 粉丝: ${info.followerCount || "-"} | 视频: ${info.videoCount || "-"}`,
50
- );
51
- }
52
-
53
- const captcha = await detectCaptcha(page);
54
- if (captcha && captcha.visible) {
55
- log(`[验证码] @${username} 页面出现验证码`);
56
- result.captchaDetected = true;
57
- result.captchaStage = result.captchaStage || "video-page";
58
- result.captchaMessage = result.captchaMessage || "视频页出现验证码";
59
- }
60
-
61
- // 采集视频
62
- log(` 采集视频 (最多 ${maxVideos} 个)...`);
63
- const videoList = await collectVideos(page, username, maxVideos, log);
64
- const videoArray = videoList ? [...videoList.values()] : [];
65
- result.collectedVideos = videoArray.length;
66
- result.discoveredVideoAuthors = videoArray.map((v) => v.author);
67
-
68
- if (videoArray.length <= 0) {
69
- result.noVideo = true;
70
- const pageError = await detectPageError(page);
71
- if (pageError) {
72
- result.restricted = true;
73
- log(` @${username} 页面受限(${pageError}),标记跳过`);
74
- }
75
- return result;
76
- }
77
-
78
- // 采集关注和粉丝
79
- log(` 采集关注 (最多 ${maxFollowing}) + 粉丝 (最多 ${maxFollowers})...`);
80
- try {
81
- const followResult = await extractFollowAndFollowers(page, {
82
- maxFollowing,
83
- maxFollowers,
84
- });
85
- result.discoveredFollowing = followResult.following || [];
86
- result.discoveredFollowers = followResult.followers || [];
87
- log(
88
- ` 关注: ${result.discoveredFollowing.length}, 粉丝: ${result.discoveredFollowers.length}`,
89
- );
90
- } catch (e) {
91
- log(` [关注/粉丝采集失败] ${e.message}`);
92
- result.discoveredFollowing = [];
93
- result.discoveredFollowers = [];
94
- }
95
-
96
- // 处理新发现的用户(关注 + 粉丝),循环执行完整 explore
97
- // follow-extractor 返回 [handle, displayName] 数组
98
- const allDiscovered = [
99
- ...result.discoveredFollowing.map((h) => ({
100
- handle: Array.isArray(h) ? h[0] : h,
101
- source: "refresh-following",
102
- })),
103
- ...result.discoveredFollowers.map((h) => ({
104
- handle: Array.isArray(h) ? h[0] : h,
105
- source: "refresh-follower",
106
- })),
107
- ];
108
-
109
- for (const { handle, source } of allDiscovered) {
110
- const uniqueId = handle.replace("@", "");
111
-
112
- // 检查用户是否已存在
113
- const existsResp = await fetch(
114
- `${serverUrl}/api/user-exists/${encodeURIComponent(uniqueId)}`,
115
- );
116
- const existsData = await existsResp.json();
117
-
118
- if (existsData.exists) {
119
- continue;
120
- }
121
-
122
- log(` [新用户] @${uniqueId} 不存在,开始探索 (来源: ${source})...`);
123
- await delay(1000, 2000);
124
-
125
- // 对新用户做完整 explore(与 explore 命令逻辑一致)
126
- const exploreResult = await processExplore(
127
- page,
128
- uniqueId,
129
- {
130
- maxComments: 10,
131
- maxGuess: 0,
132
- enableFollow: true,
133
- maxFollowing: 5,
134
- maxFollowers: 5,
135
- location: DEFAULT_TARGET_LOCATIONS_CSV,
136
- },
137
- log,
138
- );
139
-
140
- // 提交 explore 结果到服务端(和 explore 命令的 commitJob 一致)
141
- if (exploreResult.userInfo) {
142
- const guessedLocation = exploreResult.locationCreated || null;
143
-
144
- const payload = {
145
- userInfo: exploreResult.userInfo || {},
146
- discoveredVideoAuthors: (
147
- exploreResult.discoveredVideoAuthors || []
148
- ).map((item) =>
149
- typeof item === "object" ? { ...item, guessedLocation } : item,
150
- ),
151
- discoveredCommentAuthors: (
152
- exploreResult.discoveredCommentAuthors || []
153
- ).map((author) => ({ author, guessedLocation })),
154
- discoveredGuessAuthors: (
155
- exploreResult.discoveredGuessAuthors || []
156
- ).map((author) => ({ author, guessedLocation })),
157
- discoveredFollowing: (exploreResult.discoveredFollowing || []).map(
158
- (f) => ({
159
- handle: Array.isArray(f) ? f[0] : f,
160
- displayName: Array.isArray(f) ? f[1] : null,
161
- guessedLocation,
162
- }),
163
- ),
164
- discoveredFollowers: (exploreResult.discoveredFollowers || []).map(
165
- (f) => ({
166
- handle: Array.isArray(f) ? f[0] : f,
167
- displayName: Array.isArray(f) ? f[1] : null,
168
- guessedLocation,
169
- }),
170
- ),
171
- processed: exploreResult.processed,
172
- hasFollowData: exploreResult.hasFollowData,
173
- keepFollow: exploreResult.keepFollow,
174
- locationCreated: exploreResult.locationCreated,
175
- noVideo: exploreResult.noVideo,
176
- restricted: exploreResult.restricted,
177
- error: exploreResult.error,
178
- };
179
-
180
- const addResp = await fetch(
181
- `${serverUrl}/api/explore-new/${uniqueId}`,
182
- {
183
- method: "POST",
184
- headers: { "Content-Type": "application/json" },
185
- body: JSON.stringify(payload),
186
- },
187
- );
188
- const addResult = await addResp.json();
189
-
190
- if (!addResult.saved) {
191
- log(` [跳过] @${uniqueId} 提交失败`);
192
- continue;
193
- }
194
-
195
- result.newUsersAdded++;
196
- if (exploreResult.captchaDetected) {
197
- result.captchaDetected = true;
198
- }
199
- log(
200
- ` [已提交] @${uniqueId} ${addResult.created ? "(新用户)" : "(已存在)"} | 发现: ${addResult.newUsers?.length || 0} 个`,
201
- );
202
- }
203
-
204
- await delay(2000, 4000);
205
- }
206
- } catch (e) {
207
- log(` [错误] ${e.message}`);
208
- result.error = e.message;
209
- result.errorStack = e.stack || "";
210
- }
211
-
212
- return result;
213
- }
1
+ import {
2
+ delay,
3
+ retryWithBackoff,
4
+ detectPageError,
5
+ assertPageUrl,
6
+ } from "./modules/page-helpers.js";
7
+ import { detectCaptcha } from "./modules/captcha-handler.js";
8
+ import { getUserInfo, collectVideos } from "../videos/core.js";
9
+ import { extractFollowAndFollowers } from "./modules/follow-extractor.js";
10
+ import { processExplore } from "./explore-core.js";
11
+ import { DEFAULT_TARGET_LOCATIONS_CSV } from "../lib/target-locations.js";
12
+
13
+ export async function processRefresh(page, username, serverUrl, options, log) {
14
+ const { maxFollowing = 100, maxFollowers = 100, maxVideos = 100 } = options;
15
+
16
+ const result = {
17
+ userInfo: null,
18
+ discoveredVideoAuthors: [],
19
+ discoveredFollowing: [],
20
+ discoveredFollowers: [],
21
+ newUsersAdded: 0,
22
+ collectedVideos: 0,
23
+ error: null,
24
+ };
25
+
26
+ try {
27
+ log(` 访问 @${username} 主页...`);
28
+ const homeUrl = `https://www.tiktok.com/@${username}`;
29
+ await retryWithBackoff(
30
+ async () => {
31
+ await page.goto(homeUrl, {
32
+ waitUntil: "domcontentloaded",
33
+ timeout: 30000,
34
+ });
35
+ assertPageUrl(page, `@${username}`);
36
+ },
37
+ { log },
38
+ );
39
+ await page
40
+ .waitForSelector('[class*="DivVideoList"]', { timeout: 10000 })
41
+ .catch(() => {});
42
+ await delay(1000, 2000);
43
+
44
+ log(" 获取用户信息...");
45
+ const info = await getUserInfo(page);
46
+ if (info) {
47
+ result.userInfo = info;
48
+ log(
49
+ ` 用户: ${info.nickname || username} | 粉丝: ${info.followerCount || "-"} | 视频: ${info.videoCount || "-"}`,
50
+ );
51
+ }
52
+
53
+ const captcha = await detectCaptcha(page);
54
+ if (captcha && captcha.visible) {
55
+ log(`[验证码] @${username} 页面出现验证码`);
56
+ result.captchaDetected = true;
57
+ result.captchaStage = result.captchaStage || "video-page";
58
+ result.captchaMessage = result.captchaMessage || "视频页出现验证码";
59
+ }
60
+
61
+ // 采集视频
62
+ log(` 采集视频 (最多 ${maxVideos} 个)...`);
63
+ const videoList = await collectVideos(page, username, maxVideos, log);
64
+ const videoArray = videoList ? [...videoList.values()] : [];
65
+ result.collectedVideos = videoArray.length;
66
+ result.discoveredVideoAuthors = videoArray.map((v) => v.author);
67
+
68
+ if (videoArray.length <= 0) {
69
+ result.noVideo = true;
70
+ const pageError = await detectPageError(page);
71
+ if (pageError) {
72
+ result.restricted = true;
73
+ log(` @${username} 页面受限(${pageError}),标记跳过`);
74
+ }
75
+ return result;
76
+ }
77
+
78
+ // 采集关注和粉丝
79
+ log(` 采集关注 (最多 ${maxFollowing}) + 粉丝 (最多 ${maxFollowers})...`);
80
+ try {
81
+ const followResult = await extractFollowAndFollowers(page, {
82
+ maxFollowing,
83
+ maxFollowers,
84
+ });
85
+ result.discoveredFollowing = followResult.following || [];
86
+ result.discoveredFollowers = followResult.followers || [];
87
+ log(
88
+ ` 关注: ${result.discoveredFollowing.length}, 粉丝: ${result.discoveredFollowers.length}`,
89
+ );
90
+ } catch (e) {
91
+ log(` [关注/粉丝采集失败] ${e.message}`);
92
+ result.discoveredFollowing = [];
93
+ result.discoveredFollowers = [];
94
+ }
95
+
96
+ // 处理新发现的用户(关注 + 粉丝),循环执行完整 explore
97
+ // follow-extractor 返回 [handle, displayName] 数组
98
+ const allDiscovered = [
99
+ ...result.discoveredFollowing.map((h) => ({
100
+ handle: Array.isArray(h) ? h[0] : h,
101
+ source: "refresh-following",
102
+ })),
103
+ ...result.discoveredFollowers.map((h) => ({
104
+ handle: Array.isArray(h) ? h[0] : h,
105
+ source: "refresh-follower",
106
+ })),
107
+ ];
108
+
109
+ for (const { handle, source } of allDiscovered) {
110
+ const uniqueId = handle.replace("@", "");
111
+
112
+ // 检查用户是否已存在
113
+ const existsResp = await fetch(
114
+ `${serverUrl}/api/user-exists/${encodeURIComponent(uniqueId)}`,
115
+ );
116
+ const existsData = await existsResp.json();
117
+
118
+ if (existsData.exists) {
119
+ continue;
120
+ }
121
+
122
+ log(` [新用户] @${uniqueId} 不存在,开始探索 (来源: ${source})...`);
123
+ await delay(1000, 2000);
124
+
125
+ // 对新用户做完整 explore(与 explore 命令逻辑一致)
126
+ const exploreResult = await processExplore(
127
+ page,
128
+ uniqueId,
129
+ {
130
+ maxComments: 10,
131
+ maxGuess: 0,
132
+ enableFollow: true,
133
+ maxFollowing: 5,
134
+ maxFollowers: 5,
135
+ location: DEFAULT_TARGET_LOCATIONS_CSV,
136
+ },
137
+ log,
138
+ );
139
+
140
+ // 提交 explore 结果到服务端(和 explore 命令的 commitJob 一致)
141
+ if (exploreResult.userInfo) {
142
+ const guessedLocation = exploreResult.locationCreated || null;
143
+
144
+ const payload = {
145
+ userInfo: exploreResult.userInfo || {},
146
+ discoveredVideoAuthors: (
147
+ exploreResult.discoveredVideoAuthors || []
148
+ ).map((item) =>
149
+ typeof item === "object" ? { ...item, guessedLocation } : item,
150
+ ),
151
+ discoveredCommentAuthors: (
152
+ exploreResult.discoveredCommentAuthors || []
153
+ ).map((author) => ({ author, guessedLocation })),
154
+ discoveredGuessAuthors: (
155
+ exploreResult.discoveredGuessAuthors || []
156
+ ).map((author) => ({ author, guessedLocation })),
157
+ discoveredFollowing: (exploreResult.discoveredFollowing || []).map(
158
+ (f) => ({
159
+ handle: Array.isArray(f) ? f[0] : f,
160
+ displayName: Array.isArray(f) ? f[1] : null,
161
+ guessedLocation,
162
+ }),
163
+ ),
164
+ discoveredFollowers: (exploreResult.discoveredFollowers || []).map(
165
+ (f) => ({
166
+ handle: Array.isArray(f) ? f[0] : f,
167
+ displayName: Array.isArray(f) ? f[1] : null,
168
+ guessedLocation,
169
+ }),
170
+ ),
171
+ processed: exploreResult.processed,
172
+ hasFollowData: exploreResult.hasFollowData,
173
+ keepFollow: exploreResult.keepFollow,
174
+ locationCreated: exploreResult.locationCreated,
175
+ noVideo: exploreResult.noVideo,
176
+ restricted: exploreResult.restricted,
177
+ error: exploreResult.error,
178
+ };
179
+
180
+ const addResp = await fetch(
181
+ `${serverUrl}/api/explore-new/${uniqueId}`,
182
+ {
183
+ method: "POST",
184
+ headers: { "Content-Type": "application/json" },
185
+ body: JSON.stringify(payload),
186
+ },
187
+ );
188
+ const addResult = await addResp.json();
189
+
190
+ if (!addResult.saved) {
191
+ log(` [跳过] @${uniqueId} 提交失败`);
192
+ continue;
193
+ }
194
+
195
+ result.newUsersAdded++;
196
+ if (exploreResult.captchaDetected) {
197
+ result.captchaDetected = true;
198
+ }
199
+ log(
200
+ ` [已提交] @${uniqueId} ${addResult.created ? "(新用户)" : "(已存在)"} | 发现: ${addResult.newUsers?.length || 0} 个`,
201
+ );
202
+ }
203
+
204
+ await delay(2000, 4000);
205
+ }
206
+ } catch (e) {
207
+ log(` [错误] ${e.message}`);
208
+ result.error = e.message;
209
+ result.errorStack = e.stack || "";
210
+ }
211
+
212
+ return result;
213
+ }