Commit Graph
178 Commits
Author SHA1 Message Date
Your Name 25df550304 fix: prioritize reservation conflicts by value 2026-06-23 11:46:02 +08:00
Your Name f95832579a fix: avoid live-room back on fudai retry 2026-06-23 03:09:14 +08:00
Your Name 25f7f9af9e fix: use ocr live tab and merge stuck room titles 2026-06-23 02:06:53 +08:00
Your Name 8389f85124 fix: speed up reservation direct attend 2026-06-23 01:43:17 +08:00
Your Name f129206df7 Clear runtime state at fudai startup 2026-06-19 20:18:15 +08:00
Your Name 48b0a32e24 Guard fudai retry and reservation seek verification 2026-06-19 20:01:46 +08:00
Your Name a06218dd16 Clear stale reservation direct attend state 2026-06-19 19:37:24 +08:00
Your Name b3d3f28ff3 Reduce fudai detection overhead 2026-06-19 19:16:25 +08:00
Your Name 58c1856fad Keep live title OCR in fudai detail path 2026-06-19 18:12:28 +08:00
Your Name 78a75d4843 Tune fudai detail OCR strategy 2026-06-19 14:44:17 +08:00
Your Name 32fcbc4c24 Skip full countdown OCR in fudai critical path 2026-06-19 14:30:47 +08:00
Your Name 6b987fd04f Keep task OCR out of fudai detail critical path 2026-06-19 14:12:23 +08:00
Your Name aa3690fecf Fix fudai wrong-target retry and detail OCR delay 2026-06-19 13:54:18 +08:00
Your Name 207748a901 Improve screenshot fallback and miss samples 2026-06-19 12:54:57 +08:00
Your Name ec51772cf0 Fix fudai countdown and room mapping guards 2026-06-18 19:25:46 +08:00
Your Name fc96549bd2 fix(packaging): disable paddlex model source checks 2026-06-18 13:24:55 +08:00
Your Name 22e2ed1508 Clear stale fudai cache when leaving room 2026-06-18 12:44:19 +08:00
Your Name 89fb278988 Generalize coupon overlay rejection for fudai detection 2026-06-18 12:18:25 +08:00
Your Name b9c5106f62 Harden fudai icon detection against coupon taps 2026-06-18 11:50:50 +08:00
Your Name fe1a62e92d Fix fudai live flow state and icon fallback 2026-06-18 10:40:47 +08:00
Your Name 9ffbe47bdb Improve fudai live flow diagnostics 2026-06-18 04:48:16 +08:00
Your Name 1adaefdce6 Add lightweight fudai flow diagnostics 2026-06-18 03:52:18 +08:00
Your Name 87838daad4 add windows installer packaging workflow 2026-06-09 21:58:35 +08:00
Your Name 62c84939ee add fudai detail and reservation verdict markers 2026-06-05 15:46:43 +08:00
Your Name 9b03556b7d expose fudai detail thresholds and regions 2026-06-05 15:36:10 +08:00
Your Name 5e2ca0587b preserve simple and detail logs 2026-06-04 12:05:38 +08:00
Your Name 1d564000ca add detail OCR performance diagnostics 2026-06-04 11:39:29 +08:00
Your Name 198a30dce1 完善新UI适配与日志简化 2026-06-03 12:40:06 +08:00
Your Name e51d37890a 精简像素调试图与日志 2026-06-03 02:11:45 +08:00
Your Name 1d37d57c90 修复福袋详情OCR v2与调试日志 2026-06-03 01:22:13 +08:00
Your Name 05b9d17951 fix: remove recursive run_once reentry after desktop recovery 2026-06-01 20:58:24 +08:00
Your Name 36e374ef67 refactor: split large modules and harden live-room fudai flow 2026-06-01 18:39:44 +08:00
Your Name 61dfc1c15c fix: keep parallel OCR stable and add unknown-button fallback 2026-06-01 12:18:21 +08:00
Your Name 3659d5b7da refactor: centralize web gui host/port config in path_config 2026-06-01 07:08:47 +08:00
CodexandClaude Sonnet 4.5 bb90e2983f fix(pil): 补充修复剩余 PIL Image 资源泄漏
覆盖 14 个文件中的 Image.open() 未正确关闭问题:
- fansclub_handler: 5 处(pic/pic_rgb/img 未 close)
- image_ops: 2 处(crop 后 pic 未 close)
- douyin_popups: 2 处(pic.convert 重赋值泄漏原始句柄)
- douyin_fudai: 1 处(open().convert() 链式调用泄漏)
- douyin_robot: 2 处(同上)
- save_files/direct_attend/finder/stage/find_open/detail/_common/ocr_preprocess: 各 1-2 处

