tt-help-cli-ycl 1.3.1 → 1.3.2

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 (48) hide show
  1. package/README.md +17 -17
  2. package/cli.js +9 -9
  3. package/package.json +44 -44
  4. package/src/cli/auto.js +1 -1
  5. package/src/cli/explore.js +1 -1
  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 +28 -28
  11. package/src/lib/args.js +385 -377
  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 +80 -62
  16. package/src/lib/constants.js +84 -85
  17. package/src/lib/delay.js +54 -54
  18. package/src/lib/{explore.js → 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/output.js +80 -80
  23. package/src/lib/parser.js +47 -47
  24. package/src/lib/retry.js +44 -44
  25. package/src/lib/scrape.js +40 -40
  26. package/src/lib/url.js +52 -52
  27. package/src/main.mjs +200 -200
  28. package/src/results/user-videos-bar.lar.lar.moeta.json +37 -0
  29. package/src/{auto-core.mjs → scraper/auto-core.mjs} +183 -174
  30. package/src/scraper/core.mjs +188 -182
  31. package/src/{explore-core.mjs → scraper/explore-core.mjs} +159 -148
  32. package/src/scraper/modules/captcha-handler.mjs +114 -0
  33. package/src/scraper/modules/comment-extractor.mjs +69 -57
  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 -68
  37. package/src/scraper/modules/page-helpers.mjs +46 -44
  38. package/src/scraper/modules/scroll-collector.mjs +189 -189
  39. package/src/{get-user-videos-core.mjs → videos/core.mjs} +126 -126
  40. package/src/{data-store.mjs → watch/data-store.mjs} +29 -3
  41. package/src/watch/public/index.html +444 -344
  42. package/src/watch/server.mjs +24 -1
  43. package/src/lib/auto-browser.mjs +0 -6
  44. package/src/lib/get-user-videos-browser.mjs +0 -1
  45. package/src/lib/scrape-browser.mjs +0 -1
  46. package/src/test-auto-follow.cjs +0 -109
  47. package/src/test-extractors.cjs +0 -75
  48. package/src/test-follow.cjs +0 -41
package/README.md CHANGED
@@ -1,17 +1,17 @@
1
- # tt-help
2
-
3
- TikTok user & video data scraper — extract ttSeller, verified, locationCreated from HTML source.
4
-
5
- ## Install
6
-
7
- ```bash
8
- npm i -g tt-help
9
- ```
10
-
11
- ## Usage
12
-
13
- ```bash
14
- tt-help [options] <urls...>
15
- ```
16
-
17
- 示例、代理配置、和更多用法请查看仓库或 `src/main.mjs` 中的帮助文本。
1
+ # tt-help
2
+
3
+ TikTok user & video data scraper — extract ttSeller, verified, locationCreated from HTML source.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm i -g tt-help
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```bash
14
+ tt-help [options] <urls...>
15
+ ```
16
+
17
+ 示例、代理配置、和更多用法请查看仓库或 `src/main.mjs` 中的帮助文本。
package/cli.js CHANGED
@@ -1,9 +1,9 @@
1
- #!/usr/bin/env node
2
- import { fileURLToPath } from 'url';
3
- import { dirname, resolve } from 'path';
4
-
5
- const __filename = fileURLToPath(import.meta.url);
6
- const __dirname = dirname(__filename);
7
-
8
- const mainPath = resolve(__dirname, 'src', 'main.mjs');
9
- await import(`file://${mainPath}`);
1
+ #!/usr/bin/env node
2
+ import { fileURLToPath } from 'url';
3
+ import { dirname, resolve } from 'path';
4
+
5
+ const __filename = fileURLToPath(import.meta.url);
6
+ const __dirname = dirname(__filename);
7
+
8
+ const mainPath = resolve(__dirname, 'src', 'main.mjs');
9
+ await import(`file://${mainPath}`);
package/package.json CHANGED
@@ -1,44 +1,44 @@
1
- {
2
- "name": "tt-help-cli-ycl",
3
- "version": "1.3.1",
4
- "description": "TikTok user & video data scraper - extract ttSeller, verified, locationCreated from HTML source",
5
- "type": "module",
6
- "bin": {
7
- "tt-help": "cli.js"
8
- },
9
- "main": "src/main.mjs",
10
- "files": [
11
- "cli.js",
12
- "src/"
13
- ],
14
- "scripts": {
15
- "start": "node src/main.mjs"
16
- },
17
- "keywords": [
18
- "tiktok",
19
- "scraper",
20
- "cli",
21
- "seller",
22
- "ttSeller"
23
- ],
24
- "author": "jsjhycl",
25
- "license": "ISC",
26
- "engines": {
27
- "node": ">=18"
28
- },
29
- "publishConfig": {
30
- "access": "public"
31
- },
32
- "repository": {
33
- "type": "git",
34
- "url": "git+https://github.com/jsjhycl/tt-help-cli.git"
35
- },
36
- "bugs": {
37
- "url": "https://github.com/jsjhycl/tt-help-cli/issues"
38
- },
39
- "homepage": "https://github.com/jsjhycl/tt-help-cli#readme",
40
- "dependencies": {
41
- "playwright": "^1.59.1",
42
- "undici": "^8.1.0"
43
- }
44
- }
1
+ {
2
+ "name": "tt-help-cli-ycl",
3
+ "version": "1.3.2",
4
+ "description": "TikTok user & video data scraper - extract ttSeller, verified, locationCreated from HTML source",
5
+ "type": "module",
6
+ "bin": {
7
+ "tt-help": "cli.js"
8
+ },
9
+ "main": "src/main.mjs",
10
+ "files": [
11
+ "cli.js",
12
+ "src/"
13
+ ],
14
+ "scripts": {
15
+ "start": "node src/main.mjs"
16
+ },
17
+ "keywords": [
18
+ "tiktok",
19
+ "scraper",
20
+ "cli",
21
+ "seller",
22
+ "ttSeller"
23
+ ],
24
+ "author": "jsjhycl",
25
+ "license": "ISC",
26
+ "engines": {
27
+ "node": ">=18"
28
+ },
29
+ "publishConfig": {
30
+ "access": "public"
31
+ },
32
+ "repository": {
33
+ "type": "git",
34
+ "url": "git+https://github.com/jsjhycl/tt-help-cli.git"
35
+ },
36
+ "bugs": {
37
+ "url": "https://github.com/jsjhycl/tt-help-cli/issues"
38
+ },
39
+ "homepage": "https://github.com/jsjhycl/tt-help-cli#readme",
40
+ "dependencies": {
41
+ "playwright": "^1.59.1",
42
+ "undici": "^8.1.0"
43
+ }
44
+ }
package/src/cli/auto.js CHANGED
@@ -45,7 +45,7 @@ export async function handleAuto(options) {
45
45
  console.error(`种子用户: ${added} 个新增, ${skipped} 个已存在`);
46
46
  }
47
47
 
48
- const { ensureBrowserReady, processUser } = await import('../lib/auto-browser.mjs');
48
+ const { ensureBrowserReady, processUser } = await import('../scraper/auto-core.mjs');
49
49
  const browser = await ensureBrowserReady();
50
50
 
51
51
  try {
@@ -42,7 +42,7 @@ export async function handleExplore(options) {
42
42
  console.error(`关注/粉丝: ${exploreEnableFollow ? '启用' : '禁用'}`);
43
43
  if (exploreMaxUsers > 0) console.error(`上限: ${exploreMaxUsers} 个用户`);
44
44
 
45
- const { ensureBrowserReady, processExplore } = await import('../lib/auto-browser.mjs');
45
+ const { ensureBrowserReady, processExplore } = await import('../scraper/explore-core.mjs');
46
46
  const browser = await ensureBrowserReady();
47
47
 
48
48
  try {
@@ -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('../lib/scrape-browser.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('../lib/get-user-videos-browser.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,28 @@
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 { 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
+ }