refactor(fudai): 抽 fudai_analyse.swipe 实现到 swipe_with_fallback
将 swipe 方法体(约 60 行)抽到 fudai_detail_helpers.swipe_with_fallback。 逻辑: - 首选 operation.swipe - 失败回退到 douyin_swipe_ops._adb_swipe_direct - 最后兜底记录"swipe 失败"日志 类内 swipe 方法保留薄包装。 douyin_fudai.py: 1132 → 1078 行 (-54) fudai_detail_helpers.py: 2975 → 3033 行 douyin_fudai.py 跌破 1100 行(4121 → 1078,本会话累计削减 3043 行 = -74%) 验证: - pytest 1013 passed - compile OK Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
6d5b2cfb15
commit
42ef73a9ee
2 files changed
+61
-57
No files matched your search
@@ -250,64 +250,10 @@ class fudai_analyse:
|
||||
def swipe(
|
||||
self, start_x: int, start_y: int, end_x: int, end_y: int, duration_ms: int = 300
|
||||
) -> None:
|
||||
"""兼容原版 fudai_analyse.swipe:转发到底层 operation.swipe。
|
||||
"""兼容原版 fudai_analyse.swipe:转发到底层 operation.swipe。"""
|
||||
from douyin.core.fudai_modules.fudai_detail_helpers import swipe_with_fallback
|
||||
|
||||
参数使用像素坐标,duration_ms 为滑动持续时间(毫秒)。
|
||||
"""
|
||||
try:
|
||||
# 首选底层 operation 的 swipe 实现
|
||||
try:
|
||||
self.operation.swipe(
|
||||
self.device_id, start_x, start_y, end_x, end_y, duration_ms
|
||||
)
|
||||
return
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 回退:尝试使用 douyin.handlers.douyin_swipe_ops 的 adb 命令直接发送
|
||||
try:
|
||||
from douyin.handlers import douyin_swipe_ops
|
||||
|
||||
ok = douyin_swipe_ops._adb_swipe_direct(
|
||||
getattr(self, "device_id", ""),
|
||||
start_x,
|
||||
start_y,
|
||||
end_x,
|
||||
end_y,
|
||||
duration_ms,
|
||||
self.operation,
|
||||
)
|
||||
if ok:
|
||||
return
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 最后兜底:记录滑动失败
|
||||
try:
|
||||
self._log_kv(
|
||||
"滑动",
|
||||
"swipe 失败 - 无可用实现",
|
||||
start_x=start_x,
|
||||
start_y=start_y,
|
||||
end_x=end_x,
|
||||
end_y=end_y,
|
||||
duration_ms=duration_ms,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
except Exception:
|
||||
try:
|
||||
self._log_kv(
|
||||
"滑动",
|
||||
"swipe 异常",
|
||||
start_x=start_x,
|
||||
start_y=start_y,
|
||||
end_x=end_x,
|
||||
end_y=end_y,
|
||||
duration_ms=duration_ms,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
swipe_with_fallback(self, start_x, start_y, end_x, end_y, duration_ms)
|
||||
|
||||
def load_config(self) -> None:
|
||||
"""从 config.json 加载与福袋筛选/节流相关的关键参数(精简版)。"""
|
||||
|
||||
@@ -273,6 +273,64 @@ def handle_no_fudai_in_live_room(analyser, room_pos_ref, start_time: float) -> N
|
||||
)
|
||||
|
||||
|
||||
def swipe_with_fallback(analyser, start_x: int, start_y: int, end_x: int, end_y: int, duration_ms: int = 300) -> None:
|
||||
"""fudai_analyse.swipe 的实现:转发到底层 operation.swipe,失败时回退到 ADB direct。"""
|
||||
try:
|
||||
# 首选底层 operation 的 swipe 实现
|
||||
try:
|
||||
analyser.operation.swipe(
|
||||
analyser.device_id, start_x, start_y, end_x, end_y, duration_ms
|
||||
)
|
||||
return
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 回退:尝试使用 douyin.handlers.douyin_swipe_ops 的 adb 命令直接发送
|
||||
try:
|
||||
from douyin.handlers import douyin_swipe_ops
|
||||
|
||||
ok = douyin_swipe_ops._adb_swipe_direct(
|
||||
getattr(analyser, "device_id", ""),
|
||||
start_x,
|
||||
start_y,
|
||||
end_x,
|
||||
end_y,
|
||||
duration_ms,
|
||||
analyser.operation,
|
||||
)
|
||||
if ok:
|
||||
return
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 最后兜底:记录滑动失败
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"滑动",
|
||||
"swipe 失败 - 无可用实现",
|
||||
start_x=start_x,
|
||||
start_y=start_y,
|
||||
end_x=end_x,
|
||||
end_y=end_y,
|
||||
duration_ms=duration_ms,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
except Exception:
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"滑动",
|
||||
"swipe 异常",
|
||||
start_x=start_x,
|
||||
start_y=start_y,
|
||||
end_x=end_x,
|
||||
end_y=end_y,
|
||||
duration_ms=duration_ms,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
def dispatch_stage(analyser, stage: str, seen: str, start_time: float) -> None:
|
||||
"""run_once_basic 阶段分发器:根据 stage 调用对应的 helper。
|
||||
|
||||
|
||||
Reference in new issue
Block a user