diff --git a/config/config.json b/config/config.json index 55dcd17..342fa37 100644 --- a/config/config.json +++ b/config/config.json @@ -28,7 +28,7 @@ "yanghao_fallback_enter_live_x": 540, "yanghao_fallback_enter_live_y": 1200, "fudai_find_max_attempts": 99999, - "fudai_icon_max_wait_seconds": 5.0, + "fudai_icon_max_wait_seconds": 7.0, "fudai_icon_retry_delay_seconds": 0.1, "fudai_exit_after_misses": 10, "enable_back_on_misses": false, diff --git a/douyin/fudai/douyin_fudai_core.py b/douyin/fudai/douyin_fudai_core.py index 0bb42a9..3fba74d 100644 --- a/douyin/fudai/douyin_fudai_core.py +++ b/douyin/fudai/douyin_fudai_core.py @@ -1024,10 +1024,10 @@ def get_fudai_contain(analyser, renwu: int = 2) -> Tuple[str, str, int, int, flo try: # 导入直播间标题识别函数 from fudai_detail_modules.fudai_detail_room_title import _ocr_try_room_title - + # 使用已切割的图片进行OCR识别 title, raw_text = _ocr_try_room_title(analyser, "live_room_title_mid", 0) - + # 返回结果元组 return title, raw_text except Exception as e_inner: @@ -4633,7 +4633,7 @@ def basic_join_decision( current_room_title_raw = str( getattr(analyser, "current_room_title_raw", "") or "" ).strip() - + # 如果缓存为空,才重新读取直播间标题 if not current_room_title: try: diff --git a/douyin/handlers/douyin_swipe_handler.py b/douyin/handlers/douyin_swipe_handler.py index f910823..1f96651 100644 --- a/douyin/handlers/douyin_swipe_handler.py +++ b/douyin/handlers/douyin_swipe_handler.py @@ -118,6 +118,15 @@ class SwipeHandler: except Exception: pass + # 清除直播间标题相关缓存,确保新直播间会重新识别标题 + try: + analyser.current_room_title = "" + analyser.current_room_title_raw = "" + analyser._room_title_identified_positions = set() + analyser._screenshot_ready_for_ocr = False + except Exception: + pass + # 记录当前直播间的标题和位置到运行时映射表(用于回退校验) # 切换前已记录,这里跳过避免重复 try: diff --git a/douyin/reservation/douyin_reservation_handler.py b/douyin/reservation/douyin_reservation_handler.py index 3ef103e..6d0e164 100644 --- a/douyin/reservation/douyin_reservation_handler.py +++ b/douyin/reservation/douyin_reservation_handler.py @@ -225,10 +225,12 @@ class ReservationHandler: room_pos = int(getattr(analyser, "room_pos", 0) or 0) # 检查是否已经为当前直播间识别过标题,避免重复截图和OCR - identified_positions = getattr(analyser, "_room_title_identified_positions", set()) + identified_positions = getattr( + analyser, "_room_title_identified_positions", set() + ) if not isinstance(identified_positions, set): identified_positions = set() - + if room_pos in identified_positions: # 已经识别过,直接使用缓存的标题 try: diff --git a/douyin/reservation/douyin_reservation_verify.py b/douyin/reservation/douyin_reservation_verify.py index 7bdf043..35cc217 100644 --- a/douyin/reservation/douyin_reservation_verify.py +++ b/douyin/reservation/douyin_reservation_verify.py @@ -382,10 +382,26 @@ def validate_back_to_reservation( if expected_title: try: - y_pianyi_val = int(getattr(analyser, "y_pianyi", 0) or 0) - current_title, current_title_raw = ( - douyin_fudai_detail.read_live_room_title_core(analyser, y_pianyi_val) - ) + # 优先使用缓存的直播间标题,避免重复截图和OCR + current_title = str(getattr(analyser, "current_room_title", "") or "").strip() + current_title_raw = str(getattr(analyser, "current_room_title_raw", "") or "").strip() + + if not current_title: + # 缓存为空,才重新识别 + y_pianyi_val = int(getattr(analyser, "y_pianyi", 0) or 0) + current_title, current_title_raw = ( + douyin_fudai_detail.read_live_room_title_core(analyser, y_pianyi_val) + ) + else: + try: + analyser._log_kv( + "预约", + "validate_back_to_reservation:复用缓存的直播间标题", + current_title=current_title, + log_type="DEBUG", + ) + except Exception: + pass # 计算预期标题与当前标题的相似度 ratio = 0.0 diff --git a/fudai_detail_modules/fudai_detail_reader.py b/fudai_detail_modules/fudai_detail_reader.py index bf33e2d..3228125 100644 --- a/fudai_detail_modules/fudai_detail_reader.py +++ b/fudai_detail_modules/fudai_detail_reader.py @@ -370,7 +370,7 @@ def read_fudai_detail_once(analyser: Any) -> Tuple[str, Tuple, dict]: try: ocr_start = time.time() - + content, time_text, participants, copies, prize_value_yuan = get_fudai_contain( analyser, renwu=task_count ) diff --git a/fudai_detail_modules/fudai_detail_room_title.py b/fudai_detail_modules/fudai_detail_room_title.py index a55c21a..cd0bd69 100644 --- a/fudai_detail_modules/fudai_detail_room_title.py +++ b/fudai_detail_modules/fudai_detail_room_title.py @@ -187,8 +187,23 @@ def read_live_room_title_core( 只使用指定区域 (144,144) 到 (329,185) 进行识别,避免多次截图。 """ + # 检查是否可以复用已有的截图 + screenshot_reused = False try: - analyser.operation.get_screenshot(analyser.device_id) + if getattr(analyser, "_screenshot_ready_for_ocr", False): + screenshot_reused = True + analyser._screenshot_ready_for_ocr = False # 清除标志,避免重复使用 + try: + analyser._log_kv( + "直播间标题", + "read_live_room_title_core:复用已有截图", + log_type="SCREENSHOT", + reason="screenshot_ready_for_ocr", + ) + except Exception: + pass + else: + analyser.operation.get_screenshot(analyser.device_id) except Exception as e: try: analyser._log_kv(