tt-help-cli-ycl 1.3.44 → 1.3.46
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 +33 -33
- package/cli.js +9 -9
- package/package.json +52 -52
- package/scripts/run-explore copy.bat +101 -101
- package/scripts/run-explore.bat +134 -134
- package/scripts/run-explore.ps1 +159 -159
- package/scripts/run-explore.sh +121 -121
- package/src/cli/attach.js +331 -301
- package/src/cli/auto.js +265 -265
- package/src/cli/comments.js +620 -620
- package/src/cli/config.js +170 -170
- package/src/cli/db-import.js +51 -51
- package/src/cli/explore.js +555 -555
- package/src/cli/info.js +10 -16
- package/src/cli/open.js +111 -111
- package/src/cli/progress.js +111 -111
- package/src/cli/refresh.js +288 -288
- package/src/cli/scrape.js +47 -47
- package/src/cli/utils.js +18 -18
- package/src/cli/videos.js +41 -41
- package/src/cli/videostats.js +196 -196
- package/src/cli/watch.js +30 -30
- package/src/cli/webserver.js +19 -0
- package/src/lib/api-interceptor.js +161 -161
- package/src/lib/args.js +809 -771
- package/src/lib/browser/anti-detect.js +23 -23
- package/src/lib/browser/cdp.js +261 -261
- package/src/lib/browser/health-checker.js +114 -114
- package/src/lib/browser/launch.js +43 -43
- package/src/lib/browser/page.js +184 -184
- package/src/lib/constants.js +297 -285
- 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/page-error-detector.js +109 -109
- package/src/lib/parse-ssr.mjs +69 -69
- package/src/lib/parser.js +47 -47
- package/src/lib/retry.js +45 -45
- package/src/lib/scrape.js +90 -89
- package/src/lib/target-locations.js +61 -61
- package/src/lib/tiktok-scraper.mjs +160 -106
- package/src/lib/url.js +52 -52
- package/src/main.js +73 -70
- package/src/npm-main.js +70 -69
- package/src/scraper/auto-core.js +203 -203
- package/src/scraper/core.js +255 -255
- package/src/scraper/explore-core.js +208 -208
- package/src/scraper/modules/captcha-handler.js +114 -114
- package/src/scraper/modules/follow-extractor.js +250 -250
- package/src/scraper/modules/guess-extractor.js +51 -51
- package/src/scraper/modules/page-helpers.js +48 -48
- package/src/scraper/refresh-core.js +213 -213
- package/src/videos/core.js +143 -143
- package/src/watch/data-store.js +2980 -2846
- package/src/watch/public/index.html +2355 -2285
- package/src/watch/server.js +727 -711
- package/src/webserver/server.mjs +174 -0
- package/scripts/test-captcha-lib.mjs +0 -68
- package/scripts/test-captcha.mjs +0 -81
- package/scripts/test-incognito-lib.mjs +0 -36
- package/scripts/test-login-state.mjs +0 -128
- package/scripts/test-safe-click.mjs +0 -45
- package/scripts/test-watch-db-smoke.mjs +0 -246
- package/src/results/user-videos-bar.lar.lar.moeta.json +0 -37
|
@@ -1,114 +1,114 @@
|
|
|
1
|
-
import os from "os";
|
|
2
|
-
import path from "path";
|
|
3
|
-
import { execSync } from "child_process";
|
|
4
|
-
|
|
5
|
-
const DEFAULT_BASE_PORT = 9222;
|
|
6
|
-
const DEFAULT_TOTAL_ACCOUNTS = 10;
|
|
7
|
-
const MEMORY_THRESHOLD = 0.95;
|
|
8
|
-
const ROTATE_INTERVAL_MS = 0.8 * 60 * 60 * 1000;
|
|
9
|
-
|
|
10
|
-
class HealthChecker {
|
|
11
|
-
constructor(options = {}) {
|
|
12
|
-
const basePort = options.basePort ?? DEFAULT_BASE_PORT;
|
|
13
|
-
const totalAccounts = options.totalAccounts ?? DEFAULT_TOTAL_ACCOUNTS;
|
|
14
|
-
|
|
15
|
-
this.accounts = [];
|
|
16
|
-
for (let i = 0; i < totalAccounts; i++) {
|
|
17
|
-
const port = basePort + i;
|
|
18
|
-
const profile = `p${port}`;
|
|
19
|
-
this.accounts.push({
|
|
20
|
-
port,
|
|
21
|
-
profile,
|
|
22
|
-
userDataDir: path.join(
|
|
23
|
-
os.homedir(),
|
|
24
|
-
"Library",
|
|
25
|
-
"Application Support",
|
|
26
|
-
`Microsoft Edge For Testing_${profile}`,
|
|
27
|
-
),
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
this.currentIndex = 0;
|
|
31
|
-
this.startTime = Date.now();
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
getCurrentAccount() {
|
|
35
|
-
return this.accounts[this.currentIndex];
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
getNextAccount() {
|
|
39
|
-
this.currentIndex = (this.currentIndex + 1) % this.accounts.length;
|
|
40
|
-
this.startTime = Date.now(); // 切换后重置运行时间
|
|
41
|
-
return this.accounts[this.currentIndex];
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
check() {
|
|
45
|
-
let memUsage;
|
|
46
|
-
const platform = os.platform();
|
|
47
|
-
|
|
48
|
-
if (platform === "darwin") {
|
|
49
|
-
// macOS 上 os.freemem() 不包含 inactive 内存,导致虚高
|
|
50
|
-
// 使用 vm_stat 获取准确数据
|
|
51
|
-
try {
|
|
52
|
-
const vmStat = execSync("vm_stat", { encoding: "utf-8" });
|
|
53
|
-
const parsePages = (line) => {
|
|
54
|
-
const match = line.match(/Pages (\w+(?:\s+\w+)*):\s+(\d+)/);
|
|
55
|
-
return match ? parseInt(match[2], 10) : 0;
|
|
56
|
-
};
|
|
57
|
-
const lines = vmStat.trim().split("\n");
|
|
58
|
-
const pageSize = 16384;
|
|
59
|
-
const active = parsePages(
|
|
60
|
-
lines.find((l) => l.includes("active")) || "",
|
|
61
|
-
);
|
|
62
|
-
const wired = parsePages(
|
|
63
|
-
lines.find((l) => l.includes("wired down")) || "",
|
|
64
|
-
);
|
|
65
|
-
const compressor = parsePages(
|
|
66
|
-
lines.find((l) => l.includes("occupied by compressor")) || "",
|
|
67
|
-
);
|
|
68
|
-
const total = os.totalmem();
|
|
69
|
-
const used = (active + wired + compressor) * pageSize;
|
|
70
|
-
memUsage = used / total;
|
|
71
|
-
} catch {
|
|
72
|
-
// 降级:使用估算
|
|
73
|
-
const total = os.totalmem();
|
|
74
|
-
const free = os.freemem();
|
|
75
|
-
const inactiveEstimate = total * 0.35;
|
|
76
|
-
memUsage = 1 - (free + inactiveEstimate) / total;
|
|
77
|
-
}
|
|
78
|
-
} else {
|
|
79
|
-
memUsage = 1 - os.freemem() / os.totalmem();
|
|
80
|
-
}
|
|
81
|
-
const memPercent = (memUsage * 100).toFixed(1);
|
|
82
|
-
|
|
83
|
-
if (memUsage >= MEMORY_THRESHOLD) {
|
|
84
|
-
const currentPort = this.accounts[this.currentIndex].port;
|
|
85
|
-
return {
|
|
86
|
-
shouldSwitch: true,
|
|
87
|
-
reason: `端口 ${currentPort} | 系统内存 ${memPercent}%`,
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
const elapsed = Date.now() - this.startTime;
|
|
92
|
-
if (elapsed >= ROTATE_INTERVAL_MS) {
|
|
93
|
-
const mins = Math.round(elapsed / 60000);
|
|
94
|
-
const currentPort = this.accounts[this.currentIndex].port;
|
|
95
|
-
return {
|
|
96
|
-
shouldSwitch: true,
|
|
97
|
-
reason: `端口 ${currentPort} | 运行 ${mins} 分钟`,
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// 计算预计切换时间
|
|
102
|
-
const remainingMs = ROTATE_INTERVAL_MS - elapsed;
|
|
103
|
-
const remainingMins = Math.round(remainingMs / 60000);
|
|
104
|
-
const memHeadroom = ((MEMORY_THRESHOLD - memUsage) * 100).toFixed(1);
|
|
105
|
-
const currentPort = this.accounts[this.currentIndex].port;
|
|
106
|
-
|
|
107
|
-
return {
|
|
108
|
-
shouldSwitch: false,
|
|
109
|
-
info: `端口 ${currentPort} | 内存 ${memPercent}% (余量 ${memHeadroom}%) | 定时轮换 ${remainingMins} 分钟后`,
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
export { HealthChecker };
|
|
1
|
+
import os from "os";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { execSync } from "child_process";
|
|
4
|
+
|
|
5
|
+
const DEFAULT_BASE_PORT = 9222;
|
|
6
|
+
const DEFAULT_TOTAL_ACCOUNTS = 10;
|
|
7
|
+
const MEMORY_THRESHOLD = 0.95;
|
|
8
|
+
const ROTATE_INTERVAL_MS = 0.8 * 60 * 60 * 1000;
|
|
9
|
+
|
|
10
|
+
class HealthChecker {
|
|
11
|
+
constructor(options = {}) {
|
|
12
|
+
const basePort = options.basePort ?? DEFAULT_BASE_PORT;
|
|
13
|
+
const totalAccounts = options.totalAccounts ?? DEFAULT_TOTAL_ACCOUNTS;
|
|
14
|
+
|
|
15
|
+
this.accounts = [];
|
|
16
|
+
for (let i = 0; i < totalAccounts; i++) {
|
|
17
|
+
const port = basePort + i;
|
|
18
|
+
const profile = `p${port}`;
|
|
19
|
+
this.accounts.push({
|
|
20
|
+
port,
|
|
21
|
+
profile,
|
|
22
|
+
userDataDir: path.join(
|
|
23
|
+
os.homedir(),
|
|
24
|
+
"Library",
|
|
25
|
+
"Application Support",
|
|
26
|
+
`Microsoft Edge For Testing_${profile}`,
|
|
27
|
+
),
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
this.currentIndex = 0;
|
|
31
|
+
this.startTime = Date.now();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
getCurrentAccount() {
|
|
35
|
+
return this.accounts[this.currentIndex];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
getNextAccount() {
|
|
39
|
+
this.currentIndex = (this.currentIndex + 1) % this.accounts.length;
|
|
40
|
+
this.startTime = Date.now(); // 切换后重置运行时间
|
|
41
|
+
return this.accounts[this.currentIndex];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
check() {
|
|
45
|
+
let memUsage;
|
|
46
|
+
const platform = os.platform();
|
|
47
|
+
|
|
48
|
+
if (platform === "darwin") {
|
|
49
|
+
// macOS 上 os.freemem() 不包含 inactive 内存,导致虚高
|
|
50
|
+
// 使用 vm_stat 获取准确数据
|
|
51
|
+
try {
|
|
52
|
+
const vmStat = execSync("vm_stat", { encoding: "utf-8" });
|
|
53
|
+
const parsePages = (line) => {
|
|
54
|
+
const match = line.match(/Pages (\w+(?:\s+\w+)*):\s+(\d+)/);
|
|
55
|
+
return match ? parseInt(match[2], 10) : 0;
|
|
56
|
+
};
|
|
57
|
+
const lines = vmStat.trim().split("\n");
|
|
58
|
+
const pageSize = 16384;
|
|
59
|
+
const active = parsePages(
|
|
60
|
+
lines.find((l) => l.includes("active")) || "",
|
|
61
|
+
);
|
|
62
|
+
const wired = parsePages(
|
|
63
|
+
lines.find((l) => l.includes("wired down")) || "",
|
|
64
|
+
);
|
|
65
|
+
const compressor = parsePages(
|
|
66
|
+
lines.find((l) => l.includes("occupied by compressor")) || "",
|
|
67
|
+
);
|
|
68
|
+
const total = os.totalmem();
|
|
69
|
+
const used = (active + wired + compressor) * pageSize;
|
|
70
|
+
memUsage = used / total;
|
|
71
|
+
} catch {
|
|
72
|
+
// 降级:使用估算
|
|
73
|
+
const total = os.totalmem();
|
|
74
|
+
const free = os.freemem();
|
|
75
|
+
const inactiveEstimate = total * 0.35;
|
|
76
|
+
memUsage = 1 - (free + inactiveEstimate) / total;
|
|
77
|
+
}
|
|
78
|
+
} else {
|
|
79
|
+
memUsage = 1 - os.freemem() / os.totalmem();
|
|
80
|
+
}
|
|
81
|
+
const memPercent = (memUsage * 100).toFixed(1);
|
|
82
|
+
|
|
83
|
+
if (memUsage >= MEMORY_THRESHOLD) {
|
|
84
|
+
const currentPort = this.accounts[this.currentIndex].port;
|
|
85
|
+
return {
|
|
86
|
+
shouldSwitch: true,
|
|
87
|
+
reason: `端口 ${currentPort} | 系统内存 ${memPercent}%`,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const elapsed = Date.now() - this.startTime;
|
|
92
|
+
if (elapsed >= ROTATE_INTERVAL_MS) {
|
|
93
|
+
const mins = Math.round(elapsed / 60000);
|
|
94
|
+
const currentPort = this.accounts[this.currentIndex].port;
|
|
95
|
+
return {
|
|
96
|
+
shouldSwitch: true,
|
|
97
|
+
reason: `端口 ${currentPort} | 运行 ${mins} 分钟`,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// 计算预计切换时间
|
|
102
|
+
const remainingMs = ROTATE_INTERVAL_MS - elapsed;
|
|
103
|
+
const remainingMins = Math.round(remainingMs / 60000);
|
|
104
|
+
const memHeadroom = ((MEMORY_THRESHOLD - memUsage) * 100).toFixed(1);
|
|
105
|
+
const currentPort = this.accounts[this.currentIndex].port;
|
|
106
|
+
|
|
107
|
+
return {
|
|
108
|
+
shouldSwitch: false,
|
|
109
|
+
info: `端口 ${currentPort} | 内存 ${memPercent}% (余量 ${memHeadroom}%) | 定时轮换 ${remainingMins} 分钟后`,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export { HealthChecker };
|
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
import { accessSync } from 'fs';
|
|
2
|
-
|
|
3
|
-
export function detectBrowser() {
|
|
4
|
-
const isMac = process.platform === 'darwin';
|
|
5
|
-
const isWin = process.platform === 'win32';
|
|
6
|
-
const isLinux = process.platform === 'linux';
|
|
7
|
-
|
|
8
|
-
const paths = [];
|
|
9
|
-
|
|
10
|
-
if (isMac) {
|
|
11
|
-
paths.push(
|
|
12
|
-
'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
|
|
13
|
-
'/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary',
|
|
14
|
-
'/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge',
|
|
15
|
-
'/Applications/Brave Browser.app/Contents/MacOS/Brave Browser',
|
|
16
|
-
);
|
|
17
|
-
} else if (isWin) {
|
|
18
|
-
const localAppData = process.env.LOCALAPPDATA || '';
|
|
19
|
-
const programFiles = process.env.PROGRAMFILES || '';
|
|
20
|
-
const programFilesX86 = process.env['PROGRAMFILES(X86)'] || '';
|
|
21
|
-
paths.push(
|
|
22
|
-
`${programFiles}\\Google\\Chrome\\Application\\chrome.exe`,
|
|
23
|
-
`${programFilesX86}\\Google\\Chrome\\Application\\chrome.exe`,
|
|
24
|
-
`${localAppData}\\Google\\Chrome\\Application\\chrome.exe`,
|
|
25
|
-
`${programFiles}\\Microsoft\\Edge\\Application\\msedge.exe`,
|
|
26
|
-
`${programFilesX86}\\Microsoft\\Edge\\Application\\msedge.exe`,
|
|
27
|
-
);
|
|
28
|
-
} else if (isLinux) {
|
|
29
|
-
paths.push(
|
|
30
|
-
'/usr/bin/google-chrome',
|
|
31
|
-
'/usr/bin/google-chrome-stable',
|
|
32
|
-
'/usr/bin/chromium-browser',
|
|
33
|
-
'/usr/bin/chromium',
|
|
34
|
-
'/snap/bin/chromium',
|
|
35
|
-
'/usr/bin/microsoft-edge',
|
|
36
|
-
);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
for (const p of paths) {
|
|
40
|
-
try { accessSync(p); return p; } catch { /* not found */ }
|
|
41
|
-
}
|
|
42
|
-
return null;
|
|
43
|
-
}
|
|
1
|
+
import { accessSync } from 'fs';
|
|
2
|
+
|
|
3
|
+
export function detectBrowser() {
|
|
4
|
+
const isMac = process.platform === 'darwin';
|
|
5
|
+
const isWin = process.platform === 'win32';
|
|
6
|
+
const isLinux = process.platform === 'linux';
|
|
7
|
+
|
|
8
|
+
const paths = [];
|
|
9
|
+
|
|
10
|
+
if (isMac) {
|
|
11
|
+
paths.push(
|
|
12
|
+
'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
|
|
13
|
+
'/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary',
|
|
14
|
+
'/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge',
|
|
15
|
+
'/Applications/Brave Browser.app/Contents/MacOS/Brave Browser',
|
|
16
|
+
);
|
|
17
|
+
} else if (isWin) {
|
|
18
|
+
const localAppData = process.env.LOCALAPPDATA || '';
|
|
19
|
+
const programFiles = process.env.PROGRAMFILES || '';
|
|
20
|
+
const programFilesX86 = process.env['PROGRAMFILES(X86)'] || '';
|
|
21
|
+
paths.push(
|
|
22
|
+
`${programFiles}\\Google\\Chrome\\Application\\chrome.exe`,
|
|
23
|
+
`${programFilesX86}\\Google\\Chrome\\Application\\chrome.exe`,
|
|
24
|
+
`${localAppData}\\Google\\Chrome\\Application\\chrome.exe`,
|
|
25
|
+
`${programFiles}\\Microsoft\\Edge\\Application\\msedge.exe`,
|
|
26
|
+
`${programFilesX86}\\Microsoft\\Edge\\Application\\msedge.exe`,
|
|
27
|
+
);
|
|
28
|
+
} else if (isLinux) {
|
|
29
|
+
paths.push(
|
|
30
|
+
'/usr/bin/google-chrome',
|
|
31
|
+
'/usr/bin/google-chrome-stable',
|
|
32
|
+
'/usr/bin/chromium-browser',
|
|
33
|
+
'/usr/bin/chromium',
|
|
34
|
+
'/snap/bin/chromium',
|
|
35
|
+
'/usr/bin/microsoft-edge',
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
for (const p of paths) {
|
|
40
|
+
try { accessSync(p); return p; } catch { /* not found */ }
|
|
41
|
+
}
|
|
42
|
+
return null;
|
|
43
|
+
}
|