diff --git a/config/config.json b/config/config.json index f727481..a32d23b 100644 --- a/config/config.json +++ b/config/config.json @@ -44,7 +44,7 @@ "yanghao_comment_prob": 1.0, "yanghao_icon_roi_size": 240, "yanghao_icon_match_threshold": 0.77, - "yanghao_step_screenshot": true, + "yanghao_step_screenshot": false, "yanghao_like_roi_offset_x": 0, "yanghao_like_roi_offset_y": -50, "yanghao_fav_roi_offset_x": 40, @@ -65,8 +65,8 @@ "fudai_quiet_hours_enabled": true, "fudai_quiet_start_hour": 2, "fudai_quiet_end_hour": 9, - "yanghao_enabled": true, - "yanghao_enable_actions": true, + "yanghao_enabled": false, + "yanghao_enable_actions": false, "yanghao_like_icon_x": 0, "yanghao_like_icon_y": -1, "yanghao_fav_icon_x": -1, @@ -206,6 +206,6 @@ "fansclub_manual_wait_seconds": 3.0, "enable_streaming_screenshot": false, "fudai_exit_after_misses": 30, - "yanghao_only": true, + "yanghao_only": false, "record_room_title_mapping_enabled": true } diff --git a/docs/image/完整技术文档/1767529904236.png b/docs/image/完整技术文档/1767529904236.png new file mode 100644 index 0000000..256cded Binary files /dev/null and b/docs/image/完整技术文档/1767529904236.png differ diff --git a/docs/完整技术文档.md b/docs/完整技术文档.md index c075994..a5c788f 100644 --- a/docs/完整技术文档.md +++ b/docs/完整技术文档.md @@ -9,6 +9,51 @@ -- 变更记录 - 2026-01-03: V4.0 — 重构文档结构,补充快速上手、配置优先级、截图/OCR/日志说明、故障排查与验证清单。 +## 最近修复与配置变更(2026-01-03) + +本小节记录最近完成的若干修复与功能开关,便于开发与运维快速验证和回滚。 + +- 概要:增加能在运行时关闭对“福袋内容”和“福袋任务列表”两类 OCR 的识别开关(配置项与 GUI),并修复了在并行 OCR 失败后串行兜底不尊重配置而仍然触发 OCR 的问题;同时修复了 actions.log 轮转时的文件被占用错误(WinError 32),以及新增“连续未找到福袋时按返回退出直播间”的可配置行为。 + +- 主要变更点(代码 / 配置): + - 配置项:在 `config/config.json` 中添加 + - `fudai_disable_content_recognition`(布尔) — 关闭福袋内容 OCR + - `fudai_disable_task_recognition`(布尔) — 关闭福袋任务列表 OCR + - `fudai_exit_after_misses`(整数) — 连续未找到福袋 N 次后按返回退出直播间 + - GUI:`gui/gui_app.py` 增加对应复选框/数值输入,并在保存时写入 `config/config.json`。 + - 核心修复: + - `douyin/fudai/core/fudai_detail_reader.py`: + - 并行/备用并行/串行兜底分支均尊重 `fudai_disable_content_recognition` 与 `fudai_disable_task_recognition`,避免在配置启用时仍执行 OCR。 + - 在串行兜底中添加了跳过日志(例如:"跳过串行福袋内容OCR识别(配置启用)")。 + - `douyin/fudai/douyin_fudai_core.py`:保留并使用内容 OCR 开关的判定逻辑(跳过调度/提交)。 + - `douyin/core/douyin_flow_control.py`:修复了导致模块导入失败的语法错误,并实现了“连续未找到福袋按返回退出”的计数与触发逻辑。 + - 日志写法修正:将 ad-hoc 的直接写 actions.log 的行为替换为通过统一 logger 输出,避免 RotatingFileHandler 在 Windows 上轮转时报 WinError 32(文件被占用)。相关调整见 `douyin/handlers/douyin_screenshot_manager.py` / `douyin/logging/*`。 + +- 验证要点(运行时观察): + - 当 `fudai_disable_content_recognition` 为 true 时,日志中应出现至少一条: + - `跳过福袋内容OCR识别(配置启用)` 或 `跳过备用福袋内容OCR识别(配置启用)` 或 `跳过串行福袋内容OCR识别(配置启用)`。 + - 并且不会出现新的 `OCR识别福袋内容` 的性能/计时条目(即不再有与 content OCR 相关的耗时统计)。 + - 当 `fudai_disable_task_recognition` 为 true 时,日志中应出现: + - `跳过福袋任务列表OCR识别(配置启用)`,并且不会有任务列表 OCR 的原始输出条目。 + - 连续未找到福袋触发退出:将 `fudai_exit_after_misses` 设为小值(例如 3),运行短会话,日志应出现类似: + - `连续未找到福袋达到阈值:按返回键退出直播间`(或相近日志),并能在 `logs/actions.log` 中看到对应的返回按键事件。 + - actions.log 轮转问题:在长时间运行后触发日志轮转,确认不会再出现 Windows 的 `PermissionError` / `WinError 32` 异常。 + +- 快速验证命令(仓库根目录,PowerShell): + +```powershell +# 语法检查 +python -m py_compile douyin/fudai/core/fudai_detail_reader.py + +# 在 config 里临时启用开关(手动修改 config/config.json)后运行一次短会话 +python run_cli.py --wait-minutes 0 --device-id + +# 在日志中查找跳过消息(示例) +Select-String -Path logs\*.log -Pattern "跳过福袋内容OCR识别|跳过福袋任务列表OCR识别|连续未找到福袋" +``` + +如果需要,我可以把这些验证步骤写成一键脚本 `tools/verify_fudai_disable.sh` / `tools/verify_fudai_disable.ps1` 以便 CI 调用。 + ## 快速步骤(3 分钟上手) 1. 克隆仓库并进入目录 @@ -361,12 +406,11 @@ PY ```javascript run_once_basic(recursion_depth=0) - ↓ -[检查1] 预约回退直接参与标志 (_reservation_back_direct_attend) - ├─> 是 → _handle_reservation_direct_attend() → return - └─> 否 → 继续 - ↓ -[检查2] 等待开奖状态 (_waiting_for_lottery_result) + ↓ + [检查1] 预约回退处理(直接参与标志已移除) + └─> 如需回退则在回退流程中直接处理参与逻辑(不再使用 `_reservation_back_direct_attend` 或 `_force_attend_after_reservation_back` 标志) + ↓ + [检查2] 等待开奖状态 (_waiting_for_lottery_result) ├─> 是 → 检查预约抢占 → 检查开奖结果 → return └─> 否 → 继续 ↓ @@ -711,11 +755,11 @@ def fudai_choujiang(self, device_id: str = "", y_pianyi: int = 0, - 同时清空状态文件,确保外部查看时也是空的 - 标记已运行过(`_first_run_once_basic = False`) 2. **预约回退检查**: - - 如果启用高价值预约且预约队列不为空,调用 `process_reservation_attend_window()` 检查是否需要回退 - - 如果触发回退,设置 `_reservation_back_direct_attend = True` + - 如果启用高价值预约且预约队列不为空,调用 `process_reservation_attend_window()` 检查是否需要回退 + - 如果触发回退,回退流程会决定是否立即参与(不再设置运行时标志 `_reservation_back_direct_attend`) - **1. 检查预约回退直接参与标志** (`_reservation_back_direct_attend`) - - 如果为 `True`,调用 `_handle_reservation_direct_attend()` 处理并返回 + **1. 预约回退处理(直接参与标志已移除)** + - 如果回退流程决定立即参与,会在回退内部直接处理参与逻辑并返回;否则按常规流程继续 **2. 获取截图并执行阶段诊断** - 调用 `operation.get_screenshot()` 获取截图 @@ -787,12 +831,13 @@ def run_once_basic(self) -> None: return if process_reservation_attend_window(...): - self._reservation_back_direct_attend = True + # 回退触发:在回退逻辑中直接处理立即参与行为(已移除 `_reservation_back_direct_attend` 标志) + # 例如:回退完成后会在回退流程中决定是否立即参与,并设置相应的锁定期/待处理状态 + pass - # 1. 检查预约回退直接参与标志 - if self._reservation_back_direct_attend: - self._handle_reservation_direct_attend() - return + # 1. 预约回退处理(直接参与标志已移除) + # 如果回退流程决定需要立即参与,则在回退流程内部直接调用参与处理逻辑; + # 否则按常规流程继续执行阶段诊断与详情处理。 # 2. 检查跳过阶段诊断标志 if self._skip_stage_diagnosis_and_find_fudai: @@ -1715,7 +1760,7 @@ if success: - **参数**: - `analyser: Any`: 分析器对象 - **返回值**: 无 -- **调用位置**: `run_once_basic()` 中检查到 `_reservation_back_direct_attend = True` 时调用 +- **调用位置**: `run_once_basic()` 中回退处理会直接触发参与逻辑(不再依赖 `_reservation_back_direct_attend` 标志) - **主要流程**: 1. **检查预约队列**: 如果预约队列为空,回退到正常流程(调用 `_handle_in_fudai_detail()`) 2. **检查福袋是否过期**: @@ -1760,7 +1805,7 @@ if success: - 移除匹配的预约,保留不匹配的预约 - 记录移除日志 - **清除标志**: - - 清除 `_reservation_back_direct_attend = False` + - 清除相关运行时标志(已移除,不再使用) - 清除 `reservation_after_action_pending = False` **配置参数**: @@ -2965,7 +3010,7 @@ UNKNOWN = "UNKNOWN" # 未知阶段 #### 8.2.1 预约回退直接参与标志 -- **属性名**: `_reservation_back_direct_attend: bool` +-- **属性名**: `_reservation_back_direct_attend`: 已移除(不再作为运行时属性使用) - **作用**: 标记预约回退后是否直接参与(跳过阶段诊断和福袋查找) - **设置时机**: 预约回退成功后设置为 `True` - **清除时机**: 参与完成后清除 diff --git a/douyin/other/douyin_yanghao.py b/douyin/other/douyin_yanghao.py index da8543e..20009bf 100644 --- a/douyin/other/douyin_yanghao.py +++ b/douyin/other/douyin_yanghao.py @@ -973,15 +973,15 @@ def yanghao_wait(analyser, total_seconds: int) -> None: print( f"[养号] yanghao_enabled=0:跳过推荐页养号(不再等待 {int(total_seconds)}s,快速继续)" ) - try: - debug_on = bool(str(os.environ.get("YANGHAO_DEBUG", "")).strip()) - except Exception: - debug_on = False - if debug_on: - print( - f"[养号][DEBUG] like_tpl='{like_tpl}' exists={like_tpl_exists}; fav_tpl='{fav_tpl}' exists={fav_tpl_exists}; project_root={project_root}" - ) - pass + try: + debug_on = bool(str(os.environ.get("YANGHAO_DEBUG", "")).strip()) + except Exception: + debug_on = False + if debug_on: + print( + f"[养号][DEBUG] like_tpl='{like_tpl}' exists={like_tpl_exists}; fav_tpl='{fav_tpl}' exists={fav_tpl_exists}; project_root={project_root}" + ) + pass return # 只保留推荐页养号;增加“间隔(冷却)”控制,避免触发过于频繁 diff --git a/tools/_dump_lines.py b/tools/_dump_lines.py index 2303169..e87503a 100644 --- a/tools/_dump_lines.py +++ b/tools/_dump_lines.py @@ -1,6 +1,7 @@ import sys -p='douyin/other/douyin_yanghao.py' -with open(p,'rb') as f: - lines=f.read().splitlines() -for i in range(959,979): + +p = "douyin/other/douyin_yanghao.py" +with open(p, "rb") as f: + lines = f.read().splitlines() +for i in range(959, 979): print(f"{i+1:4}: {lines[i]!r}") diff --git a/tools/test_yanghao_detection.py b/tools/test_yanghao_detection.py index cc5aecb..d86c5ed 100644 --- a/tools/test_yanghao_detection.py +++ b/tools/test_yanghao_detection.py @@ -167,9 +167,7 @@ def search_best_roi_for_polygon(poly, tpl_path, label): action_scale = float(getattr(a, "yanghao_fav_roi_scale", 1.5)) except Exception: action_scale = 1.5 - base_size_px = max( - 1, int(base_size * max(scale_x, scale_y) * float(action_scale)) - ) + base_size_px = max(1, int(base_size * max(scale_x, scale_y) * float(action_scale))) offsets = list(range(-120, 121, 12)) size_muls = [0.8, 1.0, 1.2, 1.4, 1.6, 1.8, 2.0, 2.2] @@ -298,7 +296,9 @@ def main(): if os.path.exists(cfg_path): with open(cfg_path, "r", encoding="utf-8") as f: cfg = json.load(f) - if isinstance(cfg.get("yanghao_like_poly"), list) and cfg.get("yanghao_like_poly"): + if isinstance(cfg.get("yanghao_like_poly"), list) and cfg.get( + "yanghao_like_poly" + ): like_poly = cfg.get("yanghao_like_poly") else: rx1 = cfg.get("yanghao_like_rect_x1") @@ -306,9 +306,16 @@ def main(): rx2 = cfg.get("yanghao_like_rect_x2") ry2 = cfg.get("yanghao_like_rect_y2") if all(v is not None for v in [rx1, ry1, rx2, ry2]): - like_poly = [[int(rx1), int(ry1)], [int(rx2), int(ry1)], [int(rx2), int(ry2)], [int(rx1), int(ry2)]] + like_poly = [ + [int(rx1), int(ry1)], + [int(rx2), int(ry1)], + [int(rx2), int(ry2)], + [int(rx1), int(ry2)], + ] - if isinstance(cfg.get("yanghao_fav_poly"), list) and cfg.get("yanghao_fav_poly"): + if isinstance(cfg.get("yanghao_fav_poly"), list) and cfg.get( + "yanghao_fav_poly" + ): fav_poly = cfg.get("yanghao_fav_poly") else: rx1 = cfg.get("yanghao_fav_rect_x1") @@ -316,7 +323,12 @@ def main(): rx2 = cfg.get("yanghao_fav_rect_x2") ry2 = cfg.get("yanghao_fav_rect_y2") if all(v is not None for v in [rx1, ry1, rx2, ry2]): - fav_poly = [[int(rx1), int(ry1)], [int(rx2), int(ry1)], [int(rx2), int(ry2)], [int(rx1), int(ry2)]] + fav_poly = [ + [int(rx1), int(ry1)], + [int(rx2), int(ry1)], + [int(rx2), int(ry2)], + [int(rx1), int(ry2)], + ] except Exception: pass