tt-help-cli-ycl 1.3.12 → 1.3.14
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 +47 -45
- package/scripts/run-explore.bat +68 -68
- package/scripts/run-explore.ps1 +81 -81
- package/scripts/run-explore.sh +73 -73
- package/scripts/test-captcha-lib.mjs +68 -0
- package/scripts/test-captcha.mjs +81 -0
- package/scripts/test-incognito-lib.mjs +36 -0
- package/scripts/test-login-state.mjs +128 -0
- package/scripts/test-safe-click.mjs +45 -0
- package/src/cli/attach.js +160 -0
- package/src/cli/auto.js +186 -157
- package/src/cli/config.js +39 -3
- package/src/cli/explore.js +234 -193
- package/src/cli/info.js +88 -0
- package/src/cli/progress.js +111 -111
- package/src/cli/refresh.js +216 -0
- 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 +517 -402
- package/src/lib/browser/anti-detect.js +23 -23
- package/src/lib/browser/cdp.js +52 -10
- package/src/lib/browser/launch.js +43 -43
- package/src/lib/browser/page.js +146 -87
- package/src/lib/constants.js +199 -115
- 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/output.js +80 -80
- package/src/lib/parse-ssr.mjs +69 -0
- package/src/lib/parser.js +47 -47
- package/src/lib/retry.js +45 -45
- package/src/lib/scrape.js +89 -40
- package/src/lib/tiktok-scraper.mjs +176 -0
- package/src/lib/url.js +52 -52
- package/src/main.js +12 -16
- package/src/results/user-videos-bar.lar.lar.moeta.json +37 -0
- package/src/scraper/auto-core.js +203 -194
- package/src/scraper/core.js +211 -190
- package/src/scraper/explore-core.js +162 -171
- package/src/scraper/modules/captcha-handler.js +114 -114
- package/src/scraper/modules/comment-extractor.js +74 -69
- package/src/scraper/modules/follow-extractor.js +121 -121
- package/src/scraper/modules/guess-extractor.js +51 -51
- package/src/scraper/modules/page-helpers.js +48 -48
- package/src/scraper/refresh-core.js +179 -0
- package/src/videos/core.js +126 -126
- package/src/watch/data-store.js +536 -302
- package/src/watch/public/index.html +721 -701
- package/src/watch/server.js +527 -359
package/src/cli/explore.js
CHANGED
|
@@ -1,193 +1,234 @@
|
|
|
1
|
-
import { getOrCreatePage } from '../lib/browser/page.js';
|
|
2
|
-
import { delay, getDelayConfig, setDelayConfig } from '../scraper/modules/page-helpers.js';
|
|
3
|
-
import { userId as configuredUserId, saveUserId } from '../lib/constants.js';
|
|
4
|
-
import { getMacOrUuid } from '../lib/mac-or-uuid.js';
|
|
5
|
-
import { ensureBrowserReady as ensureBrowserReadyCDP } from '../lib/browser/cdp.js';
|
|
6
|
-
import path from 'path';
|
|
7
|
-
import os from 'os';
|
|
8
|
-
|
|
9
|
-
const MAX_RETRY_WAIT = 5 * 60 * 1000;
|
|
10
|
-
|
|
11
|
-
async function withRetry(label, fn) {
|
|
12
|
-
let backoff = 1000;
|
|
13
|
-
while (true) {
|
|
14
|
-
try {
|
|
15
|
-
return await fn();
|
|
16
|
-
} catch (err) {
|
|
17
|
-
console.error(`[连接] ${label} 失败: ${err.message},${backoff / 1000}秒后重试...`);
|
|
18
|
-
await new Promise(r => setTimeout(r, backoff));
|
|
19
|
-
if (backoff < MAX_RETRY_WAIT) backoff *= 2;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
async function apiPost(url, body) {
|
|
25
|
-
return withRetry(`POST ${url}`, async () => {
|
|
26
|
-
const res = await fetch(url, {
|
|
27
|
-
method: 'POST',
|
|
28
|
-
headers: { 'Content-Type': 'application/json' },
|
|
29
|
-
body: JSON.stringify(body),
|
|
30
|
-
});
|
|
31
|
-
return res.json();
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
async function apiGet(url) {
|
|
36
|
-
return withRetry(`GET ${url}`, async () => {
|
|
37
|
-
const res = await fetch(url);
|
|
38
|
-
return res.json();
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export async function handleExplore(options) {
|
|
43
|
-
const {
|
|
44
|
-
exploreUsernames, explorePreset, exploreMaxComments, exploreMaxGuess,
|
|
45
|
-
exploreEnableFollow, exploreMaxFollowing, exploreMaxFollowers,
|
|
46
|
-
exploreLocation, exploreMaxUsers, serverUrl,
|
|
47
|
-
explorePort, exploreProfile, exploreUserId,
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
console.error(
|
|
68
|
-
console.error(
|
|
69
|
-
console.error(
|
|
70
|
-
|
|
71
|
-
console.error(
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
if (
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
let
|
|
87
|
-
let
|
|
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
|
-
enableFollow: exploreEnableFollow,
|
|
117
|
-
maxFollowing: exploreMaxFollowing,
|
|
118
|
-
maxFollowers: exploreMaxFollowers,
|
|
119
|
-
location: exploreLocation,
|
|
120
|
-
browser,
|
|
121
|
-
}, console.error);
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
})
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
1
|
+
import { getOrCreatePage, isBrowserClosedError, relaunchBrowser } from '../lib/browser/page.js';
|
|
2
|
+
import { delay, getDelayConfig, setDelayConfig } from '../scraper/modules/page-helpers.js';
|
|
3
|
+
import { userId as configuredUserId, saveUserId } from '../lib/constants.js';
|
|
4
|
+
import { getMacOrUuid } from '../lib/mac-or-uuid.js';
|
|
5
|
+
import { ensureBrowserReady as ensureBrowserReadyCDP } from '../lib/browser/cdp.js';
|
|
6
|
+
import path from 'path';
|
|
7
|
+
import os from 'os';
|
|
8
|
+
|
|
9
|
+
const MAX_RETRY_WAIT = 5 * 60 * 1000;
|
|
10
|
+
|
|
11
|
+
async function withRetry(label, fn) {
|
|
12
|
+
let backoff = 1000;
|
|
13
|
+
while (true) {
|
|
14
|
+
try {
|
|
15
|
+
return await fn();
|
|
16
|
+
} catch (err) {
|
|
17
|
+
console.error(`[连接] ${label} 失败: ${err.message},${backoff / 1000}秒后重试...`);
|
|
18
|
+
await new Promise(r => setTimeout(r, backoff));
|
|
19
|
+
if (backoff < MAX_RETRY_WAIT) backoff *= 2;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
async function apiPost(url, body) {
|
|
25
|
+
return withRetry(`POST ${url}`, async () => {
|
|
26
|
+
const res = await fetch(url, {
|
|
27
|
+
method: 'POST',
|
|
28
|
+
headers: { 'Content-Type': 'application/json' },
|
|
29
|
+
body: JSON.stringify(body),
|
|
30
|
+
});
|
|
31
|
+
return res.json();
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async function apiGet(url) {
|
|
36
|
+
return withRetry(`GET ${url}`, async () => {
|
|
37
|
+
const res = await fetch(url);
|
|
38
|
+
return res.json();
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export async function handleExplore(options) {
|
|
43
|
+
const {
|
|
44
|
+
exploreUsernames, explorePreset, exploreMaxComments, exploreMaxGuess,
|
|
45
|
+
exploreEnableFollow, exploreMaxFollowing, exploreMaxFollowers,
|
|
46
|
+
exploreLocation, exploreMaxUsers, serverUrl,
|
|
47
|
+
explorePort, exploreProfile, exploreUserId,
|
|
48
|
+
exploreMaxVideos,
|
|
49
|
+
} = options;
|
|
50
|
+
|
|
51
|
+
let userId = exploreUserId || configuredUserId;
|
|
52
|
+
if (!userId) {
|
|
53
|
+
userId = await getMacOrUuid();
|
|
54
|
+
saveUserId(userId);
|
|
55
|
+
console.error(`[初始化] 未检测到本地用户编号,已生成并使用: ${userId}`);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
setDelayConfig(explorePreset);
|
|
59
|
+
|
|
60
|
+
await apiGet(`${serverUrl}/api/stats`);
|
|
61
|
+
|
|
62
|
+
if (exploreUsernames && exploreUsernames.length > 0) {
|
|
63
|
+
const { added, skipped } = await apiPost(`${serverUrl}/api/users`, { usernames: exploreUsernames });
|
|
64
|
+
console.error(`种子用户: ${added} 个新增, ${skipped} 个已存在`);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
console.error(`\n国家筛选: ${exploreLocation}`);
|
|
68
|
+
console.error(`视频采集: ${exploreMaxVideos || 1}`);
|
|
69
|
+
console.error(`关注/粉丝: ${exploreEnableFollow ? '启用' : '禁用'}`);
|
|
70
|
+
console.error(`服务器: ${serverUrl}(断开会自动重连)`);
|
|
71
|
+
if (exploreMaxUsers > 0) console.error(`上限: ${exploreMaxUsers} 个用户`);
|
|
72
|
+
console.error(`CDP 端口: ${explorePort || 9222}, 用户编号: ${userId}`);
|
|
73
|
+
if (exploreProfile) console.error(`浏览器配置: ${exploreProfile}`);
|
|
74
|
+
|
|
75
|
+
const cdpOptions = {};
|
|
76
|
+
if (explorePort) cdpOptions.port = explorePort;
|
|
77
|
+
if (exploreProfile) {
|
|
78
|
+
cdpOptions.userDataDir = path.join(os.homedir(), 'Library', 'Application Support', `Microsoft Edge For Testing_${exploreProfile}`);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
let browser = await ensureBrowserReadyCDP(cdpOptions);
|
|
82
|
+
const { processExplore } = await import('../scraper/explore-core.js');
|
|
83
|
+
|
|
84
|
+
const page = await getOrCreatePage(browser);
|
|
85
|
+
|
|
86
|
+
let processedCount = 0;
|
|
87
|
+
let errorCount = 0;
|
|
88
|
+
let consecutiveNetworkErrors = 0;
|
|
89
|
+
|
|
90
|
+
while (true) {
|
|
91
|
+
const job = await apiGet(`${serverUrl}/api/job?userId=${encodeURIComponent(userId)}`);
|
|
92
|
+
if (!job.hasJob) break;
|
|
93
|
+
|
|
94
|
+
const username = job.user.uniqueId;
|
|
95
|
+
processedCount++;
|
|
96
|
+
|
|
97
|
+
if (consecutiveNetworkErrors > 0) {
|
|
98
|
+
const waitTime = consecutiveNetworkErrors <= 2
|
|
99
|
+
? 0
|
|
100
|
+
: consecutiveNetworkErrors <= 5
|
|
101
|
+
? 30000
|
|
102
|
+
: 300000;
|
|
103
|
+
if (waitTime > 0) {
|
|
104
|
+
console.error(` [网络] 连续 ${consecutiveNetworkErrors} 次网络异常,等待 ${waitTime / 1000}s 后重试...`);
|
|
105
|
+
await new Promise(r => setTimeout(r, waitTime));
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
console.error(`\n[${processedCount}] 探索 @${username}...`);
|
|
110
|
+
|
|
111
|
+
const { switchMax } = getDelayConfig();
|
|
112
|
+
await delay(switchMax, switchMax * 3);
|
|
113
|
+
|
|
114
|
+
let result = await processExplore(page, username, {
|
|
115
|
+
maxVideos: exploreMaxVideos,
|
|
116
|
+
enableFollow: exploreEnableFollow,
|
|
117
|
+
maxFollowing: exploreMaxFollowing,
|
|
118
|
+
maxFollowers: exploreMaxFollowers,
|
|
119
|
+
location: exploreLocation,
|
|
120
|
+
browser,
|
|
121
|
+
}, console.error);
|
|
122
|
+
|
|
123
|
+
// 浏览器关闭检测:processExplore 内部 catch 了异常,需要从 result.error 判断
|
|
124
|
+
if (result.error && isBrowserClosedError(new Error(result.error))) {
|
|
125
|
+
const newBrowser = await relaunchBrowser(cdpOptions, explorePort || 9222);
|
|
126
|
+
browser = newBrowser;
|
|
127
|
+
const newPage = await getOrCreatePage(browser);
|
|
128
|
+
Object.assign(page, newPage);
|
|
129
|
+
// 重试当前用户
|
|
130
|
+
result = await processExplore(page, username, {
|
|
131
|
+
maxVideos: exploreMaxVideos,
|
|
132
|
+
enableFollow: exploreEnableFollow,
|
|
133
|
+
maxFollowing: exploreMaxFollowing,
|
|
134
|
+
maxFollowers: exploreMaxFollowers,
|
|
135
|
+
location: exploreLocation,
|
|
136
|
+
browser,
|
|
137
|
+
}, console.error);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if (result.restricted) {
|
|
141
|
+
consecutiveNetworkErrors = 0;
|
|
142
|
+
await apiPost(`${serverUrl}/api/job/${username}`, { restricted: true, userInfo: result.userInfo || {} });
|
|
143
|
+
if (exploreMaxUsers > 0 && processedCount >= exploreMaxUsers) {
|
|
144
|
+
console.error(`\n已达上限 ${exploreMaxUsers} 个用户,停止处理`);
|
|
145
|
+
break;
|
|
146
|
+
}
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (result.error) {
|
|
151
|
+
consecutiveNetworkErrors++;
|
|
152
|
+
errorCount++;
|
|
153
|
+
await apiPost(`${serverUrl}/api/job/${username}`, { error: result.error });
|
|
154
|
+
const errorType = consecutiveNetworkErrors > 1 ? 'network' : 'other';
|
|
155
|
+
await withRetry('report error', () =>
|
|
156
|
+
apiPost(`${serverUrl}/api/error-report`, {
|
|
157
|
+
userId,
|
|
158
|
+
username,
|
|
159
|
+
errorType,
|
|
160
|
+
errorMessage: result.error,
|
|
161
|
+
stage: 'process',
|
|
162
|
+
errorStack: result.errorStack || '',
|
|
163
|
+
})
|
|
164
|
+
).catch(() => {});
|
|
165
|
+
if (exploreMaxUsers > 0 && processedCount >= exploreMaxUsers) {
|
|
166
|
+
console.error(`\n已达上限 ${exploreMaxUsers} 个用户,停止处理`);
|
|
167
|
+
break;
|
|
168
|
+
}
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if (result.captchaDetected) {
|
|
173
|
+
await withRetry('report captcha', () =>
|
|
174
|
+
apiPost(`${serverUrl}/api/error-report`, {
|
|
175
|
+
userId,
|
|
176
|
+
username,
|
|
177
|
+
errorType: 'captcha',
|
|
178
|
+
errorMessage: result.captchaMessage || '页面出现验证码',
|
|
179
|
+
stage: result.captchaStage || 'video-page',
|
|
180
|
+
errorStack: '',
|
|
181
|
+
})
|
|
182
|
+
).catch(() => {});
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
consecutiveNetworkErrors = 0;
|
|
186
|
+
|
|
187
|
+
const guessedLocation = result.locationCreated || null;
|
|
188
|
+
|
|
189
|
+
const payload = {
|
|
190
|
+
userInfo: result.userInfo || {},
|
|
191
|
+
discoveredFollowing: (result.discoveredFollowing || []).map(f => ({
|
|
192
|
+
handle: Array.isArray(f) ? f[0] : f,
|
|
193
|
+
displayName: Array.isArray(f) ? f[1] : null,
|
|
194
|
+
guessedLocation,
|
|
195
|
+
})),
|
|
196
|
+
discoveredFollowers: (result.discoveredFollowers || []).map(f => ({
|
|
197
|
+
handle: Array.isArray(f) ? f[0] : f,
|
|
198
|
+
displayName: Array.isArray(f) ? f[1] : null,
|
|
199
|
+
guessedLocation,
|
|
200
|
+
})),
|
|
201
|
+
processed: result.processed,
|
|
202
|
+
hasFollowData: result.hasFollowData,
|
|
203
|
+
keepFollow: result.keepFollow,
|
|
204
|
+
locationCreated: result.locationCreated,
|
|
205
|
+
noVideo: result.noVideo,
|
|
206
|
+
collectedVideos: result.collectedVideos,
|
|
207
|
+
};
|
|
208
|
+
await apiPost(`${serverUrl}/api/job/${username}`, payload);
|
|
209
|
+
|
|
210
|
+
// 视频登记
|
|
211
|
+
if (result.videoList && result.videoList.length > 0) {
|
|
212
|
+
const { registered, skipped } = await apiPost(`${serverUrl}/api/videos`, {
|
|
213
|
+
sourceUser: username,
|
|
214
|
+
videoList: result.videoList,
|
|
215
|
+
locationCreated: result.locationCreated,
|
|
216
|
+
ttSeller: result.userInfo?.ttSeller || false,
|
|
217
|
+
});
|
|
218
|
+
console.error(` 视频登记: ${registered} 条新增, ${skipped} 条已存在`);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
console.error(' 已提交');
|
|
222
|
+
|
|
223
|
+
if (exploreMaxUsers > 0 && processedCount >= exploreMaxUsers) {
|
|
224
|
+
console.error(`\n已达上限 ${exploreMaxUsers} 个用户,停止处理`);
|
|
225
|
+
break;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
const stats = await apiGet(`${serverUrl}/api/stats`);
|
|
230
|
+
console.error(`\n完成: ${processedCount} 个用户处理, ${errorCount} 个出错`);
|
|
231
|
+
console.error(` 总用户: ${stats.totalUsers}, 已完成: ${stats.processedUsers}, 待处理: ${stats.pendingUsers}, 错误: ${stats.errorUsers}`);
|
|
232
|
+
|
|
233
|
+
await browser.close().catch(() => {});
|
|
234
|
+
}
|
package/src/cli/info.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { TikTokScraper } from '../lib/tiktok-scraper.mjs';
|
|
2
|
+
import { isProfileUrl, isVideoUrl, extractUniqueId, normalizeUsername } from '../lib/url.js';
|
|
3
|
+
|
|
4
|
+
async function handleInfo(options) {
|
|
5
|
+
const { infoUrls, infoOnlyVideo } = options;
|
|
6
|
+
|
|
7
|
+
if (!infoUrls || infoUrls.length === 0) {
|
|
8
|
+
console.error('用法: tt-help info <URL> [URL2 URL3...] [--onlyvideo]');
|
|
9
|
+
console.error('');
|
|
10
|
+
console.error('参数:');
|
|
11
|
+
console.error(' <URL> TikTok 主页或视频 URL,支持多个 URL 同时查询');
|
|
12
|
+
console.error(' --onlyvideo 只返回视频信息(不返回用户信息)');
|
|
13
|
+
console.error('');
|
|
14
|
+
console.error('默认行为:');
|
|
15
|
+
console.error(' 主页 URL → 返回用户信息(bio、region、粉丝数等)');
|
|
16
|
+
console.error(' 视频 URL → 返回用户信息 + 视频信息');
|
|
17
|
+
console.error(' 视频 URL + --onlyvideo → 只返回视频信息');
|
|
18
|
+
console.error('');
|
|
19
|
+
console.error('示例:');
|
|
20
|
+
console.error(' tt-help info https://www.tiktok.com/@nike');
|
|
21
|
+
console.error(' tt-help info https://www.tiktok.com/@nike/video/7234567890');
|
|
22
|
+
console.error(' tt-help info https://www.tiktok.com/@nike https://www.tiktok.com/@apple');
|
|
23
|
+
process.exit(1);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const scraper = new TikTokScraper({ poolSize: 1 });
|
|
27
|
+
|
|
28
|
+
try {
|
|
29
|
+
await scraper.init();
|
|
30
|
+
const result = {};
|
|
31
|
+
|
|
32
|
+
for (const url of infoUrls) {
|
|
33
|
+
if (isProfileUrl(url)) {
|
|
34
|
+
const uniqueId = extractUniqueId(url);
|
|
35
|
+
const normalized = normalizeUsername(uniqueId);
|
|
36
|
+
const user = await scraper.getUserInfo(normalized);
|
|
37
|
+
if (!user) {
|
|
38
|
+
console.error(`无法获取用户 @${uniqueId} 的信息`);
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
result[normalized] = { user };
|
|
42
|
+
console.error(`用户: @${user.uniqueId} (${user.nickname})`);
|
|
43
|
+
} else if (isVideoUrl(url)) {
|
|
44
|
+
const uniqueId = extractUniqueId(url);
|
|
45
|
+
const normalized = normalizeUsername(uniqueId);
|
|
46
|
+
|
|
47
|
+
if (infoOnlyVideo) {
|
|
48
|
+
const video = await scraper.getVideoInfo(url);
|
|
49
|
+
if (!video) {
|
|
50
|
+
console.error(`无法获取视频信息: ${url}`);
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
const key = normalized + '/video/' + video.id;
|
|
54
|
+
result[key] = { video };
|
|
55
|
+
console.error(`视频: ${video.id}`);
|
|
56
|
+
} else {
|
|
57
|
+
const [user, video] = await Promise.all([
|
|
58
|
+
scraper.getUserInfo(normalized),
|
|
59
|
+
scraper.getVideoInfo(url),
|
|
60
|
+
]);
|
|
61
|
+
const entry = {};
|
|
62
|
+
if (user) {
|
|
63
|
+
entry.user = user;
|
|
64
|
+
console.error(`用户: @${user.uniqueId} (${user.nickname})`);
|
|
65
|
+
}
|
|
66
|
+
if (video) {
|
|
67
|
+
entry.video = video;
|
|
68
|
+
console.error(`视频: ${video.id}`);
|
|
69
|
+
}
|
|
70
|
+
if (!user && !video) {
|
|
71
|
+
console.error(`无法获取信息: ${url}`);
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
const key = normalized + '/video/' + (video ? video.id : 'unknown');
|
|
75
|
+
result[key] = entry;
|
|
76
|
+
}
|
|
77
|
+
} else {
|
|
78
|
+
console.error(`无法识别 URL: ${url}`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
console.log(JSON.stringify(result, null, 2));
|
|
83
|
+
} finally {
|
|
84
|
+
await scraper.close();
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export { handleInfo };
|