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,157 +1,157 @@
1
- $packageName = "tt-help-cli-ycl"
2
- $configPath = Join-Path $env:USERPROFILE ".tt-help.json"
3
-
4
- Write-Host "========================================"
5
- Write-Host " tt-help-cli-ycl 一键启动脚本 (Windows)"
6
- Write-Host "========================================"
7
-
8
- # ---------- 0. 根据本机 IP 自动选择 server ----------
9
- $localIp = $null
10
- try {
11
- $localIp = Get-WmiObject Win32_NetworkAdapterConfiguration |
12
- Where-Object { $_.IPEnabled -eq $true } |
13
- ForEach-Object { $_.IPAddress } |
14
- Where-Object {
15
- $_ -match '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$' -and
16
- $_ -ne '127.0.0.1' -and
17
- $_ -notlike '169.254.*'
18
- } |
19
- Select-Object -First 1
20
- } catch {
21
- }
22
- if (-not $localIp) {
23
- try {
24
- $localIp = Get-NetIPAddress -AddressFamily IPv4 -ErrorAction Stop |
25
- Where-Object { $_.IPAddress -ne '127.0.0.1' -and $_.IPAddress -notlike '169.254.*' } |
26
- Select-Object -First 1 -ExpandProperty IPAddress
27
- } catch {
28
- }
29
- }
30
- if (-not $localIp) {
31
- try {
32
- $localIp = [System.Net.Dns]::GetHostAddresses([System.Net.Dns]::GetHostName()) |
33
- Where-Object {
34
- $_.AddressFamily -eq [System.Net.Sockets.AddressFamily]::InterNetwork -and
35
- $_.IPAddressToString -ne '127.0.0.1' -and
36
- $_.IPAddressToString -notlike '169.254.*'
37
- } |
38
- Select-Object -First 1 -ExpandProperty IPAddressToString
39
- } catch {
40
- }
41
- }
42
- Write-Host "[提示] 本机 IP: $(if ($localIp) { $localIp } else { '未检测到' })"
43
- if ($localIp -and $localIp -match '^172\.18\.154\.') {
44
- $targetServer = "http://172.18.154.201:3001"
45
- Write-Host "[提示] 检测到内网 IP: $localIp,使用内网 server"
46
- } else {
47
- $targetServer = "http://117.71.53.99:17301"
48
- Write-Host "[提示] 未检测到内网 IP,使用公网 server"
49
- }
50
-
51
- # ---------- 1. 检查/安装最新版本 ----------
52
- $latestVersion = npm view $packageName version 2>$null
53
-
54
- if (-not $latestVersion) {
55
- Write-Host "[错误] 无法从 npm 获取最新版本信息"
56
- exit 1
57
- }
58
-
59
- $installedVersion = ""
60
- $output = npm list -g $packageName --depth=0 2>$null
61
- if ($output -match "$packageName@([\d.]+)") {
62
- $installedVersion = $matches[1]
63
- }
64
-
65
- if (-not $installedVersion) {
66
- Write-Host "[提示] tt-help-cli-ycl 未安装,正在安装最新版本..."
67
- npm install -g $packageName 2>$null
68
- if ($LASTEXITCODE -eq 0) {
69
- Write-Host "[OK] 安装完成: $latestVersion"
70
- } else {
71
- Write-Host "[错误] 安装失败,请手动执行: npm install -g $packageName"
72
- exit 1
73
- }
74
- } elseif ($installedVersion -eq $latestVersion) {
75
- Write-Host "[OK] tt-help-cli-ycl 已是最新版本: $latestVersion"
76
- } else {
77
- Write-Host "[提示] 当前版本: $installedVersion, 最新版本: $latestVersion"
78
- Write-Host "[执行] 正在升级最新版本..."
79
- npm install -g $packageName 2>$null
80
- if ($LASTEXITCODE -eq 0) {
81
- Write-Host "[OK] 升级完成: $latestVersion"
82
- } else {
83
- Write-Host "[警告] 升级失败,请手动执行: npm install -g $packageName"
84
- }
85
- }
86
-
87
- # ---------- 2. 检查/设置 server 配置 ----------
88
- $currentServer = ""
89
- if (Test-Path $configPath) {
90
- try {
91
- $config = Get-Content $configPath -Raw | ConvertFrom-Json
92
- $currentServer = $config.server
93
- } catch {
94
- $currentServer = ""
95
- }
96
- }
97
-
98
- if ($currentServer -eq $targetServer) {
99
- Write-Host "[OK] Server 配置正确: $targetServer"
100
- } else {
101
- $currentDisplay = if ($currentServer) { $currentServer } else { "未设置" }
102
- Write-Host "[提示] 当前 server: $currentDisplay, 目标: $targetServer"
103
- Write-Host "[执行] 正在设置 server 配置..."
104
-
105
- node -e "
106
- const fs = require('fs');
107
- const path = require('path');
108
- const configPath = path.join(require('os').homedir(), '.tt-help.json');
109
- let cfg = {};
110
- try { cfg = JSON.parse(fs.readFileSync(configPath, 'utf-8')); } catch(e) {}
111
- cfg.server = '$targetServer';
112
- fs.writeFileSync(configPath, JSON.stringify(cfg, null, 2), 'utf-8');
113
- console.log(' 已写入: ' + configPath);
114
- "
115
- Write-Host "[OK] Server 配置已设置"
116
- }
117
-
118
- # ---------- 3. 询问用户参数 ----------
119
- Write-Host ""
120
- Write-Host "========================================"
121
- Write-Host " 参数配置"
122
- Write-Host "========================================"
123
-
124
- $inputBasePort = Read-Host "起始端口 (--base-port) [默认: 9222]"
125
- $basePort = if ($inputBasePort) { $inputBasePort } else { "9222" }
126
-
127
- $inputPortCount = Read-Host "端口数量 (--port-count) [默认: 10]"
128
- $portCount = if ($inputPortCount) { $inputPortCount } else { "10" }
129
-
130
- $inputJobLocations = Read-Host "任务国家 (--job-locations) [默认: 无,使用全部]"
131
- $jobLocationsArg = if ($inputJobLocations) { "--job-locations $inputJobLocations" } else { "" }
132
-
133
- # ---------- 4. 获取配置中的用户编号并拼接 ----------
134
- $configUserId = ""
135
- if (Test-Path $configPath) {
136
- try {
137
- $config = Get-Content $configPath -Raw | ConvertFrom-Json
138
- $configUserId = $config.userId
139
- } catch {
140
- $configUserId = ""
141
- }
142
- }
143
- if (-not $configUserId) { $configUserId = "user" }
144
- $userId = "${configUserId}_${basePort}_${portCount}"
145
-
146
- # ---------- 5. 启动 tt-help explore ----------
147
- Write-Host ""
148
- Write-Host "========================================"
149
- Write-Host " 启动 tt-help explore"
150
- Write-Host "========================================"
151
- Write-Host " 用户编号: $userId"
152
- Write-Host " 起始端口: $basePort"
153
- Write-Host " 端口数量: $portCount"
154
- if ($inputJobLocations) { Write-Host " 任务国家: $inputJobLocations" }
155
- Write-Host " 速度: stealth (最慢)"
156
- Write-Host "========================================"
157
- tt-help explore stealth --user-id $userId --base-port $basePort --port-count $portCount $jobLocationsArg
1
+ $packageName = "tt-help-cli-ycl"
2
+ $configPath = Join-Path $env:USERPROFILE ".tt-help.json"
3
+
4
+ Write-Host "========================================"
5
+ Write-Host " tt-help-cli-ycl 一键启动脚本 (Windows)"
6
+ Write-Host "========================================"
7
+
8
+ # ---------- 0. 根据本机 IP 自动选择 server ----------
9
+ $localIp = $null
10
+ try {
11
+ $localIp = Get-WmiObject Win32_NetworkAdapterConfiguration |
12
+ Where-Object { $_.IPEnabled -eq $true } |
13
+ ForEach-Object { $_.IPAddress } |
14
+ Where-Object {
15
+ $_ -match '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$' -and
16
+ $_ -ne '127.0.0.1' -and
17
+ $_ -notlike '169.254.*'
18
+ } |
19
+ Select-Object -First 1
20
+ } catch {
21
+ }
22
+ if (-not $localIp) {
23
+ try {
24
+ $localIp = Get-NetIPAddress -AddressFamily IPv4 -ErrorAction Stop |
25
+ Where-Object { $_.IPAddress -ne '127.0.0.1' -and $_.IPAddress -notlike '169.254.*' } |
26
+ Select-Object -First 1 -ExpandProperty IPAddress
27
+ } catch {
28
+ }
29
+ }
30
+ if (-not $localIp) {
31
+ try {
32
+ $localIp = [System.Net.Dns]::GetHostAddresses([System.Net.Dns]::GetHostName()) |
33
+ Where-Object {
34
+ $_.AddressFamily -eq [System.Net.Sockets.AddressFamily]::InterNetwork -and
35
+ $_.IPAddressToString -ne '127.0.0.1' -and
36
+ $_.IPAddressToString -notlike '169.254.*'
37
+ } |
38
+ Select-Object -First 1 -ExpandProperty IPAddressToString
39
+ } catch {
40
+ }
41
+ }
42
+ Write-Host "[提示] 本机 IP: $(if ($localIp) { $localIp } else { '未检测到' })"
43
+ if ($localIp -and $localIp -match '^172\.18\.154\.') {
44
+ $targetServer = "http://172.18.154.201:3001"
45
+ Write-Host "[提示] 检测到内网 IP: $localIp,使用内网 server"
46
+ } else {
47
+ $targetServer = "http://117.71.53.99:17301"
48
+ Write-Host "[提示] 未检测到内网 IP,使用公网 server"
49
+ }
50
+
51
+ # ---------- 1. 检查/安装最新版本 ----------
52
+ $latestVersion = npm view $packageName version 2>$null
53
+
54
+ if (-not $latestVersion) {
55
+ Write-Host "[错误] 无法从 npm 获取最新版本信息"
56
+ exit 1
57
+ }
58
+
59
+ $installedVersion = ""
60
+ $output = npm list -g $packageName --depth=0 2>$null
61
+ if ($output -match "$packageName@([\d.]+)") {
62
+ $installedVersion = $matches[1]
63
+ }
64
+
65
+ if (-not $installedVersion) {
66
+ Write-Host "[提示] tt-help-cli-ycl 未安装,正在安装最新版本..."
67
+ npm install -g $packageName 2>$null
68
+ if ($LASTEXITCODE -eq 0) {
69
+ Write-Host "[OK] 安装完成: $latestVersion"
70
+ } else {
71
+ Write-Host "[错误] 安装失败,请手动执行: npm install -g $packageName"
72
+ exit 1
73
+ }
74
+ } elseif ($installedVersion -eq $latestVersion) {
75
+ Write-Host "[OK] tt-help-cli-ycl 已是最新版本: $latestVersion"
76
+ } else {
77
+ Write-Host "[提示] 当前版本: $installedVersion, 最新版本: $latestVersion"
78
+ Write-Host "[执行] 正在升级最新版本..."
79
+ npm install -g $packageName 2>$null
80
+ if ($LASTEXITCODE -eq 0) {
81
+ Write-Host "[OK] 升级完成: $latestVersion"
82
+ } else {
83
+ Write-Host "[警告] 升级失败,请手动执行: npm install -g $packageName"
84
+ }
85
+ }
86
+
87
+ # ---------- 2. 检查/设置 server 配置 ----------
88
+ $currentServer = ""
89
+ if (Test-Path $configPath) {
90
+ try {
91
+ $config = Get-Content $configPath -Raw | ConvertFrom-Json
92
+ $currentServer = $config.server
93
+ } catch {
94
+ $currentServer = ""
95
+ }
96
+ }
97
+
98
+ if ($currentServer -eq $targetServer) {
99
+ Write-Host "[OK] Server 配置正确: $targetServer"
100
+ } else {
101
+ $currentDisplay = if ($currentServer) { $currentServer } else { "未设置" }
102
+ Write-Host "[提示] 当前 server: $currentDisplay, 目标: $targetServer"
103
+ Write-Host "[执行] 正在设置 server 配置..."
104
+
105
+ node -e "
106
+ const fs = require('fs');
107
+ const path = require('path');
108
+ const configPath = path.join(require('os').homedir(), '.tt-help.json');
109
+ let cfg = {};
110
+ try { cfg = JSON.parse(fs.readFileSync(configPath, 'utf-8')); } catch(e) {}
111
+ cfg.server = '$targetServer';
112
+ fs.writeFileSync(configPath, JSON.stringify(cfg, null, 2), 'utf-8');
113
+ console.log(' 已写入: ' + configPath);
114
+ "
115
+ Write-Host "[OK] Server 配置已设置"
116
+ }
117
+
118
+ # ---------- 3. 询问用户参数 ----------
119
+ Write-Host ""
120
+ Write-Host "========================================"
121
+ Write-Host " 参数配置"
122
+ Write-Host "========================================"
123
+
124
+ $inputBasePort = Read-Host "起始端口 (--base-port) [默认: 9222]"
125
+ $basePort = if ($inputBasePort) { $inputBasePort } else { "9222" }
126
+
127
+ $inputPortCount = Read-Host "端口数量 (--port-count) [默认: 10]"
128
+ $portCount = if ($inputPortCount) { $inputPortCount } else { "10" }
129
+
130
+ $inputJobLocations = Read-Host "任务国家 (--job-locations) [默认: 无,使用全部]"
131
+ $jobLocationsArg = if ($inputJobLocations) { "--job-locations $inputJobLocations" } else { "" }
132
+
133
+ # ---------- 4. 获取配置中的用户编号并拼接 ----------
134
+ $configUserId = ""
135
+ if (Test-Path $configPath) {
136
+ try {
137
+ $config = Get-Content $configPath -Raw | ConvertFrom-Json
138
+ $configUserId = $config.userId
139
+ } catch {
140
+ $configUserId = ""
141
+ }
142
+ }
143
+ if (-not $configUserId) { $configUserId = "user" }
144
+ $userId = "${configUserId}_${basePort}_${portCount}"
145
+
146
+ # ---------- 5. 启动 tt-help explore ----------
147
+ Write-Host ""
148
+ Write-Host "========================================"
149
+ Write-Host " 启动 tt-help explore"
150
+ Write-Host "========================================"
151
+ Write-Host " 用户编号: $userId"
152
+ Write-Host " 起始端口: $basePort"
153
+ Write-Host " 端口数量: $portCount"
154
+ if ($inputJobLocations) { Write-Host " 任务国家: $inputJobLocations" }
155
+ Write-Host " 速度: stealth (最慢)"
156
+ Write-Host "========================================"
157
+ tt-help explore stealth --user-id $userId --base-port $basePort --port-count $portCount $jobLocationsArg
@@ -1,119 +1,119 @@
1
- #!/bin/bash
2
-
3
- PACKAGENAME="tt-help-cli-ycl"
4
- CONFIG_PATH="$HOME/.tt-help.json"
5
-
6
- echo "========================================"
7
- echo " tt-help-cli-ycl 一键启动脚本 (macOS)"
8
- echo "========================================"
9
-
10
- # ---------- 0. 根据本机 IP 自动选择 server ----------
11
- LOCAL_IP=$(ifconfig | awk '/inet / && $2 != "127.0.0.1" { print $2; exit }')
12
-
13
- echo "[提示] 本机 IP: ${LOCAL_IP:-未检测到}"
14
-
15
- if [[ "$LOCAL_IP" =~ ^172\.18\.154\.[0-9]+$ ]]; then
16
- TARGET_SERVER="http://172.18.154.201:3001"
17
- echo "[提示] 检测到内网 IP: $LOCAL_IP,使用内网 server"
18
- else
19
- TARGET_SERVER="http://117.71.53.99:17301"
20
- echo "[提示] 未检测到内网 IP,使用公网 server"
21
- fi
22
-
23
- # ---------- 1. 检查/安装最新版本 ----------
24
- LATEST_VERSION=$(npm view "$PACKAGENAME" version 2>/dev/null)
25
-
26
- if [ -z "$LATEST_VERSION" ]; then
27
- echo "[错误] 无法从 npm 获取最新版本信息"
28
- exit 1
29
- fi
30
-
31
- INSTALLED_VERSION=$(npm list -g "$PACKAGENAME" --depth=0 2>/dev/null | grep "$PACKAGENAME@" | head -1 | sed 's/.*@//' | sed 's/[) ].*//')
32
-
33
- if [ -z "$INSTALLED_VERSION" ]; then
34
- echo "[提示] tt-help-cli-ycl 未安装,正在安装最新版本..."
35
- npm install -g "$PACKAGENAME"
36
- if [ $? -eq 0 ]; then
37
- echo "[OK] 安装完成: $LATEST_VERSION"
38
- else
39
- echo "[错误] 安装失败,请手动执行: npm install -g $PACKAGENAME"
40
- exit 1
41
- fi
42
- elif [ "$INSTALLED_VERSION" = "$LATEST_VERSION" ]; then
43
- echo "[OK] tt-help-cli-ycl 已是最新版本: $LATEST_VERSION"
44
- else
45
- echo "[提示] 当前版本: $INSTALLED_VERSION, 最新版本: $LATEST_VERSION"
46
- echo "[执行] 正在升级最新版本..."
47
- npm install -g "$PACKAGENAME" 2>/dev/null
48
- if [ $? -eq 0 ]; then
49
- echo "[OK] 安装完成: $LATEST_VERSION"
50
- else
51
- echo "[警告] 自动安装失败,尝试手动更新..."
52
- npm update -g "$PACKAGENAME"
53
- fi
54
- fi
55
-
56
- # ---------- 2. 检查/设置 server 配置 ----------
57
- CURRENT_SERVER=""
58
- if [ -f "$CONFIG_PATH" ]; then
59
- CURRENT_SERVER=$(node -e "try{const c=JSON.parse(require('fs').readFileSync('$CONFIG_PATH','utf-8'));console.log(c.server||'')}catch(e){}" 2>/dev/null)
60
- fi
61
-
62
- if [ "$CURRENT_SERVER" = "$TARGET_SERVER" ]; then
63
- echo "[OK] Server 配置正确: $TARGET_SERVER"
64
- else
65
- echo "[提示] 当前 server: ${CURRENT_SERVER:-未设置}, 目标: $TARGET_SERVER"
66
- echo "[执行] 正在设置 server 配置..."
67
- node -e "
68
- const fs = require('fs');
69
- const path = require('path');
70
- const configPath = path.join(require('os').homedir(), '.tt-help.json');
71
- let cfg = {};
72
- try { cfg = JSON.parse(fs.readFileSync(configPath, 'utf-8')); } catch(e) {}
73
- cfg.server = '$TARGET_SERVER';
74
- fs.writeFileSync(configPath, JSON.stringify(cfg, null, 2), 'utf-8');
75
- console.log(' 已写入: ' + configPath);
76
- "
77
- echo "[OK] Server 配置已设置"
78
- fi
79
-
80
- # ---------- 3. 询问用户参数 ----------
81
- echo ""
82
- echo "========================================"
83
- echo " 参数配置"
84
- echo "========================================"
85
-
86
- printf "起始端口 (--base-port) [默认: 9222]: "
87
- read INPUT_BASE_PORT
88
- BASE_PORT="${INPUT_BASE_PORT:-9222}"
89
-
90
- printf "端口数量 (--port-count) [默认: 10]: "
91
- read INPUT_PORT_COUNT
92
- PORT_COUNT="${INPUT_PORT_COUNT:-10}"
93
-
94
- printf "任务国家 (--job-locations) [默认: 无,使用全部]: "
95
- read INPUT_JOB_LOCATIONS
96
-
97
- # ---------- 4. 获取配置中的用户编号并拼接 ----------
98
- CONFIG_USER_ID=""
99
- if [ -f "$CONFIG_PATH" ]; then
100
- CONFIG_USER_ID=$(node -e "try{const c=JSON.parse(require('fs').readFileSync('$CONFIG_PATH','utf-8'));console.log(c.userId||'')}catch(e){}" 2>/dev/null)
101
- fi
102
- if [ -z "$CONFIG_USER_ID" ]; then
103
- CONFIG_USER_ID="user"
104
- fi
105
- USER_ID="${CONFIG_USER_ID}_${BASE_PORT}_${PORT_COUNT}"
106
-
107
- echo ""
108
- echo "========================================"
109
- echo " 启动 tt-help explore"
110
- echo "========================================"
111
- echo " 用户编号: $USER_ID"
112
- echo " 起始端口: $BASE_PORT"
113
- echo " 端口数量: $PORT_COUNT"
114
- if [ -n "$INPUT_JOB_LOCATIONS" ]; then echo " 任务国家: $INPUT_JOB_LOCATIONS"; fi
115
- echo " 速度: stealth (最慢)"
116
- echo "========================================"
117
- JOB_LOC_ARGS=""
118
- if [ -n "$INPUT_JOB_LOCATIONS" ]; then JOB_LOC_ARGS="--job-locations $INPUT_JOB_LOCATIONS"; fi
119
- tt-help explore stealth --user-id "$USER_ID" --base-port "$BASE_PORT" --port-count "$PORT_COUNT" $JOB_LOC_ARGS
1
+ #!/bin/bash
2
+
3
+ PACKAGENAME="tt-help-cli-ycl"
4
+ CONFIG_PATH="$HOME/.tt-help.json"
5
+
6
+ echo "========================================"
7
+ echo " tt-help-cli-ycl 一键启动脚本 (macOS)"
8
+ echo "========================================"
9
+
10
+ # ---------- 0. 根据本机 IP 自动选择 server ----------
11
+ LOCAL_IP=$(ifconfig | awk '/inet / && $2 != "127.0.0.1" { print $2; exit }')
12
+
13
+ echo "[提示] 本机 IP: ${LOCAL_IP:-未检测到}"
14
+
15
+ if [[ "$LOCAL_IP" =~ ^172\.18\.154\.[0-9]+$ ]]; then
16
+ TARGET_SERVER="http://172.18.154.201:3001"
17
+ echo "[提示] 检测到内网 IP: $LOCAL_IP,使用内网 server"
18
+ else
19
+ TARGET_SERVER="http://117.71.53.99:17301"
20
+ echo "[提示] 未检测到内网 IP,使用公网 server"
21
+ fi
22
+
23
+ # ---------- 1. 检查/安装最新版本 ----------
24
+ LATEST_VERSION=$(npm view "$PACKAGENAME" version 2>/dev/null)
25
+
26
+ if [ -z "$LATEST_VERSION" ]; then
27
+ echo "[错误] 无法从 npm 获取最新版本信息"
28
+ exit 1
29
+ fi
30
+
31
+ INSTALLED_VERSION=$(npm list -g "$PACKAGENAME" --depth=0 2>/dev/null | grep "$PACKAGENAME@" | head -1 | sed 's/.*@//' | sed 's/[) ].*//')
32
+
33
+ if [ -z "$INSTALLED_VERSION" ]; then
34
+ echo "[提示] tt-help-cli-ycl 未安装,正在安装最新版本..."
35
+ npm install -g "$PACKAGENAME"
36
+ if [ $? -eq 0 ]; then
37
+ echo "[OK] 安装完成: $LATEST_VERSION"
38
+ else
39
+ echo "[错误] 安装失败,请手动执行: npm install -g $PACKAGENAME"
40
+ exit 1
41
+ fi
42
+ elif [ "$INSTALLED_VERSION" = "$LATEST_VERSION" ]; then
43
+ echo "[OK] tt-help-cli-ycl 已是最新版本: $LATEST_VERSION"
44
+ else
45
+ echo "[提示] 当前版本: $INSTALLED_VERSION, 最新版本: $LATEST_VERSION"
46
+ echo "[执行] 正在升级最新版本..."
47
+ npm install -g "$PACKAGENAME" 2>/dev/null
48
+ if [ $? -eq 0 ]; then
49
+ echo "[OK] 安装完成: $LATEST_VERSION"
50
+ else
51
+ echo "[警告] 自动安装失败,尝试手动更新..."
52
+ npm update -g "$PACKAGENAME"
53
+ fi
54
+ fi
55
+
56
+ # ---------- 2. 检查/设置 server 配置 ----------
57
+ CURRENT_SERVER=""
58
+ if [ -f "$CONFIG_PATH" ]; then
59
+ CURRENT_SERVER=$(node -e "try{const c=JSON.parse(require('fs').readFileSync('$CONFIG_PATH','utf-8'));console.log(c.server||'')}catch(e){}" 2>/dev/null)
60
+ fi
61
+
62
+ if [ "$CURRENT_SERVER" = "$TARGET_SERVER" ]; then
63
+ echo "[OK] Server 配置正确: $TARGET_SERVER"
64
+ else
65
+ echo "[提示] 当前 server: ${CURRENT_SERVER:-未设置}, 目标: $TARGET_SERVER"
66
+ echo "[执行] 正在设置 server 配置..."
67
+ node -e "
68
+ const fs = require('fs');
69
+ const path = require('path');
70
+ const configPath = path.join(require('os').homedir(), '.tt-help.json');
71
+ let cfg = {};
72
+ try { cfg = JSON.parse(fs.readFileSync(configPath, 'utf-8')); } catch(e) {}
73
+ cfg.server = '$TARGET_SERVER';
74
+ fs.writeFileSync(configPath, JSON.stringify(cfg, null, 2), 'utf-8');
75
+ console.log(' 已写入: ' + configPath);
76
+ "
77
+ echo "[OK] Server 配置已设置"
78
+ fi
79
+
80
+ # ---------- 3. 询问用户参数 ----------
81
+ echo ""
82
+ echo "========================================"
83
+ echo " 参数配置"
84
+ echo "========================================"
85
+
86
+ printf "起始端口 (--base-port) [默认: 9222]: "
87
+ read INPUT_BASE_PORT
88
+ BASE_PORT="${INPUT_BASE_PORT:-9222}"
89
+
90
+ printf "端口数量 (--port-count) [默认: 10]: "
91
+ read INPUT_PORT_COUNT
92
+ PORT_COUNT="${INPUT_PORT_COUNT:-10}"
93
+
94
+ printf "任务国家 (--job-locations) [默认: 无,使用全部]: "
95
+ read INPUT_JOB_LOCATIONS
96
+
97
+ # ---------- 4. 获取配置中的用户编号并拼接 ----------
98
+ CONFIG_USER_ID=""
99
+ if [ -f "$CONFIG_PATH" ]; then
100
+ CONFIG_USER_ID=$(node -e "try{const c=JSON.parse(require('fs').readFileSync('$CONFIG_PATH','utf-8'));console.log(c.userId||'')}catch(e){}" 2>/dev/null)
101
+ fi
102
+ if [ -z "$CONFIG_USER_ID" ]; then
103
+ CONFIG_USER_ID="user"
104
+ fi
105
+ USER_ID="${CONFIG_USER_ID}_${BASE_PORT}_${PORT_COUNT}"
106
+
107
+ echo ""
108
+ echo "========================================"
109
+ echo " 启动 tt-help explore"
110
+ echo "========================================"
111
+ echo " 用户编号: $USER_ID"
112
+ echo " 起始端口: $BASE_PORT"
113
+ echo " 端口数量: $PORT_COUNT"
114
+ if [ -n "$INPUT_JOB_LOCATIONS" ]; then echo " 任务国家: $INPUT_JOB_LOCATIONS"; fi
115
+ echo " 速度: stealth (最慢)"
116
+ echo "========================================"
117
+ JOB_LOC_ARGS=""
118
+ if [ -n "$INPUT_JOB_LOCATIONS" ]; then JOB_LOC_ARGS="--job-locations $INPUT_JOB_LOCATIONS"; fi
119
+ tt-help explore stealth --user-id "$USER_ID" --base-port "$BASE_PORT" --port-count "$PORT_COUNT" $JOB_LOC_ARGS
@@ -0,0 +1,68 @@
1
+ import { chromium } from 'playwright';
2
+
3
+ const URL = 'https://www.tiktok.com/@mariaelenasanchez607/video/7630110959650000150';
4
+
5
+ async function main() {
6
+ const browser = await chromium.connectOverCDP('http://127.0.0.1:9222');
7
+ const page = browser.contexts()[0].pages()[0];
8
+
9
+ // 测试 detectCaptcha
10
+ console.error('=== 测试 detectCaptcha (无验证码) ===');
11
+ await page.goto(URL, { waitUntil: 'domcontentloaded', timeout: 30000 });
12
+ await page.waitForTimeout(3000);
13
+
14
+ const { detectCaptcha, closeCaptcha, handleCaptcha } = await import('../src/scraper/modules/captcha-handler.mjs');
15
+
16
+ const r1 = await detectCaptcha(page);
17
+ console.error('未点击评论:', JSON.stringify(r1));
18
+
19
+ // 点击评论触发验证码
20
+ await page.evaluate(() => {
21
+ const all = document.querySelectorAll('button');
22
+ for (const el of all) {
23
+ if (/^评论$/.test(el.textContent?.trim()) && el.offsetParent !== null && el.getBoundingClientRect().width > 0) {
24
+ el.click();
25
+ break;
26
+ }
27
+ }
28
+ });
29
+ await page.waitForTimeout(3000);
30
+
31
+ console.error('\n=== 测试 detectCaptcha (有验证码) ===');
32
+ const r2 = await detectCaptcha(page);
33
+ console.error('点击评论后:', JSON.stringify(r2));
34
+
35
+ console.error('\n=== 测试 closeCaptcha ===');
36
+ const r3 = await closeCaptcha(page);
37
+ await page.waitForTimeout(1000);
38
+ console.error('关闭结果:', JSON.stringify(r3));
39
+
40
+ const r4 = await detectCaptcha(page);
41
+ console.error('关闭后检测:', JSON.stringify(r4));
42
+
43
+ console.error('\n=== 测试 handleCaptcha (完整流程) ===');
44
+ // 重新触发
45
+ await page.goto(URL, { waitUntil: 'domcontentloaded', timeout: 30000 });
46
+ await page.waitForTimeout(3000);
47
+ await page.evaluate(() => {
48
+ const all = document.querySelectorAll('button');
49
+ for (const el of all) {
50
+ if (/^评论$/.test(el.textContent?.trim()) && el.offsetParent !== null && el.getBoundingClientRect().width > 0) {
51
+ el.click();
52
+ break;
53
+ }
54
+ }
55
+ });
56
+ await page.waitForTimeout(3000);
57
+
58
+ const r5 = await handleCaptcha(page);
59
+ console.error('handleCaptcha 结果:', JSON.stringify(r5));
60
+
61
+ await page.screenshot({ path: '/tmp/lib-test-final.png' });
62
+ console.error('\n最终截图: /tmp/lib-test-final.png');
63
+ }
64
+
65
+ main().catch(err => {
66
+ console.error('错误:', err);
67
+ process.exit(1);
68
+ });