tt-help-cli-ycl 1.3.5 → 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 -94
  5. package/src/cli/explore.js +147 -116
  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 -28
  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 -80
  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 -183
  30. package/src/scraper/core.mjs +190 -188
  31. package/src/scraper/explore-core.mjs +162 -159
  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 -46
  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 -239
  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,111 +1,111 @@
1
- import { writeFileSync } from 'fs';
2
- import { formatOutput } from '../lib/output.js';
3
- import { deduplicate } from '../lib/output.js';
4
- import { applyFilter, formatFilterDescription } from '../lib/filter.js';
5
- import { calculateConcurrency, createMultiProgressBars, renderMultiProgressBars, clearProgressBars } from '../lib/io.js';
6
- import { randomDelay } from '../lib/delay.js';
7
-
8
- export async function processUrlsWithProgress({
9
- urls,
10
- proxyUrl,
11
- outputFile,
12
- outputFormat,
13
- filter,
14
- processFn,
15
- label = '数据',
16
- }) {
17
- const allResults = [];
18
- const errors = [];
19
-
20
- if (urls.length === 0) {
21
- console.error('\n未获取到数据');
22
- if (outputFile) writeFileSync(outputFile, '[]', 'utf-8');
23
- return;
24
- }
25
-
26
- const concurrency = calculateConcurrency(urls.length);
27
- const bars = createMultiProgressBars(concurrency);
28
-
29
- const slots = Array.from({ length: concurrency }, () => []);
30
- urls.forEach((url, i) => slots[i % concurrency].push(url));
31
-
32
- bars.forEach((bar, i) => {
33
- bar.total = slots[i].length;
34
- bar.status = slots[i].length > 0 ? 'running' : 'done';
35
- });
36
-
37
- renderMultiProgressBars(bars);
38
-
39
- const workers = slots.map(async (slotUrls, slotIndex) => {
40
- for (const url of slotUrls) {
41
- bars[slotIndex].url = url;
42
- renderMultiProgressBars(bars);
43
-
44
- await randomDelay();
45
-
46
- try {
47
- const results = await processFn(url, proxyUrl);
48
- allResults.push(...results);
49
- bars[slotIndex].current++;
50
- bars[slotIndex].status = 'running';
51
- } catch (err) {
52
- errors.push({ url, message: err.message });
53
- bars[slotIndex].current++;
54
- bars[slotIndex].status = 'error';
55
- }
56
-
57
- renderMultiProgressBars(bars);
58
- }
59
- bars[slotIndex].status = bars[slotIndex].current === bars[slotIndex].total ? 'done' : 'error';
60
- renderMultiProgressBars(bars);
61
- });
62
-
63
- await Promise.all(workers);
64
- clearProgressBars();
65
-
66
- const uniqueResults = deduplicate(allResults);
67
- const filteredResults = applyFilter(uniqueResults, filter);
68
-
69
- if (errors.length > 0) {
70
- const firstMsg = errors[0].message;
71
- const isProxyError = ['不可用', '连接被拒绝', '连接中断', '超时', '无法解析']
72
- .some(kw => firstMsg.includes(kw));
73
-
74
- if (filteredResults.length === 0) {
75
- if (isProxyError) {
76
- console.error(` 所有请求失败,请检查代理: ${proxyUrl}\n`);
77
- } else {
78
- const show = errors.slice(0, 5);
79
- for (const e of show) console.error(` ✗ ${e.url}: ${e.message}\n`);
80
- if (errors.length > 5) console.error(` ... 还有 ${errors.length - 5} 个失败\n`);
81
- }
82
- console.error('未获取到数据');
83
- if (outputFile) writeFileSync(outputFile, '[]', 'utf-8');
84
- return;
85
- } else {
86
- if (isProxyError) {
87
- console.error(` ${errors.length} 个请求失败,请检查代理: ${proxyUrl}\n`);
88
- } else {
89
- console.error(` ${errors.length} 个失败:`);
90
- const show = errors.slice(0, 5);
91
- for (const e of show) console.error(` ✗ ${e.url}: ${e.message}`);
92
- if (errors.length > 5) console.error(` ... 还有 ${errors.length - 5} 个`);
93
- }
94
- }
95
- }
96
-
97
- const output = formatOutput(filteredResults, outputFormat);
98
-
99
- if (outputFile) {
100
- writeFileSync(outputFile, output, 'utf-8');
101
- console.log(`\n结果已写入: ${outputFile}`);
102
- } else {
103
- process.stdout.write(output + '\n');
104
- }
105
-
106
- if (filter) {
107
- console.log(`\n共 ${uniqueResults.length} 个${label},过滤后 ${filteredResults.length} 个(过滤条件: ${formatFilterDescription(filter)})`);
108
- } else {
109
- console.log(`\n共 ${filteredResults.length} 个${label}`);
110
- }
111
- }
1
+ import { writeFileSync } from 'fs';
2
+ import { formatOutput } from '../lib/output.js';
3
+ import { deduplicate } from '../lib/output.js';
4
+ import { applyFilter, formatFilterDescription } from '../lib/filter.js';
5
+ import { calculateConcurrency, createMultiProgressBars, renderMultiProgressBars, clearProgressBars } from '../lib/io.js';
6
+ import { randomDelay } from '../lib/delay.js';
7
+
8
+ export async function processUrlsWithProgress({
9
+ urls,
10
+ proxyUrl,
11
+ outputFile,
12
+ outputFormat,
13
+ filter,
14
+ processFn,
15
+ label = '数据',
16
+ }) {
17
+ const allResults = [];
18
+ const errors = [];
19
+
20
+ if (urls.length === 0) {
21
+ console.error('\n未获取到数据');
22
+ if (outputFile) writeFileSync(outputFile, '[]', 'utf-8');
23
+ return;
24
+ }
25
+
26
+ const concurrency = calculateConcurrency(urls.length);
27
+ const bars = createMultiProgressBars(concurrency);
28
+
29
+ const slots = Array.from({ length: concurrency }, () => []);
30
+ urls.forEach((url, i) => slots[i % concurrency].push(url));
31
+
32
+ bars.forEach((bar, i) => {
33
+ bar.total = slots[i].length;
34
+ bar.status = slots[i].length > 0 ? 'running' : 'done';
35
+ });
36
+
37
+ renderMultiProgressBars(bars);
38
+
39
+ const workers = slots.map(async (slotUrls, slotIndex) => {
40
+ for (const url of slotUrls) {
41
+ bars[slotIndex].url = url;
42
+ renderMultiProgressBars(bars);
43
+
44
+ await randomDelay();
45
+
46
+ try {
47
+ const results = await processFn(url, proxyUrl);
48
+ allResults.push(...results);
49
+ bars[slotIndex].current++;
50
+ bars[slotIndex].status = 'running';
51
+ } catch (err) {
52
+ errors.push({ url, message: err.message });
53
+ bars[slotIndex].current++;
54
+ bars[slotIndex].status = 'error';
55
+ }
56
+
57
+ renderMultiProgressBars(bars);
58
+ }
59
+ bars[slotIndex].status = bars[slotIndex].current === bars[slotIndex].total ? 'done' : 'error';
60
+ renderMultiProgressBars(bars);
61
+ });
62
+
63
+ await Promise.all(workers);
64
+ clearProgressBars();
65
+
66
+ const uniqueResults = deduplicate(allResults);
67
+ const filteredResults = applyFilter(uniqueResults, filter);
68
+
69
+ if (errors.length > 0) {
70
+ const firstMsg = errors[0].message;
71
+ const isProxyError = ['不可用', '连接被拒绝', '连接中断', '超时', '无法解析']
72
+ .some(kw => firstMsg.includes(kw));
73
+
74
+ if (filteredResults.length === 0) {
75
+ if (isProxyError) {
76
+ console.error(` 所有请求失败,请检查代理: ${proxyUrl}\n`);
77
+ } else {
78
+ const show = errors.slice(0, 5);
79
+ for (const e of show) console.error(` ✗ ${e.url}: ${e.message}\n`);
80
+ if (errors.length > 5) console.error(` ... 还有 ${errors.length - 5} 个失败\n`);
81
+ }
82
+ console.error('未获取到数据');
83
+ if (outputFile) writeFileSync(outputFile, '[]', 'utf-8');
84
+ return;
85
+ } else {
86
+ if (isProxyError) {
87
+ console.error(` ${errors.length} 个请求失败,请检查代理: ${proxyUrl}\n`);
88
+ } else {
89
+ console.error(` ${errors.length} 个失败:`);
90
+ const show = errors.slice(0, 5);
91
+ for (const e of show) console.error(` ✗ ${e.url}: ${e.message}`);
92
+ if (errors.length > 5) console.error(` ... 还有 ${errors.length - 5} 个`);
93
+ }
94
+ }
95
+ }
96
+
97
+ const output = formatOutput(filteredResults, outputFormat);
98
+
99
+ if (outputFile) {
100
+ writeFileSync(outputFile, output, 'utf-8');
101
+ console.log(`\n结果已写入: ${outputFile}`);
102
+ } else {
103
+ process.stdout.write(output + '\n');
104
+ }
105
+
106
+ if (filter) {
107
+ console.log(`\n共 ${uniqueResults.length} 个${label},过滤后 ${filteredResults.length} 个(过滤条件: ${formatFilterDescription(filter)})`);
108
+ } else {
109
+ console.log(`\n共 ${filteredResults.length} 个${label}`);
110
+ }
111
+ }
package/src/cli/scrape.js CHANGED
@@ -1,47 +1,47 @@
1
- import { writeFileSync } from 'fs';
2
-
3
- export async function handleScrape(options) {
4
- const { scrapeUrl, scrapePreset, scrapeMaxVideos, scrapeMaxComments, scrapeMaxGuess, scrapeSwitchDelay, scrapeCommentDelay, outputFile } = options;
5
-
6
- if (!scrapeUrl) {
7
- console.error('用法: tt-help scrape <视频URL> [preset] [最大视频数] [最大评论数] [-o 输出路径]');
8
- console.error('预设: fast, normal, slow, stealth');
9
- console.error('选项: -o, --output <路径> 输出到文件(默认输出到 stdout)');
10
- console.error(' --switch-delay <ms> 视频切换延迟(毫秒)');
11
- console.error(' --comment-delay <ms> 评论滚动延迟(毫秒)');
12
- process.exit(1);
13
- }
14
-
15
- const { runScrape } = await import('../scraper/core.mjs');
16
-
17
- let browser;
18
- try {
19
- const { output, browser: b } = await runScrape({
20
- videoUrl: scrapeUrl,
21
- maxVideos: scrapeMaxVideos,
22
- maxComments: scrapeMaxComments,
23
- maxGuess: scrapeMaxGuess,
24
- preset: scrapePreset,
25
- switchMax: scrapeSwitchDelay,
26
- commentMax: scrapeCommentDelay,
27
- log: console.error,
28
- });
29
- browser = b;
30
-
31
- const json = JSON.stringify(output, null, 2);
32
- if (outputFile) {
33
- writeFileSync(outputFile, json, 'utf-8');
34
- console.error(`结果已写入: ${outputFile}`);
35
- } else {
36
- process.stdout.write(json + '\n');
37
- }
38
-
39
- const stats = output.stats;
40
- console.error(`\n共 ${stats.totalVideos} 个视频, ${stats.uniqueVideoAuthors} 个视频作者, ${stats.uniqueCommentAuthors} 个评论作者, ${stats.uniqueGuessAuthors} 个猜你喜欢作者`);
41
- } catch (err) {
42
- console.error(`浏览器抓取失败: ${err.message}`);
43
- process.exit(1);
44
- } finally {
45
- if (browser) await browser.close().catch(() => {});
46
- }
47
- }
1
+ import { writeFileSync } from 'fs';
2
+
3
+ export async function handleScrape(options) {
4
+ const { scrapeUrl, scrapePreset, scrapeMaxVideos, scrapeMaxComments, scrapeMaxGuess, scrapeSwitchDelay, scrapeCommentDelay, outputFile } = options;
5
+
6
+ if (!scrapeUrl) {
7
+ console.error('用法: tt-help scrape <视频URL> [preset] [最大视频数] [最大评论数] [-o 输出路径]');
8
+ console.error('预设: fast, normal, slow, stealth');
9
+ console.error('选项: -o, --output <路径> 输出到文件(默认输出到 stdout)');
10
+ console.error(' --switch-delay <ms> 视频切换延迟(毫秒)');
11
+ console.error(' --comment-delay <ms> 评论滚动延迟(毫秒)');
12
+ process.exit(1);
13
+ }
14
+
15
+ const { runScrape } = await import('../scraper/core.mjs');
16
+
17
+ let browser;
18
+ try {
19
+ const { output, browser: b } = await runScrape({
20
+ videoUrl: scrapeUrl,
21
+ maxVideos: scrapeMaxVideos,
22
+ maxComments: scrapeMaxComments,
23
+ maxGuess: scrapeMaxGuess,
24
+ preset: scrapePreset,
25
+ switchMax: scrapeSwitchDelay,
26
+ commentMax: scrapeCommentDelay,
27
+ log: console.error,
28
+ });
29
+ browser = b;
30
+
31
+ const json = JSON.stringify(output, null, 2);
32
+ if (outputFile) {
33
+ writeFileSync(outputFile, json, 'utf-8');
34
+ console.error(`结果已写入: ${outputFile}`);
35
+ } else {
36
+ process.stdout.write(json + '\n');
37
+ }
38
+
39
+ const stats = output.stats;
40
+ console.error(`\n共 ${stats.totalVideos} 个视频, ${stats.uniqueVideoAuthors} 个视频作者, ${stats.uniqueCommentAuthors} 个评论作者, ${stats.uniqueGuessAuthors} 个猜你喜欢作者`);
41
+ } catch (err) {
42
+ console.error(`浏览器抓取失败: ${err.message}`);
43
+ process.exit(1);
44
+ } finally {
45
+ if (browser) await browser.close().catch(() => {});
46
+ }
47
+ }
package/src/cli/utils.js CHANGED
@@ -1,18 +1,18 @@
1
- import { writeFileSync } from 'fs';
2
-
3
- export function cleanError(msg) {
4
- return msg
5
- .replace(/\x1b\[[0-9;]*m/g, '')
6
- .replace(/\s*- navigating to.*/s, '')
7
- .replace(/\s*Call log:/s, '')
8
- .trim();
9
- }
10
-
11
- export function writeJson(data, outputFile) {
12
- const json = JSON.stringify(data, null, 2);
13
- if (outputFile) {
14
- writeFileSync(outputFile, json, 'utf-8');
15
- } else {
16
- process.stdout.write(json + '\n');
17
- }
18
- }
1
+ import { writeFileSync } from 'fs';
2
+
3
+ export function cleanError(msg) {
4
+ return msg
5
+ .replace(/\x1b\[[0-9;]*m/g, '')
6
+ .replace(/\s*- navigating to.*/s, '')
7
+ .replace(/\s*Call log:/s, '')
8
+ .trim();
9
+ }
10
+
11
+ export function writeJson(data, outputFile) {
12
+ const json = JSON.stringify(data, null, 2);
13
+ if (outputFile) {
14
+ writeFileSync(outputFile, json, 'utf-8');
15
+ } else {
16
+ process.stdout.write(json + '\n');
17
+ }
18
+ }
package/src/cli/videos.js CHANGED
@@ -1,41 +1,41 @@
1
- import { writeFileSync } from 'fs';
2
-
3
- export async function handleVideos(options) {
4
- const { videosUsername, videosMax, outputFile } = options;
5
-
6
- if (!videosUsername) {
7
- console.error('用法: tt-help videos <用户名> [最大视频数] [-o 输出路径]');
8
- console.error('示例: tt-help videos bar.lar.lar.moeta 1000');
9
- console.error(' tt-help videos username 50 -o videos.json');
10
- console.error('');
11
- console.error('选项: -o, --output <路径> 输出到文件(默认输出到 stdout)');
12
- process.exit(1);
13
- }
14
-
15
- const { runGetUserVideos } = await import('../videos/core.mjs');
16
-
17
- let browser;
18
- try {
19
- const { output, browser: b } = await runGetUserVideos({
20
- username: videosUsername,
21
- maxVideos: videosMax,
22
- log: console.error,
23
- });
24
- browser = b;
25
-
26
- const json = JSON.stringify(output, null, 2);
27
- if (outputFile) {
28
- writeFileSync(outputFile, json, 'utf-8');
29
- console.error(`结果已写入: ${outputFile}`);
30
- } else {
31
- process.stdout.write(json + '\n');
32
- }
33
-
34
- console.error(`\n共 ${output.videos.length} 个视频, 用户: @${videosUsername}`);
35
- } catch (err) {
36
- console.error(`获取用户视频失败: ${err.message}`);
37
- process.exit(1);
38
- } finally {
39
- if (browser) await browser.close().catch(() => {});
40
- }
41
- }
1
+ import { writeFileSync } from 'fs';
2
+
3
+ export async function handleVideos(options) {
4
+ const { videosUsername, videosMax, outputFile } = options;
5
+
6
+ if (!videosUsername) {
7
+ console.error('用法: tt-help videos <用户名> [最大视频数] [-o 输出路径]');
8
+ console.error('示例: tt-help videos bar.lar.lar.moeta 1000');
9
+ console.error(' tt-help videos username 50 -o videos.json');
10
+ console.error('');
11
+ console.error('选项: -o, --output <路径> 输出到文件(默认输出到 stdout)');
12
+ process.exit(1);
13
+ }
14
+
15
+ const { runGetUserVideos } = await import('../videos/core.mjs');
16
+
17
+ let browser;
18
+ try {
19
+ const { output, browser: b } = await runGetUserVideos({
20
+ username: videosUsername,
21
+ maxVideos: videosMax,
22
+ log: console.error,
23
+ });
24
+ browser = b;
25
+
26
+ const json = JSON.stringify(output, null, 2);
27
+ if (outputFile) {
28
+ writeFileSync(outputFile, json, 'utf-8');
29
+ console.error(`结果已写入: ${outputFile}`);
30
+ } else {
31
+ process.stdout.write(json + '\n');
32
+ }
33
+
34
+ console.error(`\n共 ${output.videos.length} 个视频, 用户: @${videosUsername}`);
35
+ } catch (err) {
36
+ console.error(`获取用户视频失败: ${err.message}`);
37
+ process.exit(1);
38
+ } finally {
39
+ if (browser) await browser.close().catch(() => {});
40
+ }
41
+ }
package/src/cli/watch.js CHANGED
@@ -1,28 +1,31 @@
1
- import { writeFileSync, existsSync } from 'fs';
2
- import { startWatchServer, openBrowser } from '../watch/server.mjs';
3
-
4
- export async function handleWatch(options) {
5
- const { outputFile, watchPort } = options;
6
-
7
- if (!outputFile) {
8
- console.error('用法: tt-help watch -o <数据文件> [-p 端口]');
9
- console.error('示例: tt-help watch -o data.json');
10
- console.error(' tt-help watch -o data.json -p 8080');
11
- process.exit(1);
12
- }
13
-
14
- if (!existsSync(outputFile)) {
15
- console.error(`文件不存在: ${outputFile}`);
16
- process.exit(1);
17
- }
18
-
19
- const { server, port } = await startWatchServer(outputFile, watchPort);
20
- openBrowser(port);
21
-
22
- process.once('SIGINT', () => {
23
- server.close();
24
- process.exit(0);
25
- });
26
-
27
- console.error('按 Ctrl+C 停止监控服务');
28
- }
1
+ import { existsSync } from 'fs';
2
+ import { createStore } from '../watch/data-store.mjs';
3
+ import { startWatchServer, openBrowser } from '../watch/server.mjs';
4
+
5
+ export async function handleWatch(options) {
6
+ const { outputFile, watchPort } = options;
7
+
8
+ if (!outputFile) {
9
+ console.error('用法: tt-help watch -o <数据文件> [-p 端口]');
10
+ console.error('示例: tt-help watch -o data.json');
11
+ console.error(' tt-help watch -o data.json -p 8080');
12
+ process.exit(1);
13
+ }
14
+
15
+ if (!existsSync(outputFile)) {
16
+ console.error(`文件不存在: ${outputFile}`);
17
+ process.exit(1);
18
+ }
19
+
20
+ const store = createStore(outputFile);
21
+ const { server, port } = await startWatchServer(outputFile, watchPort, store);
22
+ openBrowser(port);
23
+
24
+ process.once('SIGINT', () => {
25
+ store.stopBackup();
26
+ server.close();
27
+ process.exit(0);
28
+ });
29
+
30
+ console.error('按 Ctrl+C 停止监控服务');
31
+ }