From 3edbd9a293e9888373e858166e8a659215b93583 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sat, 17 Jan 2026 20:00:32 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E7=9B=B4=E6=92=AD?= =?UTF-8?q?=E9=97=B4=E6=A0=87=E9=A2=98=E8=AE=B0=E5=BD=95=E9=80=BB=E8=BE=91?= =?UTF-8?q?=EF=BC=8C=E9=81=BF=E5=85=8D=E9=87=8D=E5=A4=8D=E8=AE=B0=E5=BD=95?= =?UTF-8?q?=E5=B9=B6=E8=B0=83=E6=95=B4=E4=BD=8D=E7=BD=AE=E6=98=A0=E5=B0=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- douyin/handlers/douyin_swipe_handler.py | 61 +++++++++++++++++++++---- 1 file changed, 52 insertions(+), 9 deletions(-) diff --git a/douyin/handlers/douyin_swipe_handler.py b/douyin/handlers/douyin_swipe_handler.py index 5e83625..c4c0321 100644 --- a/douyin/handlers/douyin_swipe_handler.py +++ b/douyin/handlers/douyin_swipe_handler.py @@ -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)