tt-help-cli-ycl 1.3.6 → 1.3.7

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 (46) hide show
  1. package/README.md +17 -17
  2. package/cli.js +9 -9
  3. package/package.json +45 -45
  4. package/src/cli/auto.js +131 -121
  5. package/src/cli/explore.js +147 -138
  6. package/src/cli/progress.js +111 -111
  7. package/src/cli/scrape.js +47 -47
  8. package/src/cli/utils.js +18 -18
  9. package/src/cli/videos.js +41 -41
  10. package/src/cli/watch.js +31 -31
  11. package/src/lib/args.js +391 -391
  12. package/src/lib/browser/anti-detect.js +23 -23
  13. package/src/lib/browser/cdp.js +142 -142
  14. package/src/lib/browser/launch.js +43 -43
  15. package/src/lib/browser/page.js +87 -87
  16. package/src/lib/constants.js +109 -95
  17. package/src/lib/delay.js +54 -54
  18. package/src/lib/explore-fetch.js +118 -118
  19. package/src/lib/fetcher.js +45 -45
  20. package/src/lib/filter.js +66 -66
  21. package/src/lib/io.js +54 -54
  22. package/src/lib/mac-or-uuid.js +82 -0
  23. package/src/lib/output.js +80 -80
  24. package/src/lib/parser.js +47 -47
  25. package/src/lib/retry.js +44 -44
  26. package/src/lib/scrape.js +40 -40
  27. package/src/lib/url.js +52 -52
  28. package/src/main.mjs +221 -221
  29. package/src/scraper/auto-core.mjs +185 -185
  30. package/src/scraper/core.mjs +190 -190
  31. package/src/scraper/explore-core.mjs +162 -162
  32. package/src/scraper/modules/captcha-handler.mjs +114 -114
  33. package/src/scraper/modules/comment-extractor.mjs +69 -69
  34. package/src/scraper/modules/follow-extractor.mjs +121 -121
  35. package/src/scraper/modules/guess-extractor.mjs +51 -51
  36. package/src/scraper/modules/page-error-detector.mjs +70 -70
  37. package/src/scraper/modules/page-helpers.mjs +48 -48
  38. package/src/scraper/modules/scroll-collector.mjs +189 -189
  39. package/src/test-auto-follow.cjs +109 -0
  40. package/src/test-extractors.cjs +75 -0
  41. package/src/test-follow.cjs +41 -0
  42. package/src/videos/core.mjs +126 -126
  43. package/src/watch/data-store.mjs +258 -261
  44. package/src/watch/public/index.html +466 -465
  45. package/src/watch/server.mjs +291 -281
  46. package/src/results/user-videos-bar.lar.lar.moeta.json +0 -37
