feat: 优化直播间标题记录逻辑,避免重复记录并调整位置映射
This commit is contained in:
1 parent
3ce0aa73dd
commit
3edbd9a293
1 file changed
+52
-9
@@ -75,8 +75,35 @@ class SwipeHandler:
|
||||
skip_record = bool(
|
||||
getattr(analyser, "_skip_record_title_during_seek", False)
|
||||
)
|
||||
if not skip_record:
|
||||
# 如果该位置已经有福袋信息(并行OCR已记录),则无需再记录一次,避免重复截图/IO
|
||||
should_skip_due_to_fudai = False
|
||||
try:
|
||||
room_pos = int(getattr(analyser, "room_pos", 0) or 0)
|
||||
room_pos_map = getattr(analyser, "_room_pos_to_title_map", {}) or {}
|
||||
entry = None
|
||||
if isinstance(room_pos_map, dict):
|
||||
entry = (
|
||||
room_pos_map.get(room_pos)
|
||||
if room_pos in room_pos_map
|
||||
else room_pos_map.get(str(room_pos))
|
||||
)
|
||||
if isinstance(entry, dict) and bool(entry.get("has_fudai", False)):
|
||||
should_skip_due_to_fudai = True
|
||||
except Exception:
|
||||
should_skip_due_to_fudai = False
|
||||
|
||||
if not skip_record and not should_skip_due_to_fudai:
|
||||
analyser._record_room_title_and_pos() # type: ignore[attr-defined]
|
||||
else:
|
||||
if should_skip_due_to_fudai:
|
||||
try:
|
||||
analyser._log_kv( # type: ignore[attr-defined]
|
||||
"预约",
|
||||
"[预约] 跳过记录:当前位置已有福袋信息,跳过重复记录",
|
||||
room_pos=room_pos,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
@@ -355,6 +382,12 @@ class SwipeHandler:
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
# 每次实际向上回退时,调整运行时的 room_pos,避免映射继续向下编号
|
||||
try:
|
||||
cur_pos = int(getattr(analyser, "room_pos", 0) or 0)
|
||||
analyser.room_pos = max(0, cur_pos - 1)
|
||||
except Exception:
|
||||
analyser.room_pos = 0
|
||||
except Exception:
|
||||
# 回退到 operation.swipe
|
||||
analyser.operation.swipe(
|
||||
@@ -365,6 +398,12 @@ class SwipeHandler:
|
||||
end_y,
|
||||
swipe_duration_ms,
|
||||
)
|
||||
# 如果使用 fallback 的 operation.swipe,也要同步 room_pos
|
||||
try:
|
||||
cur_pos = int(getattr(analyser, "room_pos", 0) or 0)
|
||||
analyser.room_pos = max(0, cur_pos - 1)
|
||||
except Exception:
|
||||
analyser.room_pos = 0
|
||||
try:
|
||||
analyser._log_kv( # type: ignore[attr-defined]
|
||||
"流程", "回退直播间 {}/{}".format(i + 1, back_times)
|
||||
@@ -374,17 +413,21 @@ class SwipeHandler:
|
||||
analyser.operation.delay(0.1) # 减少回退延迟,从2秒改为0.1秒
|
||||
except Exception:
|
||||
pass
|
||||
# 回到第一个后,计数归零,但不重置位置以保持映射表连续性
|
||||
# 回到第一个后,计数归零,并将 room_pos 重置为 0(从 0 开始记录映射)
|
||||
analyser.operation.delay(3)
|
||||
try:
|
||||
analyser._swipe_times = 0
|
||||
# 不设置 analyser.room_pos = 0,以避免映射表从0开始覆盖
|
||||
# analyser.room_pos = 0 # 注释掉这行
|
||||
# 不调用 _record_room_title_and_pos() 以避免覆盖位置0的现有记录
|
||||
# try:
|
||||
# analyser._record_room_title_and_pos() # type: ignore[attr-defined]
|
||||
# except Exception:
|
||||
# pass
|
||||
# 重置当前位置为 0,使后续映射从 0 开始记录,避免继续往下编号导致重复
|
||||
try:
|
||||
analyser.room_pos = 0
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 记录当前位置(位置0)到映射表,便于 GUI 立即更新
|
||||
try:
|
||||
analyser._record_room_title_and_pos() # type: ignore[attr-defined]
|
||||
except Exception:
|
||||
pass
|
||||
# 清除连续未找到福袋计数,避免与其他回退逻辑重复
|
||||
try:
|
||||
setattr(analyser, "_consecutive_no_fudai_count", 0)
|
||||
|
||||
Reference in new issue
Block a user