Codex and Claude 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
Codex and Claude 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
Codex and Claude Sonnet 4.5
96fdc96f24
refactor(cleanup): 移除剩余死代码模块
...
- 删除 douyin/utils/douyin_text_utils.py 及其测试
- 移除 performance_tracker.py 中未使用的 track_function 方法
- 移除 param_usage_tracer.py 中未使用的 stop_tracing / is_enabled
- 清理 bin/run_cli.py 和 tests/test_imports.py 中的残留引用
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com >
2026-05-23 21:58:41 +08:00
Codex and Claude Sonnet 4.5
c4544489ac
refactor(coords): 提取点击坐标常量,消除硬编码
...
在 coords.py 添加 DETAIL_OUTSIDE_CLICK、PARTICIPATE_BTN_CLICK、
FANSCLUB_JOIN_CLICK、FANSCLUB_JOIN_FALLBACK_CLICK 常量,
替换 fudai_attend/fansclub_handler/join_decision 中的硬编码坐标。
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com >
2026-05-23 21:20:17 +08:00
Codex and Claude Sonnet 4.5
d19d5bfc56
refactor(cleanup): 移除 logging 模块死代码
...
- unified_logger.py: 删除 5 个从未使用的装饰器/函数
- internal_loggers.py: 删除 3 个未使用方法和工厂函数
- action_logger.py: 删除 3 个未使用方法
- log_formatter.py: 删除 6 个未使用格式化函数(保留 GUI 依赖的 4 个)
- 同步更新 __init__.py 和测试文件
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com >
2026-05-23 21:04:35 +08:00
Codex and Claude 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
Codex and Claude 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
Codex and Claude Sonnet 4.5
ca00258bf3
fix(code-quality): 修复 NameError 风险和死代码清理
...
- detect_by_template.py: 添加缺失的 os 和 path_config 导入
- join_decision.py: 添加缺失的 is_watch_task_fudai 导入
- read_once.py: 添加缺失的 Optional 类型导入
- fudai_detail_validator.py: 使用 extract_2digits 做更健壮的数字解析
- screenshot_manager: 移除未使用的导入和死代码
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com >
2026-05-23 20:22:52 +08:00
Codex and Claude Sonnet 4.5
e62314fa25
fix(import): 修复 fudai_attend 相对导入路径错误
...
join_decision.py 在 fudai_filter_pkg 子包内,用 .fudai_attend 会查找
fudai_filter_pkg.fudai_attend(不存在),实际模块在上层 core 包。
改为 ..fudai_attend。
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com >
2026-05-23 19:26:58 +08:00
Codex and Claude 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
Codex and Claude 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
Codex and Claude Sonnet 4.5
8fd38dd30b
fix(fudai): validator 内容检查正确尊重 disable 配置
...
当 config.json 中 fudai_disable_content_recognition=true 时,
跳过内容为空的检查。原实现在 except 块中丢失 disable_content
状态,导致配置生效时仍误判内容为空为验证失败。
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com >
2026-05-23 19:00:32 +08:00
Codex and Claude Sonnet 4.5
d850af2c44
fix(fudai): 验证器不再因内容为空而拒绝有效福袋
...
当奖品价值>0且倒计时合理时,内容为空是正常的(部分福袋无文字
内容),不应判定验证失败导致跳过参与。
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com >
2026-05-23 18:39:13 +08:00
Codex
842dd254e3
fix: correct import path for check_detail_height in detect_fudai_detail_page
...
The relative import from .douyin_detection was looking in the
douyin/detection/pixel/ package, but douyin_detection.py lives
at douyin/detection/douyin_detection.py. This caused every fudai
detail page detection to fail with detection_exception, making the
system always treat successful detail page opens as misclicks.
2026-05-23 17:05:43 +08:00
Codex and Claude Sonnet 4.5
6f38907119
fix(fudai/reservation): 修 3 处拆模块遗留 NameError
...
- douyin_fudai_core.py: get_fudai_contain 引用 TASK_LIST / PARTICIPATE_BUTTON
但只导入了 LIVE_ROOM_TITLE,运行时必触发 NameError
- douyin_reservation_verify.py: match_reservation 末尾日志引用
current_title,但该变量仅在 if expected_title 块内赋值,
expected_title 为空时 NameError(被 try/except 吞掉但丢失日志)
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com >
2026-05-23 13:28:54 +08:00
Codex and Claude 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
Codex and Claude 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
Codex and Claude 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
Codex and Claude 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
Codex and Claude Opus 4.7
e737002b1e
refactor(stage): 抽 "不在直播间" OCR 检测分支到 ocr_detection (1245 → 807)
...
diagnose_stage_from_current_screen L336-774 是 438 行 "if not in_live_room:"
分支:
- 步骤 2.5:购物红包 OCR 复查(像素命中红包背景时再用 OCR 二次确认)
- 步骤 3:OCR 推荐页/关注列表/直播列表标签栏(含两次精确确认子流程)
抽到 douyin_stage_handler_pkg/ocr_detection.py:
- detect_pages_via_ocr(...) 入口,内部化 in_live_room 检查
- _check_redpacket_ocr_when_not_in_live_room 步骤 2.5
- _confirm_follow_list 关注列表精确截图 + OCR 模式 0/1
- _confirm_live_list 直播列表精确截图 + OCR 模式 0/1
返回 Optional[Tuple[str, str]]:
- ("RECOMMEND_PAGE"/"FOLLOW_LIST"/"LIVE_LIST"/"SHOPPING_REDPACKET_POPUP"
/"IN_LIVE_ROOM", reason) → caller 立即 return
- None → in_live_room=True,caller 继续后续逻辑
主函数对应位置替换为 17 行委托,_log/_log_summary/_log_separator 通过
参数传入,保持日志格式完全一致。
1361 passed.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com >
2026-05-23 02:59:02 +08:00
Codex and Claude Opus 4.7
df273ab231
refactor(stage): 抽 OCR 弹窗确认段到 popup_verification (1385 → 1230)
...
diagnose_stage_from_current_screen L1203-1358 是 156 行"未命中任何阶段
但像素检测到弹窗背景"段,用 OCR 二次确认避免直播间背景色误判:
- 优惠券弹窗:OCR "参与按钮" 区域找"开心收下"(支持模式 0+1 并行)
- 购物红包弹窗:OCR "診斷購物紅包" 区域找"购物红包/邀你抢/抢红包"
抽到 douyin_stage_handler_pkg/popup_verification.py:
- verify_popup_via_ocr(...) 入口,返回 Optional[Tuple[str, str]]
- ("COUPON_POPUP", reason) / ("SHOPPING_REDPACKET_POPUP", reason)
→ caller 立即 return 该元组
- None → 没有可疑弹窗或 OCR 确认失败,caller 继续后续逻辑
主函数对应位置替换为 17 行委托,保留原 _log / _log_summary 嵌套闭包通过参数传入,
保持日志格式完全一致。
1361 passed.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com >
2026-05-23 02:54:00 +08:00
Codex and Claude Opus 4.7
d60b83af68
refactor(reservation): 抽回退校验+二次回退到 attend_window_verify (1437 → 898)
...
attend_window.process_reservation_attend_window 中 L754-1293 是 540 行
"if ok:"分支:回退操作成功后等待直播间加载 → 调
douyin_reservation_verify.validate_back_to_reservation 校验 → 校验失败时
通过映射表重定位 + 二次回退。
抽到 reservation_logic/attend_window_verify.py:
- handle_back_verify(...) 入口,返回 Optional[bool]
- True/False → 主函数应立即返回该值
- None → 校验通过/禁用/异常,主函数继续设置锁定期
- _handle_verify_failure: 校验失败的处理流程
- _remap_target_via_room_titles: 映射表重定位(target + 当前直播间位置)
- _retry_seek_with_mapped_diff: 根据 mapped_pos_diff 决定是否二次回退
- diff=0 + room_pos_before_map 不一致 → 设置 _seek_direction_hint 重试
- diff=0 + 一致 → 跳过二次回退
主函数对应位置替换为 14 行委托。
1361 passed.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com >
2026-05-23 02:49:37 +08:00
Codex and Claude 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
Codex and Claude 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
Codex and Claude Opus 4.7
b200002a00
refactor(finder): 抽 OpenCV 模板匹配兜底到 finder_template_match (635 → 417)
...
check_have_fudai_with_ready_screenshot L288-513 是像素检测都失败时的最后
兜底(226 行):cv2.matchTemplate(TM_CCOEFF_NORMED) + minMaxLoc 在
156..269 × 351..451 搜索区域里找 fudai.png 模板。
抽到 douyin/detection/detection_pkg/finder_template_match.py:
- match_template(analyser, pic_new, rx, ry, y_pianyi_val, loop) → (det, x)
- _resolve_template_path 从 path_config / 项目根 assets 解析模板路径
(兜底走 .. 回退,避免推到 detection_pkg/assets)
- _save_search_roi 提取 last_match.png 的保存逻辑
主 finder.py 替换为 7 行委托,从 635 → 417 行。
新增 9 个单元测试覆盖:
- _resolve_template_path:用 path_config / 兜底
- 早出条件:模板路径不存在 / cv2.imread 返回 None / 搜索区域无效
- 命中:max_val>=threshold 时 detected_x 是 1080 基准
- 不命中:max_val<threshold 时返回 False
- 模板太大:cv2.resize 被调用
- cv2 不可用时安全返回 False
1345 passed (+9)。
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com >
2026-05-23 02:26:49 +08:00
Codex and Claude Opus 4.7
ab846dae0f
refactor(finder): 抽逐像素兜底扫描到 finder_pixel_scan (817 → 635)
...
check_have_fudai_with_ready_screenshot L279-461 是 numpy 失败时的逐像素
兜底(183 行):optimal_x 从历史 / 默认热区中心选起 → 检查 5 个 y 偏移
(0/±1/±2)→ 每行从 optimal 向两侧交替搜索 → 最后从左到右兜底。
抽到 douyin/detection/detection_pkg/finder_pixel_scan.py:
- scan_pixel_by_pixel(analyser, pic_new, rx, ry, y_pianyi_val) → (detected, x)
- _is_target_pixel / _safe_check_pixel / _pick_optimal_x / _search_along_y
4 个独立纯函数,每个职责单一
颜色范围常量与 finder_numpy_scan 对齐(_R_MIN/_MAX 等)。
主 finder.py 替换为 8 行委托。
新增 15 个单元测试覆盖:
- _is_target_pixel 边界 / _safe_check_pixel 异常兜底
- _pick_optimal_x 历史命中/越界/无历史 3 种路径
- scan_pixel_by_pixel 主路径成功 / y 偏移 / 越界失败 / pic 异常兜底
1336 passed (+15)。
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com >
2026-05-23 02:20:25 +08:00
Codex and Claude Opus 4.7
07cdd662c2
refactor(finder): 抽 numpy 加速扫描段到 finder_numpy_scan (937 → 811)
...
check_have_fudai_with_ready_screenshot L271-397 是"numpy 加速水平带扫描"
逻辑(126 行):ROI 裁剪 → RGB 颜色掩码 → 列聚合 → 从最优起始列向两侧
交替搜索第一个匹配列 → 写回 last_fudai_x。
抽到 douyin/detection/detection_pkg/finder_numpy_scan.py:
- scan_with_numpy(analyser, pic_new, rx, ry, y_pianyi_val, optimal_x_scaled)
→ (detected, detected_x)
- numpy ImportError / 异常时返回 (False, None),让 caller 走逐像素兜底
主 finder.py 替换为 7 行委托。
新增 8 个单元测试(用真实 PIL.Image + numpy 构造小图):
- 空图返回 False
- 整图目标色命中 + last_fudai_x 写回
- 仅在某段列有目标色,命中位置在该段
- y_pianyi_val 偏移正确传递到扫描带
- ROI 越界返回 False
- optimal_x_scaled 在命中区时优先返回该位置
1321 passed (+8)。
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com >
2026-05-23 02:15:43 +08:00
Codex and Claude Opus 4.7
1514122981
chore(finder): 删 check_have_fudai_with_ready_screenshot 末尾 501 行死代码 (1438 → 937)
...
L938-1438 全部位于 L936 `return False` 之后,永远不会执行:
- 旧版重复参数初始化(retry_delay_s / max_wait_s 等)
- 已被弃用的模板匹配兜底代码块
- 末尾的"以下为旧的像素检测代码"注释块
文件大小直接砍 35%,无任何行为变化。
1313 passed.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com >
2026-05-23 02:09:36 +08:00
Codex and Claude Opus 4.7
f718dfe2e4
refactor(fudai_attend): 抽 1057 行粉丝团门槛分支到 fansclub_handler (1629 → 573)
...
attend_choujiang 中"加入粉丝团/粉丝团"按钮分支占 1057 行,含一个 751 行的
内嵌闭包 _recover_to_fudai_detail_after_fansclub 处理"加入页"恢复。该分支
是文件中最大的单一逻辑块,独立性高(没有共享主流程的局部变量,全靠 analyser
属性传递状态)。
新建 fudai_attend_pkg/fansclub_handler.py(1070 行)作为整段抽出后的目的地。
导出顶层函数 handle_fansclub_branch(analyser, attend_button_text) -> bool。
attend_choujiang 中原 elif 块替换为 4 行委托:
elif attend_button_text and (
"加入粉丝团" in attend_button_text or "粉丝团" in attend_button_text
):
return handle_fansclub_branch(analyser, attend_button_text)
行为完全保留:
- 设置 analyser.last_attend_fail_reason = "fansclub_required"
- 第一步点参与按钮 (543, 2070)
- 第二步 OCR 找加入粉丝团按钮 + bbox 中心点击(fallback 区域中心)
- 第三步关闭详情页 (500, 470)
- 第四步根据 auto_join_fansclub 等待
- 第五步 _recover_to_fudai_detail_after_fansclub 在加入页再点击 + 返回直播间
新增 9 个单元测试覆盖:
- 总返回 True
- 设置 fail_reason = "fansclub_required"
- 必经的两次坐标点击 (543,2070) / (500,470)
- 截图缺失/OCR 抛异常时的兜底
- auto_join 启用/禁用分支
1313 passed (+9)。
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com >
2026-05-23 02:05:38 +08:00
Codex and Claude Opus 4.7
2f0eb90d98
refactor(fudai_core): 抽 6 个 fallback OCR 闭包到 OcrTaskRunnerFallback (1350 → 1194)
...
主并行 OCR 失败时走的备用路径里有 6 个 ocr_*_fallback 闭包,结构与
OcrTaskRunner 类似但更简单(不计耗时、countdown 不做数字提取、日志
tag 改为"备用OCR..."),共 156 行。
复用 ocr_tasks.py 模块新增 OcrTaskRunnerFallback 类,与 OcrTaskRunner
共享 _safe_preprocess / _BUTTON_KEYWORDS / _read_disable_flag。
主流程 6 个闭包定义换成 14 行 runner 实例化 + 方法绑定。
新增 10 个单元测试覆盖 Fallback 的所有方法(disable 跳过 / 异常 /
countdown 不提取数字 / button 关键词短路 + retry)。
1304 passed (+10)。
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com >
2026-05-23 01:58:13 +08:00
Codex and Claude Opus 4.7
f38b373636
refactor(fudai_core): 抽 7 个并行 OCR 闭包到 ocr_tasks 模块 (1659 → 1328)
...
get_fudai_contain L222-553 有 7 个 ocr_* 闭包:task_list / content /
countdown_mm / countdown_ss / value / button / live_room_title。每个都遵循
同样的模板(计时 + analyse_pic_word/digits + perf 字典 + 异常日志),共 330 行。
抽到 douyin_fudai_core_pkg/ocr_tasks.py 的 OcrTaskRunner 类:
- 7 个方法对应 7 个并行任务
- 共享耗时 dict + lock 在构造器传入
- _record_duration / _log_warn 提取出共有的 finally + except 模板
- _BUTTON_KEYWORDS 关键词常量化(原本是闭包里硬编码 tuple)
- _safe_preprocess 顶层 helper
主流程从 7 个闭包定义 + 配置开关重复读取(330 行)变成 22 行 runner 实例化 +
方法绑定,并保留 ocr_task_list / ocr_content / ... 名字给后续 executor.submit
当作 Callable 传入,行为完全不变。
新增 22 个单元测试覆盖:
- _safe_preprocess 兜底
- 7 个方法的成功 / disable 跳过 / 异常 / 边界
- ocr_button 关键词短路 + 重试逻辑
- 所有方法都正确记录耗时到 perf_durations
1294 passed (+22)。
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com >
2026-05-23 01:52:22 +08:00
Codex and Claude Opus 4.7
457edcfdc8
refactor(fudai_core): 合并 4 个 renwu 分支截图准备到 cut_regions (1825 → 1651)
...
get_fudai_contain L160-334 按 renwu (1/2/3/其他) 重复 4 次相似的 175 行
分支,每个分支都做"内容/倒计时(切两段)/价值"4 次 cut_pic + 可选调试截图,
唯一差异只是 countdown_box 常量。
抽到 douyin_fudai_core_pkg/cut_regions.py:
- _select_countdown_box(renwu) 选坐标
- cut_detail_regions(analyser, renwu, save_debug_images) 统一切割
原 175 行 4 个重复分支替换为 8 行调用,净减 167 行。
新增 12 个单元测试覆盖:
- _select_countdown_box 4 种 renwu
- cut_detail_regions 调 cut_pic 4 次 / 名称顺序 / 30%-30% 分割比例
- save_debug_images 开关效果
1272 passed (+12)。
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com >
2026-05-23 01:47:36 +08:00
Codex and Claude Opus 4.7
03b471513d
refactor(fudai_core): 抽 _run_heavy_ocr 闭包到 heavy_ocr 模块 (1953 → 1822)
...
_run_heavy_ocr 是 get_fudai_contain 中的 142 行闭包,按需对 6 个字段
(task_list / content / countdown_mm / countdown_ss / value / button)
跑较重的 OCR 模型补齐轻量 OCR 漏掉的字段。
抽到 douyin_fudai_core_pkg/heavy_ocr.py:
- run_heavy_ocr(analyser, fields) 顶层主函数
- _read_disable_flag(analyser, attr, cfg_key) 提取重复的 attr→config.json
fallback 配置开关读取(原闭包里 task_list 和 content 各重复一次)
- _ocr_digits_with_fallback(analyser, picname) 提取 mm/ss 分支共有的
digits→word 兜底数字提取逻辑
原闭包改为 4 行委托。配置开关、日志和异常兜底行为完全一致。
新增 18 个单元测试覆盖:
- _read_disable_flag 4 种状态(attr 优先 / config 兜底 / 都缺 / 文件不存在)
- _ocr_digits_with_fallback 5 个分支
- run_heavy_ocr 9 个字段组合 + disable 跳过路径
1260 passed (+18)。
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com >
2026-05-23 01:39:24 +08:00
Codex and Claude Opus 4.7
2707773b15
refactor(fudai_core): 抽 _read_countdown_split 闭包到 countdown_split 模块 (2124 → 1953)
...
douyin_fudai_core.py 的 get_fudai_contain 函数体只有 1 个,但里面嵌了
多个闭包做 OCR 子任务。最大的 _read_countdown_split (172 行) 把倒计时
区域分割成"分钟"+"秒"两段分别识别再组合 mm:ss。
抽到 douyin_fudai_core_pkg/countdown_split.py 的 read_countdown_split
顶层函数(203 行,含独立的 _extract_digits 纯函数)。原闭包改为薄壳委托,
保留 box 默认绑定 analyser/save_debug_images 闭包变量的语义。
新增 16 个单元测试覆盖:
- _extract_digits 纯函数(前导零 / 非数字 / 边界)
- read_countdown_split 主路径 + OCR 失败 + 秒>=60 警告 + 切图失败
- 切割比例(30% / 30%)正确性
- save_debug_images 开关效果
1242 passed (+16)。
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com >
2026-05-23 01:30:35 +08:00
Codex and Claude 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
Codex and Claude 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
Codex and Claude 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
Codex and Claude 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
Codex and Claude Opus 4.7
61cdf7b445
refactor(fudai): 抽 _handle_in_fudai_detail 步骤1 第二次打开分支 (2216 → 2079)
...
新增 handle_second_open_branch helper:
- 取 _last_fudai_detail_tuple;缺失/无效则重新读取(兜底)
- 有效缓存:从 countdown_tuple 提取 future_ts/原始秒数 + 设到 self
- 调 attend_choujiang:成功清标志 / 失败累加计数 / 异常 fall through
顺手修了一个 latent bug:first-open 抽出后 caller 还在用 step3_start /
skip / skip_reason 这些已不在作用域里的变量。改成从 self._last_fudai_detail_tuple
重新取 detail,去掉无意义的 step3_elapsed 日志,step4 的 skip 参数
直接传 (False, "") —— skip 已在 first-open 内部处理完。
净减 146 行嵌套样板。新增 6 个 second-open 单元测试覆盖:
- 缓存缺失重读 + fall through
- 短 tuple 触发重读
- attend 成功清标志清失败计数
- attend 失败累加计数
- attend 异常 fall through
- 缓存有效时正确设置 _current_fudai_future_ts
至此 _handle_in_fudai_detail 总长 506 → 215 行(-58%),
douyin_fudai.py 累计 4121 → 2079(-2042 行 / -50%)。
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com >
2026-05-22 22:18:33 +08:00
Codex and Claude Opus 4.7
ca953cb4ba
refactor(fudai): 抽 _handle_in_fudai_detail 步骤2+3 第一次打开分支 (2568 → 2216)
...
新增 5 个 helper 到 handle_detail_helpers.py:
- handle_first_open_branch 第一次打开主入口
- _validate_first_open_detail 数据验证失败处理
- _check_skip_and_handle 筛选检查 + 高价值预约 + 切房
- _try_high_value_reservation 高价值倒计时阈值判断(return/continue/still_skip)
- _handle_skip_filter 普通筛选不通过:关详情 + 切房
- _fallback_swipe_up swipe_up_to_next_live 不存在时的兜底
净减 354 行嵌套样板代码。新增 8 个单元测试覆盖:
- detail 无效 / 短 tuple
- 数据验证失败
- 筛选通过保存数据
- 普通筛选不通过 + needswitch true/false
- 高价值阈值内立即参与
- 高价值阈值外记预约
至此 _handle_in_fudai_detail 总长 1010 → 506 行(-50%),
douyin_fudai.py 累计 4121 → 2216(-1905 行 / -46%)。
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com >
2026-05-22 22:00:24 +08:00
Codex and Claude Opus 4.7
aeb51f73c7
chore(fudai): 清理 _handle_in_fudai_detail 死代码 + 4 处重复 cleanup
...
- 1 处 dead code:is_second_open 重复赋值(同一变量连读两次)
- 4 处内联"清除任务数量标志 + 嵌套 try"块用 _hd_helpers._clear_task_count_flag 替换
净减 50 行重复样板,2614 → 2568 行。
全套 1172 个测试通过。
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com >
2026-05-22 21:35:38 +08:00
Codex and Claude Opus 4.7
0540610c75
refactor(fudai): 抽 _handle_in_fudai_detail last_status 检查到 helper (2872 → 2614)
...
新增 3 个 helper:
- check_last_status_branch:根据 _last_fudai_detail_status 路由 4 个状态
(coupon_popup / watch_task / validation_failed / error)
- _clear_task_count_flag:清除 _fudai_detail_task_count_from_stage(多分支共用)
- _handle_error_status:error + reason=task_count_zero 时连续 3 次切直播间
净减 260 行重复样板代码。新增 9 个单元测试覆盖:
- 4 种已知 status 各自分支
- 未知/空 status 不触发
- task_count_zero 第 1 次仅累计、第 3 次强制切房 / needswitch=False 不切
至此 _handle_in_fudai_detail 总长 1010 → 752 行,
douyin_fudai.py 累计 4121 → 2614(-1507 行 / -37%)。
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com >
2026-05-22 21:23:26 +08:00
Codex and Claude Opus 4.7
7b6dec820b
refactor(fudai): 抽 _handle_in_fudai_detail 步骤3末尾两个小段 (2926 → 2872)
...
新增 2 个 helper:
- check_invalid_detail_fallback:兜底检查(content="" + value=0 → 视为无效详情)
- prepare_for_attend:记 attend_before_ts + 提取 future_ts + 重置 _detail_closed_by_attend
净减 54 行重复样板代码。新增 9 个单元测试覆盖:
- 空内容+0价值识别为无效
- 正常内容不触发兜底
- detail tuple 短或非 tuple 不抛
- prepare_for_attend 正确返回 attend_before_ts 和写入 future_ts
至此 _handle_in_fudai_detail 总长 1872 → 1010 行(-862 行 / -46%),
douyin_fudai.py 4121 → 2872(累计 -1249 行 / -30%)。
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com >
2026-05-22 21:16:06 +08:00
Codex and Claude Opus 4.7
8a975f2bf6
refactor(fudai): 抽 _handle_in_fudai_detail 步骤4 到 handle_detail_helpers (3174 → 2926)
...
新增 3 个 helper:
- step4_make_join_decision:参与决策入口(detail=None 短路 + 调 basic_join_decision)
- _handle_reservation_completion:参与成功是预约福袋时的锁定期处理 + 队列清理
- _close_detail_after_attend:根据 _detail_closed_by_attend 决定是否点 click_back
净减 251 行重复代码。新增 7 个 step4 单元测试覆盖:
- detail=None 短路
- join_decision 失败不设标志
- countdown 有效设标志 + 关详情
- attend 已关详情时跳过 click_back
- 预约福袋无其他预约 → 清锁定期
- 预约福袋有其他预约 → 设保护期
- countdown 已过期不设标志
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com >
2026-05-22 21:09:24 +08:00
Codex and Claude Opus 4.7
a92cec4ff9
refactor(recovery): 抽 3 处桌面自救重复逻辑到 douyin/core/recovery 共享模块
...
新增 douyin/core/recovery.py(113 行):
- is_douyin_foreground(top_pkg): 统一判断前台是否抖音相关包
- recover_to_douyin(analyser, log=...): 桌面自救主入口(先 launch_package,失败回退点击)
- fallback_click_recovery(analyser, log=...): 旧的点击坐标自救兜底
3 处调用点收敛:
- fudai_modules/run_once_basic_helpers.handle_desktop_recovery:80 行 → 18 行
- douyin/other/douyin_yanghao.py: 3 段重复块(原 ~80 行 each)→ 单行调用
总计净减 -269 行重复代码。新增 13 个 recovery 单元测试 + 修测试 mock。
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com >
2026-05-22 19:20:29 +08:00
Codex and Claude Opus 4.7
4c1d95d4b5
feat(recovery): 桌面自救改用包名启动抖音,点击坐标降为兜底
...
当检测到不在抖音前台时,原先点击桌面图标 + 直播 + 进入直播间 3 步坐标的方式
依赖图标位置和分辨率,不同设备/桌面常常失败。改为优先调用 ADB 包名启动:
- underlying_operations 新增 launch_package(device_id, pkg):
monkey -p <pkg> -c android.intent.category.LAUNCHER 1(主路径)
失败回退到 am start -n <pkg>/<MainActivity>(多个常见 activity 兜底)
默认按 com.ss.android.ugc.aweme / .lite / TikTok 顺序尝试
- 新增 is_douyin_foreground 便捷方法
- 改造 3 处自救点:
fudai_modules/run_once_basic_helpers.py:handle_desktop_recovery
douyin/other/douyin_yanghao.py(养号循环 + _yanghao_check_and_recover_from_desktop ×2)
包名启动失败时仍走旧的点击逻辑作为兜底,向后兼容
新增 12 个单元测试覆盖 launch_package 主路径/兜底/失败和自救新行为。
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com >
2026-05-22 19:08:09 +08:00
Codex and Claude Opus 4.7
3aca02fae4
refactor(fudai): 抽 run_once_basic 2 段独立逻辑到 run_once_basic_helpers (3233 → 3174)
...
新增 2 个 helper:
- handle_just_recorded_reservation:刚记录预约后强制切换直播间
- handle_skip_stage_diagnosis:0.5 跳过阶段检测分支
新增 5 个单元测试。行为保持不变。
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com >
2026-05-22 18:37:18 +08:00
Codex and Claude Opus 4.7
695a84d8b5
refactor(fudai): 抽 _handle_in_fudai_detail 入口检查到 handle_detail_helpers (3294 → 3233)
...
抽出 2 个独立函数到 fudai_modules/handle_detail_helpers.py:
- log_entry_flags:进入方法时记录关键 flags
- handle_consecutive_failures_check:连续参与失败次数检查
新增 5 个单元测试覆盖阈值、needswitch 分支。行为保持不变。
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com >
2026-05-22 18:31:43 +08:00
Codex and Claude Opus 4.7
5802586b20
refactor(fudai): 拆 run_once_basic 6 段独立逻辑到 run_once_basic_helpers (4121 → 3294)
...
抽出 6 个独立函数到 fudai_modules/run_once_basic_helpers.py:
- handle_waiting_for_lottery_result:等待开奖期间持续 OCR 检测
- handle_no_attend_timeout:30 分钟未参与回到推荐页
- handle_desktop_recovery:桌面检测自救
- screenshot_and_diagnose:截图 + 阶段诊断
- handle_high_value_room_revisit:高价值房间重访
- dispatch_stage_branch:弹窗/详情/直播间/推荐页/开奖结果分发
新增 15 个单元测试覆盖各分支。run_once_basic 体积大幅瘦身但行为保持不变。
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com >
2026-05-22 18:22:17 +08:00
Codex and Claude Opus 4.7
af8145b8a8
补 fudai_filter_pkg / logging_pkg 单元测试 + 修 monitor 缺 datetime import
...
新增测试:
- test_fudai_filter_pkg (24)
覆盖 helpers / should_skip / join_decision 三个子模块
含 _is_short_countdown_text / is_watch_task_fudai / check_contain
+ should_skip_fudai_by_config 5 个业务场景断言(高价值通过 / 观看任务跳过 /
低价值跳过 / 黑名单跳过 / 单间模式必参)
- test_logging_pkg (22)
覆盖 _common 全局状态 + handlers 类构造 + cleanup 纯函数边界 + monitor
类构造 + config 全部对外 API(get_logger 缓存 / get_caller_info /
format_exception_info / LogContext / log_function_call 装饰器)
修复 1 个真实回归 bug:
- douyin/logging/douyin_logging_pkg/monitor.py 缺 from datetime import datetime
(原文件用的是 from datetime import datetime, timedelta;拆分时只写了
import 模块导致 datetime.now() 抛 NameError)
修复后 LogRotationMonitor 可正常构造
回归:
- 全套 581 → 627 (+46 用例)
- 全部 627 passed in 22s
- compileall exit 0
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com >
2026-05-21 21:01:15 +08:00