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.
- package/README.md +17 -17
- package/cli.js +9 -9
- package/package.json +45 -45
- package/src/cli/auto.js +131 -94
- package/src/cli/explore.js +147 -116
- 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 -28
- 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 -80
- 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 -183
- package/src/scraper/core.mjs +190 -188
- package/src/scraper/explore-core.mjs +162 -159
- 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 -46
- 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 -239
- package/src/watch/public/index.html +466 -465
- package/src/watch/server.mjs +291 -281
- package/src/results/user-videos-bar.lar.lar.moeta.json +0 -37
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,45 +1,45 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "tt-help-cli-ycl",
|
|
3
|
-
"version": "1.3.
|
|
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
|
-
"tt-help-cli-ycl": "^1.3.2",
|
|
43
|
-
"undici": "^8.1.0"
|
|
44
|
-
}
|
|
45
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "tt-help-cli-ycl",
|
|
3
|
+
"version": "1.3.7",
|
|
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
|
+
"tt-help-cli-ycl": "^1.3.2",
|
|
43
|
+
"undici": "^8.1.0"
|
|
44
|
+
}
|
|
45
|
+
}
|
package/src/cli/auto.js
CHANGED
|
@@ -1,94 +1,131 @@
|
|
|
1
|
-
import { getOrCreatePage } from '../lib/browser/page.js';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
1
|
+
import { getOrCreatePage } from '../lib/browser/page.js';
|
|
2
|
+
import { userId as configuredUserId, saveUserId } from '../lib/constants.js';
|
|
3
|
+
import { getMacOrUuid } from '../lib/mac-or-uuid.js';
|
|
4
|
+
|
|
5
|
+
const MAX_RETRY_WAIT = 5 * 60 * 1000;
|
|
6
|
+
|
|
7
|
+
async function withRetry(label, fn) {
|
|
8
|
+
let backoff = 1000;
|
|
9
|
+
while (true) {
|
|
10
|
+
try {
|
|
11
|
+
return await fn();
|
|
12
|
+
} catch (err) {
|
|
13
|
+
console.error(`[连接] ${label} 失败: ${err.message},${backoff / 1000}秒后重试...`);
|
|
14
|
+
await new Promise(r => setTimeout(r, backoff));
|
|
15
|
+
if (backoff < MAX_RETRY_WAIT) backoff *= 2;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async function apiPost(url, body) {
|
|
21
|
+
return withRetry(`POST ${url}`, async () => {
|
|
22
|
+
const res = await fetch(url, {
|
|
23
|
+
method: 'POST',
|
|
24
|
+
headers: { 'Content-Type': 'application/json' },
|
|
25
|
+
body: JSON.stringify(body),
|
|
26
|
+
});
|
|
27
|
+
return res.json();
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async function apiGet(url) {
|
|
32
|
+
return withRetry(`GET ${url}`, async () => {
|
|
33
|
+
const res = await fetch(url);
|
|
34
|
+
return res.json();
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export async function handleAuto(options) {
|
|
39
|
+
const { autoUsernames, autoCollectMax, autoScrapeDepth, autoMaxComments, autoMaxGuess,
|
|
40
|
+
autoPreset, autoSwitchDelay, autoCommentDelay, serverUrl,
|
|
41
|
+
autoEnableFollow, autoMaxFollowing, autoMaxFollowers } = options;
|
|
42
|
+
|
|
43
|
+
let userId = configuredUserId;
|
|
44
|
+
if (!userId) {
|
|
45
|
+
userId = await getMacOrUuid();
|
|
46
|
+
saveUserId(userId);
|
|
47
|
+
console.error(`[初始化] 未检测到本地用户编号,已生成并使用: ${userId}`);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const runOptions = {
|
|
51
|
+
collectMax: autoCollectMax,
|
|
52
|
+
scrapeDepth: autoScrapeDepth,
|
|
53
|
+
maxComments: autoMaxComments,
|
|
54
|
+
maxGuess: autoMaxGuess,
|
|
55
|
+
preset: autoPreset,
|
|
56
|
+
switchMax: autoSwitchDelay,
|
|
57
|
+
commentMax: autoCommentDelay,
|
|
58
|
+
enableFollow: autoEnableFollow,
|
|
59
|
+
maxFollowing: autoMaxFollowing,
|
|
60
|
+
maxFollowers: autoMaxFollowers,
|
|
61
|
+
userId,
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
await apiGet(`${serverUrl}/api/stats`);
|
|
65
|
+
|
|
66
|
+
if (autoUsernames.length > 0) {
|
|
67
|
+
const { added, skipped } = await apiPost(`${serverUrl}/api/users`, { usernames: autoUsernames });
|
|
68
|
+
console.error(`种子用户: ${added} 个新增, ${skipped} 个已存在`);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
console.error(`服务器: ${serverUrl}(断开会自动重连)`);
|
|
72
|
+
|
|
73
|
+
const { ensureBrowserReady, processUser } = await import('../scraper/auto-core.mjs');
|
|
74
|
+
const browser = await ensureBrowserReady();
|
|
75
|
+
|
|
76
|
+
const page = await getOrCreatePage(browser);
|
|
77
|
+
|
|
78
|
+
let processedCount = 0;
|
|
79
|
+
let errorCount = 0;
|
|
80
|
+
|
|
81
|
+
while (true) {
|
|
82
|
+
const job = await apiGet(`${serverUrl}/api/job?userId=${encodeURIComponent(userId)}`);
|
|
83
|
+
if (!job.hasJob) break;
|
|
84
|
+
|
|
85
|
+
const username = job.user.uniqueId;
|
|
86
|
+
processedCount++;
|
|
87
|
+
let proxyRetry = 0;
|
|
88
|
+
|
|
89
|
+
while (true) {
|
|
90
|
+
console.error(`\n[${processedCount}] 处理 @${username}...${proxyRetry > 0 ? ` (代理重试 ${proxyRetry})` : ''}`);
|
|
91
|
+
|
|
92
|
+
const result = await processUser(page, username, { ...runOptions, browser }, console.error);
|
|
93
|
+
|
|
94
|
+
if (result.restricted) {
|
|
95
|
+
await apiPost(`${serverUrl}/api/job/${username}`, result);
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (result.error && result.error.includes('代理错误')) {
|
|
100
|
+
proxyRetry++;
|
|
101
|
+
console.error(` [代理错误] ${result.error},等待 10s 后重试...`);
|
|
102
|
+
await new Promise(r => setTimeout(r, 10000));
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (result.error) {
|
|
107
|
+
errorCount++;
|
|
108
|
+
await apiPost(`${serverUrl}/api/job/${username}`, result);
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const payload = {
|
|
113
|
+
userInfo: result.userInfo || {},
|
|
114
|
+
discoveredVideoAuthors: result.discoveredVideoAuthors || [],
|
|
115
|
+
discoveredCommentAuthors: result.discoveredCommentAuthors || [],
|
|
116
|
+
discoveredGuessAuthors: result.discoveredGuessAuthors || [],
|
|
117
|
+
discoveredFollowing: result.discoveredFollowing || [],
|
|
118
|
+
discoveredFollowers: result.discoveredFollowers || [],
|
|
119
|
+
};
|
|
120
|
+
await apiPost(`${serverUrl}/api/job/${username}`, payload);
|
|
121
|
+
console.error(' 已提交');
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const stats = await apiGet(`${serverUrl}/api/stats`);
|
|
127
|
+
console.error(`\n完成: ${processedCount} 个用户处理, ${errorCount} 个出错`);
|
|
128
|
+
console.error(` 总用户: ${stats.totalUsers}, 已完成: ${stats.processedUsers}, 待处理: ${stats.pendingUsers}, 错误: ${stats.errorUsers}`);
|
|
129
|
+
|
|
130
|
+
await browser.close().catch(() => {});
|
|
131
|
+
}
|
package/src/cli/explore.js
CHANGED
|
@@ -1,116 +1,147 @@
|
|
|
1
|
-
import { getOrCreatePage } from '../lib/browser/page.js';
|
|
2
|
-
import { delay, getDelayConfig, setDelayConfig } from '../scraper/modules/page-helpers.mjs';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
}
|
|
1
|
+
import { getOrCreatePage } from '../lib/browser/page.js';
|
|
2
|
+
import { delay, getDelayConfig, setDelayConfig } from '../scraper/modules/page-helpers.mjs';
|
|
3
|
+
import { userId as configuredUserId, saveUserId } from '../lib/constants.js';
|
|
4
|
+
import { getMacOrUuid } from '../lib/mac-or-uuid.js';
|
|
5
|
+
|
|
6
|
+
const MAX_RETRY_WAIT = 5 * 60 * 1000;
|
|
7
|
+
|
|
8
|
+
async function withRetry(label, fn) {
|
|
9
|
+
let backoff = 1000;
|
|
10
|
+
while (true) {
|
|
11
|
+
try {
|
|
12
|
+
return await fn();
|
|
13
|
+
} catch (err) {
|
|
14
|
+
console.error(`[连接] ${label} 失败: ${err.message},${backoff / 1000}秒后重试...`);
|
|
15
|
+
await new Promise(r => setTimeout(r, backoff));
|
|
16
|
+
if (backoff < MAX_RETRY_WAIT) backoff *= 2;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async function apiPost(url, body) {
|
|
22
|
+
return withRetry(`POST ${url}`, async () => {
|
|
23
|
+
const res = await fetch(url, {
|
|
24
|
+
method: 'POST',
|
|
25
|
+
headers: { 'Content-Type': 'application/json' },
|
|
26
|
+
body: JSON.stringify(body),
|
|
27
|
+
});
|
|
28
|
+
return res.json();
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async function apiGet(url) {
|
|
33
|
+
return withRetry(`GET ${url}`, async () => {
|
|
34
|
+
const res = await fetch(url);
|
|
35
|
+
return res.json();
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export async function handleExplore(options) {
|
|
40
|
+
const {
|
|
41
|
+
exploreUsernames, explorePreset, exploreMaxComments, exploreMaxGuess,
|
|
42
|
+
exploreEnableFollow, exploreMaxFollowing, exploreMaxFollowers,
|
|
43
|
+
exploreLocation, exploreMaxUsers, serverUrl,
|
|
44
|
+
} = options;
|
|
45
|
+
|
|
46
|
+
let userId = configuredUserId;
|
|
47
|
+
if (!userId) {
|
|
48
|
+
userId = await getMacOrUuid();
|
|
49
|
+
saveUserId(userId);
|
|
50
|
+
console.error(`[初始化] 未检测到本地用户编号,已生成并使用: ${userId}`);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
setDelayConfig(explorePreset);
|
|
54
|
+
|
|
55
|
+
await apiGet(`${serverUrl}/api/stats`);
|
|
56
|
+
|
|
57
|
+
if (exploreUsernames && exploreUsernames.length > 0) {
|
|
58
|
+
const { added, skipped } = await apiPost(`${serverUrl}/api/users`, { usernames: exploreUsernames });
|
|
59
|
+
console.error(`种子用户: ${added} 个新增, ${skipped} 个已存在`);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
console.error(`\n国家筛选: ${exploreLocation}`);
|
|
63
|
+
console.error(`评论: ${exploreMaxComments}, 猜你喜欢: ${exploreMaxGuess}`);
|
|
64
|
+
console.error(`关注/粉丝: ${exploreEnableFollow ? '启用' : '禁用'}`);
|
|
65
|
+
console.error(`服务器: ${serverUrl}(断开会自动重连)`);
|
|
66
|
+
if (exploreMaxUsers > 0) console.error(`上限: ${exploreMaxUsers} 个用户`);
|
|
67
|
+
|
|
68
|
+
const { ensureBrowserReady, processExplore } = await import('../scraper/explore-core.mjs');
|
|
69
|
+
const browser = await ensureBrowserReady();
|
|
70
|
+
|
|
71
|
+
const page = await getOrCreatePage(browser);
|
|
72
|
+
|
|
73
|
+
let processedCount = 0;
|
|
74
|
+
let errorCount = 0;
|
|
75
|
+
|
|
76
|
+
while (true) {
|
|
77
|
+
const job = await apiGet(`${serverUrl}/api/job?userId=${encodeURIComponent(userId)}`);
|
|
78
|
+
if (!job.hasJob) break;
|
|
79
|
+
|
|
80
|
+
const username = job.user.uniqueId;
|
|
81
|
+
processedCount++;
|
|
82
|
+
let proxyRetry = 0;
|
|
83
|
+
|
|
84
|
+
while (true) {
|
|
85
|
+
console.error(`\n[${processedCount}] 探索 @${username}...${proxyRetry > 0 ? ` (代理重试 ${proxyRetry})` : ''}`);
|
|
86
|
+
|
|
87
|
+
const { switchMax } = getDelayConfig();
|
|
88
|
+
await delay(switchMax, switchMax * 3);
|
|
89
|
+
|
|
90
|
+
const result = await processExplore(page, username, {
|
|
91
|
+
maxComments: exploreMaxComments,
|
|
92
|
+
maxGuess: exploreMaxGuess,
|
|
93
|
+
enableFollow: exploreEnableFollow,
|
|
94
|
+
maxFollowing: exploreMaxFollowing,
|
|
95
|
+
maxFollowers: exploreMaxFollowers,
|
|
96
|
+
location: exploreLocation,
|
|
97
|
+
browser,
|
|
98
|
+
}, console.error);
|
|
99
|
+
|
|
100
|
+
if (result.restricted) {
|
|
101
|
+
await apiPost(`${serverUrl}/api/job/${username}`, { restricted: true, userInfo: result.userInfo || {} });
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (result.error && result.error.includes('代理错误')) {
|
|
106
|
+
proxyRetry++;
|
|
107
|
+
console.error(` [代理错误] ${result.error},等待 10s 后重试...`);
|
|
108
|
+
await new Promise(r => setTimeout(r, 10000));
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (result.error) {
|
|
113
|
+
errorCount++;
|
|
114
|
+
await apiPost(`${serverUrl}/api/job/${username}`, { error: result.error });
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const payload = {
|
|
119
|
+
userInfo: result.userInfo || {},
|
|
120
|
+
discoveredVideoAuthors: result.discoveredVideoAuthors || [],
|
|
121
|
+
discoveredCommentAuthors: result.discoveredCommentAuthors || [],
|
|
122
|
+
discoveredGuessAuthors: result.discoveredGuessAuthors || [],
|
|
123
|
+
discoveredFollowing: result.discoveredFollowing || [],
|
|
124
|
+
discoveredFollowers: result.discoveredFollowers || [],
|
|
125
|
+
processed: result.processed,
|
|
126
|
+
hasFollowData: result.hasFollowData,
|
|
127
|
+
keepFollow: result.keepFollow,
|
|
128
|
+
locationCreated: result.locationCreated,
|
|
129
|
+
noVideo: result.noVideo,
|
|
130
|
+
};
|
|
131
|
+
await apiPost(`${serverUrl}/api/job/${username}`, payload);
|
|
132
|
+
console.error(' 已提交');
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (exploreMaxUsers > 0 && processedCount >= exploreMaxUsers) {
|
|
137
|
+
console.error(`\n已达上限 ${exploreMaxUsers} 个用户,停止处理`);
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const stats = await apiGet(`${serverUrl}/api/stats`);
|
|
143
|
+
console.error(`\n完成: ${processedCount} 个用户处理, ${errorCount} 个出错`);
|
|
144
|
+
console.error(` 总用户: ${stats.totalUsers}, 已完成: ${stats.processedUsers}, 待处理: ${stats.pendingUsers}, 错误: ${stats.errorUsers}`);
|
|
145
|
+
|
|
146
|
+
await browser.close().catch(() => {});
|
|
147
|
+
}
|