优化后台截图功能

This commit is contained in:
Your Name committed 2025-12-31 11:55:01 +08:00
1 parent 223c127e11
commit ace3bbfa04
70 files changed
+4392 -871

No files matched your search

+32
View File
@@ -154,6 +154,38 @@ def find_and_open_fudai_detail(
)
except Exception:
pass
# 同步保存一个福袋图标的完整调试截图(确保无论检测路径如何都能保存)
try:
from PIL import Image
import path_config
from douyin.handlers import douyin_screenshot_manager
screenshot_path = path_config.get_screenshot_path()
if os.path.exists(screenshot_path):
img = Image.open(screenshot_path)
img.load()
pic_rgb_full = img.convert("RGB")
# 使用与检测处相同的命名(pixel_detect + fudai_icon + detected)
debug_path = douyin_screenshot_manager.save_debug_image(
pic_rgb_full,
operation_type="pixel_detect",
picname="fudai_icon",
step="detected",
coords=None,
extra_info={"source": "flow_on_detect", "click_x": click_x, "click_y": click_y},
)
if debug_path:
try:
analyser._log_kv(
"[调试图像]",
"流程检测到福袋图标后保存完整截图",
path=debug_path,
)
except Exception:
pass
except Exception:
# 不要让调试保存影响主流程
pass
# 优先走底层 operation.click,失败再尝试 analyser.click
try:
+21 -3
View File
@@ -21,7 +21,7 @@ from douyin.stage import douyin_stage
from douyin.detection import douyin_detection
from douyin.fudai import douyin_fudai_detail
from douyin.fudai import douyin_fudai_core
from douyin.core import douyin_flow_control
import douyin.core.douyin_flow_control as douyin_flow_control
from douyin.other import douyin_live_room
from douyin.reservation import douyin_reservation_logic
from douyin.utils import douyin_config
@@ -313,6 +313,24 @@ class fudai_analyse:
except Exception:
self.resolution_ratio_x, self.resolution_ratio_y = 1080, 2400
# 启动后台截图服务(多线程优化)
try:
from operations.screenshot_service import ScreenshotService
service = ScreenshotService.get_instance()
if self.device_id:
service.start(self.device_id, interval=1.5)
# 验证服务是否启动成功
time.sleep(0.1) # 短暂等待
if service.is_running():
self._log_kv("截图服务", "后台截图服务启动成功", device_id=self.device_id, interval=1.5)
else:
self._log_kv("截图服务", "后台截图服务启动失败", device_id=self.device_id)
else:
self._log_kv("截图服务", "设备ID为空,无法启动后台截图服务")
except Exception as e:
# 服务启动失败不影响主流程,回退到直接截图
self._log_kv("截图服务", "后台截图服务启动异常", error=str(e))
# 记录运行开始
from datetime import datetime
@@ -1231,7 +1249,7 @@ class fudai_analyse:
except Exception:
pass
# 查找福袋并打开详情页
from douyin.core import douyin_flow_control
import douyin.core.douyin_flow_control as douyin_flow_control
room_pos_ref = [int(getattr(self, "room_pos", 0) or 0)]
original_max_wait = getattr(
@@ -2054,7 +2072,7 @@ class fudai_analyse:
pass
# 查找福袋并打开详情页(使用 switch_room_wait_after_stage_diag_seconds 作为最大等待时间)
from douyin.core import douyin_flow_control
import douyin.core.douyin_flow_control as douyin_flow_control
room_pos_ref = [int(getattr(self, "room_pos", 0) or 0)]
# 临时设置 fudai_icon_max_wait_seconds 为 switch_room_wait_after_stage_diag_seconds
+19 -1
View File
@@ -13,7 +13,7 @@ import time
from typing import Any, Optional
from douyin.stage import douyin_stage
from douyin.core import douyin_flow_control
import douyin.core.douyin_flow_control as douyin_flow_control
from douyin.reservation import douyin_reservation_logic
from douyin.utils import douyin_helpers
from douyin.stage import douyin_stage_handler
@@ -57,6 +57,24 @@ class MainFlowController:
except Exception:
analyser.resolution_ratio_x, analyser.resolution_ratio_y = 1080, 2400
# 启动后台截图服务(多线程优化)
try:
from operations.screenshot_service import ScreenshotService
service = ScreenshotService.get_instance()
if analyser.device_id:
service.start(analyser.device_id, interval=1.5)
# 验证服务是否启动成功
time.sleep(0.1) # 短暂等待
if service.is_running():
analyser._log_kv("截图服务", "后台截图服务启动成功", device_id=analyser.device_id, interval=1.5)
else:
analyser._log_kv("截图服务", "后台截图服务启动失败", device_id=analyser.device_id)
else:
analyser._log_kv("截图服务", "设备ID为空,无法启动后台截图服务")
except Exception as e:
# 服务启动失败不影响主流程,回退到直接截图
analyser._log_kv("截图服务", "后台截图服务启动异常", error=str(e))
# 记录运行开始时间
analyser._run_start_ts = time.time()
@@ -105,6 +105,8 @@ class BaseFudaiMixin:
@@ -222,7 +222,7 @@ class MainLogicMixin(BaseFudaiMixin):
"""直播间有无福袋的处理逻辑。"""
try:
# 使用 flow_control 来查找和打开福袋
from douyin.core import douyin_flow_control
import douyin.core.douyin_flow_control as douyin_flow_control
room_pos_ref = [int(getattr(self, "room_pos", 0) or 0)]
opened = douyin_flow_control.find_and_open_fudai_detail(self, room_pos_ref)
@@ -79,6 +79,8 @@ class RoomUtilsMixin:
+1 -1
View File
@@ -1,5 +1,5 @@
{
"updated_ts": 1767105402.1814883,
"updated_ts": 1767151029.2816675,
"reason": "startup_clear",
"room_pos": 0,
"current_room_title": "",