@@ -1,69 +1,69 @@
1
- import { delay, getDelayConfig, closeCommentPanel } from "./page-helpers.mjs";
2
- import { scrollAndCollect } from "./scroll-collector.mjs";
3
- import { waitAndGetCaptcha } from "./captcha-handler.mjs";
4
-
5
- async function openCommentPanel(page) {
6
- const tabs = page.locator('[class*="tabbar-item"]');
7
- const commentTab = tabs.filter({ hasText: "评论" }).first();
8
- await commentTab.click();
9
-
10
- // 等待短暂时间让页面渲染
11
- await new Promise(r => setTimeout(r, 2000));
12
-
13
- // 检测验证码
14
- await waitAndGetCaptcha(page, {
15
- waitMs: 180000,
16
- pollInterval: 5000,
17
- log: console.error,
18
- });
19
-
20
- await page
21
- .waitForSelector('[class*="CommentListContainer"]', { timeout: 5000 })
22
- .catch(() => {});
23
- await page
24
- .waitForFunction(
25
- () => {
26
- const list = document.querySelector('[class*="CommentListContainer"]');
27
- return list && list.children.length > 0;
28
- },
29
- { timeout: 10000 },
30
- )
31
- .catch(() => {});
32
- }
33
-
34
- async function extractCommentAuthors(page, maxComments = 10) {
35
- await openCommentPanel(page);
36
-
37
- const config = getDelayConfig();
38
- const allAuthors = await scrollAndCollect(page, {
39
- container: '[class*="CommentMain"]',
40
- findScrollable: true,
41
- collectFn: (container) => {
42
- const list = document.querySelector('[class*="CommentListContainer"]');
43
- if (!list) return { items: [] };
44
- const authors = [];
45
- Array.from(list.children).forEach((wrapper) => {
46
- const link = wrapper.querySelector(
47
- '[class*="UsernameContentWrapper"] a',
48
- );
49
- if (link) {
50
- const href = link.href || link.getAttribute("href");
51
- const m = href && href.match(/@([^/]+)/);
52
- if (m) authors.push("@" + m[1]);
53
- }
54
- });
55
- return { items: authors };
56
- },
57
- uniqueKey: (a) => a,
58
- maxItems: maxComments,
59
- delayRange: [Math.round(config.commentMax * 0.3), config.commentMax],
60
- staleThreshold: 2,
61
- });
62
-
63
- await closeCommentPanel(page);
64
- await delay(Math.round(config.commentMax * 0.3), config.commentMax);
65
-
66
- return allAuthors.slice(0, maxComments);
67
- }
68
-
69
- export { extractCommentAuthors };
1
+ import { delay, getDelayConfig, closeCommentPanel } from "./page-helpers.mjs";
2
+ import { scrollAndCollect } from "./scroll-collector.mjs";
3
+ import { waitAndGetCaptcha } from "./captcha-handler.mjs";
4
+
5
+ async function openCommentPanel(page) {
6
+ const tabs = page.locator('[class*="tabbar-item"]');
7
+ const commentTab = tabs.filter({ hasText: "评论" }).first();
8
+ await commentTab.click();
9
+
10
+ // 等待短暂时间让页面渲染
11
+ await new Promise(r => setTimeout(r, 2000));
12
+
13
+ // 检测验证码
14
+ await waitAndGetCaptcha(page, {
15
+ waitMs: 180000,
16
+ pollInterval: 5000,
17
+ log: console.error,
18
+ });
19
+
20
+ await page
21
+ .waitForSelector('[class*="CommentListContainer"]', { timeout: 5000 })
22
+ .catch(() => {});
23
+ await page
24
+ .waitForFunction(
25
+ () => {
26
+ const list = document.querySelector('[class*="CommentListContainer"]');
27
+ return list && list.children.length > 0;
28
+ },
29
+ { timeout: 10000 },
30
+ )
31
+ .catch(() => {});
32
+ }
33
+
34
+ async function extractCommentAuthors(page, maxComments = 10) {
35
+ await openCommentPanel(page);
36
+
37
+ const config = getDelayConfig();
38
+ const allAuthors = await scrollAndCollect(page, {
39
+ container: '[class*="CommentMain"]',
40
+ findScrollable: true,
41
+ collectFn: (container) => {
42
+ const list = document.querySelector('[class*="CommentListContainer"]');
43
+ if (!list) return { items: [] };
44
+ const authors = [];
45
+ Array.from(list.children).forEach((wrapper) => {
46
+ const link = wrapper.querySelector(
47
+ '[class*="UsernameContentWrapper"] a',
48
+ );
49
+ if (link) {
50
+ const href = link.href || link.getAttribute("href");
51
+ const m = href && href.match(/@([^/]+)/);
52
+ if (m) authors.push("@" + m[1]);
53
+ }
54
+ });
55
+ return { items: authors };
56
+ },
57
+ uniqueKey: (a) => a,
58
+ maxItems: maxComments,
59
+ delayRange: [Math.round(config.commentMax * 0.3), config.commentMax],
60
+ staleThreshold: 2,
61
+ });
62
+
63
+ await closeCommentPanel(page);
64
+ await delay(Math.round(config.commentMax * 0.3), config.commentMax);
65
+
66
+ return allAuthors.slice(0, maxComments);
67
+ }
68
+
69
+ export { extractCommentAuthors };
@@ -1,121 +1,121 @@
1
- import { delay, getDelayConfig } from "./page-helpers.mjs";
2
- import { scrollAndCollect } from "./scroll-collector.mjs";
3
-
4
- const FILTER_WORDS = ["主页", "已关注", "粉丝", "推荐"];
5
-
6
- async function waitForListContent(page, minChildren = 1, timeout = 15000) {
7
- await page
8
- .waitForFunction(
9
- (min) => {
10
- const container = document.querySelector(
11
- "[class*=DivUserListContainer]",
12
- );
13
- return container && container.children.length >= min;
14
- },
15
- minChildren,
16
- { timeout },
17
- )
18
- .catch(() => {});
19
- }
20
-
21
- async function openFollowModal(page) {
22
- const el = await page.$("[data-e2e=following]");
23
- if (!el) {
24
- throw new Error(
25
- "未找到 [data-e2e=following] 元素,请确认当前页面为用户主页",
26
- );
27
- }
28
- await el.evaluate((el) => el.parentElement.click());
29
- await page
30
- .waitForSelector("[class*=DivUserListContainer]", { timeout: 5000 })
31
- .catch(() => {
32
- throw new Error("关注弹窗未出现 DivUserListContainer");
33
- });
34
- await waitForListContent(page, 1, 3000);
35
- }
36
-
37
- async function switchToFollowersTab(page) {
38
- await page.evaluate(() => {
39
- const tabs = document.querySelectorAll("[class*=DivTabItem]");
40
- for (const tab of tabs) {
41
- if (tab.textContent?.includes("粉丝")) {
42
- tab.click();
43
- return;
44
- }
45
- }
46
- throw new Error("未找到粉丝 Tab");
47
- });
48
- await waitForListContent(page, 1, 3000);
49
- }
50
-
51
- async function closeFollowModal(page) {
52
- await page.evaluate(() => {
53
- const closeBtn = document.querySelector("[data-e2e=follow-popup-close]");
54
- if (closeBtn) closeBtn.click();
55
- });
56
- await page.waitForTimeout(500);
57
- }
58
-
59
- function createUserCollectFn() {
60
- return (container) => {
61
- const FILTER_WORDS = ["主页", "已关注", "粉丝", "推荐"];
62
- const modal = document.querySelector("[class*=eyhy6180]");
63
- const root = modal || document;
64
- const users = [];
65
- const seen = new Set();
66
- const links = root.querySelectorAll('a[href*="/@"]');
67
- for (const link of links) {
68
- const match = link.href.match(/@([^/?]+)/);
69
- if (!match) continue;
70
- const handle = "@" + decodeURIComponent(match[1]);
71
- const text = (link.textContent || "").trim();
72
- if (text.length <= 2) continue;
73
- if (FILTER_WORDS.includes(text)) continue;
74
- if (seen.has(handle)) continue;
75
- seen.add(handle);
76
- users.push({ handle, displayName: text });
77
- }
78
- return { items: users };
79
- };
80
- }
81
-
82
- async function extractUsersFromModal(page, maxUsers) {
83
- const config = getDelayConfig();
84
- const minDelay = Math.max(300, Math.round(config.commentMax * 0.3));
85
- const maxDelay = Math.max(800, config.commentMax);
86
-
87
- const allUsers = await scrollAndCollect(page, {
88
- container: "[class*=DivUserListContainer]",
89
- findScrollable: false,
90
- collectFn: createUserCollectFn(),
91
- uniqueKey: (u) => u.handle,
92
- maxItems: maxUsers,
93
- delayRange: [minDelay, maxDelay],
94
- staleThreshold: 2,
95
- });
96
-
97
- return allUsers.slice(0, maxUsers);
98
- }
99
-
100
- async function extractFollowAndFollowers(page, options = {}) {
101
- const { maxFollowing = 999, maxFollowers = 999, log = () => {} } = options;
102
-
103
- await openFollowModal(page);
104
-
105
- const following = await extractUsersFromModal(page, maxFollowing);
106
- log(` 已关注: ${following.length}`);
107
-
108
- await switchToFollowersTab(page);
109
-
110
- const followers = await extractUsersFromModal(page, maxFollowers);
111
- log(` 粉丝: ${followers.length}`);
112
-
113
- await closeFollowModal(page);
114
-
115
- return {
116
- following: following.map((u) => [u.handle, u.displayName]),
117
- followers: followers.map((u) => [u.handle, u.displayName]),
118
- };
119
- }
120
-
121
- export { extractFollowAndFollowers };
1
+ import { delay, getDelayConfig } from "./page-helpers.mjs";
2
+ import { scrollAndCollect } from "./scroll-collector.mjs";
3
+
4
+ const FILTER_WORDS = ["主页", "已关注", "粉丝", "推荐"];
5
+
6
+ async function waitForListContent(page, minChildren = 1, timeout = 15000) {
7
+ await page
8
+ .waitForFunction(
9
+ (min) => {
10
+ const container = document.querySelector(
11
+ "[class*=DivUserListContainer]",
12
+ );
13
+ return container && container.children.length >= min;
14
+ },
15
+ minChildren,
16
+ { timeout },
17
+ )
18
+ .catch(() => {});
19
+ }
20
+
21
+ async function openFollowModal(page) {
22
+ const el = await page.$("[data-e2e=following]");
23
+ if (!el) {
24
+ throw new Error(
25
+ "未找到 [data-e2e=following] 元素,请确认当前页面为用户主页",
26
+ );
27
+ }
28
+ await el.evaluate((el) => el.parentElement.click());
29
+ await page
30
+ .waitForSelector("[class*=DivUserListContainer]", { timeout: 5000 })
31
+ .catch(() => {
32
+ throw new Error("关注弹窗未出现 DivUserListContainer");
33
+ });
34
+ await waitForListContent(page, 1, 3000);
35
+ }
36
+
37
+ async function switchToFollowersTab(page) {
38
+ await page.evaluate(() => {
39
+ const tabs = document.querySelectorAll("[class*=DivTabItem]");
40
+ for (const tab of tabs) {
41
+ if (tab.textContent?.includes("粉丝")) {
42
+ tab.click();
43
+ return;
44
+ }
45
+ }
46
+ throw new Error("未找到粉丝 Tab");
47
+ });
48
+ await waitForListContent(page, 1, 3000);
49
+ }
50
+
51
+ async function closeFollowModal(page) {
52
+ await page.evaluate(() => {
53
+ const closeBtn = document.querySelector("[data-e2e=follow-popup-close]");
54
+ if (closeBtn) closeBtn.click();
55
+ });
56
+ await page.waitForTimeout(500);
57
+ }
58
+
59
+ function createUserCollectFn() {
60
+ return (container) => {
61
+ const FILTER_WORDS = ["主页", "已关注", "粉丝", "推荐"];
62
+ const modal = document.querySelector("[class*=eyhy6180]");
63
+ const root = modal || document;
64
+ const users = [];
65
+ const seen = new Set();
66
+ const links = root.querySelectorAll('a[href*="/@"]');
67
+ for (const link of links) {
68
+ const match = link.href.match(/@([^/?]+)/);
69
+ if (!match) continue;
70
+ const handle = "@" + decodeURIComponent(match[1]);
71
+ const text = (link.textContent || "").trim();
72
+ if (text.length <= 2) continue;
73
+ if (FILTER_WORDS.includes(text)) continue;
74
+ if (seen.has(handle)) continue;
75
+ seen.add(handle);
76
+ users.push({ handle, displayName: text });
77
+ }
78
+ return { items: users };
79
+ };
80
+ }
81
+
82
+ async function extractUsersFromModal(page, maxUsers) {
83
+ const config = getDelayConfig();
84
+ const minDelay = Math.max(300, Math.round(config.commentMax * 0.3));
85
+ const maxDelay = Math.max(800, config.commentMax);
86
+
87
+ const allUsers = await scrollAndCollect(page, {
88
+ container: "[class*=DivUserListContainer]",
89
+ findScrollable: false,
90
+ collectFn: createUserCollectFn(),
91
+ uniqueKey: (u) => u.handle,
92
+ maxItems: maxUsers,
93
+ delayRange: [minDelay, maxDelay],
94
+ staleThreshold: 2,
95
+ });
96
+
97
+ return allUsers.slice(0, maxUsers);
98
+ }
99
+
100
+ async function extractFollowAndFollowers(page, options = {}) {
101
+ const { maxFollowing = 999, maxFollowers = 999, log = () => {} } = options;
102
+
103
+ await openFollowModal(page);
104
+
105
+ const following = await extractUsersFromModal(page, maxFollowing);
106
+ log(` 已关注: ${following.length}`);
107
+
108
+ await switchToFollowersTab(page);
109
+
110
+ const followers = await extractUsersFromModal(page, maxFollowers);
111
+ log(` 粉丝: ${followers.length}`);
112
+
113
+ await closeFollowModal(page);
114
+
115
+ return {
116
+ following: following.map((u) => [u.handle, u.displayName]),
117
+ followers: followers.map((u) => [u.handle, u.displayName]),
118
+ };
119
+ }
120
+
121
+ export { extractFollowAndFollowers };
@@ -1,51 +1,51 @@
1
- import { delay, getDelayConfig, closeCommentPanel } from './page-helpers.mjs';
2
- import { scrollAndCollect } from './scroll-collector.mjs';
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.mjs';
2
+ import { scrollAndCollect } from './scroll-collector.mjs';
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,70 +1,70 @@
1
- const PATTERNS = {
2
- login_required: [
3
- "登录 TikTok",
4
- "登录后查看",
5
- "查看需登录",
6
- "Log in to TikTok",
7
- "Login to TikTok",
8
- "观众管理功能",
9
- "Viewer management",
10
- "私密账号",
11
- "私密状态",
12
- ],
13
- captcha: [
14
- "captcha",
15
- "verify",
16
- "验证码",
17
- "点击下一步",
18
- "Press and hold",
19
- "slide to verify",
20
- "滑动验证",
21
- "人机验证",
22
- "安全验证",
23
- ],
24
- rate_limited: [
25
- "访问过于频繁",
26
- "操作过于频繁",
27
- "too many requests",
28
- "rate limit",
29
- "稍后再试",
30
- "try again later",
31
- "请稍后再来",
32
- ],
33
- region_blocked: [
34
- "地区限制",
35
- "not available in your",
36
- "此内容不可用",
37
- "content not available",
38
- "currently unavailable",
39
- "抱歉,此内容",
40
- "此页面不可用",
41
- ],
42
- not_found: [
43
- "页面不存在",
44
- "page not found",
45
- "找不到",
46
- "Couldn't find this",
47
- "nothing here",
48
- "此页面不存在",
49
- "没有内容",
50
- "发起对话",
51
- "0 条评论",
52
- ],
53
- };
54
-
55
- export async function detectPageError(page) {
56
- return page.evaluate((patterns) => {
57
- const bodyText = document.body.innerText;
58
- const lower = bodyText.toLowerCase();
59
-
60
- for (const [type, phrases] of Object.entries(patterns)) {
61
- for (const phrase of phrases) {
62
- if (lower.includes(phrase.toLowerCase())) {
63
- return type;
64
- }
65
- }
66
- }
67
-
68
- return null;
69
- }, PATTERNS);
70
- }
1
+ const PATTERNS = {
2
+ login_required: [
3
+ "登录 TikTok",
4
+ "登录后查看",
5
+ "查看需登录",
6
+ "Log in to TikTok",
7
+ "Login to TikTok",
8
+ "观众管理功能",
9
+ "Viewer management",
10
+ "私密账号",
11
+ "私密状态",
12
+ ],
13
+ captcha: [
14
+ "captcha",
15
+ "verify",
16
+ "验证码",
17
+ "点击下一步",
18
+ "Press and hold",
19
+ "slide to verify",
20
+ "滑动验证",
21
+ "人机验证",
22
+ "安全验证",
23
+ ],
24
+ rate_limited: [
25
+ "访问过于频繁",
26
+ "操作过于频繁",
27
+ "too many requests",
28
+ "rate limit",
29
+ "稍后再试",
30
+ "try again later",
31
+ "请稍后再来",
32
+ ],
33
+ region_blocked: [
34
+ "地区限制",
35
+ "not available in your",
36
+ "此内容不可用",
37
+ "content not available",
38
+ "currently unavailable",
39
+ "抱歉,此内容",
40
+ "此页面不可用",
41
+ ],
42
+ not_found: [
43
+ "页面不存在",
44
+ "page not found",
45
+ "找不到",
46
+ "Couldn't find this",
47
+ "nothing here",
48
+ "此页面不存在",
49
+ "没有内容",
50
+ "发起对话",
51
+ "0 条评论",
52
+ ],
53
+ };
54
+
55
+ export async function detectPageError(page) {
56
+ return page.evaluate((patterns) => {
57
+ const bodyText = document.body.innerText;
58
+ const lower = bodyText.toLowerCase();
59
+
60
+ for (const [type, phrases] of Object.entries(patterns)) {
61
+ for (const phrase of phrases) {
62
+ if (lower.includes(phrase.toLowerCase())) {
63
+ return type;
64
+ }
65
+ }
66
+ }
67
+
68
+ return null;
69
+ }, PATTERNS);
70
+ }