Files
douyin_guaji-main/douyin/detection/pixel/_common.py
T
CodexandClaude Opus 4.7 c0b8ff3ba6 拆分 douyin_pixel (1172 → 4 个子模块 + 33 行 shim)
把 douyin/detection/douyin_pixel.py 按职责拆成
douyin/detection/pixel/ 子包:

- _common (32)     _safe_open_screenshot_rgb
- popups (444)     优惠券 / 红包 / 抽奖结果弹窗检测
- buttons (340)    参与按钮 / 粉丝团加入红色区域检测
- stage (436)      直播间图标 / 福袋详情 / 综合阶段状态读取

原文件改为 33 行 re-export shim,9 个公共符号全部保留。
detect_fudai_detail_page 等 6 处外部引用、detect_attend_button_red_area
等 2 处外部引用全部不需修改。

回归:
- 5 个新文件 + shim compileall 通过
- pytest 353 passed / 1 skipped
- 旧 import 路径与新子包路径返回同一函数对象

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-21 16:37:06 +08:00

33 lines
991 B
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# pyright: reportGeneralTypeIssues=false
# pyright: reportAttributeAccessIssue=false
# pyright: reportMissingModuleSource=false
# pyright: reportUnknownMemberType=false
# pyright: reportUnknownVariableType=false
# pylint: disable=no-member
"""pixel._common - 共享工具函数。
只包含 _safe_open_screenshot_rgb:安全打开截图为 RGB Image,
处理 truncated/损坏文件。被 popups / buttons / stage 子模块共用。
"""
import os
from typing import Any, Optional
from PIL import Image
def _safe_open_screenshot_rgb(pic_path: str) -> Optional[Image.Image]:
try:
if not pic_path or (not os.path.exists(pic_path)):
return None
pic = Image.open(pic_path)
pic.load() # Force load to catch truncated files early
return pic.convert("RGB")
except (OSError, IOError, SyntaxError):
# Handle truncated image files
return None
except Exception as e: # type: ignore[general-exception]
return None