tt-help-cli-ycl 1.3.48 → 1.3.50

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 (64) hide show
  1. package/README.md +33 -33
  2. package/cli.js +9 -9
  3. package/package.json +52 -52
  4. package/scripts/run-explore copy.bat +101 -101
  5. package/scripts/run-explore.bat +134 -134
  6. package/scripts/run-explore.ps1 +159 -159
  7. package/scripts/run-explore.sh +121 -121
  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/scripts/test-watch-db-smoke.mjs +246 -0
  14. package/src/cli/attach.js +331 -331
  15. package/src/cli/auto.js +265 -265
  16. package/src/cli/comments.js +620 -620
  17. package/src/cli/config.js +170 -170
  18. package/src/cli/db-import.js +51 -51
  19. package/src/cli/explore.js +555 -555
  20. package/src/cli/open.js +109 -111
  21. package/src/cli/progress.js +111 -111
  22. package/src/cli/refresh.js +288 -288
  23. package/src/cli/scrape.js +47 -47
  24. package/src/cli/utils.js +18 -18
  25. package/src/cli/videos.js +41 -41
  26. package/src/cli/videostats.js +196 -196
  27. package/src/cli/watch.js +30 -30
  28. package/src/lib/api-interceptor.js +161 -161
  29. package/src/lib/args.js +809 -809
  30. package/src/lib/browser/anti-detect.js +23 -23
  31. package/src/lib/browser/cdp.js +261 -261
  32. package/src/lib/browser/health-checker.js +114 -114
  33. package/src/lib/browser/launch.js +43 -43
  34. package/src/lib/browser/page.js +184 -184
  35. package/src/lib/constants.js +297 -297
  36. package/src/lib/delay.js +54 -54
  37. package/src/lib/explore-fetch.js +118 -118
  38. package/src/lib/fetcher.js +45 -45
  39. package/src/lib/filter.js +66 -66
  40. package/src/lib/io.js +54 -54
  41. package/src/lib/output.js +80 -80
  42. package/src/lib/page-error-detector.js +109 -109
  43. package/src/lib/parse-ssr.mjs +69 -69
  44. package/src/lib/parser.js +47 -47
  45. package/src/lib/retry.js +45 -45
  46. package/src/lib/scrape.js +90 -90
  47. package/src/lib/target-locations.js +61 -61
  48. package/src/lib/tiktok-scraper.mjs +98 -61
  49. package/src/lib/url.js +52 -52
  50. package/src/main.js +73 -73
  51. package/src/npm-main.js +70 -70
  52. package/src/results/user-videos-bar.lar.lar.moeta.json +37 -0
  53. package/src/scraper/auto-core.js +203 -203
  54. package/src/scraper/core.js +255 -255
  55. package/src/scraper/explore-core.js +208 -208
  56. package/src/scraper/modules/captcha-handler.js +114 -114
  57. package/src/scraper/modules/follow-extractor.js +250 -250
  58. package/src/scraper/modules/guess-extractor.js +51 -51
  59. package/src/scraper/modules/page-helpers.js +48 -48
  60. package/src/scraper/refresh-core.js +213 -213
  61. package/src/videos/core.js +143 -143
  62. package/src/watch/data-store.js +2980 -2980
  63. package/src/watch/public/index.html +2355 -2355
  64. package/src/watch/server.js +727 -727
@@ -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
+ }