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,194 +1,194 @@
1
- import { delay, getDelayConfig } from "./page-helpers.js";
2
- import { scrollAndCollect } from "./scroll-collector.js";
3
-
4
- const FILTER_WORDS = ["主页", "已关注", "粉丝", "推荐"];
5
-
6
- const FOLLOW_TRIGGER_SELECTORS = [
7
- "[data-e2e=following]",
8
- 'a[href$="/following"]',
9
- 'a[href*="/following"]',
10
- '[data-e2e*="following"]',
11
- ];
12
-
13
- async function waitForFollowTrigger(page, timeout = 15000) {
14
- await page
15
- .waitForFunction(
16
- (selectors) => {
17
- for (const selector of selectors) {
18
- if (document.querySelector(selector)) return true;
19
- }
20
-
21
- const textMatchers = [/^关注$/, /^Following$/i, /^已关注$/];
22
- const nodes = document.querySelectorAll("a,button,div,span");
23
- for (const node of nodes) {
24
- const text = (node.textContent || "").trim();
25
- if (textMatchers.some((matcher) => matcher.test(text))) return true;
26
- }
27
-
28
- return false;
29
- },
30
- FOLLOW_TRIGGER_SELECTORS,
31
- { timeout },
32
- )
33
- .catch(() => {});
34
- }
35
-
36
- async function waitForListContent(page, minChildren = 1, timeout = 15000) {
37
- await page
38
- .waitForFunction(
39
- (min) => {
40
- const container = document.querySelector(
41
- "[class*=DivUserListContainer]",
42
- );
43
- return container && container.children.length >= min;
44
- },
45
- minChildren,
46
- { timeout },
47
- )
48
- .catch(() => {});
49
- }
50
-
51
- async function openFollowModal(page) {
52
- const tryOpen = async () =>
53
- page.evaluate((selectors) => {
54
- const clickTarget = (node) => {
55
- if (!node) return false;
56
- const clickable =
57
- node.closest('a,button,[role="button"]') ||
58
- node.parentElement ||
59
- node;
60
- clickable.click();
61
- return true;
62
- };
63
-
64
- for (const selector of selectors) {
65
- const node = document.querySelector(selector);
66
- if (clickTarget(node)) return selector;
67
- }
68
-
69
- const textMatchers = [/^关注$/, /^Following$/i, /^已关注$/];
70
- const nodes = Array.from(document.querySelectorAll("a,button,div,span"));
71
- for (const node of nodes) {
72
- const text = (node.textContent || "").trim();
73
- if (!text) continue;
74
- if (textMatchers.some((matcher) => matcher.test(text))) {
75
- if (clickTarget(node)) return `text:${text}`;
76
- }
77
- }
78
-
79
- return null;
80
- }, FOLLOW_TRIGGER_SELECTORS);
81
-
82
- let opened = null;
83
- for (let attempt = 1; attempt <= 3; attempt++) {
84
- await waitForFollowTrigger(page, attempt === 1 ? 15000 : 8000);
85
- opened = await tryOpen();
86
- if (opened) break;
87
-
88
- await page
89
- .evaluate(() => {
90
- window.scrollTo({ top: 0, behavior: "instant" });
91
- })
92
- .catch(() => {});
93
- await delay(800, 1500);
94
- }
95
-
96
- if (!opened) {
97
- throw new Error(
98
- "未找到关注入口元素,请确认当前页面为用户主页或页面结构已变化",
99
- );
100
- }
101
- await page.waitForSelector("[class*=DivUserListContainer]", {
102
- timeout: 30000,
103
- });
104
- await waitForListContent(page, 1, 5000);
105
- }
106
-
107
- async function switchToFollowersTab(page) {
108
- await page.evaluate(() => {
109
- const tabs = document.querySelectorAll("[class*=DivTabItem]");
110
- for (const tab of tabs) {
111
- if (tab.textContent?.includes("粉丝")) {
112
- tab.click();
113
- return;
114
- }
115
- }
116
- throw new Error("未找到粉丝 Tab");
117
- });
118
- await page.waitForSelector("[class*=DivUserListContainer]", {
119
- timeout: 30000,
120
- });
121
- await waitForListContent(page, 1, 5000);
122
- }
123
-
124
- async function closeFollowModal(page) {
125
- await page.evaluate(() => {
126
- const closeBtn = document.querySelector("[data-e2e=follow-popup-close]");
127
- if (closeBtn) closeBtn.click();
128
- });
129
- await page.waitForTimeout(500);
130
- }
131
-
132
- function createUserCollectFn() {
133
- return (container) => {
134
- const FILTER_WORDS = ["主页", "已关注", "粉丝", "推荐"];
135
- const modal = document.querySelector("[class*=eyhy6180]");
136
- const root = modal || document;
137
- const users = [];
138
- const seen = new Set();
139
- const links = root.querySelectorAll('a[href*="/@"]');
140
- for (const link of links) {
141
- const match = link.href.match(/@([^/?]+)/);
142
- if (!match) continue;
143
- const handle = "@" + decodeURIComponent(match[1]);
144
- const text = (link.textContent || "").trim();
145
- if (text.length <= 2) continue;
146
- if (FILTER_WORDS.includes(text)) continue;
147
- if (seen.has(handle)) continue;
148
- seen.add(handle);
149
- users.push({ handle, displayName: text });
150
- }
151
- return { items: users };
152
- };
153
- }
154
-
155
- async function extractUsersFromModal(page, maxUsers) {
156
- const config = getDelayConfig();
157
- const minDelay = Math.max(300, Math.round(config.commentMax * 0.3));
158
- const maxDelay = Math.max(800, config.commentMax);
159
-
160
- const allUsers = await scrollAndCollect(page, {
161
- container: "[class*=DivUserListContainer]",
162
- findScrollable: false,
163
- collectFn: createUserCollectFn(),
164
- uniqueKey: (u) => u.handle,
165
- maxItems: maxUsers,
166
- delayRange: [minDelay, maxDelay],
167
- staleThreshold: 2,
168
- });
169
-
170
- return allUsers.slice(0, maxUsers);
171
- }
172
-
173
- async function extractFollowAndFollowers(page, options = {}) {
174
- const { maxFollowing = 999, maxFollowers = 999, log = () => {} } = options;
175
-
176
- await openFollowModal(page);
177
-
178
- const following = await extractUsersFromModal(page, maxFollowing);
179
- log(` 已关注: ${following.length}`);
180
-
181
- await switchToFollowersTab(page);
182
-
183
- const followers = await extractUsersFromModal(page, maxFollowers);
184
- log(` 粉丝: ${followers.length}`);
185
-
186
- await closeFollowModal(page);
187
-
188
- return {
189
- following: following.map((u) => [u.handle, u.displayName]),
190
- followers: followers.map((u) => [u.handle, u.displayName]),
191
- };
192
- }
193
-
194
- export { extractFollowAndFollowers };
1
+ import { delay, getDelayConfig } from "./page-helpers.js";
2
+ import { scrollAndCollect } from "./scroll-collector.js";
3
+
4
+ const FILTER_WORDS = ["主页", "已关注", "粉丝", "推荐"];
5
+
6
+ const FOLLOW_TRIGGER_SELECTORS = [
7
+ "[data-e2e=following]",
8
+ 'a[href$="/following"]',
9
+ 'a[href*="/following"]',
10
+ '[data-e2e*="following"]',
11
+ ];
12
+
13
+ async function waitForFollowTrigger(page, timeout = 15000) {
14
+ await page
15
+ .waitForFunction(
16
+ (selectors) => {
17
+ for (const selector of selectors) {
18
+ if (document.querySelector(selector)) return true;
19
+ }
20
+
21
+ const textMatchers = [/^关注$/, /^Following$/i, /^已关注$/];
22
+ const nodes = document.querySelectorAll("a,button,div,span");
23
+ for (const node of nodes) {
24
+ const text = (node.textContent || "").trim();
25
+ if (textMatchers.some((matcher) => matcher.test(text))) return true;
26
+ }
27
+
28
+ return false;
29
+ },
30
+ FOLLOW_TRIGGER_SELECTORS,
31
+ { timeout },
32
+ )
33
+ .catch(() => {});
34
+ }
35
+
36
+ async function waitForListContent(page, minChildren = 1, timeout = 15000) {
37
+ await page
38
+ .waitForFunction(
39
+ (min) => {
40
+ const container = document.querySelector(
41
+ "[class*=DivUserListContainer]",
42
+ );
43
+ return container && container.children.length >= min;
44
+ },
45
+ minChildren,
46
+ { timeout },
47
+ )
48
+ .catch(() => {});
49
+ }
50
+
51
+ async function openFollowModal(page) {
52
+ const tryOpen = async () =>
53
+ page.evaluate((selectors) => {
54
+ const clickTarget = (node) => {
55
+ if (!node) return false;
56
+ const clickable =
57
+ node.closest('a,button,[role="button"]') ||
58
+ node.parentElement ||
59
+ node;
60
+ clickable.click();
61
+ return true;
62
+ };
63
+
64
+ for (const selector of selectors) {
65
+ const node = document.querySelector(selector);
66
+ if (clickTarget(node)) return selector;
67
+ }
68
+
69
+ const textMatchers = [/^关注$/, /^Following$/i, /^已关注$/];
70
+ const nodes = Array.from(document.querySelectorAll("a,button,div,span"));
71
+ for (const node of nodes) {
72
+ const text = (node.textContent || "").trim();
73
+ if (!text) continue;
74
+ if (textMatchers.some((matcher) => matcher.test(text))) {
75
+ if (clickTarget(node)) return `text:${text}`;
76
+ }
77
+ }
78
+
79
+ return null;
80
+ }, FOLLOW_TRIGGER_SELECTORS);
81
+
82
+ let opened = null;
83
+ for (let attempt = 1; attempt <= 3; attempt++) {
84
+ await waitForFollowTrigger(page, attempt === 1 ? 15000 : 8000);
85
+ opened = await tryOpen();
86
+ if (opened) break;
87
+
88
+ await page
89
+ .evaluate(() => {
90
+ window.scrollTo({ top: 0, behavior: "instant" });
91
+ })
92
+ .catch(() => {});
93
+ await delay(800, 1500);
94
+ }
95
+
96
+ if (!opened) {
97
+ throw new Error(
98
+ "未找到关注入口元素,请确认当前页面为用户主页或页面结构已变化",
99
+ );
100
+ }
101
+ await page.waitForSelector("[class*=DivUserListContainer]", {
102
+ timeout: 30000,
103
+ });
104
+ await waitForListContent(page, 1, 5000);
105
+ }
106
+
107
+ async function switchToFollowersTab(page) {
108
+ await page.evaluate(() => {
109
+ const tabs = document.querySelectorAll("[class*=DivTabItem]");
110
+ for (const tab of tabs) {
111
+ if (tab.textContent?.includes("粉丝")) {
112
+ tab.click();
113
+ return;
114
+ }
115
+ }
116
+ throw new Error("未找到粉丝 Tab");
117
+ });
118
+ await page.waitForSelector("[class*=DivUserListContainer]", {
119
+ timeout: 30000,
120
+ });
121
+ await waitForListContent(page, 1, 5000);
122
+ }
123
+
124
+ async function closeFollowModal(page) {
125
+ await page.evaluate(() => {
126
+ const closeBtn = document.querySelector("[data-e2e=follow-popup-close]");
127
+ if (closeBtn) closeBtn.click();
128
+ });
129
+ await page.waitForTimeout(500);
130
+ }
131
+
132
+ function createUserCollectFn() {
133
+ return (container) => {
134
+ const FILTER_WORDS = ["主页", "已关注", "粉丝", "推荐"];
135
+ const modal = document.querySelector("[class*=eyhy6180]");
136
+ const root = modal || document;
137
+ const users = [];
138
+ const seen = new Set();
139
+ const links = root.querySelectorAll('a[href*="/@"]');
140
+ for (const link of links) {
141
+ const match = link.href.match(/@([^/?]+)/);
142
+ if (!match) continue;
143
+ const handle = "@" + decodeURIComponent(match[1]);
144
+ const text = (link.textContent || "").trim();
145
+ if (text.length <= 2) continue;
146
+ if (FILTER_WORDS.includes(text)) continue;
147
+ if (seen.has(handle)) continue;
148
+ seen.add(handle);
149
+ users.push({ handle, displayName: text });
150
+ }
151
+ return { items: users };
152
+ };
153
+ }
154
+
155
+ async function extractUsersFromModal(page, maxUsers) {
156
+ const config = getDelayConfig();
157
+ const minDelay = Math.max(300, Math.round(config.commentMax * 0.3));
158
+ const maxDelay = Math.max(800, config.commentMax);
159
+
160
+ const allUsers = await scrollAndCollect(page, {
161
+ container: "[class*=DivUserListContainer]",
162
+ findScrollable: false,
163
+ collectFn: createUserCollectFn(),
164
+ uniqueKey: (u) => u.handle,
165
+ maxItems: maxUsers,
166
+ delayRange: [minDelay, maxDelay],
167
+ staleThreshold: 2,
168
+ });
169
+
170
+ return allUsers.slice(0, maxUsers);
171
+ }
172
+
173
+ async function extractFollowAndFollowers(page, options = {}) {
174
+ const { maxFollowing = 999, maxFollowers = 999, log = () => {} } = options;
175
+
176
+ await openFollowModal(page);
177
+
178
+ const following = await extractUsersFromModal(page, maxFollowing);
179
+ log(` 已关注: ${following.length}`);
180
+
181
+ await switchToFollowersTab(page);
182
+
183
+ const followers = await extractUsersFromModal(page, maxFollowers);
184
+ log(` 粉丝: ${followers.length}`);
185
+
186
+ await closeFollowModal(page);
187
+
188
+ return {
189
+ following: following.map((u) => [u.handle, u.displayName]),
190
+ followers: followers.map((u) => [u.handle, u.displayName]),
191
+ };
192
+ }
193
+
194
+ export { extractFollowAndFollowers };
@@ -1,51 +1,51 @@
1
- import { delay, getDelayConfig, closeCommentPanel } from './page-helpers.js';
2
- import { scrollAndCollect } from './scroll-collector.js';
3
-
4
- async function openGuessTab(page) {
5
- const tabs = page.locator('[class*="tabbar-item"]');
6
- const guessTab = tabs.filter({ hasText: /猜你喜欢/i }).first();
7
- await guessTab.click();
8
- const config = getDelayConfig();
9
- await delay(Math.round(config.commentMax * 0.5), config.commentMax);
10
- await page.waitForSelector('[class*="Related"]', { timeout: 5000 }).catch(() => {});
11
- }
12
-
13
- async function extractGuessVideos(page, maxVideos = 10) {
14
- await openGuessTab(page);
15
-
16
- const config = getDelayConfig();
17
- const allVideos = await scrollAndCollect(page, {
18
- container: '[class*="Related"]',
19
- findScrollable: true,
20
- collectFn: (container) => {
21
- const items = [];
22
- Array.from(container.querySelectorAll('[class*="DivItemContainer"]')).forEach(item => {
23
- const link = item.querySelector('a[href*="/video/"]');
24
- if (link) {
25
- const href = link.href || link.getAttribute('href');
26
- const m = href && href.match(/@([^/]+)\/video\/(\d+)/);
27
- if (m) {
28
- items.push({
29
- author: '@' + m[1],
30
- videoId: m[2],
31
- url: href,
32
- title: '',
33
- });
34
- }
35
- }
36
- });
37
- return { items };
38
- },
39
- uniqueKey: (v) => v.videoId,
40
- maxItems: maxVideos,
41
- delayRange: [Math.round(config.commentMax * 0.3), config.commentMax],
42
- staleThreshold: 3,
43
- });
44
-
45
- await closeCommentPanel(page);
46
- await delay(Math.round(config.commentMax * 0.3), config.commentMax);
47
-
48
- return allVideos.slice(0, maxVideos);
49
- }
50
-
51
- export { extractGuessVideos };
1
+ import { delay, getDelayConfig, closeCommentPanel } from './page-helpers.js';
2
+ import { scrollAndCollect } from './scroll-collector.js';
3
+
4
+ async function openGuessTab(page) {
5
+ const tabs = page.locator('[class*="tabbar-item"]');
6
+ const guessTab = tabs.filter({ hasText: /猜你喜欢/i }).first();
7
+ await guessTab.click();
8
+ const config = getDelayConfig();
9
+ await delay(Math.round(config.commentMax * 0.5), config.commentMax);
10
+ await page.waitForSelector('[class*="Related"]', { timeout: 5000 }).catch(() => {});
11
+ }
12
+
13
+ async function extractGuessVideos(page, maxVideos = 10) {
14
+ await openGuessTab(page);
15
+
16
+ const config = getDelayConfig();
17
+ const allVideos = await scrollAndCollect(page, {
18
+ container: '[class*="Related"]',
19
+ findScrollable: true,
20
+ collectFn: (container) => {
21
+ const items = [];
22
+ Array.from(container.querySelectorAll('[class*="DivItemContainer"]')).forEach(item => {
23
+ const link = item.querySelector('a[href*="/video/"]');
24
+ if (link) {
25
+ const href = link.href || link.getAttribute('href');
26
+ const m = href && href.match(/@([^/]+)\/video\/(\d+)/);
27
+ if (m) {
28
+ items.push({
29
+ author: '@' + m[1],
30
+ videoId: m[2],
31
+ url: href,
32
+ title: '',
33
+ });
34
+ }
35
+ }
36
+ });
37
+ return { items };
38
+ },
39
+ uniqueKey: (v) => v.videoId,
40
+ maxItems: maxVideos,
41
+ delayRange: [Math.round(config.commentMax * 0.3), config.commentMax],
42
+ staleThreshold: 3,
43
+ });
44
+
45
+ await closeCommentPanel(page);
46
+ await delay(Math.round(config.commentMax * 0.3), config.commentMax);
47
+
48
+ return allVideos.slice(0, maxVideos);
49
+ }
50
+
51
+ export { extractGuessVideos };
@@ -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;