diff --git a/douyin/core/douyin_fudai.py b/douyin/core/douyin_fudai.py index 7169313..c8f7d1a 100644 --- a/douyin/core/douyin_fudai.py +++ b/douyin/core/douyin_fudai.py @@ -1295,93 +1295,12 @@ class fudai_analyse: return elif last_status == "error": # 检查是否是任务数量为0的错误 - try: - last_extra = getattr(self, "_last_fudai_detail_extra", {}) - if ( - isinstance(last_extra, dict) - and last_extra.get("reason") == "task_count_zero" - ): - # 记录连续失败次数 - consecutive_failures = ( - getattr(self, "_fudai_detail_consecutive_failures", 0) or 0 - ) - consecutive_failures += 1 - try: - self._fudai_detail_consecutive_failures = ( - consecutive_failures - ) - except Exception: - pass + from douyin.core.fudai_modules.fudai_detail_helpers import ( + handle_task_count_zero_error, + ) - # 如果连续失败3次,强制关闭详情页并切换直播间,避免卡死 - if consecutive_failures >= 3: - try: - self._log_kv( - "流程", - "_handle_in_fudai_detail:连续3次识别到任务数量为0,强制关闭详情页并切换直播间,避免卡死", - consecutive_failures=consecutive_failures, - ) - except Exception: - pass - # 强制关闭详情页 - try: - douyin_fudai_detail.close_fudai_detail(self) - self.operation.delay(0.5) - except Exception: - pass - # 切换直播间 - try: - needswitch = bool(getattr(self, "needswitch", True)) - except Exception: - needswitch = True - if needswitch: - try: - from douyin.core.fudai_modules.fudai_detail_helpers import ( - fallback_swipe_up_to_next_live, - ) - - fallback_swipe_up_to_next_live(self) - self.operation.delay(0.5) - except Exception: - pass - # 重置失败计数 - try: - self._fudai_detail_consecutive_failures = 0 - except Exception: - pass - - # 清除任务数量标志 - clear_task_count_flag(self) - - elapsed = time.time() - start_time - self._log_kv( - "流程", - "_handle_in_fudai_detail完成(连续失败)", - elapsed_seconds=round(elapsed, 2), - ) - return - else: - try: - self._log_kv( - "流程", - "_handle_in_fudai_detail:检测到任务数量为0,跳过后续处理", - consecutive_failures=consecutive_failures, - ) - except Exception: - pass - - # 清除任务数量标志 - clear_task_count_flag(self) - - elapsed = time.time() - start_time - self._log_kv( - "流程", - "_handle_in_fudai_detail完成(任务数量为0)", - elapsed_seconds=round(elapsed, 2), - ) - return - except Exception: - pass + if handle_task_count_zero_error(self, start_time): + return except Exception: pass diff --git a/douyin/core/fudai_modules/fudai_detail_helpers.py b/douyin/core/fudai_modules/fudai_detail_helpers.py index 0a3bb9a..f667cb7 100644 --- a/douyin/core/fudai_modules/fudai_detail_helpers.py +++ b/douyin/core/fudai_modules/fudai_detail_helpers.py @@ -42,6 +42,101 @@ def log_screenshot_failed( pass +def handle_task_count_zero_error(analyser, start_time: float) -> bool: + """_handle_in_fudai_detail 中"task_count_zero"错误的处理。 + + 流程: + - 累加 _fudai_detail_consecutive_failures 计数 + - 连续 3 次失败:强制关闭详情 + 切换直播间 + 重置计数 + 写完成日志 + - 否则:写日志 + 写完成日志 + + 返回: + True:已处理 task_count_zero 错误(调用方应直接 return) + False:不是 task_count_zero 错误或处理异常,调用方继续 + """ + from douyin.fudai import douyin_fudai_detail + + try: + last_extra = getattr(analyser, "_last_fudai_detail_extra", {}) + if not ( + isinstance(last_extra, dict) + and last_extra.get("reason") == "task_count_zero" + ): + return False + + # 记录连续失败次数 + consecutive_failures = ( + getattr(analyser, "_fudai_detail_consecutive_failures", 0) or 0 + ) + consecutive_failures += 1 + try: + analyser._fudai_detail_consecutive_failures = consecutive_failures + except Exception: + pass + + if consecutive_failures >= 3: + # 连续失败 3 次:强制关闭 + 切换 + 重置 + try: + analyser._log_kv( + "流程", + "_handle_in_fudai_detail:连续3次识别到任务数量为0,强制关闭详情页并切换直播间,避免卡死", + consecutive_failures=consecutive_failures, + ) + except Exception: + pass + try: + douyin_fudai_detail.close_fudai_detail(analyser) + analyser.operation.delay(0.5) + except Exception: + pass + + try: + needswitch = bool(getattr(analyser, "needswitch", True)) + except Exception: + needswitch = True + if needswitch: + try: + fallback_swipe_up_to_next_live(analyser) + analyser.operation.delay(0.5) + except Exception: + pass + try: + analyser._fudai_detail_consecutive_failures = 0 + except Exception: + pass + + clear_task_count_flag(analyser) + + elapsed = time.time() - start_time + analyser._log_kv( + "流程", + "_handle_in_fudai_detail完成(连续失败)", + elapsed_seconds=round(elapsed, 2), + ) + return True + else: + try: + analyser._log_kv( + "流程", + "_handle_in_fudai_detail:检测到任务数量为0,跳过后续处理", + consecutive_failures=consecutive_failures, + ) + except Exception: + pass + + clear_task_count_flag(analyser) + + elapsed = time.time() - start_time + analyser._log_kv( + "流程", + "_handle_in_fudai_detail完成(任务数量为0)", + elapsed_seconds=round(elapsed, 2), + ) + return True + except Exception: + return False + + def process_reservation_multi_room_mode( analyser, focus_ref,