统一修复模式:分离 open 与 convert,try/finally 确保原始句柄关闭。

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-05-23 22:49:50 +08:00
CodexandClaude Sonnet 4.5 c3746b0207 fix(pil): 修复 PIL Image 资源泄漏
Image.open() 后未 close() 导致文件句柄泄漏,用 _raw + try/finally 模式修复。

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-05-23 22:42:22 +08:00
CodexandClaude Sonnet 4.5 703da834fb fix(security): 修复 shell 注入风险和类型转换未捕获问题
- path_config.py: find_executable Unix 回退路径使用 shlex.quote 防注入
- underlying_operations.py: try_set_ime IME ID 使用 shlex.quote 防注入
- screenshot_direct.py: 环境变量 float/int 转换添加 try/except 容错
- device_select.py: 用户输入 int() 转换添加 try/except 容错
- read_once.py / image_acquirer.py / detail_verifier.py: PIL Image 添加 close()
- detector.py: 移除 return 后不可达死代码
- optimized_entry.py: 统一返回值类型 int,失败时返回 0
- read_once.py: 移除 try/except 中重复的相同代码

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-05-23 20:50:26 +08:00
CodexandClaude Sonnet 4.5 4908df19d4 refactor(cleanup): 移除死代码和冗余导入
- douyin_fudai_core.py: 移除未使用的 ThreadPoolExecutor/check_contain 导入
  和被覆盖的 fudai_result_checker 导入
- ocr_executor.py: 移除重复的 _fudai_ocr_executor_state 初始化
- flow_control_pkg: 移除 stage_handler/no_fudai/find_open 中未使用的导入

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-05-23 20:27:41 +08:00
CodexandClaude Sonnet 4.5 df69c6ab67 fix(countdown): 修复长倒计时被截断到15分钟的bug
check_countdown 中 >900s 的上限过于激进,将实际的58分钟福袋截断到14:50。
改为 >3600s(1小时)上限,兼容抖音的60分钟福袋。

同时修复 _extract_digits 取后N位的问题,改为取前N位,
避免当子图意外捕获额外数字时(如 "1458")被误提取为 "58"。

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-05-23 19:22:20 +08:00
CodexandClaude Sonnet 4.5 a50f08de5a fix(fudai): 验证失败时按钮可操作则继续参与
验证失败(如内容识别被禁用导致内容为空)时,若按钮状态为
"可以参与"/"需要加入粉丝团"等可操作状态,继续走参与流程而非
直接返回,避免漏参与有效福袋。同时修正 basic_join_decision 调用签名。

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-05-23 19:03:51 +08:00
CodexandClaude Sonnet 4.5 470c68a252 fix(fudai/stage): 修 reservation_check_start NameError + ocr_detection 缩进 + stage 默认值
- douyin_fudai.py: 补回 reservation_check_start 初始化(ffd048f 拆 helper 时丢失)
- ocr_detection.py: 修 _confirm_live_list 中 OCR 变量在 if 块外赋值的缩进 bug
- ocr_detection.py: shopping_redpacket_ocr_confidence_threshold 改 getattr 兜底 0.35
- douyin_stage.py: enable_ocr_mode1 默认值 False→True;像素检测未命中补 return
- config.json: 同步 enable_ocr_mode1 默认值

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-05-23 11:22:03 +08:00
CodexandClaude Opus 4.7 a864f6e23a refactor(fudai): 抽 __init__ 配置默认值到 init_helpers (1559 → 1323)
fudai_analyse.__init__ L119-354 是 236 行配置字段默认值 + 运行时状态初始化:
- ~80 个 self.X = <default_value> 配置字段
- 30+ 个运行时状态字段
- _reservations_state_path 解析 + room_pos_map 旧文件清理

抽到 douyin/core/fudai_modules/init_helpers.py:
- apply_fudai_defaults(self): 主入口
- _apply_yanghao_defaults(self): 推荐页养号子段
- _resolve_reservations_state_path(self): 解析路径,path_config 失败时
  兜底用 ".." 回退(不再用 dirname(__file__) + "state")
- _cleanup_old_room_pos_map_files(self): 清理上次运行的 JSON/CSV/MD 导出

__init__ 中保留:
- L57-117 设备/分辨率/operation/日志系统初始化(依赖较深,难抽)
- L356-357 self.load_config()

行为完全保留:所有字段值、解析顺序、异常兜底全部不变。
test_runtime_path_anchors.test_reservations_state_path_uses_path_config 已更新
为同时检查 douyin_fudai.py 和 init_helpers.py。

