From 3ce0aa73ddb0b66eb1836b67e194735c67312149 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sat, 17 Jan 2026 19:14:16 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E5=BD=93=E5=89=8D?= =?UTF-8?q?=E7=9B=B4=E6=92=AD=E9=97=B4=E6=A0=87=E9=A2=98=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E9=80=BB=E8=BE=91=EF=BC=8C=E6=8F=90=E5=8D=87=E5=8C=B9=E9=85=8D?= =?UTF-8?q?=E5=87=86=E7=A1=AE=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- douyin/fudai/douyin_fudai_core.py | 5 +- .../reservation/douyin_reservation_handler.py | 129 +++++++++++++++--- .../reservation/douyin_reservation_logic.py | 41 ++++-- gui/gui_app.py | 27 ++-- 4 files changed, 159 insertions(+), 43 deletions(-) diff --git a/douyin/fudai/douyin_fudai_core.py b/douyin/fudai/douyin_fudai_core.py index 3fb2dd8..135f470 100644 --- a/douyin/fudai/douyin_fudai_core.py +++ b/douyin/fudai/douyin_fudai_core.py @@ -2089,9 +2089,8 @@ def get_fudai_contain(analyser, renwu: int = 2) -> Tuple[str, str, int, int, flo or str(getattr(analyser, "current_room_title_raw", "") or "") ) - button_text_for_map = ( - str(button_text_raw or "") - or str(getattr(analyser, "button_text_raw", "") or "") + button_text_for_map = str(button_text_raw or "") or str( + getattr(analyser, "button_text_raw", "") or "" ) room_info = dict(base_info) diff --git a/douyin/reservation/douyin_reservation_handler.py b/douyin/reservation/douyin_reservation_handler.py index c19fc67..d80026a 100644 --- a/douyin/reservation/douyin_reservation_handler.py +++ b/douyin/reservation/douyin_reservation_handler.py @@ -231,9 +231,6 @@ class ReservationHandler: ) if not is_parallel_recording: try: - import path_config - import os - pic_path = path_config.get_screenshot_path() if os.path.exists(pic_path): os.remove(pic_path) @@ -389,8 +386,6 @@ class ReservationHandler: if should_record: # 映射表中没有记录,需要直接识别截图记录直播间标题 try: - from douyin.fudai import douyin_fudai_detail - y_pianyi_val = int(getattr(analyser, "y_pianyi", 0) or 0) room_title, room_title_raw = ( douyin_fudai_detail.read_live_room_title_core( @@ -482,6 +477,7 @@ class ReservationHandler: except Exception: pass + @staticmethod # type: ignore[misc] def seek_reservation_room( analyser: Any, item: Dict[str, Any], operation_type: str = "预约" ) -> bool: @@ -510,6 +506,7 @@ class ReservationHandler: # 计算需要切换的次数和方向 pos_diff = target_pos - cur_pos + moved = False # 标记是否实际执行了滑动操作 try: max_back = int( @@ -545,8 +542,91 @@ class ReservationHandler: pass if pos_diff == 0: - # 已在目标位置,但仍需校验 - pass + # 已在目标位置:为了避免在校验失败后被误判为“回退成功”, + # 需要额外确认当前直播间标题与目标标题是否匹配;若无法匹配则返回 False。 + try: + # 优先使用缓存的标题 + cur_title = str( + getattr(analyser, "current_room_title", "") or "" + ).strip() + cur_title_raw = str( + getattr(analyser, "current_room_title_raw", "") or "" + ).strip() + # 如果缓存为空且有目标标题,尝试重新 OCR 识别当前直播间标题以确认 + if not cur_title and (target_room_title or target_room_title_raw): + try: + y_pianyi_val = int(getattr(analyser, "y_pianyi", 0) or 0) + room_title, room_title_raw = ( + douyin_fudai_detail.read_live_room_title_core( + analyser, y_pianyi_val + ) + ) + cur_title = (room_title or "").strip() + cur_title_raw = (room_title_raw or "").strip() + except Exception: + pass + + # 规范化并比较标题(尽量使用已有的规范化方法) + try: + from douyin.other import douyin_high_value_room + + if hasattr(douyin_high_value_room, "_normalize_room_title"): + target_norm = douyin_high_value_room._normalize_room_title( + target_room_title + ) + cur_norm = douyin_high_value_room._normalize_room_title( + cur_title + ) + else: + target_norm = (target_room_title or "").strip() + cur_norm = (cur_title or "").strip() + except Exception: + target_norm = (target_room_title or "").strip() + cur_norm = (cur_title or "").strip() + + # 如果标题匹配或包含关系视为成功,否则视为失败 + if ( + target_norm + and cur_norm + and ( + target_norm == cur_norm + or target_norm in cur_norm + or cur_norm in target_norm + ) + ): + try: + analyser._log_kv( + operation_type, + f"[{operation_type}] _seek_reservation_room:已在目标位置且标题匹配,视为回退成功", + target_pos=target_pos, + current_title=cur_title, + ) + except Exception: + pass + return True + else: + try: + analyser._log_kv( + operation_type, + f"[{operation_type}] _seek_reservation_room:已在目标位置但标题不匹配,视为回退失败", + target_pos=target_pos, + expected_title=target_room_title, + current_title=cur_title, + ) + except Exception: + pass + return False + except Exception: + # 若验证流程异常,返回 False 以避免误判 + try: + analyser._log_kv( + operation_type, + f"[{operation_type}] _seek_reservation_room:位置相同但验证异常,视为回退失败", + target_pos=target_pos, + ) + except Exception: + pass + return False elif pos_diff < 0: # 目标在上方(target_pos < cur_pos),需要向上回退(减少 room_pos) back_times = min(abs(pos_diff), max_back) if max_back > 0 else abs(pos_diff) @@ -570,6 +650,7 @@ class ReservationHandler: pass # 执行连续滑动,不在每次滑动后添加延迟(ADB滑动命令本身会等待完成) for i in range(back_times): + moved = True douyin_swipe_handler.SwipeHandler.swipe_down_back_from_live(analyser) # 只在最后一次滑动后添加短暂延迟,确保页面稳定 if i == back_times - 1 and back_times > 0: @@ -605,6 +686,7 @@ class ReservationHandler: pass # 执行连续滑动,不在每次滑动后添加延迟(ADB滑动命令本身会等待完成) for i in range(forward_times): + moved = True douyin_swipe_handler.SwipeHandler.swipe_up_to_next_live(analyser) # 只在最后一次滑动后添加短暂延迟,确保页面稳定 if i == forward_times - 1 and forward_times > 0: @@ -618,9 +700,9 @@ class ReservationHandler: except Exception: pass - # 回退过程中只执行回退操作,不进行校验 - # 校验将在 process_reservation_attend_window 中统一进行,使用映射表中的数据 - return True + # 回退过程中只执行回退操作,不进行校验;校验将在 process_reservation_attend_window 中统一进行。 + # 只有在实际执行了滑动(moved=True)时返回 True,避免在未移动时被误判为“回退成功”。 + return bool(moved) @staticmethod # type: ignore[misc] def handle_reservation_direct_attend(analyser: Any) -> None: @@ -1042,23 +1124,38 @@ def _dump_room_pos_map_to_state(analyser: Any) -> None: final_path = os.path.join(state_dir, "room_pos_map.json") tmp_path = final_path + ".tmp" - # 过滤掉空条目,只保留本次运行有值的映射 + # 过滤并保留映射: + # - 对于 dict 条目(新格式),保留完整 dict(以便包含 fudai_detail 等字段) + # - 对于旧格式 list/tuple,保持原有行为(写入 [title, title_raw]) + # 条件:如果条目没有标题/原始标题且也不包含福袋信息,则跳过 filtered = {} for k, v in room_pos_map.items(): try: if isinstance(v, dict): title = (v.get("title", "") or "").strip() title_raw = (v.get("title_raw", "") or "").strip() + has_fudai = bool(v.get("has_fudai", False)) + fudai_detail = v.get("fudai_detail") + # 如果既没有标题也没有福袋信息,则跳过 + if ( + not title + and not title_raw + and not has_fudai + and not fudai_detail + ): + continue + # 保留完整 dict,便于 GUI 读取更多字段 + filtered[str(k)] = v else: - # 兼容旧格式 + # 兼容旧格式:仍然写入 [title, title_raw] title = (v[0] or "").strip() if len(v) > 0 else "" title_raw = (v[1] or "").strip() if len(v) > 1 else "" + if not title and not title_raw: + continue + filtered[str(k)] = [title, title_raw] except Exception: - title = "" - title_raw = "" - if not title and not title_raw: + # 忽略单条处理错误,继续下一个 continue - filtered[str(k)] = [title, title_raw] # 准备写入数据:保留原有 top-level 映射结构,同时添加一个保留的元信息字段 data = dict(filtered) diff --git a/douyin/reservation/douyin_reservation_logic.py b/douyin/reservation/douyin_reservation_logic.py index 9d2f4ad..ea07b84 100644 --- a/douyin/reservation/douyin_reservation_logic.py +++ b/douyin/reservation/douyin_reservation_logic.py @@ -1885,8 +1885,13 @@ def process_reservation_attend_window( target_room_title_raw, ) ) - if mapped_target_pos is not None and mapped_target_pos > 0: - updated_target["pos_seen"] = int(mapped_target_pos) + if ( + mapped_target_pos is not None + and mapped_target_pos > 0 + ): + updated_target["pos_seen"] = int( + mapped_target_pos + ) try: analyser._log_kv( "预约", @@ -1920,12 +1925,17 @@ def process_reservation_attend_window( # 识别当前直播间标题(优先缓存,必要时重新识别) current_room_title = str( - getattr(analyser, "current_room_title", "") or "" + getattr(analyser, "current_room_title", "") + or "" ).strip() current_room_title_raw = str( - getattr(analyser, "current_room_title_raw", "") or "" + getattr(analyser, "current_room_title_raw", "") + or "" ).strip() - if not current_room_title and not current_room_title_raw: + if ( + not current_room_title + and not current_room_title_raw + ): try: from douyin.fudai import douyin_fudai_detail @@ -1935,10 +1945,8 @@ def process_reservation_attend_window( ( current_room_title, current_room_title_raw, - ) = ( - douyin_fudai_detail.read_live_room_title_core( - analyser, y_pianyi_val - ) + ) = douyin_fudai_detail.read_live_room_title_core( + analyser, y_pianyi_val ) try: analyser.current_room_title = ( @@ -1967,12 +1975,15 @@ def process_reservation_attend_window( ): try: old_room_pos = int( - getattr(analyser, "room_pos", 0) or 0 + getattr(analyser, "room_pos", 0) + or 0 ) except Exception: old_room_pos = 0 try: - analyser.room_pos = int(mapped_current_pos) + analyser.room_pos = int( + mapped_current_pos + ) except Exception: pass try: @@ -2034,8 +2045,12 @@ def process_reservation_attend_window( analyser._log_kv( "预约", "[预约] 映射表显示已在目标位置,但校验失败,跳过二次回退", - mapped_current_pos=int(mapped_current_pos), - mapped_target_pos=int(mapped_target_pos), + mapped_current_pos=int( + mapped_current_pos + ), + mapped_target_pos=int( + mapped_target_pos + ), ) except Exception: pass diff --git a/gui/gui_app.py b/gui/gui_app.py index 238d780..cf678c7 100644 --- a/gui/gui_app.py +++ b/gui/gui_app.py @@ -2759,9 +2759,7 @@ def main(): notebook.add(win_record_tab, text="中奖记录") # 将运行时映射表加入右侧 Notebook mapping_tab = ttk.Frame(notebook) - map_box = ttk.LabelFrame( - mapping_tab, text="运行时映射表(包含福袋详情)" - ) + map_box = ttk.LabelFrame(mapping_tab, text="运行时映射表(包含福袋详情)") map_box.pack(fill=X, padx=10, pady=(10, 10)) map_ctrl = ttk.Frame(map_box) @@ -2965,18 +2963,21 @@ def main(): countdown_text = "-" if isinstance(fudai_detail, dict): task_list = ( - str(fudai_detail.get("task_list") or "") - .strip() + str( + fudai_detail.get("task_list") or "" + ).strip() or "-" ) button_text = ( - str(fudai_detail.get("button_text") or "") - .strip() + str( + fudai_detail.get("button_text") or "" + ).strip() or "-" ) fudai_time = ( - str(fudai_detail.get("time_text") or "") - .strip() + str( + fudai_detail.get("time_text") or "" + ).strip() or "-" ) fudai_value = ( @@ -2994,8 +2995,12 @@ def main(): if fudai_detail.get("copies") else "-" ) - mm = str(fudai_detail.get("countdown_mm") or "").strip() - ss = str(fudai_detail.get("countdown_ss") or "").strip() + mm = str( + fudai_detail.get("countdown_mm") or "" + ).strip() + ss = str( + fudai_detail.get("countdown_ss") or "" + ).strip() if fudai_time and fudai_time != "-": countdown_text = fudai_time elif mm or ss: