douyin_robot: print → _robot_log
- 新增模块级 _robot_log(analyser, msg, level):优先 analyser._log_kv("人机校验" 类目), 退化到 logging,最后兜底 stdout - 全部 10 处裸 print → _robot_log - "无法处理 + 等待30分钟" 类提示标 level=WARNING - check_robot_pic_distance 中的 print(x, y) 与 print(x1, first_y) 改为 DEBUG 级, 附带"找到首/末像素"语义说明 回归:149 .py 编译通过;test_filter_logging / check_web_gui_config_sync 通过; 3 个公共函数(check_have_robot_analyse / deal_robot_analyse / check_robot_pic_distance) 仍可正常加载。 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
1 parent
a876d9ebb0
commit
04035abbc0
1 file changed
+43
-10
@@ -8,6 +8,39 @@ from PIL import Image # type: ignore[import]
|
||||
from douyin.fudai.core.coords import LIVE_VERIFY1, LIVE_VERIFY2, ROBOT_VERIFY
|
||||
from douyin.utils.ocr_preprocess import preprocess_for_ocr # type: ignore
|
||||
|
||||
import logging as _logging
|
||||
|
||||
# 模块级日志:优先走 analyser._log_kv,回退到 logging。
|
||||
_LOGGER = _logging.getLogger("douyin.other.douyin_robot")
|
||||
|
||||
|
||||
def _robot_log(analyser, msg: str, level: str = "INFO") -> None:
|
||||
"""统一人机校验日志出口;失败兜底 stdout。"""
|
||||
try:
|
||||
log_kv = getattr(analyser, "_log_kv", None) if analyser is not None else None
|
||||
if callable(log_kv):
|
||||
log_kv("人机校验", str(msg), level=str(level or "INFO"))
|
||||
return
|
||||
except Exception:
|
||||
pass
|
||||
try:
|
||||
lv = str(level or "INFO").upper()
|
||||
if lv == "ERROR":
|
||||
_LOGGER.error(str(msg))
|
||||
elif lv == "WARNING":
|
||||
_LOGGER.warning(str(msg))
|
||||
elif lv == "DEBUG":
|
||||
_LOGGER.debug(str(msg))
|
||||
else:
|
||||
_LOGGER.info(str(msg))
|
||||
except Exception:
|
||||
try:
|
||||
print(str(msg))
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
|
||||
|
||||
def _to_rgb_tuple(color: Any) -> tuple[int, int, int]:
|
||||
if isinstance(color, (int, float)):
|
||||
@@ -35,17 +68,17 @@ def check_have_robot_analyse(analyser) -> int | bool:
|
||||
name_live = preprocess_for_ocr(analyser, "直播验证")
|
||||
result = analyser.operation.analyse_pic_word(name_live, 0)
|
||||
if "验证" in result:
|
||||
print("存在滑动图片人机校验,需要等待完成验证。")
|
||||
_robot_log(analyser, "存在滑动图片人机校验,需要等待完成验证。")
|
||||
return 1
|
||||
if "形状相同" in result:
|
||||
print("存在点击图片人机校验,需要等待完成验证。")
|
||||
_robot_log(analyser, "存在点击图片人机校验,需要等待完成验证。")
|
||||
return 2
|
||||
|
||||
analyser.cut_pic(*LIVE_VERIFY2, "", "直播验证")
|
||||
name_live2 = preprocess_for_ocr(analyser, "直播验证")
|
||||
result = analyser.operation.analyse_pic_word(name_live2)
|
||||
if "开始检测" in result:
|
||||
print("存在人脸识别人机校验,需要等待完成验证。")
|
||||
_robot_log(analyser, "存在人脸识别人机校验,需要等待完成验证。")
|
||||
return 3
|
||||
return False
|
||||
|
||||
@@ -57,7 +90,7 @@ def deal_swipe_robot_analyse(analyser, distance: int = 400) -> None:
|
||||
else:
|
||||
targetx = 622 * analyser.resolution_ratio_x // 1080
|
||||
analyser.swipe(222, 1444, targetx, 1444, 300)
|
||||
print("滑轨滑动{}距离解锁人机验证".format(distance))
|
||||
_robot_log(analyser, "滑轨滑动{}距离解锁人机验证".format(distance))
|
||||
analyser.operation.delay(1)
|
||||
|
||||
|
||||
@@ -72,12 +105,12 @@ def deal_robot_analyse(analyser) -> None:
|
||||
analyser.operation.delay(10)
|
||||
analyser._shot_and_diagnose("人机校验", "校验后复查", analyser.device_id)
|
||||
elif robot_result == 2:
|
||||
print("无法处理图片验证的人机,点击关闭退出验证,等待30分钟")
|
||||
_robot_log(analyser, "无法处理图片验证的人机,点击关闭退出验证,等待30分钟", level="WARNING")
|
||||
analyser.click(910, 800) # 点击关闭
|
||||
analyser.operation.delay(1800)
|
||||
break
|
||||
elif robot_result == 3:
|
||||
print("无法处理人脸识别验证的人机,点击返回退出验证,等待30分钟")
|
||||
_robot_log(analyser, "无法处理人脸识别验证的人机,点击返回退出验证,等待30分钟", level="WARNING")
|
||||
analyser.operation.click_back(analyser.device_id)
|
||||
analyser.operation.delay(2)
|
||||
analyser.operation.click_back(analyser.device_id)
|
||||
@@ -87,7 +120,7 @@ def deal_robot_analyse(analyser) -> None:
|
||||
break
|
||||
swipe_times += 1
|
||||
if swipe_times >= 10:
|
||||
print("无法处理图片验证的人机,点击关闭退出验证,等待30分钟")
|
||||
_robot_log(analyser, "无法处理图片验证的人机,点击关闭退出验证,等待30分钟", level="WARNING")
|
||||
analyser.click(910, 800) # 点击关闭
|
||||
analyser.operation.delay(1800)
|
||||
|
||||
@@ -133,7 +166,7 @@ def check_robot_pic_distance(analyser) -> int:
|
||||
for x in range(5, width - 40):
|
||||
r, g, b = _to_rgb_tuple(img.getpixel((x, y)))
|
||||
if r > 240 and g > 240 and b > 240:
|
||||
print(x, y)
|
||||
_robot_log(analyser, f"找到首像素 ({x}, {y})", level="DEBUG")
|
||||
first_x = x
|
||||
first_y = y
|
||||
found_first = True
|
||||
@@ -147,8 +180,8 @@ def check_robot_pic_distance(analyser) -> int:
|
||||
for x1 in range(first_x, width - 40):
|
||||
r, g, b = _to_rgb_tuple(img.getpixel((x1, first_y)))
|
||||
if r < 50 and g < 55 and b < 85 and (r + g + b) < 150:
|
||||
print(x1, first_y)
|
||||
print("需要滑动的距离为{}".format(x1 - first_x))
|
||||
_robot_log(analyser, f"找到末像素 ({x1}, {first_y})", level="DEBUG")
|
||||
_robot_log(analyser, "需要滑动的距离为{}".format(x1 - first_x))
|
||||
return x1 - first_x
|
||||
|
||||
return 0
|
||||
Reference in new issue
Block a user