From c0df59ac26df718fb2371c04a3c00c99b8e5ca14 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 4 Jan 2026 10:18:51 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E5=AE=89=E5=85=A8?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91=EF=BC=8C?= =?UTF-8?q?=E7=A1=AE=E4=BF=9D=20detail=20=E6=95=B0=E6=8D=AE=E7=9A=84?= =?UTF-8?q?=E7=A8=B3=E5=AE=9A=E6=80=A7=E5=92=8C=E7=B1=BB=E5=9E=8B=E5=AE=89?= =?UTF-8?q?=E5=85=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- douyin/core/douyin_fudai.py | 43 +++++++++-- douyin/core/state/reservations.json | 34 ++++++--- douyin/fudai/douyin_fudai_core.py | 113 ++-------------------------- gui/web_gui.py | 7 ++ run_cli.py | 14 ++++ webui/app.js | 2 + webui/index.html | 5 ++ 7 files changed, 97 insertions(+), 121 deletions(-) diff --git a/douyin/core/douyin_fudai.py b/douyin/core/douyin_fudai.py index 99dfa04..08bf68c 100644 --- a/douyin/core/douyin_fudai.py +++ b/douyin/core/douyin_fudai.py @@ -191,6 +191,8 @@ class fudai_analyse: # 高价值直播间"回访"相关(当前仅保留配置,不在本地版强制启用复杂逻辑) self.high_value_room_revisit_enabled: bool = False self.high_value_room_revisit_only_current_run: bool = False + # 高价值直播间回访间隔(秒):重访间隔,GUI 可配置 + self.high_value_room_revisit_interval_seconds: int = 3600 # 粉丝团相关配置 self.auto_join_fansclub: bool = False # 是否自动加入粉丝团 @@ -2484,7 +2486,11 @@ class fudai_analyse: ensure_open_callback=douyin_fudai_detail.ensure_fudai_detail_open, ) # 重新读取后,更新保存的详情数据 - safe_detail = tuple(detail) if isinstance(detail, (list, tuple)) and len(detail) >= 6 else None + safe_detail = ( + tuple(detail) + if isinstance(detail, (list, tuple)) and len(detail) >= 6 + else None + ) if safe_detail: # 保持存储为 tuple,避免后续可变性导致问题 try: @@ -2496,7 +2502,11 @@ class fudai_analyse: try: # 从保存的 tuple 中安全读取倒计时信息,使用 cast 明确类型以帮助静态分析 detail = getattr(self, "_last_fudai_detail_tuple", None) - safe_detail = tuple(detail) if isinstance(detail, (list, tuple)) and len(detail) >= 6 else None + safe_detail = ( + tuple(detail) + if isinstance(detail, (list, tuple)) and len(detail) >= 6 + else None + ) if safe_detail: # 确认 safe_detail 为序列后再索引,避免静态分析误报 try: @@ -2576,7 +2586,11 @@ class fudai_analyse: # 注意:这里只检查筛选条件,不执行参与操作 # 为了避免静态分析将 `detail` 视为不可下标对象,先构造一个 # 明确为序列的本地变量 `safe_detail`(类型为 tuple),后续所有索引/解包均使用它。 - safe_detail: Optional[Tuple[Any, ...]] = tuple(detail) if isinstance(detail, (list, tuple)) and len(detail) >= 6 else None + safe_detail: Optional[Tuple[Any, ...]] = ( + tuple(detail) + if isinstance(detail, (list, tuple)) and len(detail) >= 6 + else None + ) if safe_detail: # 先进行数据验证 is_valid = True @@ -3090,7 +3104,11 @@ class fudai_analyse: # 兜底检查:如果价值为0且内容为空,也可能是优惠券弹窗或识别错误 try: - safe_detail = detail if isinstance(detail, (list, tuple)) and len(detail) >= 5 else None + safe_detail = ( + detail + if isinstance(detail, (list, tuple)) and len(detail) >= 5 + else None + ) if safe_detail: content = str(safe_detail[0] or "") try: @@ -3122,7 +3140,11 @@ class fudai_analyse: # 记录当前福袋的 future_ts,供 attend_choujiang 使用 try: - safe_detail = detail if isinstance(detail, (list, tuple)) and len(detail) >= 6 else None + safe_detail = ( + detail + if isinstance(detail, (list, tuple)) and len(detail) >= 6 + else None + ) if safe_detail: try: countdown_tuple = safe_detail[5] @@ -3168,13 +3190,20 @@ class fudai_analyse: countdown_tuple = None remain_seconds = 0 future_timestamp = 0.0 - safe_detail = detail if isinstance(detail, (list, tuple)) and len(detail) >= 6 else None + safe_detail = ( + detail + if isinstance(detail, (list, tuple)) and len(detail) >= 6 + else None + ) if safe_detail: try: countdown_tuple = safe_detail[5] except Exception: countdown_tuple = None - if isinstance(countdown_tuple, (tuple, list)) and len(countdown_tuple) >= 2: + if ( + isinstance(countdown_tuple, (tuple, list)) + and len(countdown_tuple) >= 2 + ): # countdown_tuple[0] 是 countdown_start(开始时间戳) # countdown_tuple[1] 是 countdown_end(结束时间戳/开奖时间戳) future_timestamp = float(countdown_tuple[1] or 0.0) diff --git a/douyin/core/state/reservations.json b/douyin/core/state/reservations.json index c1e057b..c37f0b8 100644 --- a/douyin/core/state/reservations.json +++ b/douyin/core/state/reservations.json @@ -1,9 +1,9 @@ { - "updated_ts": 1767492808.7388206, - "reason": "record_reservation", + "updated_ts": 1767493122.2555935, + "reason": "process_reservation", "room_pos": 0, - "current_room_title": "彩虹夫妇", - "current_room_title_raw": "彩虹夫妇", + "current_room_title": "作I帮数", + "current_room_title_raw": "作I帮数。。", "reservations": [ { "prize_value_yuan": 6999.0, @@ -13,11 +13,27 @@ "pos_seen": 0, "room_title": "彩虹夫妇", "room_title_raw": "彩虹夫妇", - "created_ts": 1767492808.7325442, - "task_count": 2, - "time_text": "06:51", - "participants": 0, - "copies": 0 + "created_ts": 1767492808.7325442 + }, + { + "prize_value_yuan": 5999.0, + "content": "", + "future_ts": 1767493379.73886, + "future_str": "2026-01-04 10:22:59", + "pos_seen": 3, + "room_title": "刘媛媛媛", + "room_title_raw": "刘媛媛.媛", + "created_ts": 1767492999.3043623 + }, + { + "prize_value_yuan": 1999.0, + "content": "", + "future_ts": 1767494003.40085, + "future_str": "2026-01-04 10:33:23", + "pos_seen": 0, + "room_title": "作川帮数", + "room_title_raw": "作川帮数。。", + "created_ts": 1767493120.9476802 } ] } \ No newline at end of file diff --git a/douyin/fudai/douyin_fudai_core.py b/douyin/fudai/douyin_fudai_core.py index 98cdf6a..5a51654 100644 --- a/douyin/fudai/douyin_fudai_core.py +++ b/douyin/fudai/douyin_fudai_core.py @@ -62,22 +62,6 @@ def _get_fudai_ocr_executor(optimal_workers: int) -> ThreadPoolExecutor: return executor -def _build_fudai_key_from_analyser(analyser) -> str: - """构造一个尽可能稳定的福袋唯一键,供统计去重使用。 - - 使用 content|prize|countdown 三元组组合。 - """ - try: - last = getattr(analyser, "_fudai_last", None) or {} - content = str(last.get("content") or "").strip() - prize = str(last.get("prize_value_yuan") or "").strip() - countdown = str(last.get("countdown") or "").strip() - key = f"{content}|{prize}|{countdown}" - return key - except Exception: - return "" - - def get_fudai_contain(analyser, renwu: int = 2) -> Tuple[str, str, int, int, float]: """获取福袋的内容和倒计时(从 `fudai_analyse.get_fudai_contain` 抽离)。""" @@ -1149,7 +1133,7 @@ def get_fudai_contain(analyser, renwu: int = 2) -> Tuple[str, str, int, int, flo "OCR识别任务列表区域", task_list_text=task_list_raw[:200] if task_list_raw else "", ) - except Exception as e_pl1: + except Exception as e_inner: try: analyser._log_kv( "错误", @@ -1169,7 +1153,7 @@ def get_fudai_contain(analyser, renwu: int = 2) -> Tuple[str, str, int, int, flo "任务列表OCR识别到'观看X分钟'类任务,直接跳过后续处理", task_list_text=task_list_raw[:200] if task_list_raw else "", ) - except Exception as e_pl2: + except Exception as e_inner: try: analyser._log_kv( "错误", @@ -1183,7 +1167,7 @@ def get_fudai_contain(analyser, renwu: int = 2) -> Tuple[str, str, int, int, flo # 设置标志,让调用方知道这是观看任务 try: analyser._is_watch_task_detected = True - except Exception as e_pl3: + except Exception as e_inner: try: analyser._log_kv( "错误", @@ -1241,7 +1225,7 @@ def get_fudai_contain(analyser, renwu: int = 2) -> Tuple[str, str, int, int, flo status=button_status, button_text=button_text[:100] if button_text else "", ) - except Exception as e_pl4: + except Exception as e_inner: try: analyser._log_kv( "错误", @@ -1262,7 +1246,7 @@ def get_fudai_contain(analyser, renwu: int = 2) -> Tuple[str, str, int, int, flo task_count=renwu, button_status=button_status or "未识别", ) - except Exception as e_pl5: + except Exception as e_inner: try: analyser._log_kv( "错误", @@ -1343,13 +1327,13 @@ def get_fudai_contain(analyser, renwu: int = 2) -> Tuple[str, str, int, int, flo name_tl2 = preprocess_for_ocr(analyser, "福袋任务列表") return analyser.operation.analyse_pic_word(name_tl2, 0) - except Exception as e_pl6: + except Exception as e_inner2: try: analyser._log_kv( "错误", "备用OCR识别任务列表失败", - error=str(e_pl6), - error_type=type(e_pl6).__name__, + error=str(e_inner2), + error_type=type(e_inner2).__name__, level="WARNING", ) except Exception: @@ -1838,40 +1822,6 @@ def get_fudai_contain(analyser, renwu: int = 2) -> Tuple[str, str, int, int, flo content=content_for_log, # 同时作为字段输出 ) - # 结构化统计日志:识别到福袋(attempt),并在首次出现时标记 unique - try: - fudai_key = _build_fudai_key_from_analyser(analyser) - analyser._log_kv( - "统计", - "fudai_seen", - metric="fudai_seen", - metric_type="attempt", - run_id=getattr(analyser, "_run_id", None), - fudai_key=fudai_key, - value=1, - ) - # 唯一口径去重(在 analyser 实例上维护一组) - try: - seen_set = getattr(analyser, "_fudai_seen_keys", None) - if seen_set is None: - seen_set = set() - setattr(analyser, "_fudai_seen_keys", seen_set) - if fudai_key and fudai_key not in seen_set: - seen_set.add(fudai_key) - analyser._log_kv( - "统计", - "fudai_seen", - metric="fudai_seen", - metric_type="unique", - run_id=getattr(analyser, "_run_id", None), - fudai_key=fudai_key, - value=1, - ) - except Exception: - pass - except Exception: - pass - # 记录进入直播间到识别到福袋的耗时(仅记录一次) try: if getattr(analyser, "_enter_live_ts", 0.0) and not getattr( @@ -2230,39 +2180,6 @@ def attend_choujiang(analyser) -> bool: analyser._log_kv("参与", "识别参与按钮", text=attend_button_text) if "参与成功" in attend_button_text: # 如果识别到已经参与抽奖 analyser._log_kv("参与", "已参与,等待开奖", result="已参与") - # 结构化统计:参与成功(已参与检测) - try: - fudai_key = _build_fudai_key_from_analyser(analyser) - analyser._log_kv( - "统计", - "fudai_attend_ok", - metric="fudai_attend_ok", - metric_type="attempt", - run_id=getattr(analyser, "_run_id", None), - fudai_key=fudai_key, - value=1, - ) - # 唯一口径 - try: - att_set = getattr(analyser, "_fudai_attend_keys", None) - if att_set is None: - att_set = set() - setattr(analyser, "_fudai_attend_keys", att_set) - if fudai_key and fudai_key not in att_set: - att_set.add(fudai_key) - analyser._log_kv( - "统计", - "fudai_attend_ok", - metric="fudai_attend_ok", - metric_type="unique", - run_id=getattr(analyser, "_run_id", None), - fudai_key=fudai_key, - value=1, - ) - except Exception: - pass - except Exception: - pass # 记录最后一次成功参与的时间 try: analyser._last_successful_attend_ts = time.time() @@ -2396,20 +2313,6 @@ def attend_choujiang(analyser) -> bool: base_y=2070, region="(306,2030)-(780,2110)", ) - # 结构化统计:点击参与(attempt) - try: - fudai_key = _build_fudai_key_from_analyser(analyser) - analyser._log_kv( - "统计", - "fudai_click_attend", - metric="fudai_click_attend", - metric_type="attempt", - run_id=getattr(analyser, "_run_id", None), - fudai_key=fudai_key, - value=1, - ) - except Exception: - pass # 设置标志:点击参与抽奖后直接查找福袋,跳过阶段检测 # 注意:点击参与按钮后会自动关闭详情页,返回直播间 diff --git a/gui/web_gui.py b/gui/web_gui.py index aea5edc..f48f790 100644 --- a/gui/web_gui.py +++ b/gui/web_gui.py @@ -1288,6 +1288,13 @@ class ProcRunner: cmd.append("--high-value-room-revisit-disabled") if high_value_room_revisit_only_current_run: cmd.append("--high-value-room-revisit-only-current-run") + # 可选:通过 GUI 指定回访间隔(秒) + try: + rv_interval = int(_pick("high_value_room_revisit_interval_seconds", 0) or 0) + except Exception: + rv_interval = 0 + if rv_interval > 0: + cmd += ["--high-value-room-revisit-interval-seconds", str(rv_interval)] # 预约回退校验开关(由 Run 面板控制) reservation_back_verify_enabled = bool( diff --git a/run_cli.py b/run_cli.py index be4c98f..6805014 100644 --- a/run_cli.py +++ b/run_cli.py @@ -199,6 +199,12 @@ def parse_args(argv: list[str]) -> argparse.Namespace: action="store_true", help="仅回访本次运行记录的高价值直播间", ) + p.add_argument( + "--high-value-room-revisit-interval-seconds", + type=int, + default=None, + help="高价值直播间回访间隔(秒),用于覆盖配置中的回访间隔", + ) p.add_argument( "--reservation-back-verify-enabled", action="store_true", @@ -465,6 +471,14 @@ def main(argv: list[str]) -> int: analyser.high_value_room_revisit_enabled = False if getattr(args, "high_value_room_revisit_only_current_run", False): analyser.high_value_room_revisit_only_current_run = True + # 回访间隔覆盖(秒) + if getattr(args, "high_value_room_revisit_interval_seconds", None) is not None: + try: + analyser.high_value_room_revisit_interval_seconds = max( + 0, int(args.high_value_room_revisit_interval_seconds) + ) + except Exception: + pass # 预约回退校验开关(命令行优先) if getattr(args, "reservation_back_verify_enabled", False): analyser.reservation_back_verify_enabled = True diff --git a/webui/app.js b/webui/app.js index c444b46..3fb5df7 100644 --- a/webui/app.js +++ b/webui/app.js @@ -42,6 +42,7 @@ const DEFAULTS = { high_value_fudai_after_action: "continue", high_value_room_revisit_enabled: true, high_value_room_revisit_only_current_run: false, + high_value_room_revisit_interval_seconds: 3600, reservation_back_verify_enabled: true, // 找福袋图标相关 fudai_find_max_attempts: 5, @@ -566,6 +567,7 @@ async function startRun() { fansclub_fail_action: cfgPart.fansclub_fail_action, high_value_room_revisit_enabled: cfgPart.high_value_room_revisit_enabled, high_value_room_revisit_only_current_run: cfgPart.high_value_room_revisit_only_current_run, + high_value_room_revisit_interval_seconds: cfgPart.high_value_room_revisit_interval_seconds, reservation_back_verify_enabled: cfgPart.reservation_back_verify_enabled, reservation_back_swipe_delay: cfgPart.reservation_back_swipe_delay, fudai_find_max_attempts: cfgPart.fudai_find_max_attempts, diff --git a/webui/index.html b/webui/index.html index 815d1f6..678a968 100644 --- a/webui/index.html +++ b/webui/index.html @@ -268,6 +268,11 @@ 仅本次运�?/span> +
+ + +
两个回访记录之间的最小间隔,单位秒(默认3600)
+