refactor: split large modules and harden live-room fudai flow
This commit is contained in:
1 parent
1845561405
commit
36e374ef67
86 files changed
+7422
-8404
No files matched your search
@@ -0,0 +1,89 @@
|
||||
# 2026-06-01 大文件继续拆分计划(续)
|
||||
|
||||
## 当前状态(更新于本轮)
|
||||
|
||||
- 已完成:
|
||||
- `gui/web_gui.py` 路由壳化,主体路由下沉到 `gui/web_gui_pkg/routes.py`
|
||||
- `douyin/core/fudai_modules/run_once_basic_helpers.py` 中预约检查与状态写盘逻辑下沉到 `run_once_basic_reservation.py`
|
||||
- `douyin/core/douyin_fudai.py` 中 `_handle_in_fudai_detail` / `_handle_live_room_has_or_not_fudai` 下沉到 `fudai_modules/live_room_handlers.py`
|
||||
- `douyin/core/underlying_operations.py` 中 `get_screenshot` 下沉到 `underlying_operations_pkg/screenshot_pipeline.py`
|
||||
- `douyin/fudai/douyin_fudai_core_legacy.py` 壳化完成,核心实现转移到 `douyin/fudai/douyin_fudai_contain_impl.py`
|
||||
- `douyin/fudai/douyin_fudai_contain_impl.py` 内部 helper 下沉到 `douyin/fudai/douyin_fudai_core_pkg/contain_helpers.py`(轻重 OCR 分流判定、参与人数提取等)
|
||||
- `douyin/fudai/douyin_fudai_contain_impl.py` 主并行/备用并行共用的按钮状态判定与回写逻辑下沉到 `douyin/fudai/douyin_fudai_core_pkg/button_state.py`
|
||||
- `douyin/fudai/douyin_fudai_contain_impl.py` 主并行/备用并行共用的并行任务提交与结果收集骨架下沉到 `douyin/fudai/douyin_fudai_core_pkg/parallel_exec.py`
|
||||
- `douyin/fudai/douyin_fudai_contain_impl.py` 主并行/备用并行共用的任务列表观看任务检测分支下沉到 `douyin/fudai/douyin_fudai_core_pkg/watch_task.py`
|
||||
- `douyin/fudai/douyin_fudai_contain_impl.py` 原始内容/清理后内容观看任务检测分支下沉到 `douyin/fudai/douyin_fudai_core_pkg/watch_task.py`
|
||||
- `douyin/fudai/douyin_fudai_contain_impl.py` 倒计时数字提取与校验分支下沉到 `douyin/fudai/douyin_fudai_core_pkg/countdown_parse.py`
|
||||
- `douyin/core/douyin_fudai.py` 的 `_capture_roi_screenshot` 与 `_match_icon_template` 下沉到 `douyin/handlers/douyin_screenshot_handler.py`
|
||||
- `douyin/core/douyin_fudai.py` 的 `fudai_choujiang` 运行循环(定时/无限模式 + 结束日志)下沉到 `douyin/core/fudai_modules/fudai_run_loop.py`
|
||||
- `douyin/core/douyin_fudai.py` 的 `run_once_basic` 前置段(启动日志/养号触发/标题记录)下沉到 `run_once_basic_helpers.run_once_basic_prelude`
|
||||
- `douyin/core/douyin_fudai.py` 的 `run_once_basic` 预约后阶段处理段下沉到 `run_once_basic_helpers.run_once_basic_post_reservation`
|
||||
- `douyin/core/underlying_operations.py` 的输入法/文本输入链路下沉到 `douyin/core/underlying_operations_pkg/text_input.py`(`input_text` / `paste_text_at` / ADBKeyboard 广播与 IME 切换等),主类保留薄转发
|
||||
- `douyin/core/fudai_modules/run_once_basic_helpers.py` 的阶段链路下沉到 `douyin/core/fudai_modules/run_once_basic_stage.py`(`screenshot_and_diagnose` / `handle_desktop_recovery` / `handle_high_value_room_revisit`),主 helper 保留薄转发
|
||||
- `douyin/core/fudai_modules/run_once_basic_helpers.py` 的粉丝团处理段下沉到 `douyin/core/fudai_modules/run_once_basic_fansclub.py`(`_handle_fansclub_join`),主 helper 保留薄转发
|
||||
- `douyin/core/fudai_modules/handle_detail_helpers.py` 的筛选与高价值预约段下沉到 `douyin/core/fudai_modules/handle_detail_filter.py`(`_check_skip_and_handle` / `_try_high_value_reservation` / `_handle_skip_filter` / `_fallback_swipe_up`),主 helper 保留薄转发
|
||||
- `douyin/core/fudai_modules/handle_detail_helpers.py` 的首开详情分支下沉到 `douyin/core/fudai_modules/handle_detail_first_open.py`(`handle_first_open_branch` / `_validate_first_open_detail`),主 helper 保留薄转发
|
||||
- `douyin/core/fudai_modules/handle_detail_helpers.py` 的二次打开与预约完成收尾下沉到 `douyin/core/fudai_modules/handle_detail_second_open.py`(`handle_second_open_branch` / `_handle_reservation_completion`),主 helper 保留薄转发
|
||||
- `douyin/stage/douyin_stage.py` 的步骤0并行像素检测下沉到 `douyin/stage/douyin_stage_handler_pkg/pixel_parallel.py`(`run_parallel_pixel_detection`),主诊断流程保留汇总与分支调度
|
||||
- `douyin/stage/douyin_stage.py` 的弹窗OCR兜底与最终阶段收尾下沉到 `douyin/stage/douyin_stage_handler_pkg/finalize_stage.py`(`finalize_stage_after_pixel`),主诊断流程保留前序分支与统一调用
|
||||
- `douyin/stage/douyin_stage.py` 的“邀你抢红包”OCR检测段下沉到 `douyin/stage/douyin_stage_handler_pkg/ocr_redpacket.py`(`detect_invite_redpacket_via_ocr`),主诊断流程保留统一调用与返回分发
|
||||
- `douyin/core/underlying_operations.py` 的 UIAutomator 交互段下沉到 `douyin/core/underlying_operations_pkg/ui_automator.py`(`_uiautomator_dump` / `tap_by_text` / `tap_close_icon`),主类保留薄转发
|
||||
- `douyin/core/underlying_operations.py` 的前台包检测与应用拉起链路下沉到 `douyin/core/underlying_operations_pkg/foreground.py`(`get_top_package` / `launch_package` / `is_douyin_foreground`),主类保留薄转发
|
||||
- `gui/web_gui.py` 的 ProcRunner 状态读取与测试入口段下沉到 `gui/web_gui_pkg/proc_runner_ops.py`(`get_reservations` / `get_high_value_rooms` / `send_back_key` / `start_test_yanghao` / `start_test_comment`),主类保留薄转发
|
||||
- `gui/web_gui.py` 的 ProcRunner 统计聚合段下沉到 `gui/web_gui_pkg/proc_runner_stats.py`(`get_stats`),主类保留薄转发
|
||||
- `webui/css/components.css` 的 Overlay/Toast 样式拆分到 `webui/css/components_overlays.css` 与 `webui/css/components_toast.css`,并在 `webui/index.html` 追加模块化样式引用,主 `components.css` 保留其余组件样式
|
||||
- `webui/index.html` 的监控/预约/日志面板与页脚区块下沉到 `webui/js/panel_templates.js`,页面改为挂载点注入(保留原 DOM id/class),主 `index.html` 继续瘦身
|
||||
- `webui/index.html` 的头部命令条与状态概览区块下沉到 `webui/js/top_templates.js`,页面改为挂载点注入(保留原 DOM id/class),主 `index.html` 继续瘦身
|
||||
- `douyin/reservation/reservation_logic/attend_window.py` 的“已参与过滤/无效时间过滤/动态提前量计算/目标快照日志”下沉到 `douyin/reservation/reservation_logic/attend_window_helpers.py`,主流程保留编排与分支顺序
|
||||
- `webui/js/runtime_actions.js` 的设备动作与测试动作下沉到 `webui/js/runtime_device_actions.js`(`selectedDeviceId` / `postDeviceAction` / `wifi*` / `forceStopRun` / `testYanghao` / `testComment`),`index.html` 已补充脚本加载顺序
|
||||
- `douyin/stage/douyin_stage_handler_pkg/check_live.py` 的分数选择策略与结果日志汇总下沉到 `douyin/stage/douyin_stage_handler_pkg/check_live_score.py`,主流程保留模板匹配编排
|
||||
- `gui/components/config_io.py` 的文本域读写与 debug/logging 配置映射下沉到 `gui/components/config_io_helpers.py`,主流程保留编排与配置字段回写顺序
|
||||
- `douyin/handlers/screenshot_manager/save_image.py` 的调试保存开关读取、保存重试机制、标注绘制逻辑下沉到 `douyin/handlers/screenshot_manager/save_image_helpers.py`(`is_debug_captures_enabled` / `save_image_with_retry` / `annotate_debug_image`),主入口保留编排与异常处理
|
||||
- `tools/coords/region_selector.py` 的菜单构建、快捷键绑定、画布事件绑定与拖放注册下沉到 `tools/coords/region_selector_ui.py`(`setup_menu` / `bind_canvas_events` / `setup_dnd`),主类保留业务状态与事件处理
|
||||
- `douyin/fudai/douyin_fudai_contain_impl.py` 的后处理聚合逻辑下沉到 `douyin/fudai/douyin_fudai_core_pkg/contain_postprocess.py`(进房耗时日志、价值OCR校验、标题写回、房间映射落盘),主流程保留编排与返回值
|
||||
- `gui/gui_core_pkg/stats_log_parser.py` 的重复正则提取与数值转换下沉到 `gui/gui_core_pkg/stats_log_parser_helpers.py`(`search_group` / `search_group_any` / `parse_int_value` / `parse_float_value` / `set_meta_*_if_match`),主解析流程保留业务事件判定
|
||||
- `douyin/reservation/reservation_logic/attend_window.py` 的尾段日志逻辑下沉到 `attend_window_helpers.py`(`log_back_failed_keep_queue` / `log_attend_window_result`),主流程保留回退决策与状态编排
|
||||
- `webui/index.html` 的 `keywords + debug` 配置面板下沉到 `webui/js/config_panel_templates.js`,页面改为 `configPanelTemplatesMount` 挂载点注入并补充脚本加载顺序(保留原 id/data-key,行为兼容)
|
||||
- `tools/coords/simple_region_selector.py` 的菜单/快捷键/画布绑定下沉到 `tools/coords/simple_region_selector_ui.py`(`setup_menu_and_shortcuts` / `bind_canvas_events`),主类保留图像处理与多边形分析流程
|
||||
- 当前 Top 大文件(源码):
|
||||
1. `webui/index.html` 53.7KB(本轮从 71.0KB 降到 53.7KB,已低于 65KB 目标)
|
||||
2. `douyin/other/douyin_yanghao.py` 29.8KB
|
||||
3. `webui/css/components.css` 29.7KB
|
||||
4. `douyin/fudai/douyin_fudai_finder_pkg/detector.py` 29.4KB
|
||||
5. `douyin/core/douyin_fudai.py` 29.0KB
|
||||
6. `douyin/reservation/reservation_logic/attend_window.py` 28.8KB(已从 35.5KB 降到 28.8KB)
|
||||
7. `gui/web_gui_pkg/stats_log_parser.py` 28.7KB
|
||||
8. `douyin/stage/douyin_stage_handler_pkg/check_live.py` 28.6KB
|
||||
9. `gui/gui_core_pkg/stats_log_parser.py` 28.4KB(已从 30.3KB 降到 28.4KB)
|
||||
10. `webui/js/ui_init.js` 27.8KB
|
||||
11. `webui/js/runtime_actions.js` 27.1KB
|
||||
|
||||
## 下一轮拆分顺序(建议)
|
||||
|
||||
1. `douyin/fudai/douyin_fudai_finder_pkg/detector.py`
|
||||
- 抽离模板匹配与阈值/回退逻辑,降低单函数复杂度。
|
||||
2. `gui/web_gui_pkg/stats_log_parser.py`
|
||||
- 参照 gui_core 侧 helper 化,统一正则提取与类型转换入口。
|
||||
3. `douyin/reservation/reservation_logic/attend_window.py`
|
||||
- 继续抽离中段“锁定期判断 + 同预约分支”中的日志与状态更新子流程。
|
||||
4. `douyin/other/douyin_yanghao.py`
|
||||
- 抽离坐标/概率配置读取与动作执行分发,降低主流程长度与分支复杂度。
|
||||
5. `webui/js/ui_init.js`
|
||||
- 分离面板切换、搜索过滤与快捷键初始化,进一步降低单文件复杂度。
|
||||
|
||||
## 验证口径
|
||||
|
||||
- 每次拆分后必须执行:
|
||||
- `python -m py_compile <改动的py文件>`
|
||||
- 如本机 `pytest` 可用,再跑相关最小测试集
|
||||
- 由于当前 shell 环境缺少 pytest,测试日志需保留:
|
||||
- `logs/pytest_*.log`
|
||||
|
||||
## 硬编码治理并行策略
|
||||
|
||||
- 优先治理“环境迁移敏感”的硬编码:
|
||||
- host/port(已收敛到 `net_config`,继续排查其它入口)
|
||||
- 本地路径、固定命令、默认端口
|
||||
- 处理方式:
|
||||
- 新增集中配置读取函数
|
||||
- 原调用点只保留薄封装,避免每处单独拼环境变量
|
||||
+50
-154
@@ -1,201 +1,97 @@
|
||||
# 迁移部署指南(新电脑 + 手机端)
|
||||
# 迁移部署指南(简版)
|
||||
|
||||
本文用于把项目迁移到另一台 Windows 电脑,并完成手机端可运行配置。
|
||||
## 1. 电脑端(最少步骤)
|
||||
|
||||
## 1. 适用范围
|
||||
|
||||
- 项目根目录:`douyin_guaji-main`
|
||||
- 目标系统:Windows 10/11
|
||||
- Python:3.10 ~ 3.12(推荐 3.10)
|
||||
- 手机:Android 5.0+(无需 Root)
|
||||
|
||||
## 2. 迁移总览
|
||||
|
||||
1. 新电脑安装 Python、ADB 并拉取项目代码
|
||||
2. 创建虚拟环境并安装依赖
|
||||
3. (可选)从旧电脑迁移运行配置与状态文件
|
||||
4. 手机上开启开发者选项/USB 调试并完成 ADB 授权
|
||||
5. 首次启动 GUI 或 CLI 做连通性验证
|
||||
|
||||
---
|
||||
|
||||
## 3. 新电脑部署步骤
|
||||
|
||||
### 3.1 安装基础软件
|
||||
|
||||
1. 安装 Python(勾选 `Add Python to PATH`)
|
||||
2. 安装 ADB(Android platform-tools),确保命令行可执行:
|
||||
1. 安装 `Python 3.10+`
|
||||
2. 安装 `ADB`(platform-tools)并加入 PATH
|
||||
3. 拉代码:
|
||||
|
||||
```powershell
|
||||
python --version
|
||||
adb version
|
||||
```
|
||||
|
||||
### 3.2 获取项目
|
||||
|
||||
```powershell
|
||||
git clone <你的仓库地址>
|
||||
git clone https://git.simgreek.com/simgreek/douyi_guaji_main.git
|
||||
cd douyin_guaji-main
|
||||
```
|
||||
|
||||
### 3.3 创建虚拟环境并安装依赖
|
||||
4. 一键部署依赖:
|
||||
|
||||
```powershell
|
||||
python -m venv .venv
|
||||
.venv\Scripts\Activate.ps1
|
||||
pip install -r requirements.txt
|
||||
bootstrap_deps.bat
|
||||
```
|
||||
|
||||
若网络较慢:
|
||||
可选:
|
||||
|
||||
```powershell
|
||||
pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
|
||||
```
|
||||
|
||||
### 3.4 依赖自检
|
||||
|
||||
```powershell
|
||||
python tools/diagnostics/check_dependencies.py
|
||||
bootstrap_deps.bat --minimal
|
||||
bootstrap_deps.bat --index-url https://pypi.tuna.tsinghua.edu.cn/simple
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 4. 从旧电脑迁移配置(推荐)
|
||||
## 2. 手机端必须操作
|
||||
|
||||
> 这一步用于保留你原来的筛选参数、高价值房间记录、预约状态。
|
||||
### 2.1 开启开发者选项
|
||||
|
||||
请从旧电脑复制以下文件到新电脑同路径:
|
||||
1. `设置 -> 关于手机`
|
||||
2. 连续点击“版本号”7次
|
||||
|
||||
1. `config/config.json`(主配置,最重要)
|
||||
2. `state/high_value_rooms.json`(高价值房间回访记录,可选)
|
||||
3. `douyin/core/state/reservations.json`(预约队列,可选)
|
||||
### 2.2 开启 USB 调试
|
||||
|
||||
可选迁移(用于调试可视化):
|
||||
|
||||
1. `douyin/core/state/room_pos_map.json`
|
||||
|
||||
说明:
|
||||
|
||||
- 这些文件多数被 `.gitignore` 忽略,不会随 `git clone` 自动带过来。
|
||||
- 如不迁移,项目会按默认配置运行。
|
||||
|
||||
---
|
||||
|
||||
## 5. 手机端必须操作
|
||||
|
||||
### 5.1 开启开发者模式与 USB 调试
|
||||
|
||||
1. 手机 `设置 -> 关于手机`,连续点击“版本号”7次
|
||||
2. 进入 `开发者选项`,打开:
|
||||
1. `设置 -> 开发者选项`
|
||||
2. 开启:
|
||||
- `USB 调试`
|
||||
- (部分机型)`USB 安装` / `USB 调试(安全设置)`
|
||||
- (部分机型)`USB 调试(安全设置)` / `USB 安装`
|
||||
|
||||
### 5.2 首次 USB 连接授权
|
||||
### 2.3 首次授权
|
||||
|
||||
1. USB 连接电脑,USB 模式选“文件传输/MTP”
|
||||
2. 手机弹出“允许 USB 调试”时,点“允许”
|
||||
1. 手机 USB 连接电脑,模式选“文件传输/MTP”
|
||||
2. 手机弹出“允许 USB 调试”时点击“允许”
|
||||
3. 电脑执行:
|
||||
|
||||
```powershell
|
||||
adb devices
|
||||
```
|
||||
|
||||
期望看到:
|
||||
|
||||
```text
|
||||
<device-id> device
|
||||
```
|
||||
|
||||
若是 `unauthorized`,说明手机还未确认授权。
|
||||
|
||||
### 5.3 安装/确认抖音 APP
|
||||
|
||||
- 手机上安装并登录要运行的抖音账号
|
||||
- 手动打开一次抖音到首页,确保账号状态正常
|
||||
|
||||
### 5.4(可选)安装 ADBKeyboard(提升文本输入兼容性)
|
||||
|
||||
项目内置 APK:`tools/adb/ADBKeyboard.apk`
|
||||
|
||||
```powershell
|
||||
adb -s <device-id> install -r tools/adb/ADBKeyboard.apk
|
||||
adb -s <device-id> shell ime list -s
|
||||
```
|
||||
|
||||
若列表里存在 `com.android.adbkeyboard/.AdbIME`,可切换:
|
||||
|
||||
```powershell
|
||||
adb -s <device-id> shell ime enable com.android.adbkeyboard/.AdbIME
|
||||
adb -s <device-id> shell ime set com.android.adbkeyboard/.AdbIME
|
||||
```
|
||||
看到 `<device-id> device` 即成功。
|
||||
如果是 `unauthorized`,重新插线并重新允许授权。
|
||||
|
||||
---
|
||||
|
||||
## 6. 首次运行验收(新电脑)
|
||||
## 3. 手机底部导航栏怎么调出(详细)
|
||||
|
||||
### 6.1 GUI 启动(推荐)
|
||||
目标:显示底部“返回/主页/多任务”按钮。
|
||||
|
||||
```powershell
|
||||
python bin/gui_app.py
|
||||
```
|
||||
### 方法 A(通用)
|
||||
|
||||
检查点:
|
||||
1. 打开设置
|
||||
2. 搜索:`System navigation` 或 `Navigation mode`
|
||||
3. 选择:`3-button navigation`(三键导航)
|
||||
|
||||
1. 设备下拉里能看到手机
|
||||
2. 点击截图可成功生成实时截图
|
||||
3. 点击开始运行后日志持续刷新,无异常退出
|
||||
常见路径:
|
||||
|
||||
### 6.2 Web GUI 启动(可选)
|
||||
- `Settings -> System -> Gestures -> System navigation`
|
||||
- 或 `Settings -> System -> Navigation mode`
|
||||
|
||||
```powershell
|
||||
python bin/webgui_launcher.py
|
||||
```
|
||||
### 方法 B(品牌常见路径)
|
||||
|
||||
浏览器访问:`http://127.0.0.1:8000/`
|
||||
- Samsung:`设置 -> 显示 -> 导航条 -> 按钮`
|
||||
- Xiaomi/Redmi/POCO:`设置 -> 桌面 -> 系统导航方式 -> 经典导航键`
|
||||
- OPPO/OnePlus:`设置 -> 系统设置 -> 系统导航方式 -> 虚拟按键`
|
||||
- vivo/iQOO:`设置 -> 系统导航 -> 导航键`
|
||||
- Huawei/Honor:`设置 -> 系统和更新 -> 系统导航方式 -> 屏幕内三键导航`
|
||||
|
||||
### 6.3 CLI 冒烟(可选)
|
||||
### 还是没显示时
|
||||
|
||||
```powershell
|
||||
python bin/run_cli.py --device-id <device-id> --wait-minutes 1 --needswitch
|
||||
```
|
||||
1. 关闭“全面屏手势/全屏手势”
|
||||
2. 退出当前全屏 App 后再切换
|
||||
3. 切换后重启手机一次
|
||||
|
||||
临时调出:从屏幕最底部向上轻划一次(很多机型会临时显示系统导航控件)。
|
||||
|
||||
---
|
||||
|
||||
## 7. WiFi ADB(可选)
|
||||
## 4. 可选迁移配置
|
||||
|
||||
首次切换 WiFi ADB 需先 USB 连接。可用两种方式:
|
||||
|
||||
1. 桌面 GUI 里的 `WiFi ADB` 按钮(推荐)
|
||||
2. 命令行脚本:
|
||||
|
||||
```powershell
|
||||
python tools/adb/auto_connect_wifi_adb.py --device <device-id>
|
||||
```
|
||||
|
||||
若连接异常,先重启 ADB:
|
||||
|
||||
```powershell
|
||||
adb kill-server
|
||||
adb start-server
|
||||
adb devices
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 8. 常见问题速查
|
||||
|
||||
1. `adb devices` 空列表:检查数据线、USB模式、USB调试是否开启
|
||||
2. 设备状态 `unauthorized`:看手机弹窗并重新授权
|
||||
3. 设备状态 `offline`:重插 USB + `adb kill-server && adb start-server`
|
||||
4. 依赖安装失败(尤其 paddle):优先用清华源重试
|
||||
5. 启动后无日志/秒退:先跑 `python tools/diagnostics/check_dependencies.py`
|
||||
|
||||
---
|
||||
|
||||
## 9. 交付给他人的最小清单
|
||||
|
||||
1. 项目代码目录 `douyin_guaji-main`
|
||||
2. 迁移说明文档(本文)
|
||||
3. (可选)你的 `config/config.json`
|
||||
4. 对方手机按第 5 节完成设置后即可跑通
|
||||
如果要保留你原来的策略和状态,再复制这些文件:
|
||||
|
||||
1. `config/config.json`
|
||||
2. `state/high_value_rooms.json`
|
||||
3. `douyin/core/state/reservations.json`
|
||||
Reference in new issue
Block a user