From d31a3ffee3e2024b1550682efc46f2dbb18e8194 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 18 Jan 2026 14:21:31 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=EF=BC=9A=E8=B0=83=E6=95=B4ba?= =?UTF-8?q?sic=5Fjoin=5Fdecision=E5=87=BD=E6=95=B0=E4=B8=AD=E7=9A=84?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5=E8=AE=A1=E6=95=B0=E9=80=BB=E8=BE=91=EF=BC=8C?= =?UTF-8?q?=E6=8F=90=E5=8D=87=E4=BB=A3=E7=A0=81=E5=8F=AF=E8=AF=BB=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- douyin/fudai/douyin_fudai_core.py | 42 +++++++---- douyin/handlers/douyin_swipe_handler.py | 5 +- .../reservation/douyin_reservation_handler.py | 51 +++++++++++++ .../reservation/douyin_reservation_logic.py | 72 +++++++++++++++---- 4 files changed, 141 insertions(+), 29 deletions(-) diff --git a/douyin/fudai/douyin_fudai_core.py b/douyin/fudai/douyin_fudai_core.py index f2cef5c..66348d2 100644 --- a/douyin/fudai/douyin_fudai_core.py +++ b/douyin/fudai/douyin_fudai_core.py @@ -2122,19 +2122,33 @@ def get_fudai_contain(analyser, renwu: int = 2) -> Tuple[str, str, int, int, flo } ) - # 并行OCR 已生成完整的 fudai_detail,本处不再自动写入运行时映射表或落盘, - # 以避免在详情页关闭前产生多余的映射写入。映射的写入由 - # ReservationHandler.record_room_title_and_pos / SwipeHandler 在切换时负责。 + # 并行OCR 已生成完整的 fudai_detail,写入运行时映射表并落盘 try: - analyser._log_kv( - "预约", - "[预约] 并行OCR完成(不写入映射表,等待后续时机写盘)", - room_pos=room_pos, - title=(title_for_map[:30] if title_for_map else ""), - fudai_content=fudai_content_text[:30] if fudai_content_text else "", - prize_value_yuan=prize_value_yuan, - log_type="DEBUG", - ) + room_pos_map[room_pos] = room_info + try: + analyser._room_pos_to_title_map = room_pos_map + except Exception: + pass + try: + from douyin.reservation import douyin_reservation_handler + + douyin_reservation_handler._dump_room_pos_map_to_state(analyser) + except Exception: + pass + try: + analyser._log_kv( + "预约", + "[预约] 并行OCR完成(已写入映射表并写盘)", + room_pos=room_pos, + title=(title_for_map[:30] if title_for_map else ""), + fudai_content=( + fudai_content_text[:30] if fudai_content_text else "" + ), + prize_value_yuan=prize_value_yuan, + log_type="DEBUG", + ) + except Exception: + pass except Exception: pass @@ -6225,7 +6239,9 @@ def basic_join_decision( analyser._consecutive_attend_failures = 0 else: # 参与失败,增加计数器 - analyser._consecutive_attend_failures = getattr(analyser, "_consecutive_attend_failures", 0) + 1 + analyser._consecutive_attend_failures = ( + getattr(analyser, "_consecutive_attend_failures", 0) + 1 + ) # 如果参与成功,记录参与结果(不再使用已废弃的强制参与标志) if result: diff --git a/douyin/handlers/douyin_swipe_handler.py b/douyin/handlers/douyin_swipe_handler.py index 4bb5dbc..5053792 100644 --- a/douyin/handlers/douyin_swipe_handler.py +++ b/douyin/handlers/douyin_swipe_handler.py @@ -107,18 +107,17 @@ class SwipeHandler: except Exception: pass - # 如果因为当前位置已有福袋信息而跳过了记录,则无需继续上滑切换(避免多余的切换) + # 如果当前位置已有福袋信息,仍允许上滑切换(避免因提前写盘导致无法切房) try: if should_skip_due_to_fudai: try: analyser._log_kv( # type: ignore[attr-defined] "预约", - "[预约] 已跳过重复记录,暂停上滑切换以完成后续流程", + "[预约] 已跳过重复记录,继续上滑切换直播间", room_pos=room_pos, ) except Exception: pass - return except Exception: pass diff --git a/douyin/reservation/douyin_reservation_handler.py b/douyin/reservation/douyin_reservation_handler.py index c202f19..13d86de 100644 --- a/douyin/reservation/douyin_reservation_handler.py +++ b/douyin/reservation/douyin_reservation_handler.py @@ -615,6 +615,57 @@ class ReservationHandler: ) except Exception: pass + # 若有方向提示,则执行一次纠偏切换,避免二次回退未触发滑动 + try: + direction_hint = str( + item.get("_seek_direction_hint", "") + ).lower() + except Exception: + direction_hint = "" + try: + already_done = bool( + item.get("_seek_mismatch_realign_done", False) + ) + except Exception: + already_done = False + + if direction_hint in ("up", "down") and not already_done: + try: + item["_seek_mismatch_realign_done"] = True + except Exception: + pass + try: + analyser._log_kv( + operation_type, + f"[{operation_type}] _seek_reservation_room:标题不匹配,执行一次纠偏切换", + direction=direction_hint, + target_pos=target_pos, + ) + except Exception: + pass + try: + analyser._skip_record_title_during_seek = True + except Exception: + pass + try: + if direction_hint == "down": + douyin_swipe_handler.SwipeHandler.swipe_down_back_from_live( + analyser + ) + else: + douyin_swipe_handler.SwipeHandler.swipe_up_to_next_live( + analyser + ) + try: + analyser.operation.delay(0.1) + except Exception: + time.sleep(0.1) + except Exception: + pass + try: + analyser._skip_record_title_during_seek = False + except Exception: + pass return False except Exception: # 若验证流程异常,返回 False 以避免误判 diff --git a/douyin/reservation/douyin_reservation_logic.py b/douyin/reservation/douyin_reservation_logic.py index ea07b84..b547646 100644 --- a/douyin/reservation/douyin_reservation_logic.py +++ b/douyin/reservation/douyin_reservation_logic.py @@ -1871,6 +1871,12 @@ def process_reservation_attend_window( # 校验失败意味着位置信息可能不准确,尝试用映射表识别“当前/目标”位置差 updated_target = dict(target) + try: + room_pos_before_map = int( + getattr(analyser, "room_pos", 0) or 0 + ) + except Exception: + room_pos_before_map = 0 mapped_target_pos = None mapped_current_pos = None try: @@ -2040,20 +2046,60 @@ def process_reservation_attend_window( except Exception: pass if mapped_pos_diff == 0: - should_retry_seek = False - try: - analyser._log_kv( - "预约", - "[预约] 映射表显示已在目标位置,但校验失败,跳过二次回退", - mapped_current_pos=int( - mapped_current_pos - ), - mapped_target_pos=int( + # 若映射表显示已在目标位置但校验失败,尝试根据回退前位置进行一次纠偏回退 + if ( + mapped_target_pos is not None + and room_pos_before_map != mapped_target_pos + ): + try: + if room_pos_before_map > int( mapped_target_pos - ), - ) - except Exception: - pass + ): + updated_target[ + "_seek_direction_hint" + ] = "down" + elif room_pos_before_map < int( + mapped_target_pos + ): + updated_target[ + "_seek_direction_hint" + ] = "up" + except Exception: + pass + try: + analyser._log_kv( + "预约", + "[预约] 映射表显示已在目标位置但校验失败,启用纠偏回退", + mapped_current_pos=int( + mapped_current_pos + ), + mapped_target_pos=int( + mapped_target_pos + ), + room_pos_before_map=int( + room_pos_before_map + ), + direction_hint=updated_target.get( + "_seek_direction_hint", "" + ), + ) + except Exception: + pass + else: + should_retry_seek = False + try: + analyser._log_kv( + "预约", + "[预约] 映射表显示已在目标位置,但校验失败,跳过二次回退", + mapped_current_pos=int( + mapped_current_pos + ), + mapped_target_pos=int( + mapped_target_pos + ), + ) + except Exception: + pass if should_retry_seek: try: