feat: 娣诲姞30鍒嗛挓瓒呮椂淇濇姢鍜屾墜鍔ㄥ彂閫佽繑鍥為敭鍔熻兘
This commit is contained in:
1 parent
fe0098c591
commit
97bda4816f
25 files changed
+22400
-23900
No files matched your search
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -111,3 +111,7 @@ python cleanup_unused_files.py
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -209,3 +209,7 @@ YYYYMMDD_HHMMSS_操作类型_图片名_步骤_坐标_额外信息.png
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -177,6 +177,10 @@ python check_dependencies.py
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -156,6 +156,10 @@ douyin_guaji
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -97,6 +97,10 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -312,3 +312,7 @@ douyin_fudai_finder.py
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
基于 ADB + OCR + 像素检测 + 模板匹配技术
|
||||
|
||||
[](version.py)
|
||||
[](version.py)
|
||||
[](https://www.python.org/)
|
||||
[](https://www.microsoft.com/windows)
|
||||
|
||||
@@ -143,6 +143,19 @@
|
||||
- 支持切换N次后回到第一个直播间(循环模式,向上回退)
|
||||
- 智能处理直播结束、网络异常等情况
|
||||
|
||||
### 11. 手动操作功能
|
||||
|
||||
- **手动发送返回键**:在GUI界面提供"发送返回键"按钮,可随时手动发送返回键到设备
|
||||
- 适用于需要手动干预的场景
|
||||
- 支持自动设备选择或手动指定设备
|
||||
|
||||
### 12. 智能超时保护
|
||||
|
||||
- **30分钟超时机制**:如果30分钟没有成功参与福袋,自动返回推荐页面并重新进入直播间
|
||||
- 防止长时间卡在某个直播间无法参与福袋
|
||||
- 自动重置运行状态,确保脚本持续有效运行
|
||||
- 记录最后一次成功参与的时间,智能判断是否需要重置
|
||||
|
||||
---
|
||||
|
||||
## 🏗️ 技术架构
|
||||
@@ -345,7 +358,11 @@ adb devices
|
||||
- 在右侧日志窗口查看运行状态
|
||||
- 点击"截图"按钮可查看实时截图
|
||||
|
||||
4. **停止运行**
|
||||
4. **手动操作**
|
||||
- 点击"发送返回键"按钮可手动发送返回键到设备
|
||||
- 适用于需要手动干预的场景
|
||||
|
||||
5. **停止运行**
|
||||
- 点击"停止"按钮
|
||||
- 或点击"强制停止"按钮(如果普通停止无效)
|
||||
|
||||
@@ -425,6 +442,7 @@ python run_cli.py \
|
||||
| `live_room_match_threshold` | float | `0.8` | 直播间检测阈值(0.0~1.0),值越高越严格,建议≥0.8 |
|
||||
| `stage_diag_max_time` | float | `15.0` | 阶段诊断的最大耗时(秒) |
|
||||
| `stage_diag_max_step_time` | float | `4.0` | 阶段诊断单步的最大耗时(秒) |
|
||||
| `no_attend_timeout_minutes` | float | `30.0` | 超时时间(分钟),如果该时间内没有成功参与福袋,则返回推荐页面重新进入直播间 |
|
||||
|
||||
### 福袋筛选设置
|
||||
|
||||
@@ -573,6 +591,11 @@ python run_cli.py \
|
||||
- 关注是否出现人机验证
|
||||
- 如频繁出现验证,降低运行频率或启用养号
|
||||
|
||||
5. **利用超时保护功能**
|
||||
- 30分钟超时功能会自动重置运行状态
|
||||
- 如果发现长时间没有参与福袋,脚本会自动返回推荐页面
|
||||
- 无需手动干预,脚本会自动恢复运行
|
||||
|
||||
### 高级使用技巧
|
||||
|
||||
1. **多账号管理**
|
||||
@@ -1183,14 +1206,40 @@ python run_cli.py \
|
||||
|
||||
**A**: 目前不支持 iOS 设备,因为 iOS 需要越狱才能使用类似 ADB 的工具。
|
||||
|
||||
### Q13: 30分钟超时功能如何工作?
|
||||
|
||||
**A**:
|
||||
1. 脚本会记录最后一次成功参与福袋的时间
|
||||
2. 如果30分钟内没有成功参与福袋,会自动返回推荐页面
|
||||
3. 然后重新进入直播间,重置运行状态
|
||||
4. 这样可以防止长时间卡在某个直播间无法参与福袋
|
||||
|
||||
### Q14: 如何使用手动发送返回键功能?
|
||||
|
||||
**A**:
|
||||
1. 在GUI界面找到"发送返回键"按钮(位于"测试评论"按钮旁边)
|
||||
2. 点击按钮即可发送返回键到当前设备
|
||||
3. 如果没有指定设备,会自动选择第一个可用设备
|
||||
4. 适用于需要手动干预的场景
|
||||
|
||||
---
|
||||
|
||||
## 📜 版本历史
|
||||
|
||||
### V3.3.2 (2025-12-22)
|
||||
### V3.3.3 (2025-12-XX)
|
||||
|
||||
**当前版本**
|
||||
|
||||
- ✨ **新增功能**:
|
||||
- 手动发送返回键按钮:在GUI界面添加"发送返回键"按钮,支持随时手动发送返回键
|
||||
- 30分钟超时保护:如果30分钟没有成功参与福袋,自动返回推荐页面并重新进入直播间
|
||||
- 智能超时检测:记录最后一次成功参与的时间,智能判断是否需要重置
|
||||
- 🐛 修复:修复代码中的缩进错误和残留代码块
|
||||
- 🔧 优化:完善错误处理和日志记录
|
||||
- 📝 更新:完善文档和 README
|
||||
|
||||
### V3.3.2 (2025-12-22)
|
||||
|
||||
- 🚀 **性能优化**:所有串行OCR改为并行执行,显著提升识别速度
|
||||
- 福袋内容、倒计时、价值识别并行执行
|
||||
- 倒计时分割识别(分钟+秒)并行执行
|
||||
|
||||
@@ -70,3 +70,7 @@ python 生成WPS流程图.py
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
+31
-3
@@ -6,6 +6,11 @@
|
||||
本文件包含完整的程序流程图,可以直接在WPS中创建流程图使用。
|
||||
建议使用WPS演示(WPS演示文稿)的"插入 → 形状 → 流程图"功能创建。
|
||||
|
||||
【版本信息】
|
||||
版本: V3.3.3+
|
||||
最后更新: 2025-12-XX
|
||||
主要更新: 30分钟超时保护、手动操作功能、并行OCR优化、回退逻辑修复
|
||||
|
||||
================================================================================
|
||||
一、主流程图
|
||||
================================================================================
|
||||
@@ -20,6 +25,23 @@
|
||||
↓
|
||||
【循环】主循环开始
|
||||
↓
|
||||
【判断】检查30分钟超时(V3.3.3+)
|
||||
├─ 【判断】是否成功参与过?
|
||||
│ ├─ 是 → 【判断】距离最后参与是否超过30分钟?
|
||||
│ │ ├─ 是 → 【操作】返回推荐页面(多次点击返回键,最多10次)
|
||||
│ │ │ ↓
|
||||
│ │ │ 【操作】点击关注标签
|
||||
│ │ │ ↓
|
||||
│ │ │ 【操作】点击进入直播间(连点2次)
|
||||
│ │ │ ↓
|
||||
│ │ │ 【操作】重置超时时间
|
||||
│ │ │ ↓
|
||||
│ │ │ 【延迟】延迟2秒 → 返回主循环
|
||||
│ │ └─ 否 → 继续
|
||||
│ └─ 否 → 【判断】运行时间是否超过30分钟?
|
||||
│ ├─ 是 → 【操作】返回推荐页面(同上)
|
||||
│ └─ 否 → 继续
|
||||
↓
|
||||
【判断】是否启用高价值预约且有预约队列?
|
||||
├─ 是 → 【处理】处理预约回退
|
||||
│ ├─ 检查队列是否已满
|
||||
@@ -331,9 +353,15 @@
|
||||
│ └─ 否 → 【操作】记录为预约(剩余秒数大于阈值)
|
||||
└─ 否 → 【操作】立即参与抽奖
|
||||
↓
|
||||
【返回】已参与 / 已记录预约
|
||||
↓
|
||||
【结束】
|
||||
【判断】参与成功?(V3.3.3+)
|
||||
├─ 是 → 【操作】更新最后成功参与时间(_last_successful_attend_ts)
|
||||
│ ↓
|
||||
│ 【操作】关闭详情页
|
||||
│ ↓
|
||||
│ 【延迟】延迟1秒 → 返回主循环
|
||||
└─ 否 → 【记录】记录错误
|
||||
↓
|
||||
【延迟】延迟1秒 → 返回主循环
|
||||
|
||||
|
||||
================================================================================
|
||||
|
||||
@@ -81,6 +81,10 @@ else:
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
+2
-2
@@ -5,9 +5,9 @@
|
||||
"min_prize_value_yuan": 1.0,
|
||||
"min_participants": 0,
|
||||
"max_participants": 0,
|
||||
"skip_if_countdown_gt_seconds": 150,
|
||||
"skip_if_countdown_gt_seconds": 600,
|
||||
"reset_after_swipes_enabled": true,
|
||||
"reset_after_swipes": 2,
|
||||
"reset_after_swipes": 50,
|
||||
"auto_join_fansclub": true,
|
||||
"fansclub_fail_action": "switch",
|
||||
"high_value_fudai_enabled": true,
|
||||
|
||||
+398
-94
@@ -258,16 +258,36 @@ def check_have_fudai_with_ready_screenshot(
|
||||
except Exception:
|
||||
retry_delay_s = 0.6
|
||||
try:
|
||||
max_wait_s = float(getattr(analyser, "fudai_icon_max_wait_seconds", 4.0) or 4.0)
|
||||
max_wait_s = float(getattr(analyser, "fudai_icon_max_wait_seconds", 5.0) or 5.0)
|
||||
except Exception:
|
||||
max_wait_s = 4.0
|
||||
max_wait_s = 5.0
|
||||
if retry_delay_s < 0.1:
|
||||
retry_delay_s = 0.1 # 最小间隔改为0.1秒
|
||||
if max_wait_s < 0:
|
||||
max_wait_s = 0.0
|
||||
# 防止无限等待:最大等待时间限制为30秒
|
||||
if max_wait_s > 30.0:
|
||||
max_wait_s = 30.0
|
||||
|
||||
loop = 0
|
||||
max_loops = int(max_wait_s / retry_delay_s) + 10 # 额外的循环次数保护
|
||||
consecutive_failures = 0 # 连续失败计数
|
||||
max_consecutive_failures = 5 # 最大连续失败次数
|
||||
|
||||
while (time.time() - func_start) < max_wait_s:
|
||||
# 额外的循环次数保护:防止无限循环
|
||||
if loop >= max_loops:
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"[找福袋图标] 警告",
|
||||
"达到最大循环次数限制,提前退出",
|
||||
max_loops=max_loops,
|
||||
elapsed_s=round(time.time() - func_start, 2),
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
break
|
||||
|
||||
# 每次循环都重新截图(除了第一次如果已经提供了截图)
|
||||
if not (screenshot_ready and loop == 0):
|
||||
try:
|
||||
@@ -298,6 +318,19 @@ def check_have_fudai_with_ready_screenshot(
|
||||
# 如果截图读取失败,等待后继续下一次循环
|
||||
if pic is None:
|
||||
loop += 1
|
||||
consecutive_failures += 1
|
||||
# 如果连续失败太多次,提前退出
|
||||
if consecutive_failures >= max_consecutive_failures:
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"[找福袋图标] 警告",
|
||||
"连续截图失败次数过多,提前退出",
|
||||
consecutive_failures=consecutive_failures,
|
||||
elapsed_s=round(time.time() - func_start, 2),
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
break
|
||||
# 检查是否还有剩余时间
|
||||
elapsed = time.time() - func_start
|
||||
if elapsed < max_wait_s:
|
||||
@@ -331,6 +364,22 @@ def check_have_fudai_with_ready_screenshot(
|
||||
scan_x_start = 41 * rx // 1080
|
||||
scan_x_end = min(410 * rx // 1080, width)
|
||||
scan_y = 403 * ry // 2400 + y_pianyi_val
|
||||
|
||||
# 获取最优搜索起始位置(使用历史记录或默认值)
|
||||
try:
|
||||
# 尝试获取上次找到的福袋位置(1080基准)
|
||||
last_fudai_x = int(getattr(analyser, "last_fudai_x", 0) or 0)
|
||||
if last_fudai_x > 0 and scan_x_start <= last_fudai_x <= scan_x_end:
|
||||
optimal_x_scaled = last_fudai_x * rx // 1080
|
||||
else:
|
||||
# 使用默认最优位置:最热门区域中心(98-240的中心,约169)
|
||||
optimal_x_scaled = 169 * rx // 1080
|
||||
except Exception:
|
||||
# 使用默认最优位置
|
||||
optimal_x_scaled = 169 * rx // 1080
|
||||
|
||||
# 确保最优位置在搜索范围内
|
||||
optimal_x_scaled = max(scan_x_start, min(optimal_x_scaled, scan_x_end - 1))
|
||||
|
||||
# 保存完整截图用于调试(检测前)
|
||||
try:
|
||||
@@ -404,11 +453,46 @@ def check_have_fudai_with_ready_screenshot(
|
||||
# 至少需要2个像素匹配(避免单个噪点误判)
|
||||
valid_cols = cols >= 2
|
||||
if valid_cols.any():
|
||||
# 找到第一个有效匹配的列
|
||||
col_idx = int(_np.argmax(valid_cols))
|
||||
# 优化:从最优位置开始向左右两侧搜索
|
||||
roi_width = x2 - x1
|
||||
optimal_col = optimal_x_scaled - x1 # 转换为ROI内的列索引
|
||||
optimal_col = max(0, min(optimal_col, roi_width - 1))
|
||||
|
||||
# 从最优位置开始,向左右两侧交替搜索
|
||||
found_col = None
|
||||
search_range = max(optimal_col, roi_width - optimal_col)
|
||||
|
||||
# 先检查最优位置本身
|
||||
if valid_cols[optimal_col]:
|
||||
found_col = optimal_col
|
||||
else:
|
||||
# 向左右两侧交替搜索
|
||||
for offset in range(1, search_range + 1):
|
||||
# 先检查右侧
|
||||
right_col = optimal_col + offset
|
||||
if right_col < roi_width and valid_cols[right_col]:
|
||||
found_col = right_col
|
||||
break
|
||||
# 再检查左侧
|
||||
left_col = optimal_col - offset
|
||||
if left_col >= 0 and valid_cols[left_col]:
|
||||
found_col = left_col
|
||||
break
|
||||
|
||||
# 如果没找到,回退到原来的方法(从左到右)
|
||||
if found_col is None:
|
||||
found_col = int(_np.argmax(valid_cols))
|
||||
|
||||
col_idx = found_col
|
||||
# 计算检测到的x坐标:转换为1080基准坐标,确保精度
|
||||
detected_x = int((x1 + col_idx) * 1080.0 / max(1, rx))
|
||||
detected = True
|
||||
|
||||
# 保存找到的位置作为下次的最优位置
|
||||
try:
|
||||
analyser.last_fudai_x = detected_x
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 双截图记录:保存成功识别存档截图
|
||||
try:
|
||||
@@ -464,6 +548,23 @@ def check_have_fudai_with_ready_screenshot(
|
||||
scan_x_start = 41 * rx // 1080
|
||||
scan_x_end = min(410 * rx // 1080, pic_width)
|
||||
scan_y = 403 * ry // 2400 + y_pianyi_val
|
||||
|
||||
# 获取最优搜索起始位置(使用历史记录或默认值)
|
||||
try:
|
||||
# 尝试获取上次找到的福袋位置(1080基准)
|
||||
last_fudai_x = int(getattr(analyser, "last_fudai_x", 0) or 0)
|
||||
if last_fudai_x > 0 and scan_x_start <= last_fudai_x * rx // 1080 <= scan_x_end:
|
||||
optimal_x_scaled = last_fudai_x * rx // 1080
|
||||
else:
|
||||
# 使用默认最优位置:最热门区域中心(98-240的中心,约169)
|
||||
optimal_x_scaled = 169 * rx // 1080
|
||||
except Exception:
|
||||
# 使用默认最优位置
|
||||
optimal_x_scaled = 169 * rx // 1080
|
||||
|
||||
# 确保最优位置在搜索范围内
|
||||
optimal_x_scaled = max(scan_x_start, min(optimal_x_scaled, scan_x_end - 1))
|
||||
|
||||
# 确保y坐标在有效范围内
|
||||
if 0 <= scan_y < pic_height:
|
||||
# 精度优化:同时检查上下几行像素,提高检测准确性
|
||||
@@ -471,82 +572,145 @@ def check_have_fudai_with_ready_screenshot(
|
||||
check_y = scan_y + offset_y
|
||||
if not (0 <= check_y < pic_height):
|
||||
continue
|
||||
for x_scaled in range(scan_x_start, scan_x_end):
|
||||
|
||||
# 优化:从最优位置开始向左右两侧搜索
|
||||
found_x = None
|
||||
search_range = max(optimal_x_scaled - scan_x_start, scan_x_end - optimal_x_scaled)
|
||||
|
||||
# 先检查最优位置本身
|
||||
try:
|
||||
px = pix[optimal_x_scaled, check_y]
|
||||
if isinstance(px, tuple) and len(px) >= 3:
|
||||
if (
|
||||
190 <= px[0] <= 206
|
||||
and 173 <= px[1] <= 196
|
||||
and 234 <= px[2] <= 250
|
||||
):
|
||||
found_x = optimal_x_scaled
|
||||
except (IndexError, TypeError):
|
||||
pass
|
||||
|
||||
# 如果最优位置没找到,向左右两侧交替搜索
|
||||
if found_x is None:
|
||||
for offset in range(1, search_range + 1):
|
||||
# 先检查右侧
|
||||
right_x = optimal_x_scaled + offset
|
||||
if right_x < scan_x_end:
|
||||
try:
|
||||
px = pix[right_x, check_y]
|
||||
if isinstance(px, tuple) and len(px) >= 3:
|
||||
if (
|
||||
190 <= px[0] <= 206
|
||||
and 173 <= px[1] <= 196
|
||||
and 234 <= px[2] <= 250
|
||||
):
|
||||
found_x = right_x
|
||||
break
|
||||
except (IndexError, TypeError):
|
||||
continue
|
||||
|
||||
# 再检查左侧
|
||||
left_x = optimal_x_scaled - offset
|
||||
if left_x >= scan_x_start:
|
||||
try:
|
||||
px = pix[left_x, check_y]
|
||||
if isinstance(px, tuple) and len(px) >= 3:
|
||||
if (
|
||||
190 <= px[0] <= 206
|
||||
and 173 <= px[1] <= 196
|
||||
and 234 <= px[2] <= 250
|
||||
):
|
||||
found_x = left_x
|
||||
break
|
||||
except (IndexError, TypeError):
|
||||
continue
|
||||
|
||||
# 如果还是没找到,回退到原来的方法(从左到右)
|
||||
if found_x is None:
|
||||
for x_scaled in range(scan_x_start, scan_x_end):
|
||||
try:
|
||||
px = pix[x_scaled, check_y]
|
||||
if isinstance(px, tuple) and len(px) >= 3:
|
||||
if (
|
||||
190 <= px[0] <= 206
|
||||
and 173 <= px[1] <= 196
|
||||
and 234 <= px[2] <= 250
|
||||
):
|
||||
found_x = x_scaled
|
||||
break
|
||||
except (IndexError, TypeError):
|
||||
continue
|
||||
|
||||
if found_x is not None:
|
||||
# 转换回1080基准坐标
|
||||
detected_x = int(found_x * 1080.0 / max(1, rx))
|
||||
detected = True
|
||||
|
||||
# 保存找到的位置作为下次的最优位置
|
||||
try:
|
||||
px = pix[x_scaled, check_y]
|
||||
# 检查RGB值是否匹配福袋图标颜色(适度放宽范围)
|
||||
if isinstance(px, tuple) and len(px) >= 3:
|
||||
if (
|
||||
190 <= px[0] <= 206
|
||||
and 173 <= px[1] <= 196
|
||||
and 234 <= px[2] <= 250
|
||||
):
|
||||
# 转换回1080基准坐标
|
||||
detected_x = int(x_scaled * 1080.0 / max(1, rx))
|
||||
detected = True
|
||||
analyser.last_fudai_x = detected_x
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 双截图记录:保存成功识别存档截图
|
||||
try:
|
||||
import douyin_screenshot_manager
|
||||
# 双截图记录:保存成功识别存档截图
|
||||
try:
|
||||
import douyin_screenshot_manager
|
||||
|
||||
detect_roi = pic_new.crop(
|
||||
(
|
||||
scan_x_start,
|
||||
max(0, scan_y - 3),
|
||||
scan_x_end,
|
||||
min(pic_height, scan_y + 4),
|
||||
)
|
||||
).convert("RGB")
|
||||
douyin_screenshot_manager.save_last_success(
|
||||
detect_roi,
|
||||
operation_type="pixel_detect",
|
||||
)
|
||||
|
||||
# 保存完整截图(检测成功)
|
||||
pic_rgb_full = pic_new.convert("RGB")
|
||||
debug_path = douyin_screenshot_manager.save_debug_image(
|
||||
pic_rgb_full,
|
||||
operation_type="pixel_detect",
|
||||
picname="fudai_icon",
|
||||
step="detected",
|
||||
coords=(
|
||||
scan_x_start,
|
||||
max(0, scan_y - 3),
|
||||
scan_x_end,
|
||||
min(pic_height, scan_y + 4),
|
||||
),
|
||||
extra_info={
|
||||
"detected_x": detected_x,
|
||||
"detected_x_scaled": x_scaled,
|
||||
"scan_range": f"x:{scan_x_start}-{scan_x_end}, y:{scan_y}",
|
||||
"resolution": f"{rx}x{ry}",
|
||||
"result": "success"
|
||||
}
|
||||
)
|
||||
if debug_path:
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"[调试图像]",
|
||||
"福袋图标检测成功保存完整截图",
|
||||
path=debug_path,
|
||||
detected_x=detected_x
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
except Exception:
|
||||
pass
|
||||
detect_roi = pic_new.crop(
|
||||
(
|
||||
scan_x_start,
|
||||
max(0, scan_y - 3),
|
||||
scan_x_end,
|
||||
min(pic_height, scan_y + 4),
|
||||
)
|
||||
).convert("RGB")
|
||||
douyin_screenshot_manager.save_last_success(
|
||||
detect_roi,
|
||||
operation_type="pixel_detect",
|
||||
)
|
||||
|
||||
# 保存完整截图(检测成功)
|
||||
pic_rgb_full = pic_new.convert("RGB")
|
||||
debug_path = douyin_screenshot_manager.save_debug_image(
|
||||
pic_rgb_full,
|
||||
operation_type="pixel_detect",
|
||||
picname="fudai_icon",
|
||||
step="detected",
|
||||
coords=(
|
||||
scan_x_start,
|
||||
max(0, scan_y - 3),
|
||||
scan_x_end,
|
||||
min(pic_height, scan_y + 4),
|
||||
),
|
||||
extra_info={
|
||||
"detected_x": detected_x,
|
||||
"detected_x_scaled": found_x,
|
||||
"scan_range": f"x:{scan_x_start}-{scan_x_end}, y:{scan_y}",
|
||||
"resolution": f"{rx}x{ry}",
|
||||
"result": "success"
|
||||
}
|
||||
)
|
||||
if debug_path:
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"[调试图像]",
|
||||
"福袋图标检测成功保存完整截图",
|
||||
path=debug_path,
|
||||
detected_x=detected_x
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
try:
|
||||
analyser.last_find_fudai_time = time.time()
|
||||
except Exception:
|
||||
pass
|
||||
break
|
||||
except (IndexError, TypeError):
|
||||
continue
|
||||
if detected:
|
||||
break
|
||||
try:
|
||||
analyser.last_find_fudai_time = time.time()
|
||||
except Exception:
|
||||
pass
|
||||
break # 找到后退出offset_y循环
|
||||
|
||||
if detected:
|
||||
pass # 已设置 detected = True
|
||||
break # 找到后退出外层循环
|
||||
except Exception:
|
||||
# 像素检测失败,记录但不影响主流程
|
||||
pass
|
||||
@@ -773,6 +937,9 @@ def check_have_fudai_with_ready_screenshot(
|
||||
pass
|
||||
|
||||
if detected and detected_x is not None:
|
||||
# 重置连续失败计数
|
||||
consecutive_failures = 0
|
||||
|
||||
# 统计:每次"进入直播间"后首次找到福袋图标耗时
|
||||
try:
|
||||
enter_ts = float(getattr(analyser, "_enter_live_ts", 0.0) or 0.0)
|
||||
@@ -823,28 +990,49 @@ def check_have_fudai_with_ready_screenshot(
|
||||
return int(detected_x or 0)
|
||||
|
||||
loop += 1
|
||||
# 每轮记录一次轻量调试信息(帮助诊断为何未命中)
|
||||
try:
|
||||
elapsed_ms = int((time.time() - func_start) * 1000)
|
||||
sample_color = None
|
||||
consecutive_failures += 1
|
||||
|
||||
# 如果连续失败太多次,提前退出(避免无效循环)
|
||||
if consecutive_failures >= max_consecutive_failures:
|
||||
try:
|
||||
mid_x = (scan_x_start + scan_x_end) // 2
|
||||
if 0 <= scan_y < height and 0 <= mid_x < width:
|
||||
pix_sample = pic_new.load()
|
||||
sample_color = pix_sample[mid_x, scan_y]
|
||||
elapsed_ms = int((time.time() - func_start) * 1000)
|
||||
analyser._log_kv(
|
||||
"[找福袋图标] 警告",
|
||||
"连续检测失败次数过多,提前退出",
|
||||
consecutive_failures=consecutive_failures,
|
||||
loop=loop,
|
||||
elapsed_ms=elapsed_ms,
|
||||
scan_y=scan_y,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
break
|
||||
|
||||
# 每轮记录一次轻量调试信息(帮助诊断为何未命中)
|
||||
# 只在每3次循环记录一次,减少日志量
|
||||
if loop % 3 == 0:
|
||||
try:
|
||||
elapsed_ms = int((time.time() - func_start) * 1000)
|
||||
sample_color = None
|
||||
analyser._log_kv(
|
||||
"[找福袋图标] 循环中",
|
||||
loop=loop,
|
||||
elapsed_ms=elapsed_ms,
|
||||
scan_y=scan_y,
|
||||
scan_x_start=scan_x_start,
|
||||
scan_x_end=scan_x_end,
|
||||
sample_color=str(sample_color) if sample_color is not None else "None",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
try:
|
||||
mid_x = (scan_x_start + scan_x_end) // 2
|
||||
if 0 <= scan_y < height and 0 <= mid_x < width:
|
||||
pix_sample = pic_new.load()
|
||||
sample_color = pix_sample[mid_x, scan_y]
|
||||
except Exception:
|
||||
sample_color = None
|
||||
analyser._log_kv(
|
||||
"[找福袋图标] 循环中",
|
||||
loop=loop,
|
||||
elapsed_ms=elapsed_ms,
|
||||
scan_y=scan_y,
|
||||
scan_x_start=scan_x_start,
|
||||
scan_x_end=scan_x_end,
|
||||
sample_color=str(sample_color) if sample_color is not None else "None",
|
||||
consecutive_failures=consecutive_failures,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 检查是否还有剩余时间
|
||||
elapsed = time.time() - func_start
|
||||
@@ -856,6 +1044,9 @@ def check_have_fudai_with_ready_screenshot(
|
||||
analyser.operation.delay(sleep_time)
|
||||
except Exception:
|
||||
time.sleep(sleep_time)
|
||||
else:
|
||||
# 时间已到,退出循环
|
||||
break
|
||||
|
||||
# 像素检测未找到时,返回 False,并记录总耗时与循环次数
|
||||
try:
|
||||
@@ -1441,3 +1632,116 @@ def check_in_fudai_detail(analyser: Any) -> bool:
|
||||
|
||||
analyser._detection_cache[cache_key] = (now, False)
|
||||
return False
|
||||
|
||||
|
||||
# ========== 以下为旧的像素检测代码,已暂时禁用 ==========
|
||||
# 像素检测代码已删除,使用模板匹配替代
|
||||
# 如需恢复像素检测,请参考 git 历史记录
|
||||
|
||||
|
||||
def check_in_fudai_detail(analyser: Any) -> bool:
|
||||
"""Detect whether we are currently on the fudai detail page."""
|
||||
_ensure_detection_cache(analyser)
|
||||
cache_key = "check_in_fudai_detail"
|
||||
now = time.time()
|
||||
cached = analyser._detection_cache.get(cache_key)
|
||||
if cached:
|
||||
cached_ts, cached_result = cached
|
||||
ttl = float(getattr(analyser, "_detection_cache_ttl", 2.0) or 2.0)
|
||||
if (now - cached_ts) < ttl:
|
||||
return bool(cached_result)
|
||||
|
||||
path = os.path.join(os.path.dirname(__file__), "pic")
|
||||
pic1_path = os.path.join(path, "screenshot.png")
|
||||
try:
|
||||
try:
|
||||
pic0 = Image.open(pic1_path)
|
||||
pic0.load()
|
||||
pic = pic0.convert("RGBA")
|
||||
except Exception:
|
||||
try:
|
||||
analyser.operation.get_screenshot(analyser.device_id)
|
||||
pic0 = Image.open(pic1_path)
|
||||
pic0.load()
|
||||
pic = pic0.convert("RGBA")
|
||||
except Exception:
|
||||
analyser._detection_cache[cache_key] = (now, False)
|
||||
return False
|
||||
|
||||
pix = pic.load()
|
||||
width, height = pic.size
|
||||
try:
|
||||
rx = int(getattr(analyser, "resolution_ratio_x", 1080) or 1080)
|
||||
except Exception:
|
||||
rx = 1080
|
||||
try:
|
||||
ry = int(getattr(analyser, "resolution_ratio_y", 2400) or 2400)
|
||||
except Exception:
|
||||
ry = 2400
|
||||
try:
|
||||
y_pianyi_val = int(getattr(analyser, "y_pianyi", 0) or 0)
|
||||
except Exception:
|
||||
y_pianyi_val = 0
|
||||
|
||||
x = 536 * rx // 1080
|
||||
if not (0 <= x < width):
|
||||
analyser._detection_cache[cache_key] = (now, False)
|
||||
return False
|
||||
|
||||
base_ys = (883, 983, 1058)
|
||||
offsets = (0, y_pianyi_val, -y_pianyi_val)
|
||||
|
||||
for base_y in base_ys:
|
||||
y0 = base_y * ry // 2400
|
||||
for dy in offsets:
|
||||
y = y0 + dy
|
||||
if not (0 <= y < height):
|
||||
continue
|
||||
try:
|
||||
p = pix[x, y]
|
||||
if not (isinstance(p, tuple) and len(p) >= 3):
|
||||
continue
|
||||
r, g, b = int(p[0]), int(p[1]), int(p[2])
|
||||
if 30 <= r <= 38 and 34 <= g <= 40 and 78 <= b <= 84:
|
||||
analyser._detection_cache[cache_key] = (now, True)
|
||||
return True
|
||||
except Exception:
|
||||
continue
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# OCR fallback (lighter version of original implementation)
|
||||
try:
|
||||
try:
|
||||
min_interval = float(
|
||||
getattr(analyser, "detail_ocr_check_min_interval_seconds", 8.0) or 0.0
|
||||
)
|
||||
except Exception:
|
||||
min_interval = 8.0
|
||||
last = float(getattr(analyser, "_last_detail_ocr_check_ts", 0.0) or 0.0)
|
||||
if min_interval > 0 and (now - last) < min_interval:
|
||||
analyser._detection_cache[cache_key] = (now, False)
|
||||
return False
|
||||
analyser._last_detail_ocr_check_ts = now
|
||||
|
||||
analyser.cut_pic(306, 2030, 780, 2110, "", "参与按钮")
|
||||
t_btn = str(analyser.operation.analyse_pic_word("参与按钮", 0) or "")
|
||||
keywords = (
|
||||
"参与",
|
||||
"评论",
|
||||
"还需看播",
|
||||
"无法参与",
|
||||
"时长不足",
|
||||
"粉丝团",
|
||||
"开始观看",
|
||||
)
|
||||
if not t_btn or not any(k in t_btn for k in keywords):
|
||||
t_btn = str(analyser.operation.analyse_pic_word("参与按钮", 1) or "")
|
||||
if any(k in t_btn for k in keywords):
|
||||
analyser._detection_cache[cache_key] = (now, True)
|
||||
return True
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
analyser._detection_cache[cache_key] = (now, False)
|
||||
return False
|
||||
+144
-1
@@ -138,11 +138,88 @@ def find_and_open_fudai_detail(
|
||||
# 优先走底层 operation.click,失败再尝试 analyser.click
|
||||
try:
|
||||
analyser.operation.click(device_id, click_x, click_y)
|
||||
analyser.operation.delay(1.0)
|
||||
analyser.operation.delay(1.5) # 增加延迟,等待页面加载
|
||||
|
||||
# 点击后验证:检测是否误点击到嘉年华页面
|
||||
try:
|
||||
analyser.operation.get_screenshot(device_id)
|
||||
pic_path = path_config.get_screenshot_path()
|
||||
if os.path.exists(pic_path):
|
||||
pic = Image.open(pic_path)
|
||||
pic.load()
|
||||
|
||||
# 检测嘉年华页面:通过OCR识别"嘉年华"文字
|
||||
try:
|
||||
# 截取顶部标题区域进行OCR检测
|
||||
analyser.cut_pic(400, 100, 800, 200, "", "检测嘉年华标题")
|
||||
jiahua_text = str(analyser.operation.analyse_pic_word("检测嘉年华标题", 0) or "")
|
||||
|
||||
# 检查是否包含嘉年华相关关键词
|
||||
jiahua_keywords = ("嘉年华", "抖音嘉年华", "狂欢", "活动")
|
||||
if jiahua_text and any(kw in jiahua_text for kw in jiahua_keywords):
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"流程",
|
||||
"find_and_open_fudai_detail:误点击到嘉年华页面,返回",
|
||||
detected_x=int(x),
|
||||
click_x=click_x,
|
||||
click_y=click_y,
|
||||
ocr_text=jiahua_text[:50],
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
# 返回直播间
|
||||
analyser.operation.click_back(device_id)
|
||||
analyser.operation.delay(1.0)
|
||||
# 清除历史位置,避免下次继续误点击
|
||||
try:
|
||||
analyser.last_fudai_x = 0
|
||||
except Exception:
|
||||
pass
|
||||
return False
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 验证是否成功打开福袋详情页
|
||||
pic_rgb = pic.convert("RGB")
|
||||
rx = int(getattr(analyser, "resolution_ratio_x", 1080) or 1080)
|
||||
ry = int(getattr(analyser, "resolution_ratio_y", 2400) or 2400)
|
||||
y_pianyi = int(getattr(analyser, "y_pianyi", 0) or 0)
|
||||
|
||||
import douyin_pixel
|
||||
is_in_detail = douyin_pixel.detect_fudai_detail_page(
|
||||
pic_rgb, rx, ry, y_pianyi
|
||||
)
|
||||
|
||||
if not is_in_detail:
|
||||
# 如果不在福袋详情页,可能是误点击,返回
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"流程",
|
||||
"find_and_open_fudai_detail:点击后未检测到福袋详情页,可能误点击",
|
||||
detected_x=int(x),
|
||||
click_x=click_x,
|
||||
click_y=click_y,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
# 返回直播间
|
||||
analyser.operation.click_back(device_id)
|
||||
analyser.operation.delay(1.0)
|
||||
# 清除历史位置,避免下次继续误点击
|
||||
try:
|
||||
analyser.last_fudai_x = 0
|
||||
except Exception:
|
||||
pass
|
||||
return False
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
return True
|
||||
except Exception:
|
||||
try:
|
||||
analyser.click(x, base_y)
|
||||
analyser.operation.delay(1.5)
|
||||
return True
|
||||
except Exception:
|
||||
return False
|
||||
@@ -259,6 +336,72 @@ def handle_no_fudai_situation(
|
||||
return False
|
||||
|
||||
|
||||
def filter_fudai_detail(
|
||||
analyser: Any,
|
||||
detail: Tuple,
|
||||
x: int,
|
||||
needswitch: bool,
|
||||
post_switch_delay_s: float,
|
||||
close_detail_callback,
|
||||
swipe_up_switch_callback,
|
||||
add_reservation_callback,
|
||||
) -> bool:
|
||||
"""福袋详情过滤逻辑:根据 config.json 对福袋进行基础筛选。"""
|
||||
skip, reason = should_skip_fudai_by_config(analyser, detail)
|
||||
try:
|
||||
content = str(detail[0] or "") if isinstance(detail, tuple) and len(detail) >= 1 else ""
|
||||
analyser._log_kv(
|
||||
"流程",
|
||||
"filter_fudai_detail",
|
||||
x=x,
|
||||
needswitch=needswitch,
|
||||
skip=int(bool(skip)),
|
||||
reason=reason,
|
||||
content_preview=content[:60] if content else "",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
if not skip:
|
||||
return False
|
||||
|
||||
try:
|
||||
close_detail_callback(analyser)
|
||||
except Exception:
|
||||
try:
|
||||
analyser.operation.click_back(analyser.device_id)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
if needswitch and swipe_up_switch_callback:
|
||||
try:
|
||||
swipe_up_switch_callback()
|
||||
analyser.operation.delay(post_switch_delay_s or 1.2)
|
||||
except Exception:
|
||||
try:
|
||||
time.sleep(post_switch_delay_s or 1.2)
|
||||
except Exception:
|
||||
pass
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
# 简单策略:轻微等待 + 上滑切换
|
||||
try:
|
||||
analyser.operation.delay(1.0)
|
||||
except Exception:
|
||||
time.sleep(1.0)
|
||||
|
||||
if needswitch and swipe_up_switch_callback:
|
||||
swipe_up_switch_callback()
|
||||
try:
|
||||
analyser.operation.delay(post_switch_delay_s or 1.2)
|
||||
except Exception:
|
||||
time.sleep(post_switch_delay_s or 1.2)
|
||||
|
||||
return False
|
||||
|
||||
|
||||
def filter_fudai_detail(
|
||||
analyser: Any,
|
||||
detail: Tuple,
|
||||
|
||||
+171
-2
@@ -85,6 +85,11 @@ class fudai_analyse:
|
||||
self._last_diag_stage: str = "INIT"
|
||||
self._last_diag_seen: str = "-"
|
||||
self._last_diag_ts: float = 0.0
|
||||
|
||||
# 30分钟超时相关:记录最后一次成功参与福袋的时间
|
||||
self._last_successful_attend_ts: float = 0.0
|
||||
self._no_attend_timeout_minutes: float = 30.0 # 30分钟没有参与成功则返回推荐页面
|
||||
self._run_start_ts: float = time.time() # 记录运行开始时间,用于从未成功参与时的超时检查
|
||||
|
||||
# 与配置相关的核心字段(只初始化最关键的几项,其余保持默认)
|
||||
self.contains_not_want: list[str] = []
|
||||
@@ -1194,7 +1199,61 @@ class fudai_analyse:
|
||||
# ========== 主循环骨架(基础抢福袋 + 简化预约抢占) ==========
|
||||
def run_once_basic(self) -> None:
|
||||
"""单轮基础抢福袋流程(包含简化版高价值福袋预约回退)。"""
|
||||
# 0. 若启用高价值预约:先处理"是否需要回退到预约直播间"
|
||||
# 0. 检查30分钟超时:如果30分钟没有成功参与福袋,则返回推荐页面并重新进入直播间
|
||||
try:
|
||||
last_attend_ts = float(getattr(self, "_last_successful_attend_ts", 0.0) or 0.0)
|
||||
timeout_minutes = float(getattr(self, "_no_attend_timeout_minutes", 30.0) or 30.0)
|
||||
current_ts = time.time()
|
||||
run_start_ts = float(getattr(self, "_run_start_ts", current_ts) or current_ts)
|
||||
|
||||
# 如果从未成功参与过,且运行时间超过30分钟,则触发超时
|
||||
# 如果成功参与过,检查距离最后一次成功参与是否超过30分钟
|
||||
if last_attend_ts > 0:
|
||||
elapsed_minutes = (current_ts - last_attend_ts) / 60.0
|
||||
if elapsed_minutes >= timeout_minutes:
|
||||
try:
|
||||
self._log_kv(
|
||||
"超时",
|
||||
f"30分钟未参与成功福袋,返回推荐页面重新进入直播间",
|
||||
last_attend_minutes_ago=round(elapsed_minutes, 1),
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
# 返回推荐页面并重新进入直播间
|
||||
self._return_to_recommend_and_reenter_live()
|
||||
# 重置最后成功参与时间,避免立即再次触发
|
||||
try:
|
||||
self._last_successful_attend_ts = current_ts
|
||||
except Exception:
|
||||
pass
|
||||
return
|
||||
else:
|
||||
# 从未成功参与过,检查运行时间
|
||||
elapsed_minutes = (current_ts - run_start_ts) / 60.0
|
||||
if elapsed_minutes >= timeout_minutes:
|
||||
try:
|
||||
self._log_kv(
|
||||
"超时",
|
||||
f"运行{round(elapsed_minutes, 1)}分钟仍未参与成功福袋,返回推荐页面重新进入直播间",
|
||||
run_minutes=round(elapsed_minutes, 1),
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
# 返回推荐页面并重新进入直播间
|
||||
self._return_to_recommend_and_reenter_live()
|
||||
# 重置运行开始时间,避免立即再次触发
|
||||
try:
|
||||
self._run_start_ts = current_ts
|
||||
except Exception:
|
||||
pass
|
||||
return
|
||||
except Exception as e:
|
||||
try:
|
||||
self._log_kv("超时", "检查30分钟超时时出错", error=str(e))
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 0.1. 若启用高价值预约:先处理"是否需要回退到预约直播间"
|
||||
try:
|
||||
if getattr(self, "high_value_fudai_enabled", False) and self.reservations:
|
||||
|
||||
@@ -1340,6 +1399,9 @@ class fudai_analyse:
|
||||
try:
|
||||
current_pos = int(getattr(self, "room_pos", 0) or 0)
|
||||
back_times = abs(current_pos)
|
||||
# 防止无限循环:最大回退次数限制为100
|
||||
if back_times > 100:
|
||||
back_times = 100
|
||||
if back_times > 0:
|
||||
for i in range(back_times):
|
||||
_swipe_down_once()
|
||||
@@ -1557,7 +1619,8 @@ class fudai_analyse:
|
||||
self._last_diag_stage = stage
|
||||
self._last_diag_seen = seen
|
||||
self._last_diag_ts = time.time()
|
||||
self._log_kv(tag, msg, stage=stage, seen=seen)
|
||||
# 使用位置参数调用,避免与关键字参数冲突
|
||||
self._log_kv(tag, msg, **{"stage": stage, "seen": seen})
|
||||
else:
|
||||
self._log_kv(tag, msg)
|
||||
except Exception as e:
|
||||
@@ -1591,6 +1654,104 @@ class fudai_analyse:
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
def _return_to_recommend_and_reenter_live(self) -> None:
|
||||
"""返回推荐页面并重新进入直播间。
|
||||
|
||||
通过多次点击返回键返回到推荐页面,然后点击关注标签并进入直播间。
|
||||
"""
|
||||
try:
|
||||
self._log_kv("超时", "开始返回推荐页面")
|
||||
|
||||
# 多次点击返回键,直到到达推荐页面(最多尝试10次)
|
||||
max_back_clicks = 10
|
||||
for i in range(max_back_clicks):
|
||||
try:
|
||||
# 截图并诊断当前阶段
|
||||
ok = self.operation.get_screenshot(self.device_id)
|
||||
if not ok:
|
||||
self._log_kv("超时", f"获取截图失败 ({i+1}/{max_back_clicks})")
|
||||
# 即使截图失败,也尝试点击返回键
|
||||
self.operation.click_back(self.device_id)
|
||||
self.operation.delay(1.0)
|
||||
continue
|
||||
|
||||
# 诊断当前阶段
|
||||
stage, seen = self._diagnose_stage_from_current_screen()
|
||||
|
||||
# 如果已经在推荐页面,跳出循环
|
||||
if stage == "RECOMMEND_PAGE":
|
||||
self._log_kv("超时", f"已到达推荐页面 ({i+1}次返回键)")
|
||||
break
|
||||
|
||||
# 点击返回键
|
||||
self.operation.click_back(self.device_id)
|
||||
self.operation.delay(1.0)
|
||||
|
||||
if i == max_back_clicks - 1:
|
||||
self._log_kv("超时", f"已点击{max_back_clicks}次返回键,可能未到达推荐页面")
|
||||
except Exception as e:
|
||||
try:
|
||||
self._log_kv("超时", f"返回推荐页面时出错 ({i+1}/{max_back_clicks})", error=str(e))
|
||||
except Exception:
|
||||
pass
|
||||
# 继续尝试点击返回键
|
||||
try:
|
||||
self.operation.click_back(self.device_id)
|
||||
self.operation.delay(1.0)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 等待页面稳定
|
||||
self.operation.delay(2.0)
|
||||
|
||||
# 再次截图确认当前阶段
|
||||
try:
|
||||
ok = self.operation.get_screenshot(self.device_id)
|
||||
if ok:
|
||||
stage, seen = self._diagnose_stage_from_current_screen()
|
||||
self._log_kv("超时", "确认当前阶段", stage=stage, seen=seen)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 点击关注标签并进入直播间(复用现有逻辑)
|
||||
try:
|
||||
# 点击关注标签 (709, 169) - 基于1080x2400分辨率
|
||||
follow_tab_x = int(709 * self.resolution_ratio_x // 1080)
|
||||
follow_tab_y = int(169 * self.resolution_ratio_y // 2400)
|
||||
self.operation.click(self.device_id, follow_tab_x, follow_tab_y)
|
||||
self._log_kv("超时", "点击关注标签", x=follow_tab_x, y=follow_tab_y)
|
||||
self.operation.delay(2.0)
|
||||
|
||||
# 点击进入直播间的位置 (103, 385),连点两次
|
||||
enter_live_x = int(103 * self.resolution_ratio_x // 1080)
|
||||
enter_live_y = int(385 * self.resolution_ratio_y // 2400)
|
||||
self.operation.click(self.device_id, enter_live_x, enter_live_y)
|
||||
self.operation.delay(0.6)
|
||||
self.operation.click(self.device_id, enter_live_x, enter_live_y)
|
||||
self._log_kv(
|
||||
"超时",
|
||||
"点击进入直播间位置",
|
||||
x=enter_live_x,
|
||||
y=enter_live_y,
|
||||
次数=2,
|
||||
)
|
||||
self.operation.delay(2.0)
|
||||
|
||||
self._log_kv("超时", "已重新进入直播间")
|
||||
except Exception as e:
|
||||
self._log_kv("超时", "重新进入直播间时出错", error=str(e))
|
||||
# 如果出错,尝试回退
|
||||
try:
|
||||
self.operation.click_back(self.device_id)
|
||||
self.operation.delay(1.0)
|
||||
except Exception:
|
||||
pass
|
||||
except Exception as e:
|
||||
try:
|
||||
self._log_kv("超时", "返回推荐页面并重新进入直播间时出错", error=str(e))
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
def swipe_down_back_from_live(self) -> None:
|
||||
"""上划回退到上一个直播间(供预约/无福袋逻辑使用)。"""
|
||||
try:
|
||||
@@ -1646,6 +1807,9 @@ class fudai_analyse:
|
||||
|
||||
# 回退次数按当前已切换次数来(更符合"回到本轮第一个直播间"的语义)
|
||||
back_times = int(swipe_times)
|
||||
# 防止无限循环:最大回退次数限制为100
|
||||
if back_times > 100:
|
||||
back_times = 100
|
||||
if back_times <= 0:
|
||||
return 0
|
||||
|
||||
@@ -1709,6 +1873,11 @@ class fudai_analyse:
|
||||
max_back = int(getattr(self, "high_value_fudai_max_swipe_back", 60) or 60)
|
||||
except Exception:
|
||||
max_back = 60
|
||||
# 防止无限循环:最大回退次数限制为100
|
||||
if max_back > 100:
|
||||
max_back = 100
|
||||
if max_back < 0:
|
||||
max_back = 0
|
||||
|
||||
try:
|
||||
self._log_kv(
|
||||
|
||||
@@ -691,6 +691,11 @@ def attend_choujiang(analyser) -> bool:
|
||||
analyser._log_kv("参与", "识别参与按钮", text=attend_button_text)
|
||||
if "参与成功" in attend_button_text: # 如果识别到已经参与抽奖
|
||||
analyser._log_kv("参与", "已参与,等待开奖", result="已参与")
|
||||
# 记录最后一次成功参与的时间
|
||||
try:
|
||||
analyser._last_successful_attend_ts = time.time()
|
||||
except Exception:
|
||||
pass
|
||||
analyser.click(500, 470) # 点击刚才打开福袋的旁边位置
|
||||
analyser._log_kv("参与", "关闭福袋详情", action="关闭详情")
|
||||
return True
|
||||
|
||||
+414
-30
@@ -263,12 +263,63 @@ class FudaiDetector:
|
||||
valid_cols = cols >= 2 # 至少2个像素匹配
|
||||
|
||||
if valid_cols.any():
|
||||
# 从右往左查找:找到最后一个匹配的列(最右边的)
|
||||
# 使用argmax在反转后的数组中找到第一个True的位置
|
||||
valid_cols_reversed = valid_cols[::-1]
|
||||
col_idx_reversed = int(np.argmax(valid_cols_reversed))
|
||||
col_idx = len(valid_cols) - 1 - col_idx_reversed
|
||||
detected_x = int((x1 + col_idx) * 1080.0 / max(1, self.rx))
|
||||
# 优化:从最优位置开始向左右两侧搜索
|
||||
roi_width = x2 - x1
|
||||
|
||||
# 获取最优搜索起始位置(使用历史记录或默认值)
|
||||
try:
|
||||
# 尝试获取上次找到的福袋位置(1080基准)
|
||||
last_fudai_x = int(getattr(self.analyser, "last_fudai_x", 0) or 0)
|
||||
if last_fudai_x > 0:
|
||||
optimal_x_scaled = last_fudai_x * self.rx // 1080
|
||||
optimal_col = optimal_x_scaled - x1
|
||||
if optimal_col < 0 or optimal_col >= roi_width:
|
||||
# 如果历史位置不在当前区域内,使用区域中心
|
||||
optimal_col = roi_width // 2
|
||||
else:
|
||||
# 使用区域中心作为最优位置
|
||||
optimal_col = roi_width // 2
|
||||
except Exception:
|
||||
# 使用区域中心作为最优位置
|
||||
optimal_col = roi_width // 2
|
||||
|
||||
optimal_col = max(0, min(optimal_col, roi_width - 1))
|
||||
|
||||
# 从最优位置开始,向左右两侧交替搜索
|
||||
found_col = None
|
||||
search_range = max(optimal_col, roi_width - optimal_col)
|
||||
|
||||
# 先检查最优位置本身
|
||||
if valid_cols[optimal_col]:
|
||||
found_col = optimal_col
|
||||
else:
|
||||
# 向左右两侧交替搜索
|
||||
for offset in range(1, search_range + 1):
|
||||
# 先检查右侧
|
||||
right_col = optimal_col + offset
|
||||
if right_col < roi_width and valid_cols[right_col]:
|
||||
found_col = right_col
|
||||
break
|
||||
# 再检查左侧
|
||||
left_col = optimal_col - offset
|
||||
if left_col >= 0 and valid_cols[left_col]:
|
||||
found_col = left_col
|
||||
break
|
||||
|
||||
# 如果没找到,回退到原来的方法(从右往左)
|
||||
if found_col is None:
|
||||
valid_cols_reversed = valid_cols[::-1]
|
||||
col_idx_reversed = int(np.argmax(valid_cols_reversed))
|
||||
found_col = len(valid_cols) - 1 - col_idx_reversed
|
||||
|
||||
detected_x = int((x1 + found_col) * 1080.0 / max(1, self.rx))
|
||||
|
||||
# 保存找到的位置作为下次的最优位置
|
||||
try:
|
||||
self.analyser.last_fudai_x = detected_x
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
elapsed = (time.time() - start_time) * 1000
|
||||
|
||||
try:
|
||||
@@ -278,6 +329,8 @@ class FudaiDetector:
|
||||
elapsed_ms=round(elapsed, 2),
|
||||
x=detected_x,
|
||||
region=f"({x1},{y_top})-({x2},{y_bottom})",
|
||||
optimal_col=optimal_col,
|
||||
found_col=found_col,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
@@ -289,41 +342,126 @@ class FudaiDetector:
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 回退到逐像素检测(从右往左查找)
|
||||
# 回退到逐像素检测(从最优位置开始向左右两侧搜索)
|
||||
try:
|
||||
pix = pic.load()
|
||||
y_range_int = int(y_range) if y_range is not None else 7
|
||||
|
||||
# 获取最优搜索起始位置(使用历史记录或默认值)
|
||||
try:
|
||||
# 尝试获取上次找到的福袋位置(1080基准)
|
||||
last_fudai_x = int(getattr(self.analyser, "last_fudai_x", 0) or 0)
|
||||
if last_fudai_x > 0:
|
||||
optimal_x_scaled = last_fudai_x * self.rx // 1080
|
||||
if optimal_x_scaled < x1 or optimal_x_scaled >= x2:
|
||||
# 如果历史位置不在当前区域内,使用区域中心
|
||||
optimal_x_scaled = (x1 + x2) // 2
|
||||
else:
|
||||
# 使用区域中心作为最优位置
|
||||
optimal_x_scaled = (x1 + x2) // 2
|
||||
except Exception:
|
||||
# 使用区域中心作为最优位置
|
||||
optimal_x_scaled = (x1 + x2) // 2
|
||||
|
||||
optimal_x_scaled = max(x1, min(optimal_x_scaled, x2 - 1))
|
||||
|
||||
for offset_y in range(-y_range_int // 2, y_range_int // 2 + 1):
|
||||
check_y = scan_y + offset_y
|
||||
if not (0 <= check_y < height):
|
||||
continue
|
||||
|
||||
# 从右往左查找:从x2-1到x1
|
||||
for x_scaled in range(x2 - 1, x1 - 1, -1):
|
||||
# 优化:从最优位置开始向左右两侧搜索
|
||||
found_x = None
|
||||
search_range = max(optimal_x_scaled - x1, x2 - optimal_x_scaled)
|
||||
|
||||
# 先检查最优位置本身
|
||||
try:
|
||||
px = pix[optimal_x_scaled, check_y]
|
||||
if isinstance(px, tuple) and len(px) >= 3:
|
||||
if (
|
||||
190 <= px[0] <= 206
|
||||
and 173 <= px[1] <= 196
|
||||
and 234 <= px[2] <= 250
|
||||
):
|
||||
found_x = optimal_x_scaled
|
||||
except (IndexError, TypeError):
|
||||
pass
|
||||
|
||||
# 如果最优位置没找到,向左右两侧交替搜索
|
||||
if found_x is None:
|
||||
for offset in range(1, search_range + 1):
|
||||
# 先检查右侧
|
||||
right_x = optimal_x_scaled + offset
|
||||
if right_x < x2:
|
||||
try:
|
||||
px = pix[right_x, check_y]
|
||||
if isinstance(px, tuple) and len(px) >= 3:
|
||||
if (
|
||||
190 <= px[0] <= 206
|
||||
and 173 <= px[1] <= 196
|
||||
and 234 <= px[2] <= 250
|
||||
):
|
||||
found_x = right_x
|
||||
break
|
||||
except (IndexError, TypeError):
|
||||
continue
|
||||
|
||||
# 再检查左侧
|
||||
left_x = optimal_x_scaled - offset
|
||||
if left_x >= x1:
|
||||
try:
|
||||
px = pix[left_x, check_y]
|
||||
if isinstance(px, tuple) and len(px) >= 3:
|
||||
if (
|
||||
190 <= px[0] <= 206
|
||||
and 173 <= px[1] <= 196
|
||||
and 234 <= px[2] <= 250
|
||||
):
|
||||
found_x = left_x
|
||||
break
|
||||
except (IndexError, TypeError):
|
||||
continue
|
||||
|
||||
# 如果还是没找到,回退到原来的方法(从右往左)
|
||||
if found_x is None:
|
||||
for x_scaled in range(x2 - 1, x1 - 1, -1):
|
||||
try:
|
||||
px = pix[x_scaled, check_y]
|
||||
if isinstance(px, tuple) and len(px) >= 3:
|
||||
if (
|
||||
190 <= px[0] <= 206
|
||||
and 173 <= px[1] <= 196
|
||||
and 234 <= px[2] <= 250
|
||||
):
|
||||
found_x = x_scaled
|
||||
break
|
||||
except (IndexError, TypeError):
|
||||
continue
|
||||
|
||||
if found_x is not None:
|
||||
detected_x = int(found_x * 1080.0 / max(1, self.rx))
|
||||
|
||||
# 保存找到的位置作为下次的最优位置
|
||||
try:
|
||||
px = pix[x_scaled, check_y]
|
||||
if isinstance(px, tuple) and len(px) >= 3:
|
||||
if (
|
||||
190 <= px[0] <= 206
|
||||
and 173 <= px[1] <= 196
|
||||
and 234 <= px[2] <= 250
|
||||
):
|
||||
detected_x = int(x_scaled * 1080.0 / max(1, self.rx))
|
||||
elapsed = (time.time() - start_time) * 1000
|
||||
self.analyser.last_fudai_x = detected_x
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
elapsed = (time.time() - start_time) * 1000
|
||||
|
||||
try:
|
||||
self.analyser._log_kv(
|
||||
"[福袋查找] 像素检测",
|
||||
f"{region['name']}命中(回退模式,从右往左)",
|
||||
elapsed_ms=round(elapsed, 2),
|
||||
x=detected_x,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
try:
|
||||
self.analyser._log_kv(
|
||||
"[福袋查找] 像素检测",
|
||||
f"{region['name']}命中(回退模式,从最优位置搜索)",
|
||||
elapsed_ms=round(elapsed, 2),
|
||||
x=detected_x,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
return detected_x
|
||||
except (IndexError, TypeError):
|
||||
continue
|
||||
return detected_x
|
||||
if found_x is not None:
|
||||
break # 找到后退出offset_y循环
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
@@ -1277,6 +1415,9 @@ class FudaiFinder:
|
||||
self.retry_delay_s = 0.1
|
||||
if self.max_wait_s < 0:
|
||||
self.max_wait_s = 0.0
|
||||
# 防止无限等待:最大等待时间限制为30秒
|
||||
if self.max_wait_s > 30.0:
|
||||
self.max_wait_s = 30.0
|
||||
|
||||
def find_and_open(
|
||||
self, screenshot_ready: bool = False, verify_after_click: bool = True
|
||||
@@ -1305,7 +1446,24 @@ class FudaiFinder:
|
||||
|
||||
# 主循环:按时间限制重试
|
||||
loop = 0
|
||||
max_loops = int(self.max_wait_s / self.retry_delay_s) + 10 # 额外的循环次数保护
|
||||
consecutive_failures = 0 # 连续失败计数
|
||||
max_consecutive_failures = 5 # 最大连续失败次数
|
||||
|
||||
while (time.time() - overall_start) < self.max_wait_s:
|
||||
# 额外的循环次数保护:防止无限循环
|
||||
if loop >= max_loops:
|
||||
try:
|
||||
self.analyser._log_kv(
|
||||
"[福袋查找] 警告",
|
||||
"达到最大循环次数限制,提前退出",
|
||||
max_loops=max_loops,
|
||||
elapsed_s=round(time.time() - overall_start, 2),
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
break
|
||||
|
||||
# 1. 获取截图
|
||||
pic = self.acquirer.acquire_screenshot(
|
||||
force_refresh=not (screenshot_ready and loop == 0)
|
||||
@@ -1313,6 +1471,19 @@ class FudaiFinder:
|
||||
|
||||
if pic is None:
|
||||
loop += 1
|
||||
consecutive_failures += 1
|
||||
# 如果连续失败太多次,提前退出
|
||||
if consecutive_failures >= max_consecutive_failures:
|
||||
try:
|
||||
self.analyser._log_kv(
|
||||
"[福袋查找] 警告",
|
||||
"连续截图失败次数过多,提前退出",
|
||||
consecutive_failures=consecutive_failures,
|
||||
elapsed_s=round(time.time() - overall_start, 2),
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
break
|
||||
elapsed = time.time() - overall_start
|
||||
if elapsed < self.max_wait_s:
|
||||
remaining_time = self.max_wait_s - elapsed
|
||||
@@ -1381,6 +1552,8 @@ class FudaiFinder:
|
||||
detected_x, detect_method = self.detector.detect(pic)
|
||||
|
||||
if detected_x is not None:
|
||||
# 重置连续失败计数
|
||||
consecutive_failures = 0
|
||||
# 保存完整截图(检测成功)
|
||||
try:
|
||||
import douyin_screenshot_manager
|
||||
@@ -1466,6 +1639,22 @@ class FudaiFinder:
|
||||
return True, detected_x
|
||||
|
||||
loop += 1
|
||||
consecutive_failures += 1
|
||||
|
||||
# 如果连续失败太多次,提前退出(避免无效循环)
|
||||
if consecutive_failures >= max_consecutive_failures:
|
||||
try:
|
||||
overall_elapsed = (time.time() - overall_start) * 1000
|
||||
self.analyser._log_kv(
|
||||
"[福袋查找] 警告",
|
||||
"连续检测失败次数过多,提前退出",
|
||||
consecutive_failures=consecutive_failures,
|
||||
loop=loop,
|
||||
total_elapsed_ms=round(overall_elapsed, 2),
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
break
|
||||
|
||||
# 检查是否还有剩余时间
|
||||
elapsed = time.time() - overall_start
|
||||
@@ -1474,6 +1663,201 @@ class FudaiFinder:
|
||||
sleep_time = min(self.retry_delay_s, remaining_time)
|
||||
if sleep_time > 0:
|
||||
self.analyser.operation.delay(sleep_time)
|
||||
else:
|
||||
# 时间已到,退出循环
|
||||
break
|
||||
|
||||
# 未找到
|
||||
overall_elapsed = (time.time() - overall_start) * 1000
|
||||
try:
|
||||
self.analyser._log_kv(
|
||||
"[福袋查找] 完成",
|
||||
"未找到",
|
||||
total_elapsed_ms=round(overall_elapsed, 2),
|
||||
loops=loop,
|
||||
max_wait_s=self.max_wait_s,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
return False, None
|
||||
|
||||
def _record_find_fudai_time(self, detected_x: int):
|
||||
"""记录首次找到福袋的时间"""
|
||||
try:
|
||||
enter_ts = float(getattr(self.analyser, "_enter_live_ts", 0.0) or 0.0)
|
||||
if enter_ts > 0:
|
||||
dt = time.time() - enter_ts
|
||||
if not getattr(self.analyser, "_enter_live_fudai_logged", False):
|
||||
try:
|
||||
self.analyser._enter_live_fudai_logged = True
|
||||
except Exception:
|
||||
pass
|
||||
try:
|
||||
reason = str(
|
||||
getattr(self.analyser, "_enter_live_reason", "") or ""
|
||||
)
|
||||
except Exception:
|
||||
reason = ""
|
||||
try:
|
||||
self.analyser._log_kv(
|
||||
"性能",
|
||||
"进入直播间后找到福袋耗时",
|
||||
seconds=round(dt, 2),
|
||||
enter_reason=reason,
|
||||
fudai_x=detected_x,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
def check_have_fudai_with_ready_screenshot_optimized(
|
||||
analyser: Any, screenshot_ready: bool = False
|
||||
) -> int:
|
||||
"""优化的福袋查找函数(兼容原接口,仅检测不点击)
|
||||
|
||||
参数:
|
||||
analyser: 分析器对象
|
||||
screenshot_ready: 是否已有可用截图
|
||||
|
||||
返回:
|
||||
福袋X坐标(1080基准),未找到返回False
|
||||
"""
|
||||
# 只检测,不点击(避免与 find_and_open_fudai_detail 重复点击)
|
||||
try:
|
||||
acquirer = FudaiImageAcquirer(analyser)
|
||||
pic = acquirer.acquire_screenshot(force_refresh=not screenshot_ready)
|
||||
|
||||
if pic is None:
|
||||
return False
|
||||
|
||||
detector = FudaiDetector(analyser)
|
||||
detected_x, detect_method = detector.detect(pic)
|
||||
|
||||
if detected_x is not None:
|
||||
return int(detected_x)
|
||||
return False
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
|
||||
if detected_x is not None:
|
||||
# 重置连续失败计数
|
||||
consecutive_failures = 0
|
||||
# 保存完整截图(检测成功)
|
||||
try:
|
||||
import douyin_screenshot_manager
|
||||
pic_rgb_full = pic.convert("RGB")
|
||||
|
||||
# 获取检测区域信息用于标注
|
||||
try:
|
||||
# 找到检测成功的区域
|
||||
detected_region = None
|
||||
for region in self.detector.search_regions:
|
||||
if "y_top" in region:
|
||||
x1 = region.get("x1", 0)
|
||||
x2 = region.get("x2", 0)
|
||||
y_top = region.get("y_top", 0)
|
||||
y_bottom = region.get("y_bottom", 0)
|
||||
else:
|
||||
scan_y = region.get("y", 0)
|
||||
y_range = region.get("y_range", 7)
|
||||
x1 = region.get("x1", 0)
|
||||
x2 = region.get("x2", 0)
|
||||
y_top = max(0, scan_y - y_range // 2)
|
||||
y_bottom = scan_y + y_range // 2 + 1
|
||||
|
||||
# 检查detected_x是否在这个区域内
|
||||
detected_x_scaled = detected_x * self.detector.rx // 1080
|
||||
if x1 <= detected_x_scaled <= x2:
|
||||
detected_region = (x1, y_top, x2, y_bottom)
|
||||
break
|
||||
|
||||
coords = detected_region
|
||||
except Exception:
|
||||
coords = None
|
||||
|
||||
debug_path = douyin_screenshot_manager.save_debug_image(
|
||||
pic_rgb_full,
|
||||
operation_type="pixel_detect",
|
||||
picname="fudai_icon",
|
||||
step="detected",
|
||||
coords=coords,
|
||||
extra_info={
|
||||
"detected_x": detected_x,
|
||||
"method": detect_method,
|
||||
"loop": loop,
|
||||
"resolution": f"{self.detector.rx}x{self.detector.ry}",
|
||||
"result": "success"
|
||||
}
|
||||
)
|
||||
if debug_path:
|
||||
try:
|
||||
self.analyser._log_kv(
|
||||
"[调试图像]",
|
||||
"福袋图标检测成功保存完整截图(优化查找器)",
|
||||
path=debug_path,
|
||||
detected_x=detected_x,
|
||||
method=detect_method
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 3. 点击福袋图标
|
||||
click_success = self.executor.click(detected_x)
|
||||
|
||||
if click_success:
|
||||
# 点击成功后直接返回,不进行验证
|
||||
# 让主循环进行阶段检测,判断是否成功打开详情页
|
||||
overall_elapsed = (time.time() - overall_start) * 1000
|
||||
try:
|
||||
self.analyser._log_kv(
|
||||
"[福袋查找] 完成",
|
||||
"成功(已点击,等待阶段检测)",
|
||||
total_elapsed_ms=round(overall_elapsed, 2),
|
||||
loops=loop + 1,
|
||||
x=detected_x,
|
||||
method=detect_method,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 记录首次找到福袋的时间
|
||||
self._record_find_fudai_time(detected_x)
|
||||
return True, detected_x
|
||||
|
||||
loop += 1
|
||||
consecutive_failures += 1
|
||||
|
||||
# 如果连续失败太多次,提前退出(避免无效循环)
|
||||
if consecutive_failures >= max_consecutive_failures:
|
||||
try:
|
||||
overall_elapsed = (time.time() - overall_start) * 1000
|
||||
self.analyser._log_kv(
|
||||
"[福袋查找] 警告",
|
||||
"连续检测失败次数过多,提前退出",
|
||||
consecutive_failures=consecutive_failures,
|
||||
loop=loop,
|
||||
total_elapsed_ms=round(overall_elapsed, 2),
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
break
|
||||
|
||||
# 检查是否还有剩余时间
|
||||
elapsed = time.time() - overall_start
|
||||
if elapsed < self.max_wait_s:
|
||||
remaining_time = self.max_wait_s - elapsed
|
||||
sleep_time = min(self.retry_delay_s, remaining_time)
|
||||
if sleep_time > 0:
|
||||
self.analyser.operation.delay(sleep_time)
|
||||
else:
|
||||
# 时间已到,退出循环
|
||||
break
|
||||
|
||||
# 未找到
|
||||
overall_elapsed = (time.time() - overall_start) * 1000
|
||||
|
||||
+370
-80
@@ -1576,7 +1576,7 @@ def main():
|
||||
status_var.set("已停止")
|
||||
|
||||
# 先打包 actions 到底部(不 expand,固定在底部)
|
||||
actions.pack(fill=X, pady=(10, 0), padx=12)
|
||||
actions.pack(fill=X, pady=(10, 0), padx=12, side="bottom")
|
||||
|
||||
# 然后打包 notebook 填充剩余空间(在 actions 之上)
|
||||
notebook.pack(fill=BOTH, expand=True)
|
||||
@@ -1642,6 +1642,18 @@ def main():
|
||||
on_line(f"[错误] {e}")
|
||||
|
||||
ttk.Button(actions, text="测试评论", command=start_test_comment).pack(side=LEFT)
|
||||
|
||||
ttk.Separator(actions, orient="vertical").pack(side=LEFT, fill=Y, padx=10, pady=3)
|
||||
|
||||
def send_back_key():
|
||||
dev = device_var.get().strip()
|
||||
try:
|
||||
runner.send_back_key(dev)
|
||||
except Exception as e:
|
||||
on_line(f"[错误] 发送返回键失败: {e}")
|
||||
|
||||
ttk.Button(actions, text="发送返回键", command=send_back_key).pack(side=LEFT, padx=(0, 8))
|
||||
|
||||
ttk.Label(actions, textvariable=status_var).pack(side=RIGHT)
|
||||
|
||||
def pump_logs():
|
||||
@@ -1703,34 +1715,90 @@ def main():
|
||||
exit_code = stats.get("exit_code")
|
||||
lines.append(f"退出码: {exit_code if exit_code is not None else '-'}")
|
||||
lines.append("")
|
||||
|
||||
|
||||
# 计数器统计
|
||||
counters = stats.get("counters", {})
|
||||
if counters:
|
||||
|
||||
# 快速汇总(关键指标)
|
||||
fudai_seen = counters.get("fudai_seen", 0)
|
||||
fudai_attend_ok = counters.get("fudai_attend_ok", 0)
|
||||
fudai_result_win = counters.get("fudai_result_win", 0)
|
||||
fudai_order_success = counters.get("fudai_order_success", 0)
|
||||
|
||||
if fudai_seen > 0 or fudai_attend_ok > 0 or fudai_result_win > 0:
|
||||
lines.append("=" * 60)
|
||||
lines.append("计数器统计")
|
||||
lines.append("快速汇总")
|
||||
lines.append("=" * 60)
|
||||
|
||||
# 福袋相关
|
||||
fudai_stats = [
|
||||
("fudai_seen", "福袋识别次数"),
|
||||
("fudai_open_detail", "打开详情"),
|
||||
("fudai_click_attend", "点击参与"),
|
||||
("fudai_attend_ok", "参与成功/已参与"),
|
||||
("fudai_attend_fail", "参与失败"),
|
||||
("fudai_result_win", "中奖"),
|
||||
("fudai_result_no_win", "未中奖"),
|
||||
("fudai_order_success", "下单成功"),
|
||||
]
|
||||
for key, label in fudai_stats:
|
||||
val = counters.get(key, 0)
|
||||
if val > 0:
|
||||
lines.append(f" {label}: {val}")
|
||||
|
||||
lines.append(f"识别福袋: {fudai_seen} 个")
|
||||
lines.append(f"参与成功: {fudai_attend_ok} 次")
|
||||
lines.append(f"中奖次数: {fudai_result_win} 次")
|
||||
lines.append(f"下单成功: {fudai_order_success} 次")
|
||||
if uptime_seconds > 0:
|
||||
hours = uptime_seconds / 3600.0
|
||||
if hours > 0:
|
||||
lines.append(f"运行效率: {fudai_attend_ok / hours:.1f} 次参与/小时")
|
||||
lines.append("")
|
||||
|
||||
# 跳过原因
|
||||
skip_stats = [
|
||||
# 核心统计(总是显示,即使数据为0)
|
||||
lines.append("=" * 60)
|
||||
lines.append("核心统计")
|
||||
lines.append("=" * 60)
|
||||
|
||||
# 福袋相关核心指标(重新获取,避免重复定义)
|
||||
fudai_open_detail = counters.get("fudai_open_detail", 0)
|
||||
fudai_click_attend = counters.get("fudai_click_attend", 0)
|
||||
fudai_attend_ok = counters.get("fudai_attend_ok", 0)
|
||||
fudai_attend_fail = counters.get("fudai_attend_fail", 0)
|
||||
fudai_result_win = counters.get("fudai_result_win", 0)
|
||||
fudai_result_no_win = counters.get("fudai_result_no_win", 0)
|
||||
fudai_order_success = counters.get("fudai_order_success", 0)
|
||||
|
||||
lines.append(f"福袋识别次数: {fudai_seen}")
|
||||
lines.append(f"打开详情: {fudai_open_detail}")
|
||||
if fudai_seen > 0:
|
||||
open_rate = (fudai_open_detail / fudai_seen) * 100
|
||||
lines.append(f" 打开成功率: {open_rate:.1f}%")
|
||||
|
||||
lines.append(f"点击参与: {fudai_click_attend}")
|
||||
if fudai_open_detail > 0:
|
||||
click_rate = (fudai_click_attend / fudai_open_detail) * 100
|
||||
lines.append(f" 点击率: {click_rate:.1f}%")
|
||||
|
||||
lines.append(f"参与成功: {fudai_attend_ok}")
|
||||
lines.append(f"参与失败: {fudai_attend_fail}")
|
||||
total_attend = fudai_attend_ok + fudai_attend_fail
|
||||
if total_attend > 0:
|
||||
success_rate = (fudai_attend_ok / total_attend) * 100
|
||||
lines.append(f" 参与成功率: {success_rate:.1f}%")
|
||||
|
||||
lines.append(f"中奖次数: {fudai_result_win}")
|
||||
lines.append(f"未中奖次数: {fudai_result_no_win}")
|
||||
total_results = fudai_result_win + fudai_result_no_win
|
||||
if total_results > 0:
|
||||
win_rate = (fudai_result_win / total_results) * 100
|
||||
lines.append(f" 中奖率: {win_rate:.1f}%")
|
||||
|
||||
lines.append(f"下单成功: {fudai_order_success}")
|
||||
|
||||
# 效率统计
|
||||
if uptime_seconds > 0:
|
||||
hours = uptime_seconds / 3600.0
|
||||
if hours > 0:
|
||||
lines.append("")
|
||||
lines.append("效率统计(每小时):")
|
||||
if fudai_seen > 0:
|
||||
lines.append(f" 识别福袋: {fudai_seen / hours:.1f} 个/小时")
|
||||
if fudai_attend_ok > 0:
|
||||
lines.append(f" 参与成功: {fudai_attend_ok / hours:.1f} 次/小时")
|
||||
if total_results > 0:
|
||||
lines.append(f" 开奖次数: {total_results / hours:.1f} 次/小时")
|
||||
if fudai_result_win > 0:
|
||||
lines.append(f" 中奖次数: {fudai_result_win / hours:.2f} 次/小时")
|
||||
|
||||
lines.append("")
|
||||
|
||||
# 跳过原因统计
|
||||
skip_stats = [
|
||||
("fudai_skip_value_low", "跳过-价值过低"),
|
||||
("fudai_skip_participants_low", "跳过-人数过少"),
|
||||
("fudai_skip_participants_high", "跳过-人数过多"),
|
||||
@@ -1738,76 +1806,145 @@ def main():
|
||||
("fudai_skip_countdown_short", "跳过-倒计时太短"),
|
||||
("fudai_skip_countdown_long", "跳过-倒计时太长"),
|
||||
("fudai_skip_watch_required", "跳过-需要看播"),
|
||||
]
|
||||
skip_found = False
|
||||
]
|
||||
skip_total = sum(counters.get(key, 0) for key, _ in skip_stats)
|
||||
if skip_total > 0:
|
||||
lines.append("=" * 60)
|
||||
lines.append("跳过原因统计")
|
||||
lines.append("=" * 60)
|
||||
lines.append(f"总跳过次数: {skip_total}")
|
||||
if fudai_seen > 0:
|
||||
skip_rate = (skip_total / fudai_seen) * 100
|
||||
lines.append(f"跳过率: {skip_rate:.1f}%")
|
||||
lines.append("")
|
||||
for key, label in skip_stats:
|
||||
val = counters.get(key, 0)
|
||||
if val > 0:
|
||||
if not skip_found:
|
||||
lines.append("跳过原因统计:")
|
||||
skip_found = True
|
||||
lines.append(f" {label}: {val}")
|
||||
percentage = (val / skip_total) * 100 if skip_total > 0 else 0
|
||||
lines.append(f" {label}: {val} ({percentage:.1f}%)")
|
||||
lines.append("")
|
||||
|
||||
if skip_found:
|
||||
lines.append("")
|
||||
|
||||
# 粉丝团
|
||||
fansclub_stats = [
|
||||
("fansclub_required", "需要粉丝团"),
|
||||
("fansclub_manual_needed", "需手动加入"),
|
||||
("fansclub_unresolved", "未解决"),
|
||||
]
|
||||
fansclub_found = False
|
||||
# 粉丝团统计
|
||||
fansclub_stats = [
|
||||
("fansclub_required", "需要粉丝团"),
|
||||
("fansclub_manual_needed", "需手动加入"),
|
||||
("fansclub_unresolved", "未解决"),
|
||||
]
|
||||
fansclub_total = sum(counters.get(key, 0) for key, _ in fansclub_stats)
|
||||
if fansclub_total > 0:
|
||||
lines.append("=" * 60)
|
||||
lines.append("粉丝团相关统计")
|
||||
lines.append("=" * 60)
|
||||
for key, label in fansclub_stats:
|
||||
val = counters.get(key, 0)
|
||||
if val > 0:
|
||||
if not fansclub_found:
|
||||
lines.append("粉丝团相关:")
|
||||
fansclub_found = True
|
||||
lines.append(f" {label}: {val}")
|
||||
percentage = (val / fansclub_total) * 100 if fansclub_total > 0 else 0
|
||||
lines.append(f" {label}: {val} ({percentage:.1f}%)")
|
||||
lines.append("")
|
||||
|
||||
if fansclub_found:
|
||||
lines.append("")
|
||||
|
||||
# 直播间切换
|
||||
switch_val = counters.get("switch_room", 0)
|
||||
if switch_val > 0:
|
||||
lines.append(f"切换直播间: {switch_val}")
|
||||
switch_reasons = [
|
||||
("switch_room_no_fudai", "无福袋"),
|
||||
("switch_room_participants", "人数不符合"),
|
||||
("switch_room_value", "价值不符合"),
|
||||
("switch_room_content", "内容不符合"),
|
||||
("switch_room_countdown", "倒计时不符合"),
|
||||
("switch_room_attend_fail", "参与失败"),
|
||||
]
|
||||
reason_lines = []
|
||||
for key, label in switch_reasons:
|
||||
val = counters.get(key, 0)
|
||||
if val > 0:
|
||||
reason_lines.append(f"{label}:{val}")
|
||||
if reason_lines:
|
||||
lines.append(f" 原因: {' / '.join(reason_lines)}")
|
||||
lines.append("")
|
||||
|
||||
# 预约相关
|
||||
reservation_stats = [
|
||||
("reservation_back_verify_ok", "预约回退校验成功"),
|
||||
("reservation_back_verify_fail", "预约回退校验失败"),
|
||||
("reservation_drop_low_value", "预约丢弃低价值"),
|
||||
("reservation_clear", "清空预约队列"),
|
||||
# 直播间切换统计
|
||||
switch_val = counters.get("switch_room", 0)
|
||||
if switch_val > 0:
|
||||
lines.append("=" * 60)
|
||||
lines.append("直播间切换统计")
|
||||
lines.append("=" * 60)
|
||||
lines.append(f"总切换次数: {switch_val}")
|
||||
if uptime_seconds > 0:
|
||||
hours = uptime_seconds / 3600.0
|
||||
if hours > 0:
|
||||
lines.append(f"切换频率: {switch_val / hours:.1f} 次/小时")
|
||||
lines.append("")
|
||||
switch_reasons = [
|
||||
("switch_room_no_fudai", "无福袋"),
|
||||
("switch_room_participants", "人数不符合"),
|
||||
("switch_room_value", "价值不符合"),
|
||||
("switch_room_content", "内容不符合"),
|
||||
("switch_room_countdown", "倒计时不符合"),
|
||||
("switch_room_attend_fail", "参与失败"),
|
||||
]
|
||||
reservation_found = False
|
||||
for key, label in switch_reasons:
|
||||
val = counters.get(key, 0)
|
||||
if val > 0:
|
||||
percentage = (val / switch_val) * 100 if switch_val > 0 else 0
|
||||
lines.append(f" {label}: {val} ({percentage:.1f}%)")
|
||||
lines.append("")
|
||||
|
||||
# 预约相关统计
|
||||
reservation_stats = [
|
||||
("reservation_back_verify_ok", "预约回退校验成功"),
|
||||
("reservation_back_verify_fail", "预约回退校验失败"),
|
||||
("reservation_drop_low_value", "预约丢弃低价值"),
|
||||
("reservation_clear", "清空预约队列"),
|
||||
]
|
||||
reservation_total = sum(counters.get(key, 0) for key, _ in reservation_stats)
|
||||
if reservation_total > 0:
|
||||
lines.append("=" * 60)
|
||||
lines.append("预约相关统计")
|
||||
lines.append("=" * 60)
|
||||
verify_ok = counters.get("reservation_back_verify_ok", 0)
|
||||
verify_fail = counters.get("reservation_back_verify_fail", 0)
|
||||
verify_total = verify_ok + verify_fail
|
||||
if verify_total > 0:
|
||||
verify_rate = (verify_ok / verify_total) * 100
|
||||
lines.append(f"回退校验成功率: {verify_rate:.1f}% ({verify_ok}/{verify_total})")
|
||||
lines.append("")
|
||||
for key, label in reservation_stats:
|
||||
val = counters.get(key, 0)
|
||||
if val > 0:
|
||||
if not reservation_found:
|
||||
lines.append("预约相关:")
|
||||
reservation_found = True
|
||||
lines.append(f" {label}: {val}")
|
||||
lines.append("")
|
||||
|
||||
# 错误统计
|
||||
error_stats = [
|
||||
("fudai_open_error", "打开福袋异常"),
|
||||
("fudai_open_error_too_many", "打开失败次数过多"),
|
||||
]
|
||||
error_total = sum(counters.get(key, 0) for key, _ in error_stats)
|
||||
if error_total > 0:
|
||||
lines.append("=" * 60)
|
||||
lines.append("错误统计")
|
||||
lines.append("=" * 60)
|
||||
for key, label in error_stats:
|
||||
val = counters.get(key, 0)
|
||||
if val > 0:
|
||||
lines.append(f" {label}: {val}")
|
||||
lines.append("")
|
||||
|
||||
if reservation_found:
|
||||
lines.append("")
|
||||
# 价值统计(从事件中提取)
|
||||
events = stats.get("events", [])
|
||||
prize_values = []
|
||||
for event in events:
|
||||
meta = event.get("meta", {})
|
||||
if "prize_value_yuan" in meta and meta["prize_value_yuan"] is not None:
|
||||
try:
|
||||
prize_values.append(float(meta["prize_value_yuan"]))
|
||||
except (ValueError, TypeError):
|
||||
pass
|
||||
|
||||
if prize_values:
|
||||
lines.append("=" * 60)
|
||||
lines.append("价值统计")
|
||||
lines.append("=" * 60)
|
||||
total_value = sum(prize_values)
|
||||
avg_value = total_value / len(prize_values)
|
||||
max_value = max(prize_values)
|
||||
min_value = min(prize_values)
|
||||
lines.append(f"识别到的福袋总数: {len(prize_values)}")
|
||||
lines.append(f"总价值: {total_value:.2f} 元")
|
||||
lines.append(f"平均价值: {avg_value:.2f} 元")
|
||||
lines.append(f"最高价值: {max_value:.2f} 元")
|
||||
lines.append(f"最低价值: {min_value:.2f} 元")
|
||||
|
||||
# 价值分布
|
||||
high_value_count = sum(1 for v in prize_values if v >= 500)
|
||||
medium_value_count = sum(1 for v in prize_values if 100 <= v < 500)
|
||||
low_value_count = sum(1 for v in prize_values if v < 100)
|
||||
lines.append("")
|
||||
lines.append("价值分布:")
|
||||
lines.append(f" 高价值(≥500元): {high_value_count} ({high_value_count/len(prize_values)*100:.1f}%)")
|
||||
lines.append(f" 中价值(100-500元): {medium_value_count} ({medium_value_count/len(prize_values)*100:.1f}%)")
|
||||
lines.append(f" 低价值(<100元): {low_value_count} ({low_value_count/len(prize_values)*100:.1f}%)")
|
||||
lines.append("")
|
||||
|
||||
# 最近一次福袋信息
|
||||
fudai_last = stats.get("fudai_last", {})
|
||||
@@ -1821,6 +1958,9 @@ def main():
|
||||
copies = fudai_last.get("copies")
|
||||
if participants is not None and copies is not None:
|
||||
lines.append(f"参与人数/份数: {participants} / {copies}")
|
||||
if participants > 0 and copies > 0:
|
||||
ratio = participants / copies
|
||||
lines.append(f" 中奖概率: {1/ratio*100:.2f}% (1/{ratio:.1f})")
|
||||
prize_value = fudai_last.get("prize_value_yuan")
|
||||
if prize_value is not None:
|
||||
lines.append(f"奖品价值: {prize_value} 元")
|
||||
@@ -1859,11 +1999,22 @@ def main():
|
||||
f" 人数/份数: {win.get('participants')} / {win.get('copies')}"
|
||||
)
|
||||
|
||||
# 确保至少显示基本信息
|
||||
if not lines:
|
||||
lines.append("=" * 60)
|
||||
lines.append("统计信息")
|
||||
lines.append("=" * 60)
|
||||
lines.append("暂无统计数据")
|
||||
lines.append("")
|
||||
lines.append("提示:请先运行程序以收集统计数据")
|
||||
|
||||
stats_text.delete("1.0", "end")
|
||||
stats_text.insert("1.0", "\n".join(lines))
|
||||
except Exception as e:
|
||||
import traceback
|
||||
stats_text.delete("1.0", "end")
|
||||
stats_text.insert("1.0", f"刷新统计信息失败:{e}")
|
||||
error_detail = traceback.format_exc()
|
||||
stats_text.insert("1.0", f"刷新统计信息失败:{e}\n\n详细信息:\n{error_detail}")
|
||||
|
||||
ttk.Button(stats_top, text="刷新", command=refresh_stats).pack(side=LEFT)
|
||||
|
||||
@@ -2060,6 +2211,145 @@ def main():
|
||||
root.mainloop()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
from version import print_version_banner
|
||||
|
||||
print_version_banner("gui_app")
|
||||
except Exception:
|
||||
pass
|
||||
main()
|
||||
|
||||
actions_log_top = ttk.Frame(actions_log_tab)
|
||||
actions_log_top.pack(fill=X, padx=10, pady=(10, 0))
|
||||
actions_log_text = ScrolledText(actions_log_tab)
|
||||
actions_log_text.pack(fill=BOTH, expand=True, padx=10, pady=10)
|
||||
try:
|
||||
actions_log_text.configure(font=("Consolas", 10))
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
actions_filter_var = tk.StringVar(value="")
|
||||
|
||||
def refresh_actions_log():
|
||||
"""读取 logs/actions.log 的尾部若干行,在 GUI 中展示关键行为日志(支持简单关键字筛选)。"""
|
||||
path = os.path.join(os.path.dirname(__file__), "logs", "actions.log")
|
||||
try:
|
||||
if os.path.exists(path):
|
||||
# 仿照 web_gui 的实现:只读最后一小段,避免文件巨大
|
||||
size = os.path.getsize(path)
|
||||
read_bytes = min(size, 65536)
|
||||
with open(path, "rb") as f:
|
||||
if read_bytes < size:
|
||||
f.seek(-read_bytes, os.SEEK_END)
|
||||
data = f.read().decode("utf-8", errors="replace")
|
||||
lines = data.splitlines()
|
||||
# 只取最近 300 行
|
||||
tail = lines[-300:]
|
||||
|
||||
# 关键字筛选:若填写了筛选词,只保留包含该关键字的行
|
||||
kw = actions_filter_var.get().strip()
|
||||
if kw:
|
||||
tail = [ln for ln in tail if kw in ln]
|
||||
|
||||
actions_log_text.delete("1.0", "end")
|
||||
actions_log_text.insert("1.0", "\n".join(tail))
|
||||
actions_log_text.see("end")
|
||||
else:
|
||||
actions_log_text.delete("1.0", "end")
|
||||
actions_log_text.insert(
|
||||
"1.0", "暂无行为日志(logs/actions.log 不存在)"
|
||||
)
|
||||
except Exception as e:
|
||||
actions_log_text.delete("1.0", "end")
|
||||
actions_log_text.insert("1.0", f"读取行为日志失败:{e}")
|
||||
|
||||
ttk.Label(actions_log_top, text="关键字筛选:").pack(side=LEFT)
|
||||
ttk.Entry(actions_log_top, textvariable=actions_filter_var, width=16).pack(
|
||||
side=LEFT, padx=(0, 8)
|
||||
)
|
||||
ttk.Button(actions_log_top, text="刷新", command=refresh_actions_log).pack(
|
||||
side=LEFT
|
||||
)
|
||||
|
||||
# OCR结果显示
|
||||
ocr_results_top = ttk.Frame(ocr_results_tab)
|
||||
ocr_results_top.pack(fill=X, padx=10, pady=(10, 0))
|
||||
ocr_results_text = ScrolledText(ocr_results_tab)
|
||||
ocr_results_text.pack(fill=BOTH, expand=True, padx=10, pady=10)
|
||||
try:
|
||||
ocr_results_text.configure(font=("Consolas", 10))
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
def update_ocr_results(results):
|
||||
"""更新OCR结果标签页的显示"""
|
||||
try:
|
||||
lines = []
|
||||
lines.append("=" * 80)
|
||||
lines.append("OCR识别结果(基于最新截图)")
|
||||
lines.append("=" * 80)
|
||||
lines.append("")
|
||||
|
||||
if not results:
|
||||
lines.append('暂无OCR结果,请先点击"截图+OCR"按钮')
|
||||
else:
|
||||
# 按区域名称分组显示
|
||||
for region_name, desc, text_result, status in results:
|
||||
lines.append(f"【{region_name}】{desc}")
|
||||
lines.append(f" 状态: {status}")
|
||||
if text_result:
|
||||
# 如果文本较长,分行显示
|
||||
if len(text_result) > 100:
|
||||
lines.append(f" 识别文本: {text_result[:100]}...")
|
||||
lines.append(f" (完整文本: {text_result})")
|
||||
else:
|
||||
lines.append(f" 识别文本: {text_result}")
|
||||
else:
|
||||
lines.append(" 识别文本: (空)")
|
||||
lines.append("")
|
||||
|
||||
ocr_results_text.delete("1.0", "end")
|
||||
ocr_results_text.insert("1.0", "\n".join(lines))
|
||||
ocr_results_text.see("1.0")
|
||||
except Exception as e:
|
||||
ocr_results_text.delete("1.0", "end")
|
||||
ocr_results_text.insert("1.0", f"更新OCR结果失败:{e}")
|
||||
|
||||
ttk.Button(
|
||||
ocr_results_top, text="刷新", command=lambda: update_ocr_results([])
|
||||
).pack(side=LEFT)
|
||||
ttk.Label(ocr_results_top, text='(点击"截图+OCR"按钮自动更新)').pack(
|
||||
side=LEFT, padx=(10, 0)
|
||||
)
|
||||
|
||||
pump_logs()
|
||||
root.after(300, lambda _=None: refresh_preview() if image_var.get() else None) # type: ignore[misc]
|
||||
root.after(500, lambda _=None: refresh_stats()) # type: ignore[misc]
|
||||
root.after(500, lambda _=None: refresh_reservations()) # type: ignore[misc]
|
||||
root.after(500, lambda _=None: refresh_high_value_rooms()) # type: ignore[misc]
|
||||
root.after(500, lambda _=None: refresh_actions_log()) # type: ignore[misc]
|
||||
|
||||
# 定期刷新统计信息(每3秒)
|
||||
def auto_refresh_stats():
|
||||
if runner.is_running():
|
||||
refresh_stats()
|
||||
root.after(3000, lambda _=None: auto_refresh_stats()) # type: ignore[misc]
|
||||
|
||||
auto_refresh_stats()
|
||||
|
||||
def on_close():
|
||||
try:
|
||||
runner.stop()
|
||||
except Exception:
|
||||
pass
|
||||
root.destroy()
|
||||
|
||||
root.protocol("WM_DELETE_WINDOW", on_close)
|
||||
refresh_devices()
|
||||
root.mainloop()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
from version import print_version_banner
|
||||
|
||||
+52
@@ -325,6 +325,7 @@ class Runner:
|
||||
counters = dict(self._counters)
|
||||
fudai_last = dict(self._fudai_last)
|
||||
wins = list(self._wins[-20:]) # 只返回最近20条
|
||||
events = list(self._events[-1000:]) # 返回最近1000条事件用于统计
|
||||
|
||||
now = time.time()
|
||||
uptime = 0
|
||||
@@ -341,6 +342,7 @@ class Runner:
|
||||
"counters": counters,
|
||||
"fudai_last": fudai_last,
|
||||
"wins": wins,
|
||||
"events": events,
|
||||
}
|
||||
|
||||
def start(self, params: RunParams) -> None:
|
||||
@@ -633,6 +635,54 @@ class Runner:
|
||||
|
||||
self._reader_thread = threading.Thread(target=_reader, daemon=True)
|
||||
self._reader_thread.start()
|
||||
|
||||
def send_back_key(self, device_id: str) -> bool:
|
||||
"""手动发送返回键到指定设备。
|
||||
|
||||
Args:
|
||||
device_id: 设备ID,如果为空则使用第一个可用设备
|
||||
|
||||
Returns:
|
||||
True if successful, False otherwise
|
||||
"""
|
||||
try:
|
||||
adb_exe = find_adb_executable()
|
||||
if not adb_exe:
|
||||
self._on_line("[错误] 未找到 adb.exe")
|
||||
return False
|
||||
|
||||
# 如果没有指定设备ID,尝试获取第一个可用设备
|
||||
if not device_id or device_id.strip() == "":
|
||||
devices = list_adb_devices(adb_exe)
|
||||
if not devices:
|
||||
self._on_line("[错误] 未找到可用设备")
|
||||
return False
|
||||
device_id = devices[0]
|
||||
|
||||
# 发送返回键 (keyevent 4)
|
||||
cmd = [adb_exe, "-s", device_id, "shell", "input", "keyevent", "4"]
|
||||
proc = subprocess.run(
|
||||
cmd,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
encoding="utf-8",
|
||||
errors="replace",
|
||||
timeout=5.0,
|
||||
)
|
||||
|
||||
if proc.returncode == 0:
|
||||
self._on_line(f"[手动操作] 已发送返回键到设备: {device_id}")
|
||||
return True
|
||||
else:
|
||||
error_msg = proc.stderr or proc.stdout or "未知错误"
|
||||
self._on_line(f"[错误] 发送返回键失败: {error_msg}")
|
||||
return False
|
||||
except subprocess.TimeoutExpired:
|
||||
self._on_line("[错误] 发送返回键超时")
|
||||
return False
|
||||
except Exception as e:
|
||||
self._on_line(f"[错误] 发送返回键异常: {str(e)}")
|
||||
return False
|
||||
|
||||
def stop(self) -> None:
|
||||
if not self.is_running():
|
||||
@@ -686,3 +736,5 @@ class Runner:
|
||||
self._proc = None
|
||||
self._pid = None
|
||||
|
||||
|
||||
|
||||
@@ -38,6 +38,10 @@ paddlepaddle>=2.5.0,<3.0.0
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -54,6 +54,10 @@ ttkbootstrap>=1.10.0
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
# 抖音福袋挂机程序流程图(完整版)
|
||||
|
||||
**版本**: V3.3.2+
|
||||
**最后更新**: 2025-12-22
|
||||
**主要更新**: 并行OCR优化、回退逻辑修复
|
||||
**版本**: V3.3.3+
|
||||
**最后更新**: 2025-12-XX
|
||||
**主要更新**: 30分钟超时保护、手动操作功能、并行OCR优化、回退逻辑修复
|
||||
|
||||
## 主流程图
|
||||
|
||||
@@ -14,6 +14,22 @@ flowchart TD
|
||||
CheckTime -->|否| End([程序结束])
|
||||
CheckTime -->|是| MainLoop[主循环开始]
|
||||
|
||||
MainLoop --> CheckTimeout{检查30分钟超时<br/>V3.3.3+}
|
||||
CheckTimeout --> CheckLastAttend{是否成功参与过?}
|
||||
CheckLastAttend -->|是| CheckElapsed{距离最后参与<br/>是否超过30分钟?}
|
||||
CheckLastAttend -->|否| CheckRunTime{运行时间<br/>是否超过30分钟?}
|
||||
|
||||
CheckElapsed -->|是| ReturnToRecommend[返回推荐页面<br/>多次点击返回键<br/>最多10次]
|
||||
CheckElapsed -->|否| CheckReservation
|
||||
CheckRunTime -->|是| ReturnToRecommend
|
||||
CheckRunTime -->|否| CheckReservation
|
||||
|
||||
ReturnToRecommend --> ClickFollow[点击关注标签]
|
||||
ClickFollow --> EnterLive[点击进入直播间<br/>连点2次]
|
||||
EnterLive --> ResetTimeout[重置超时时间]
|
||||
ResetTimeout --> DelayTimeout[延迟2秒]
|
||||
DelayTimeout --> MainLoop
|
||||
|
||||
MainLoop --> CheckReservation{是否启用高价值预约<br/>且有预约队列?}
|
||||
|
||||
CheckReservation -->|是| ProcessReservation[处理预约回退<br/>检查队列是否已满<br/>检查是否需要回退到预约直播间]
|
||||
@@ -131,7 +147,8 @@ flowchart TD
|
||||
SwipeUp2 --> MainLoop
|
||||
|
||||
JoinLottery --> CheckResult{参与成功?}
|
||||
CheckResult -->|是| CloseDetail3[关闭详情页]
|
||||
CheckResult -->|是| UpdateLastAttend[更新最后成功参与时间<br/>V3.3.3+]
|
||||
UpdateLastAttend --> CloseDetail3[关闭详情页]
|
||||
CheckResult -->|否| LogError2[记录错误]
|
||||
CloseDetail3 --> Delay5[延迟1秒]
|
||||
LogError2 --> Delay5
|
||||
@@ -547,6 +564,7 @@ flowchart TD
|
||||
- **立即参与**: 通过所有筛选且剩余秒数在阈值内
|
||||
- **记录预约**: 价值达到高价值阈值且剩余秒数大于阈值
|
||||
- **丢弃**: 不满足任何筛选条件
|
||||
- **更新参与时间(V3.3.3+)**: 参与成功后更新 `_last_successful_attend_ts`,用于30分钟超时检查
|
||||
|
||||
## 数据流向
|
||||
|
||||
@@ -570,6 +588,7 @@ flowchart TD
|
||||
4. **观看任务提前检测**: OCR识别内容后立即检查是否为"观看X分钟"任务,如果是则直接返回,跳过倒计时和价值识别,节省时间并避免不必要的处理
|
||||
5. **倒计时一致性检查**: 多次读取时检查倒计时是否一致,避免识别错误导致的误判
|
||||
6. **并行像素检测**: 阶段诊断时所有像素特征并行检测,提高效率
|
||||
7. **30分钟超时保护(V3.3.3+)**: 自动检测并处理长时间无参与的情况,防止脚本卡在无效状态
|
||||
|
||||
## 配置参数影响
|
||||
|
||||
|
||||
@@ -85,3 +85,7 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -157,3 +157,7 @@ if __name__ == "__main__":
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user