- 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>
60 lines
1.6 KiB
Python
60 lines
1.6 KiB
Python
"""douyin_fudai_finder_pkg.optimized_entry - 顶层"快速找福袋"入口。
|
||
|
||
check_have_fudai_with_ready_screenshot_optimized:直接拼装 Acquirer + Detector,
|
||
跳过 FudaiFinder 重试逻辑的轻量入口。
|
||
"""
|
||
from __future__ import annotations
|
||
|
||
# pylint: disable=E1101
|
||
|
||
import os
|
||
import time
|
||
from typing import Any, Dict, Optional, Tuple
|
||
|
||
from PIL import Image
|
||
|
||
from douyin.core import path_config
|
||
|
||
# OCR 预处理接口
|
||
from douyin.utils.ocr_preprocess import preprocess_for_ocr # type: ignore
|
||
|
||
# 调试图像管理器(用于保存调试截图)
|
||
try:
|
||
from douyin.handlers import douyin_screenshot_manager
|
||
except ImportError:
|
||
douyin_screenshot_manager = None
|
||
|
||
|
||
from .detector import FudaiDetector
|
||
from .image_acquirer import FudaiImageAcquirer
|
||
|
||
|
||
def check_have_fudai_with_ready_screenshot_optimized(
|
||
analyser: Any, screenshot_ready: bool = False
|
||
) -> int:
|
||
"""优化的福袋查找函数(兼容原接口,仅检测不点击)
|
||
|
||
参数:
|
||
analyser: 分析器对象
|
||
screenshot_ready: 是否已有可用截图
|
||
|
||
返回:
|
||
福袋X坐标(1080基准),未找到返回 0
|
||
"""
|
||
# 只检测,不点击(避免与 find_and_open_fudai_detail 重复点击)
|
||
try:
|
||
acquirer = FudaiImageAcquirer(analyser)
|
||
pic = acquirer.acquire_screenshot(force_refresh=not screenshot_ready)
|
||
|
||
if pic is None:
|
||
return 0
|
||
|
||
detector = FudaiDetector(analyser)
|
||
detected_x, _detect_method = detector.detect(pic)
|
||
|
||
if detected_x is not None:
|
||
return int(detected_x)
|
||
return 0
|
||
except Exception:
|
||
return False
|