tt-help-cli-ycl 1.3.34 → 1.3.35

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 (58) hide show
  1. package/README.md +17 -17
  2. package/cli.js +9 -9
  3. package/package.json +47 -47
  4. package/scripts/run-explore copy.bat +101 -101
  5. package/scripts/run-explore.bat +132 -132
  6. package/scripts/run-explore.ps1 +157 -157
  7. package/scripts/run-explore.sh +119 -119
  8. package/scripts/test-captcha-lib.mjs +68 -0
  9. package/scripts/test-captcha.mjs +81 -0
  10. package/scripts/test-incognito-lib.mjs +36 -0
  11. package/scripts/test-login-state.mjs +128 -0
  12. package/scripts/test-safe-click.mjs +45 -0
  13. package/src/cli/attach.js +180 -180
  14. package/src/cli/auto.js +240 -240
  15. package/src/cli/config.js +152 -152
  16. package/src/cli/explore.js +488 -488
  17. package/src/cli/info.js +88 -88
  18. package/src/cli/open.js +111 -111
  19. package/src/cli/progress.js +111 -111
  20. package/src/cli/refresh.js +216 -216
  21. package/src/cli/scrape.js +47 -47
  22. package/src/cli/utils.js +18 -18
  23. package/src/cli/videos.js +41 -41
  24. package/src/cli/watch.js +31 -31
  25. package/src/lib/args.js +722 -722
  26. package/src/lib/browser/anti-detect.js +23 -23
  27. package/src/lib/browser/cdp.js +261 -261
  28. package/src/lib/browser/health-checker.js +114 -114
  29. package/src/lib/browser/launch.js +43 -43
  30. package/src/lib/browser/page.js +183 -183
  31. package/src/lib/constants.js +216 -216
  32. package/src/lib/delay.js +54 -54
  33. package/src/lib/explore-fetch.js +118 -118
  34. package/src/lib/fetcher.js +45 -45
  35. package/src/lib/filter.js +66 -66
  36. package/src/lib/io.js +54 -54
  37. package/src/lib/output.js +80 -80
  38. package/src/lib/page-error-detector.js +105 -105
  39. package/src/lib/parse-ssr.mjs +69 -69
  40. package/src/lib/parser.js +47 -47
  41. package/src/lib/retry.js +45 -45
  42. package/src/lib/scrape.js +89 -89
  43. package/src/lib/tiktok-scraper.mjs +194 -194
  44. package/src/lib/url.js +52 -52
  45. package/src/main.js +48 -48
  46. package/src/results/user-videos-bar.lar.lar.moeta.json +37 -0
  47. package/src/scraper/auto-core.js +203 -203
  48. package/src/scraper/core.js +211 -211
  49. package/src/scraper/explore-core.js +177 -167
  50. package/src/scraper/modules/captcha-handler.js +114 -114
  51. package/src/scraper/modules/follow-extractor.js +194 -194
  52. package/src/scraper/modules/guess-extractor.js +51 -51
  53. package/src/scraper/modules/page-helpers.js +48 -48
  54. package/src/scraper/refresh-core.js +179 -179
  55. package/src/videos/core.js +125 -125
  56. package/src/watch/data-store.js +1040 -1030
  57. package/src/watch/public/index.html +1458 -753
  58. package/src/watch/server.js +939 -933
@@ -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
+ }