把 douyin/other/douyin_yanghao.py 中 6 个独立小函数拆出到
douyin/other/douyin_yanghao_pkg/ 子包,巨型函数 yanghao_idle (756 行)
留在原文件,从子包 import 拿 _yanghao_log/_scaled_click/_do_comment 用。
新建子包:
- logger (40) _yanghao_log + module logger
- click_helpers (75) _scaled_click / _do_comment
- entrypoints (82) yanghao_recommend_flow / yanghao_wait /
yanghao_get_recommend_seconds
(yanghao_recommend_flow 通过 lazy import 调用 yanghao_idle)
外部 import 路径不变:
``from douyin.other.douyin_yanghao import yanghao_recommend_flow / yanghao_wait /
yanghao_get_recommend_seconds`` 等仍可用(原文件 from yanghao_pkg import * re-export)。
- _scaled_click 4 处外部引用 / _yanghao_log 1 处 / 其他 0 处
回归:
- 4 个新文件 + 改写后 douyin_yanghao.py compileall 通过
- pytest 353 passed / 1 skipped
- _yanghao_log() / yanghao_get_recommend_seconds() 调用结果正常
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
83 lines
3.1 KiB
Python
83 lines
3.1 KiB
Python
"""douyin_yanghao_pkg.entrypoints - 养号入口函数。
|
|
|
|
- yanghao_recommend_flow: 推荐页养号流程(退出直播间 → 进推荐页 → 养号)
|
|
- yanghao_wait: 养号等待函数(兼容接口)
|
|
- yanghao_get_recommend_seconds: 推荐页养号默认时长读取
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
from .logger import _yanghao_log
|
|
|
|
|
|
def _yanghao_idle_from_main(analyser, total_seconds: int) -> None:
|
|
"""懒加载 yanghao_idle(避免循环依赖:yanghao_idle 仍在原文件)。"""
|
|
from douyin.other.douyin_yanghao import yanghao_idle as _impl
|
|
_impl(analyser, total_seconds)
|
|
|
|
|
|
def yanghao_recommend_flow(analyser, total_seconds: int) -> None:
|
|
"""执行推荐页养号流程:退出直播间 -> 进入推荐页 -> 养号。
|
|
|
|
每一步操作间隔1秒,确保界面稳定。
|
|
"""
|
|
try:
|
|
# 输出设备分辨率与调试行(兼容原始日志格式)
|
|
try:
|
|
resx = int(getattr(analyser, "resolution_ratio_x", 1080) or 1080)
|
|
resy = int(getattr(analyser, "resolution_ratio_y", 2400) or 2400)
|
|
except Exception:
|
|
resx, resy = 1080, 2400
|
|
_yanghao_log(analyser, f"设备分辨率为:{resx}*{resy}")
|
|
_yanghao_log(analyser, f"[YANGHAO-ONLY] device_id={analyser.device_id} res={resx}x{resy}")
|
|
_yanghao_log(analyser, "[养号] 开始推荐页养号流程")
|
|
|
|
# 步骤1: 发送系统返回键退出当前直播间
|
|
_yanghao_log(analyser, "[养号] 步骤1: 发送系统返回键退出直播间")
|
|
analyser.operation.keyevent(analyser.device_id, 4) # KEYCODE_BACK = 4
|
|
analyser.operation.delay(3.0)
|
|
|
|
# 步骤2: 再次发送返回键确保退出
|
|
_yanghao_log(analyser, "[养号] 步骤2: 再次发送返回键")
|
|
analyser.operation.keyevent(analyser.device_id, 4) # KEYCODE_BACK = 4
|
|
analyser.operation.delay(3.0)
|
|
|
|
# 步骤3: 在推荐页执行养号
|
|
_yanghao_log(analyser, f"[养号] 步骤3: 在推荐页养号 {total_seconds} 秒")
|
|
analyser.operation.delay(3.0)
|
|
_yanghao_idle_from_main(analyser, total_seconds)
|
|
|
|
_yanghao_log(analyser, "[养号] 推荐页养号流程完成")
|
|
|
|
except Exception as e:
|
|
_yanghao_log(analyser, f"[养号] 推荐页养号流程失败: {e}")
|
|
# 失败时退化为普通养号
|
|
_yanghao_idle_from_main(analyser, total_seconds)
|
|
|
|
|
|
|
|
|
|
def yanghao_wait(analyser, total_seconds: int) -> None:
|
|
"""养号等待函数(兼容接口)。"""
|
|
if total_seconds <= 0:
|
|
return
|
|
|
|
# 检查是否启用养号
|
|
if not bool(getattr(analyser, "yanghao_enabled", True)):
|
|
_yanghao_log(analyser, "[养号] yanghao_enabled=0,跳过推荐页养号(快速继续)")
|
|
return
|
|
|
|
# 执行推荐页养号流程
|
|
yanghao_recommend_flow(analyser, total_seconds)
|
|
|
|
|
|
|
|
|
|
def yanghao_get_recommend_seconds(analyser) -> int:
|
|
"""返回推荐页养号的默认时长(兼容接口)。"""
|
|
try:
|
|
return int(getattr(analyser, "yanghao_recommend_duration_seconds", 60) or 60)
|
|
except Exception:
|
|
return 60
|