diff --git a/douyin/core/douyin_fudai.py b/douyin/core/douyin_fudai.py index 7d5729e..a96f533 100644 --- a/douyin/core/douyin_fudai.py +++ b/douyin/core/douyin_fudai.py @@ -750,95 +750,16 @@ class fudai_analyse: return # 异常时继续正常流程 else: - # 步骤2:读取福袋详情 - step2_start = time.time() - # 第一次打开:完整读取详情(包括内容、倒计时、价值) - detail = douyin_fudai_detail.read_fudai_detail_with_retries( - self, - fudai_x=0, - read_once_callback=douyin_fudai_detail.read_fudai_detail_once, - close_detail_callback=douyin_fudai_detail.close_fudai_detail, - ensure_open_callback=douyin_fudai_detail.ensure_fudai_detail_open, + # 步骤2:读取福袋详情 + 数据验证 + 筛选检查 + from douyin.core.fudai_modules.fudai_detail_helpers import ( + handle_first_open_step2, ) - # 在第一次打开时立即进行筛选检查,如果不符合要求则直接跳过 - # 注意:这里只检查筛选条件,不执行参与操作 - if detail and isinstance(detail, tuple) and len(detail) >= 6: - # 先进行数据验证 - is_valid = True - try: - is_valid, reason = douyin_fudai_detail.validate_fudai_detail( - detail, self - ) - if not is_valid: - from douyin.core.fudai_modules.fudai_detail_helpers import ( - handle_first_open_validation_failed, - ) - - handle_first_open_validation_failed( - self, start_time, step2_start, reason - ) - return - except Exception: - pass - - # 步骤3:筛选检查 - step3_start = time.time() - # 执行筛选检查(不执行参与操作,只检查是否符合筛选条件) - try: - skip, skip_reason = douyin_fudai_core.should_skip_fudai_by_config( - self, detail - ) - if skip: - # 检查是否是高价值福袋,如果是则记录预约或立即参与 - from douyin.core.fudai_modules.fudai_detail_helpers import ( - check_high_value_skip_decision, - ) - - decision = check_high_value_skip_decision( - self, detail, skip_reason, start_time - ) - if decision == "recorded": - return - elif decision == "attend": - # 不关闭详情,继续走立即参与逻辑(保存详情数据,标记为已读取) - skip = False - - # 如果不是高价值福袋,或者不是倒计时原因,筛选不通过,直接跳过 - if skip: - from douyin.core.fudai_modules.fudai_detail_helpers import ( - handle_filter_skip, - ) - - handle_filter_skip(self, skip_reason, start_time) - return - except Exception as e: - # 筛选检查异常,记录日志但继续流程 - try: - self._log_kv( - "流程", - "_handle_in_fudai_detail:筛选检查异常", - error=str(e), - ) - except Exception: - pass - - # 筛选通过,保存详情数据并标记为已读取 - from douyin.core.fudai_modules.fudai_detail_helpers import ( - save_first_open_detail, - ) - - save_first_open_detail(self, detail) - else: - # 详情数据无效,不保存,不标记为已读取 - try: - self._log_kv( - "流程", - "_handle_in_fudai_detail:第一次打开时详情数据无效,跳过", - ) - except Exception: - pass + step2_result = handle_first_open_step2(self, start_time) + if step2_result is None: return + detail, skip, skip_reason = step2_result + step3_start = time.time() # 兼容后续 step3_elapsed 日志 # 检查是否是优惠券弹窗、观看任务或识别错误:根据 _last_fudai_detail_status 分发到对应处理 from douyin.core.fudai_modules.fudai_detail_helpers import ( diff --git a/douyin/core/fudai_modules/fudai_detail_helpers.py b/douyin/core/fudai_modules/fudai_detail_helpers.py index 34a02de..77d17cb 100644 --- a/douyin/core/fudai_modules/fudai_detail_helpers.py +++ b/douyin/core/fudai_modules/fudai_detail_helpers.py @@ -273,6 +273,86 @@ def handle_no_fudai_in_live_room(analyser, room_pos_ref, start_time: float) -> N ) +def handle_first_open_step2(analyser, start_time: float): + """步骤2:第一次打开福袋详情。 + + 流程: + 1. read_fudai_detail_with_retries 完整读取详情 + 2. 验证 detail 有效性(含数据验证 + 步骤2.5 步骤3 筛选检查) + 3. 命中早返回则 helper 内部已处理;否则保存详情 + + 返回 (detail, skip, skip_reason) 三元组,调用方据此决定后续流程。 + 若已早返回,返回 None。 + """ + from douyin.fudai import douyin_fudai_core, douyin_fudai_detail + + step2_start = time.time() + # 第一次打开:完整读取详情 + detail = douyin_fudai_detail.read_fudai_detail_with_retries( + analyser, + fudai_x=0, + read_once_callback=douyin_fudai_detail.read_fudai_detail_once, + close_detail_callback=douyin_fudai_detail.close_fudai_detail, + ensure_open_callback=douyin_fudai_detail.ensure_fudai_detail_open, + ) + + skip = False + skip_reason = "" + + if detail and isinstance(detail, tuple) and len(detail) >= 6: + # 数据验证 + try: + is_valid, reason = douyin_fudai_detail.validate_fudai_detail(detail, analyser) + if not is_valid: + handle_first_open_validation_failed( + analyser, start_time, step2_start, reason + ) + return None + except Exception: + pass + + # 步骤3:筛选检查 + try: + skip, skip_reason = douyin_fudai_core.should_skip_fudai_by_config( + analyser, detail + ) + if skip: + decision = check_high_value_skip_decision( + analyser, detail, skip_reason, start_time + ) + if decision == "recorded": + return None + elif decision == "attend": + skip = False + + if skip: + handle_filter_skip(analyser, skip_reason, start_time) + return None + except Exception as e: + try: + analyser._log_kv( + "流程", + "_handle_in_fudai_detail:筛选检查异常", + error=str(e), + ) + except Exception: + pass + + # 筛选通过:保存详情数据 + save_first_open_detail(analyser, detail) + return (detail, skip, skip_reason) + else: + # 详情数据无效 + try: + analyser._log_kv( + "流程", + "_handle_in_fudai_detail:第一次打开时详情数据无效,跳过", + ) + except Exception: + pass + return None + + def maybe_run_yanghao_during_run(analyser) -> None: """如果配置了 yanghao_recommend_interval_seconds,按间隔触发推荐页养号。