tt-help-cli-ycl 1.3.45 → 1.3.47

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 (67) 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/src/cli/attach.js +331 -313
  9. package/src/cli/auto.js +265 -265
  10. package/src/cli/comments.js +620 -620
  11. package/src/cli/config.js +170 -170
  12. package/src/cli/db-import.js +51 -51
  13. package/src/cli/explore.js +555 -555
  14. package/src/cli/info.js +10 -16
  15. package/src/cli/open.js +111 -111
  16. package/src/cli/progress.js +111 -111
  17. package/src/cli/refresh.js +288 -288
  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/videostats.js +196 -196
  22. package/src/cli/watch.js +30 -30
  23. package/src/cli/webserver.js +19 -0
  24. package/src/lib/api-interceptor.js +161 -161
  25. package/src/lib/args.js +809 -778
  26. package/src/lib/browser/anti-detect.js +23 -23
  27. package/src/lib/browser/cdp.js +261 -261
  28. package/src/lib/browser/health-checker.js +114 -114
  29. package/src/lib/browser/launch.js +43 -43
  30. package/src/lib/browser/page.js +184 -184
  31. package/src/lib/constants.js +297 -287
  32. package/src/lib/delay.js +54 -54
  33. package/src/lib/explore-fetch.js +118 -118
  34. package/src/lib/fetcher.js +45 -45
  35. package/src/lib/filter.js +66 -66
  36. package/src/lib/io.js +54 -54
  37. package/src/lib/output.js +80 -80
  38. package/src/lib/page-error-detector.js +109 -109
  39. package/src/lib/parse-ssr.mjs +69 -69
  40. package/src/lib/parser.js +47 -47
  41. package/src/lib/retry.js +45 -45
  42. package/src/lib/scrape.js +90 -89
  43. package/src/lib/target-locations.js +61 -61
  44. package/src/lib/tiktok-scraper.mjs +173 -105
  45. package/src/lib/url.js +52 -52
  46. package/src/main.js +73 -70
  47. package/src/npm-main.js +70 -69
  48. package/src/scraper/auto-core.js +203 -203
  49. package/src/scraper/core.js +255 -255
  50. package/src/scraper/explore-core.js +208 -208
  51. package/src/scraper/modules/captcha-handler.js +114 -114
  52. package/src/scraper/modules/follow-extractor.js +250 -250
  53. package/src/scraper/modules/guess-extractor.js +51 -51
  54. package/src/scraper/modules/page-helpers.js +48 -48
  55. package/src/scraper/refresh-core.js +213 -213
  56. package/src/videos/core.js +143 -143
  57. package/src/watch/data-store.js +2980 -2978
  58. package/src/watch/public/index.html +2355 -2345
  59. package/src/watch/server.js +727 -727
  60. package/src/webserver/server.mjs +174 -0
  61. package/scripts/test-captcha-lib.mjs +0 -68
  62. package/scripts/test-captcha.mjs +0 -81
  63. package/scripts/test-incognito-lib.mjs +0 -36
  64. package/scripts/test-login-state.mjs +0 -128
  65. package/scripts/test-safe-click.mjs +0 -45
  66. package/scripts/test-watch-db-smoke.mjs +0 -246
  67. package/src/results/user-videos-bar.lar.lar.moeta.json +0 -37
package/src/npm-main.js CHANGED
@@ -1,69 +1,70 @@
1
- import { parseArgs } from "./lib/args.js";
2
- import { PUBLIC_HELP_TEXT } from "./lib/constants.js";
3
- import { handleInfo } from "./cli/info.js";
4
- import { handleExplore } from "./cli/explore.js";
5
- import { handleAttach } from "./cli/attach.js";
6
- import { handleConfig, showConfig, showUsage, version } from "./cli/config.js";
7
- import { handleOpen } from "./cli/open.js";
8
- import { handleComments } from "./cli/comments.js";
9
-
10
- function exitUnsupportedCommand(command) {
11
- console.error(
12
- `[${command}] 当前 npm 发布包不包含该命令;如需使用,请在仓库源码环境中运行 node src/main.js ${command} ...`,
13
- );
14
- process.exit(1);
15
- }
16
-
17
- async function main() {
18
- const parsed = parseArgs();
19
-
20
- switch (parsed.subcommand) {
21
- case "explore":
22
- return handleExplore(parsed);
23
- case "info":
24
- return handleInfo(parsed);
25
- case "attach":
26
- return handleAttach(parsed);
27
- case "watch":
28
- case "videostats":
29
- case "db-import":
30
- return exitUnsupportedCommand(parsed.subcommand);
31
- case "open":
32
- return handleOpen(parsed);
33
- case "comments":
34
- return handleComments(parsed);
35
- }
36
-
37
- const {
38
- urls,
39
- outputFile,
40
- exploreCount,
41
- showConfig: showCfg,
42
- showHelp,
43
- showVersion,
44
- configAction,
45
- configKey,
46
- configValue,
47
- } = parsed;
48
-
49
- if (showVersion) {
50
- console.log(version);
51
- process.exit(0);
52
- }
53
- if (showHelp) return showUsage(PUBLIC_HELP_TEXT);
54
- if (configAction) return handleConfig(configAction, configKey, configValue);
55
- if (showCfg) return showConfig(urls, outputFile);
56
- if (urls.length === 0 && exploreCount === 0)
57
- return showUsage(PUBLIC_HELP_TEXT);
58
-
59
- if (exploreCount > 0) {
60
- return handleExplore({ ...parsed, subcommand: "explore" });
61
- }
62
-
63
- return handleInfo(parsed);
64
- }
65
-
66
- main().catch((err) => {
67
- console.error(`错误: ${err.message}`);
68
- process.exit(1);
69
- });
1
+ import { parseArgs } from "./lib/args.js";
2
+ import { PUBLIC_HELP_TEXT } from "./lib/constants.js";
3
+ import { handleInfo } from "./cli/info.js";
4
+ import { handleExplore } from "./cli/explore.js";
5
+ import { handleAttach } from "./cli/attach.js";
6
+ import { handleConfig, showConfig, showUsage, version } from "./cli/config.js";
7
+ import { handleOpen } from "./cli/open.js";
8
+ import { handleComments } from "./cli/comments.js";
9
+
10
+ function exitUnsupportedCommand(command) {
11
+ console.error(
12
+ `[${command}] 当前 npm 发布包不包含该命令;如需使用,请在仓库源码环境中运行 node src/main.js ${command} ...`,
13
+ );
14
+ process.exit(1);
15
+ }
16
+
17
+ async function main() {
18
+ const parsed = parseArgs();
19
+
20
+ switch (parsed.subcommand) {
21
+ case "explore":
22
+ return handleExplore(parsed);
23
+ case "info":
24
+ return handleInfo(parsed);
25
+ case "attach":
26
+ return handleAttach(parsed);
27
+ case "watch":
28
+ case "webserver":
29
+ case "videostats":
30
+ case "db-import":
31
+ return exitUnsupportedCommand(parsed.subcommand);
32
+ case "open":
33
+ return handleOpen(parsed);
34
+ case "comments":
35
+ return handleComments(parsed);
36
+ }
37
+
38
+ const {
39
+ urls,
40
+ outputFile,
41
+ exploreCount,
42
+ showConfig: showCfg,
43
+ showHelp,
44
+ showVersion,
45
+ configAction,
46
+ configKey,
47
+ configValue,
48
+ } = parsed;
49
+
50
+ if (showVersion) {
51
+ console.log(version);
52
+ process.exit(0);
53
+ }
54
+ if (showHelp) return showUsage(PUBLIC_HELP_TEXT);
55
+ if (configAction) return handleConfig(configAction, configKey, configValue);
56
+ if (showCfg) return showConfig(urls, outputFile);
57
+ if (urls.length === 0 && exploreCount === 0)
58
+ return showUsage(PUBLIC_HELP_TEXT);
59
+
60
+ if (exploreCount > 0) {
61
+ return handleExplore({ ...parsed, subcommand: "explore" });
62
+ }
63
+
64
+ return handleInfo(parsed);
65
+ }
66
+
67
+ main().catch((err) => {
68
+ console.error(`错误: ${err.message}`);
69
+ process.exit(1);
70
+ });
@@ -1,203 +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
- 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 };
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 };