feat: 清理旧截图文件以避免复用过期截图,并优化截图文件检查逻辑
This commit is contained in:
1 parent
361dc973e7
commit
e091db7a54
3 files changed
+77
-11
No files matched your search
@@ -558,6 +558,30 @@ class fudai_analyse:
|
||||
wait_minutes: int = 15,
|
||||
) -> None:
|
||||
"""兼容原 fudai1.fudai_choujiang 的主入口(当前实现为精简版:仅基础抢福袋)。"""
|
||||
# 程序启动时清理旧截图文件,避免复用过期的截图
|
||||
try:
|
||||
import path_config
|
||||
import os
|
||||
pic_path = path_config.get_screenshot_path()
|
||||
if os.path.exists(pic_path):
|
||||
os.remove(pic_path)
|
||||
self._log_kv(
|
||||
"启动",
|
||||
"清理旧截图文件,避免复用过期截图",
|
||||
path=pic_path,
|
||||
log_type="SCREENSHOT",
|
||||
)
|
||||
except Exception as e:
|
||||
try:
|
||||
self._log_kv(
|
||||
"启动",
|
||||
f"清理旧截图文件失败 - {str(e)}",
|
||||
level="WARNING",
|
||||
error=str(e),
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# DEBUG: 记录函数入口
|
||||
try:
|
||||
self._log_kv(
|
||||
|
||||
@@ -224,6 +224,29 @@ class ReservationHandler:
|
||||
try:
|
||||
room_pos = int(getattr(analyser, "room_pos", 0) or 0)
|
||||
|
||||
# 在记录映射表前清理旧截图文件,避免复用过期的截图
|
||||
try:
|
||||
import path_config
|
||||
import os
|
||||
pic_path = path_config.get_screenshot_path()
|
||||
if os.path.exists(pic_path):
|
||||
os.remove(pic_path)
|
||||
analyser._log_kv(
|
||||
"预约",
|
||||
"[预约] 清理旧截图文件,避免复用过期截图",
|
||||
room_pos=room_pos,
|
||||
path=pic_path,
|
||||
log_type="SCREENSHOT",
|
||||
)
|
||||
except Exception as e:
|
||||
analyser._log_kv(
|
||||
"预约",
|
||||
f"[预约] 清理旧截图文件失败 - {str(e)}",
|
||||
room_pos=room_pos,
|
||||
level="WARNING",
|
||||
error=str(e),
|
||||
)
|
||||
|
||||
# 检查是否已经为当前直播间识别过标题,避免重复截图和OCR
|
||||
identified_positions = getattr(
|
||||
analyser, "_room_title_identified_positions", set()
|
||||
|
||||
@@ -216,17 +216,36 @@ def read_live_room_title_core(
|
||||
)
|
||||
|
||||
if os.path.exists(pic_path) and os.path.getsize(pic_path) >= 1024:
|
||||
screenshot_reused = True
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"直播间标题",
|
||||
"read_live_room_title_core:复用已有截图文件",
|
||||
log_type="SCREENSHOT",
|
||||
reason="file_exists",
|
||||
path=pic_path,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
# 检查文件修改时间,避免复用过期的截图(超过30秒的认为过期)
|
||||
import time
|
||||
file_mtime = os.path.getmtime(pic_path)
|
||||
current_time = time.time()
|
||||
if current_time - file_mtime > 30:
|
||||
# 文件太旧,不复用
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"直播间标题",
|
||||
"read_live_room_title_core:截图文件过期,不复用",
|
||||
log_type="SCREENSHOT",
|
||||
reason="file_too_old",
|
||||
path=pic_path,
|
||||
file_age_seconds=current_time - file_mtime,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
else:
|
||||
screenshot_reused = True
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"直播间标题",
|
||||
"read_live_room_title_core:复用已有截图文件",
|
||||
log_type="SCREENSHOT",
|
||||
reason="file_exists",
|
||||
path=pic_path,
|
||||
file_age_seconds=current_time - file_mtime,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
else:
|
||||
analyser.operation.get_screenshot(analyser.device_id)
|
||||
except Exception as e:
|
||||
|
||||
Reference in new issue
Block a user