1361 passed.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-23 03:13:46 +08:00
CodexandClaude Opus 4.7 3a9f01ad74 refactor(fudai_modules): 抽 swipe 兜底重复逻辑到 fudai_device_control (1238 → 1147)
handle_detail_helpers.py 中 _handle_error_status 内联段(L266-318,53 行)
和 _fallback_swipe_up 顶层函数(L1187-1239,53 行)做的是完全一样的事:
没有 swipe_up_to_next_live 时直接 ADB shell input swipe,失败再回退到
operation.swipe。重复 1:1。

新增 douyin/core/fudai_modules/fudai_device_control.py:
- fallback_swipe_up_via_adb(self): 纯 ADB 兜底 swipe
- swipe_up_or_fallback(self): 优先 swipe_up_to_next_live,否则 fallback

handle_detail_helpers 两处都改成 4 行委托。原文件去掉 os/subprocess
import,仅保留 time。

行为完全保留:分辨率换算公式、ADB 路径解析、subprocess 超时 5s、operation.swipe
最终兜底全部不变。

1361 passed.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-23 03:07:41 +08:00
CodexandClaude Opus 4.7 8ecd2783db refactor(reservation): 抽 _write_state 闭包到顶层 _write_reservations_state
_run_reservation_attend_window 内嵌的 _write_state 闭包是 75 行 JSON 状态文件
写盘逻辑(含 1s 节流),独立性强,纯写文件无副作用。

抽到顶层 _write_reservations_state(self) helper,原闭包改为单行委托。
内部用到的 import json/os/datetime 移到 helper 内部,主函数顶部去掉。

行为完全保留:
- 1s 节流(避免高频写盘)
- 缺路径时 makedirs
- 异常时通过 self._log_kv 记录 + 不抛

文件总行数 1492 → 1495(+3):闭包变成委托后总行数略增 3,但消除了
1 层嵌套,给后续测试 _write_reservations_state 留出空间(可独立测试)。

1361 passed.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-23 03:03:19 +08:00
CodexandClaude Opus 4.7 e46497ea80 refactor(underlying): 抽 cut_pic 图片裁剪到 image_ops (1574 → 1327)
underlying_operations.cut_pic L474-721 是 248 行图片裁剪管道:
- 默认/命名两个分支共享重试 3 次的截图加载验证
- 默认分支裁出 cut.png 或 ocr/<name>.png;命名分支裁出 pic/<target>/<name>.png
- 写入 _ocr_coords_cache 供 analyse_pic_word 调试图像引用
- SAVE_CUT_PIC_DEBUG_IMAGES=1 时保存 cut_pic 调试图

抽到 underlying_operations_pkg/image_ops.py:
- cut_pic(self, left_up, right_down, target, name) -> bool
- _ensure_parent_dir / _validate_coords / _save_cut_debug_images 内部 helper

主类方法替换为 4 行委托。

更新两个旧的源码断言测试以适配抽离:
- test_cut_pic_path:从 inspect.getsource(op.cut_pic) 改为读 image_ops.py 文件源码
- test_runtime_path_anchors:把 path_config.get_pic_dir() 检查范围从单一文件
  扩展到 underlying_operations.py + image_ops.py + ocr_pipeline.py 三处

1361 passed.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-23 02:43:36 +08:00
CodexandClaude Opus 4.7 8457219241 refactor(underlying): 抽 analyse_pic_word OCR 管道到 ocr_pipeline (1939 → 1560)
underlying_operations.analyse_pic_word L723-1102 是 380 行 OCR 主管道:
路径解析 + 字节缓存 + PIL 加载 + change_color 预处理 + 调试图像保存
+ EasyOCR/PaddleOCR 调用 + 置信度提取 + 缓存写回 + 成功识别落盘。

抽到 underlying_operations_pkg/ocr_pipeline.py:
- analyse_pic_word(self, picname, change_color, pic_path, return_confidence)
- _save_debug_preprocessed: 预处理后的调试图保存(仅 SAVE_OCR_DEBUG_IMAGES=1)
- _save_debug_after_ocr: 含 OCR 文本预览 + 置信度的 after_ocr 调试图
- _save_success_pic: 成功识别落盘到 ocr/<category>/<picname>_success.png

主类方法替换为 4 行委托。原行为完全保留:缓存 / 二值化 / EasyOCR vs Paddle
predict/ocr 兜底 / [None] 短路 / 异常返回空 / picname 失败诊断日志。

