tt-help-cli-ycl 1.3.6 → 1.3.8
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.
- package/README.md +17 -17
- package/cli.js +9 -9
- package/package.json +45 -45
- package/src/cli/auto.js +131 -121
- package/src/cli/explore.js +147 -138
- package/src/cli/progress.js +111 -111
- package/src/cli/scrape.js +47 -47
- package/src/cli/utils.js +18 -18
- package/src/cli/videos.js +41 -41
- package/src/cli/watch.js +31 -31
- package/src/lib/args.js +391 -391
- package/src/lib/browser/anti-detect.js +23 -23
- package/src/lib/browser/cdp.js +142 -142
- package/src/lib/browser/launch.js +43 -43
- package/src/lib/browser/page.js +87 -87
- package/src/lib/constants.js +109 -95
- package/src/lib/delay.js +54 -54
- package/src/lib/explore-fetch.js +118 -118
- package/src/lib/fetcher.js +45 -45
- package/src/lib/filter.js +66 -66
- package/src/lib/io.js +54 -54
- package/src/lib/mac-or-uuid.js +82 -0
- package/src/lib/output.js +80 -80
- package/src/lib/parser.js +47 -47
- package/src/lib/retry.js +44 -44
- package/src/lib/scrape.js +40 -40
- package/src/lib/url.js +52 -52
- package/src/main.mjs +221 -221
- package/src/scraper/auto-core.mjs +185 -185
- package/src/scraper/core.mjs +190 -190
- package/src/scraper/explore-core.mjs +162 -162
- package/src/scraper/modules/captcha-handler.mjs +114 -114
- package/src/scraper/modules/comment-extractor.mjs +69 -69
- package/src/scraper/modules/follow-extractor.mjs +121 -121
- package/src/scraper/modules/guess-extractor.mjs +51 -51
- package/src/scraper/modules/page-error-detector.mjs +70 -70
- package/src/scraper/modules/page-helpers.mjs +48 -48
- package/src/scraper/modules/scroll-collector.mjs +189 -189
- package/src/test-auto-follow.cjs +109 -0
- package/src/test-extractors.cjs +75 -0
- package/src/test-follow.cjs +41 -0
- package/src/videos/core.mjs +126 -126
- package/src/watch/data-store.mjs +258 -261
- package/src/watch/public/index.html +580 -464
- package/src/watch/server.mjs +308 -281
- package/src/results/user-videos-bar.lar.lar.moeta.json +0 -37
package/src/scraper/core.mjs
CHANGED
|
@@ -1,190 +1,190 @@
|
|
|
1
|
-
import {
|
|
2
|
-
closeCommentPanel,
|
|
3
|
-
delay,
|
|
4
|
-
ensureBrowserReady,
|
|
5
|
-
ensureTikTokPage,
|
|
6
|
-
setDelayConfig,
|
|
7
|
-
getDelayConfig,
|
|
8
|
-
retryWithBackoff,
|
|
9
|
-
assertPageUrl,
|
|
10
|
-
} from './modules/page-helpers.mjs';
|
|
11
|
-
import { extractCommentAuthors } from './modules/comment-extractor.mjs';
|
|
12
|
-
import { extractGuessVideos } from './modules/guess-extractor.mjs';
|
|
13
|
-
|
|
14
|
-
async function scrapeSingleVideo(page, maxComments, maxGuess, log, location = 'ES') {
|
|
15
|
-
const config = getDelayConfig();
|
|
16
|
-
|
|
17
|
-
await page.waitForSelector('[class*="VideoMeta"]', { timeout: 10000 }).catch(() => {});
|
|
18
|
-
await delay(Math.round(config.commentMax * 0.3), config.commentMax);
|
|
19
|
-
|
|
20
|
-
const userData = await page.evaluate(() => {
|
|
21
|
-
const result = {};
|
|
22
|
-
const m = window.location.href.match(/\/@([^/]+)\/video/);
|
|
23
|
-
if (m) result.uniqueId = m[1];
|
|
24
|
-
const authorEls = document.querySelectorAll('[class*="Author"]');
|
|
25
|
-
for (const el of authorEls) {
|
|
26
|
-
const text = (el.textContent || '').trim();
|
|
27
|
-
if (text && !text.includes('TikTok') && !text.includes('Share')) {
|
|
28
|
-
result.nickname = text;
|
|
29
|
-
break;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
const html = document.documentElement.outerHTML;
|
|
33
|
-
const locMatch = html.match(/"locationCreated":"([^"]*)/);
|
|
34
|
-
if (locMatch) result.locationCreated = locMatch[1];
|
|
35
|
-
return result;
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
const videoAuthor = userData.uniqueId ? '@' + userData.uniqueId : null;
|
|
39
|
-
if (!videoAuthor) throw new Error('无法获取视频作者');
|
|
40
|
-
|
|
41
|
-
let guessVideos = [];
|
|
42
|
-
let commentUsers = [];
|
|
43
|
-
|
|
44
|
-
if (userData.locationCreated === location) {
|
|
45
|
-
if (maxGuess > 0) {
|
|
46
|
-
guessVideos = await extractGuessVideos(page, maxGuess);
|
|
47
|
-
}
|
|
48
|
-
if (maxComments > 0) {
|
|
49
|
-
commentUsers = await extractCommentAuthors(page, maxComments);
|
|
50
|
-
}
|
|
51
|
-
await closeCommentPanel(page);
|
|
52
|
-
if (maxGuess > 0 || maxComments > 0) {
|
|
53
|
-
await delay(Math.round(config.commentMax * 0.3), config.commentMax);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
return {
|
|
58
|
-
videoAuthor,
|
|
59
|
-
uniqueId: userData.uniqueId,
|
|
60
|
-
nickname: userData.nickname,
|
|
61
|
-
locationCreated: userData.locationCreated,
|
|
62
|
-
commentUsers: [...new Set(commentUsers)],
|
|
63
|
-
guessVideos,
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
async function runScrape(options) {
|
|
68
|
-
const {
|
|
69
|
-
videoUrl, maxVideos = 20, maxComments = 999, maxGuess = 10,
|
|
70
|
-
preset = null, switchMax = null, commentMax = null,
|
|
71
|
-
log = console.error,
|
|
72
|
-
browser: externalBrowser = null, page: externalPage = null,
|
|
73
|
-
} = options;
|
|
74
|
-
|
|
75
|
-
if (preset) {
|
|
76
|
-
setDelayConfig(preset);
|
|
77
|
-
} else if (switchMax || commentMax) {
|
|
78
|
-
setDelayConfig({ switchMax: switchMax || 5000, commentMax: commentMax || 3000 });
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
const config = getDelayConfig();
|
|
82
|
-
let browser, page;
|
|
83
|
-
const isExternal = !!(externalBrowser && externalPage);
|
|
84
|
-
|
|
85
|
-
if (!isExternal) {
|
|
86
|
-
log(`视频地址: ${videoUrl}`);
|
|
87
|
-
log(`视频数: ${maxVideos}, 评论数: ${maxComments}, 猜你喜欢: ${maxGuess}, 切换延迟: ${config.switchMax}ms, 评论延迟: ${config.commentMax}ms`);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
if (isExternal) {
|
|
91
|
-
browser = externalBrowser;
|
|
92
|
-
page = externalPage;
|
|
93
|
-
} else {
|
|
94
|
-
browser = await ensureBrowserReady();
|
|
95
|
-
try {
|
|
96
|
-
page = await ensureTikTokPage(browser, videoUrl);
|
|
97
|
-
} catch (e) {
|
|
98
|
-
await browser.close().catch(() => {});
|
|
99
|
-
throw e;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
await retryWithBackoff(() => page.goto(videoUrl, { waitUntil: 'load', timeout: 30000 }), { log });
|
|
104
|
-
assertPageUrl(page, videoUrl.split('/video/')[0]);
|
|
105
|
-
await delay(Math.round(config.switchMax * 0.5), config.switchMax);
|
|
106
|
-
await closeCommentPanel(page);
|
|
107
|
-
await delay(Math.round(config.commentMax * 0.5), config.commentMax);
|
|
108
|
-
|
|
109
|
-
const allResults = [];
|
|
110
|
-
const videoAuthors = new Set();
|
|
111
|
-
const commentUsers = new Set();
|
|
112
|
-
const allCommentAuthorsList = [];
|
|
113
|
-
const allGuessAuthors = new Set();
|
|
114
|
-
const allGuessVideos = [];
|
|
115
|
-
|
|
116
|
-
for (let i = 0; i < maxVideos; i++) {
|
|
117
|
-
await delay(Math.round(config.commentMax * 0.3), config.commentMax);
|
|
118
|
-
|
|
119
|
-
let result;
|
|
120
|
-
try {
|
|
121
|
-
result = await scrapeSingleVideo(page, maxComments, maxGuess, log);
|
|
122
|
-
} catch (e) {
|
|
123
|
-
log(`[${i + 1}/${maxVideos}] 跳过: ${e.message}`);
|
|
124
|
-
if (i < maxVideos - 1) {
|
|
125
|
-
await page.evaluate(() => {
|
|
126
|
-
const container = document.querySelector('[class*="ColumnListContainer"]');
|
|
127
|
-
if (container) container.scrollTop += 700;
|
|
128
|
-
else window.scrollBy(0, 700);
|
|
129
|
-
});
|
|
130
|
-
await delay(Math.round(config.switchMax * 0.5), config.switchMax);
|
|
131
|
-
}
|
|
132
|
-
continue;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
allResults.push(result);
|
|
136
|
-
videoAuthors.add(result.videoAuthor);
|
|
137
|
-
result.commentUsers.forEach(u => commentUsers.add(u));
|
|
138
|
-
allCommentAuthorsList.push(...result.commentUsers);
|
|
139
|
-
if (result.guessVideos) {
|
|
140
|
-
allGuessVideos.push(...result.guessVideos);
|
|
141
|
-
result.guessVideos.forEach(v => { if (v.author) allGuessAuthors.add(v.author); });
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
if ((i + 1) % 5 === 0 || i === 0) {
|
|
145
|
-
log(`[${i + 1}/${maxVideos}] ${result.videoAuthor} | 昵称: ${result.nickname || '-'} | 评论用户: ${result.commentUsers.length} | 猜你喜欢: ${result.guessVideos ? result.guessVideos.length : 0}`);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
if (i < maxVideos - 1) {
|
|
149
|
-
await page.evaluate(() => {
|
|
150
|
-
const container = document.querySelector('[class*="ColumnListContainer"]');
|
|
151
|
-
if (container) container.scrollTop += 700;
|
|
152
|
-
});
|
|
153
|
-
await delay(2000, config.switchMax);
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
log(`\n结果: 视频作者 ${videoAuthors.size} | 评论用户 ${commentUsers.size} | 总评论 ${allCommentAuthorsList.length} | 猜你喜欢作者 ${allGuessAuthors.size} | 总猜中视频 ${allGuessVideos.length}`);
|
|
158
|
-
|
|
159
|
-
const videoDetails = {};
|
|
160
|
-
for (const r of allResults) {
|
|
161
|
-
const key = r.videoAuthor;
|
|
162
|
-
if (!videoDetails[key]) {
|
|
163
|
-
videoDetails[key] = {
|
|
164
|
-
videoAuthor: r.videoAuthor,
|
|
165
|
-
uniqueId: r.uniqueId,
|
|
166
|
-
nickname: r.nickname,
|
|
167
|
-
locationCreated: r.locationCreated,
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
const output = {
|
|
173
|
-
videoDetails: Object.values(videoDetails),
|
|
174
|
-
commentUsers: [...commentUsers].sort(),
|
|
175
|
-
allCommentAuthorsList,
|
|
176
|
-
guessVideos: allGuessVideos,
|
|
177
|
-
guessAuthors: [...allGuessAuthors].sort(),
|
|
178
|
-
stats: {
|
|
179
|
-
totalVideos: allResults.length,
|
|
180
|
-
uniqueVideoAuthors: videoAuthors.size,
|
|
181
|
-
uniqueCommentAuthors: commentUsers.size,
|
|
182
|
-
uniqueGuessAuthors: allGuessAuthors.size,
|
|
183
|
-
totalGuessVideos: allGuessVideos.length,
|
|
184
|
-
},
|
|
185
|
-
};
|
|
186
|
-
|
|
187
|
-
return { output, browser, isExternal };
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
export { scrapeSingleVideo, runScrape };
|
|
1
|
+
import {
|
|
2
|
+
closeCommentPanel,
|
|
3
|
+
delay,
|
|
4
|
+
ensureBrowserReady,
|
|
5
|
+
ensureTikTokPage,
|
|
6
|
+
setDelayConfig,
|
|
7
|
+
getDelayConfig,
|
|
8
|
+
retryWithBackoff,
|
|
9
|
+
assertPageUrl,
|
|
10
|
+
} from './modules/page-helpers.mjs';
|
|
11
|
+
import { extractCommentAuthors } from './modules/comment-extractor.mjs';
|
|
12
|
+
import { extractGuessVideos } from './modules/guess-extractor.mjs';
|
|
13
|
+
|
|
14
|
+
async function scrapeSingleVideo(page, maxComments, maxGuess, log, location = 'ES') {
|
|
15
|
+
const config = getDelayConfig();
|
|
16
|
+
|
|
17
|
+
await page.waitForSelector('[class*="VideoMeta"]', { timeout: 10000 }).catch(() => {});
|
|
18
|
+
await delay(Math.round(config.commentMax * 0.3), config.commentMax);
|
|
19
|
+
|
|
20
|
+
const userData = await page.evaluate(() => {
|
|
21
|
+
const result = {};
|
|
22
|
+
const m = window.location.href.match(/\/@([^/]+)\/video/);
|
|
23
|
+
if (m) result.uniqueId = m[1];
|
|
24
|
+
const authorEls = document.querySelectorAll('[class*="Author"]');
|
|
25
|
+
for (const el of authorEls) {
|
|
26
|
+
const text = (el.textContent || '').trim();
|
|
27
|
+
if (text && !text.includes('TikTok') && !text.includes('Share')) {
|
|
28
|
+
result.nickname = text;
|
|
29
|
+
break;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
const html = document.documentElement.outerHTML;
|
|
33
|
+
const locMatch = html.match(/"locationCreated":"([^"]*)/);
|
|
34
|
+
if (locMatch) result.locationCreated = locMatch[1];
|
|
35
|
+
return result;
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
const videoAuthor = userData.uniqueId ? '@' + userData.uniqueId : null;
|
|
39
|
+
if (!videoAuthor) throw new Error('无法获取视频作者');
|
|
40
|
+
|
|
41
|
+
let guessVideos = [];
|
|
42
|
+
let commentUsers = [];
|
|
43
|
+
|
|
44
|
+
if (userData.locationCreated === location) {
|
|
45
|
+
if (maxGuess > 0) {
|
|
46
|
+
guessVideos = await extractGuessVideos(page, maxGuess);
|
|
47
|
+
}
|
|
48
|
+
if (maxComments > 0) {
|
|
49
|
+
commentUsers = await extractCommentAuthors(page, maxComments);
|
|
50
|
+
}
|
|
51
|
+
await closeCommentPanel(page);
|
|
52
|
+
if (maxGuess > 0 || maxComments > 0) {
|
|
53
|
+
await delay(Math.round(config.commentMax * 0.3), config.commentMax);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return {
|
|
58
|
+
videoAuthor,
|
|
59
|
+
uniqueId: userData.uniqueId,
|
|
60
|
+
nickname: userData.nickname,
|
|
61
|
+
locationCreated: userData.locationCreated,
|
|
62
|
+
commentUsers: [...new Set(commentUsers)],
|
|
63
|
+
guessVideos,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async function runScrape(options) {
|
|
68
|
+
const {
|
|
69
|
+
videoUrl, maxVideos = 20, maxComments = 999, maxGuess = 10,
|
|
70
|
+
preset = null, switchMax = null, commentMax = null,
|
|
71
|
+
log = console.error,
|
|
72
|
+
browser: externalBrowser = null, page: externalPage = null,
|
|
73
|
+
} = options;
|
|
74
|
+
|
|
75
|
+
if (preset) {
|
|
76
|
+
setDelayConfig(preset);
|
|
77
|
+
} else if (switchMax || commentMax) {
|
|
78
|
+
setDelayConfig({ switchMax: switchMax || 5000, commentMax: commentMax || 3000 });
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const config = getDelayConfig();
|
|
82
|
+
let browser, page;
|
|
83
|
+
const isExternal = !!(externalBrowser && externalPage);
|
|
84
|
+
|
|
85
|
+
if (!isExternal) {
|
|
86
|
+
log(`视频地址: ${videoUrl}`);
|
|
87
|
+
log(`视频数: ${maxVideos}, 评论数: ${maxComments}, 猜你喜欢: ${maxGuess}, 切换延迟: ${config.switchMax}ms, 评论延迟: ${config.commentMax}ms`);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (isExternal) {
|
|
91
|
+
browser = externalBrowser;
|
|
92
|
+
page = externalPage;
|
|
93
|
+
} else {
|
|
94
|
+
browser = await ensureBrowserReady();
|
|
95
|
+
try {
|
|
96
|
+
page = await ensureTikTokPage(browser, videoUrl);
|
|
97
|
+
} catch (e) {
|
|
98
|
+
await browser.close().catch(() => {});
|
|
99
|
+
throw e;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
await retryWithBackoff(() => page.goto(videoUrl, { waitUntil: 'load', timeout: 30000 }), { log });
|
|
104
|
+
assertPageUrl(page, videoUrl.split('/video/')[0]);
|
|
105
|
+
await delay(Math.round(config.switchMax * 0.5), config.switchMax);
|
|
106
|
+
await closeCommentPanel(page);
|
|
107
|
+
await delay(Math.round(config.commentMax * 0.5), config.commentMax);
|
|
108
|
+
|
|
109
|
+
const allResults = [];
|
|
110
|
+
const videoAuthors = new Set();
|
|
111
|
+
const commentUsers = new Set();
|
|
112
|
+
const allCommentAuthorsList = [];
|
|
113
|
+
const allGuessAuthors = new Set();
|
|
114
|
+
const allGuessVideos = [];
|
|
115
|
+
|
|
116
|
+
for (let i = 0; i < maxVideos; i++) {
|
|
117
|
+
await delay(Math.round(config.commentMax * 0.3), config.commentMax);
|
|
118
|
+
|
|
119
|
+
let result;
|
|
120
|
+
try {
|
|
121
|
+
result = await scrapeSingleVideo(page, maxComments, maxGuess, log);
|
|
122
|
+
} catch (e) {
|
|
123
|
+
log(`[${i + 1}/${maxVideos}] 跳过: ${e.message}`);
|
|
124
|
+
if (i < maxVideos - 1) {
|
|
125
|
+
await page.evaluate(() => {
|
|
126
|
+
const container = document.querySelector('[class*="ColumnListContainer"]');
|
|
127
|
+
if (container) container.scrollTop += 700;
|
|
128
|
+
else window.scrollBy(0, 700);
|
|
129
|
+
});
|
|
130
|
+
await delay(Math.round(config.switchMax * 0.5), config.switchMax);
|
|
131
|
+
}
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
allResults.push(result);
|
|
136
|
+
videoAuthors.add(result.videoAuthor);
|
|
137
|
+
result.commentUsers.forEach(u => commentUsers.add(u));
|
|
138
|
+
allCommentAuthorsList.push(...result.commentUsers);
|
|
139
|
+
if (result.guessVideos) {
|
|
140
|
+
allGuessVideos.push(...result.guessVideos);
|
|
141
|
+
result.guessVideos.forEach(v => { if (v.author) allGuessAuthors.add(v.author); });
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
if ((i + 1) % 5 === 0 || i === 0) {
|
|
145
|
+
log(`[${i + 1}/${maxVideos}] ${result.videoAuthor} | 昵称: ${result.nickname || '-'} | 评论用户: ${result.commentUsers.length} | 猜你喜欢: ${result.guessVideos ? result.guessVideos.length : 0}`);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
if (i < maxVideos - 1) {
|
|
149
|
+
await page.evaluate(() => {
|
|
150
|
+
const container = document.querySelector('[class*="ColumnListContainer"]');
|
|
151
|
+
if (container) container.scrollTop += 700;
|
|
152
|
+
});
|
|
153
|
+
await delay(2000, config.switchMax);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
log(`\n结果: 视频作者 ${videoAuthors.size} | 评论用户 ${commentUsers.size} | 总评论 ${allCommentAuthorsList.length} | 猜你喜欢作者 ${allGuessAuthors.size} | 总猜中视频 ${allGuessVideos.length}`);
|
|
158
|
+
|
|
159
|
+
const videoDetails = {};
|
|
160
|
+
for (const r of allResults) {
|
|
161
|
+
const key = r.videoAuthor;
|
|
162
|
+
if (!videoDetails[key]) {
|
|
163
|
+
videoDetails[key] = {
|
|
164
|
+
videoAuthor: r.videoAuthor,
|
|
165
|
+
uniqueId: r.uniqueId,
|
|
166
|
+
nickname: r.nickname,
|
|
167
|
+
locationCreated: r.locationCreated,
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const output = {
|
|
173
|
+
videoDetails: Object.values(videoDetails),
|
|
174
|
+
commentUsers: [...commentUsers].sort(),
|
|
175
|
+
allCommentAuthorsList,
|
|
176
|
+
guessVideos: allGuessVideos,
|
|
177
|
+
guessAuthors: [...allGuessAuthors].sort(),
|
|
178
|
+
stats: {
|
|
179
|
+
totalVideos: allResults.length,
|
|
180
|
+
uniqueVideoAuthors: videoAuthors.size,
|
|
181
|
+
uniqueCommentAuthors: commentUsers.size,
|
|
182
|
+
uniqueGuessAuthors: allGuessAuthors.size,
|
|
183
|
+
totalGuessVideos: allGuessVideos.length,
|
|
184
|
+
},
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
return { output, browser, isExternal };
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export { scrapeSingleVideo, runScrape };
|