新增 16 个单元测试覆盖:
- 早出 4 种(pic_path 空/不存在/带 confidence/OCR 未初始化)
- OCR 调用路径(EasyOCR / Paddle predict / Paddle ocr 兜底 / [None] 短路 / 异常)
- 缓存命中跳过 OCR / 缓存未命中写回
- change_color 0/1/2 三种模式
- return_confidence True/False 返回类型
- autouse fixture 清 OCR 模块级缓存防止测试污染

1361 passed (+16)。

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-23 02:36:47 +08:00
CodexandClaude Opus 4.7 07eee6da52 fix(paths): 修同类型 5 处路径推导 bug + 加回归测试
cut_pic 路径 bug 之后再做地毯式排查,发现 5 处类似潜在 bug:
fallback 分支用 dirname(__file__) 推根级目录,path_config 不可用时
会指向错误位置(推到 douyin/core/pic 等子目录而非项目根 pic/)。

修复:
- underlying_operations.py: screenshot_calls.jsonl 路径 + OCR category 目录
  改用 path_config.get_logs_dir() / get_pic_dir()
- douyin_fudai.py: 2 处 actions.log 兜底路径
  优先 path_config.get_actions_log_path(),兜底加 ".." 回到项目根
- fudai_detail_room_title.py: 截图复用 fallback 路径加 ".." 回退
- fudai_detail_orchestrator_pkg/read_once.py: 同上 2 处 fallback

新增 11 个回归测试覆盖:
- 关键文件不再用单步 dirname/__file__/pic 写法
- path_config 仍把所有路径锚到 PROJECT_ROOT
- 兜底分支必须含 ".." 表示回退

注:douyin_fudai.py:299 的 reservations.json 因 dirname 恰好等于
PROJECT_ROOT/douyin/core,跟 path_config.get_reservations_path() 一致,
不是 bug,未改动。

1226 passed (+11 新增)。

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-23 01:21:27 +08:00
CodexandClaude Opus 4.7 4ab4504425 fix(cut_pic): 修截图路径错位 — pic 目录从 douyin/core/pic 改回项目根 pic
cut_pic 历史 bug:用 os.path.dirname(__file__) + "/pic" 推路径,
误指向 douyin/core/pic/(不存在),实际截图保存在 <project_root>/pic/。
日志中频繁出现"截图文件不存在: .../douyin/core/pic/screenshot.png"。

改为:
- 默认分支用 path_config.get_pic_dir() / get_screenshot_path()
- target 分支用 os.path.join(path_config.get_pic_dir(), target)

补 5 个回归测试覆盖:
- 源码不再含旧的 dirname-based 路径
- path_config 路径解析到 <project_root>/pic
- 截图缺失时 cut_pic 返回 False(重试 3 次后兜底)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-23 00:47:02 +08:00
CodexandClaude Opus 4.7 fb82213d53 refactor(underlying): 抽 _get_screenshot_direct 到 underlying_operations_pkg/screenshot_direct (2416 → 1930)
497 行的 ADB 截图实现(含 exec-out 主路径 + 多重兜底 + watchdog)整段抽到
underlying_operations_pkg/screenshot_direct.capture_screenshot_direct,
原方法保留 9 行 thin shim:

    def _get_screenshot_direct(self, device_id, path="pic"):
        from douyin.core.underlying_operations_pkg.screenshot_direct import (
            capture_screenshot_direct,
        )
        return capture_screenshot_direct(self, device_id, path)

净减 486 行。函数体过深的两层嵌套截图逻辑现在独立成模块,方便单独测试与改进。

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-22 22:55:34 +08:00
CodexandClaude Opus 4.7 ffd048ffa5 refactor(fudai): 抽 run_once_basic 0.1 高价值预约检查到 helper (2079 → 1541)
新增 5 个 helper 到 run_once_basic_helpers.py:
- handle_reservation_check          0.1 预约检查主入口
- _maybe_clear_reservations_on_first_run  首次运行清空队列 + 状态文件
- _log_reservation_check_trigger    调试日志:检查触发条件
- _run_reservation_attend_window    队列满处理 / 抢占逻辑
- _log_reservation_attend_check     调试日志:第一个预约信息

净减 538 行重复嵌套样板。新增 7 个单元测试覆盖:
- 高价值未启用 / 队列空 → return False
- 首次运行清空队列
- 正常路径调 process_reservation_attend_window
- 队列满 → return True
- needswitch=False 走单间模式 + cleanup
- 等待开奖标志不阻断流程

至此 run_once_basic 总长 612 → 88 行(-86%),douyin_fudai.py
累计 4121 → 1541(-2580 行 / -63%),不再是项目最大文件。

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-22 22:45:51 +08:00