From 245e721c94e47913deeb31151206f0ff602b87ef Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 11 Jan 2026 23:32:19 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F=EF=BC=8C=E5=A2=9E=E5=8A=A0=E6=8D=A2=E8=A1=8C?= =?UTF-8?q?=E4=BB=A5=E6=8F=90=E9=AB=98=E5=8F=AF=E8=AF=BB=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- douyin/core/douyin_fudai.py | 36 +++++++++++++++++++++++-------- douyin/fudai/core/fudai_attend.py | 14 ++++++------ douyin/fudai/douyin_fudai_core.py | 35 ++++++++++++++++++++++-------- douyin/other/douyin_yanghao.py | 1 + 4 files changed, 62 insertions(+), 24 deletions(-) diff --git a/douyin/core/douyin_fudai.py b/douyin/core/douyin_fudai.py index b55d691..08faef4 100644 --- a/douyin/core/douyin_fudai.py +++ b/douyin/core/douyin_fudai.py @@ -310,7 +310,9 @@ class fudai_analyse: self._just_switched_room: bool = False # 是否刚刚切换了直播间 # 高价值房间重访相关状态 - self._last_high_value_revisit_ts: float = time.time() # 最后一次重访时间戳,初始化为当前时间避免启动后立即重访 + self._last_high_value_revisit_ts: float = ( + time.time() + ) # 最后一次重访时间戳,初始化为当前时间避免启动后立即重访 self._current_run_revisit_count: int = 0 # 本次运行的重访次数 self._current_run_high_value_rooms: list[dict[str, Any]] = ( [] @@ -1605,7 +1607,9 @@ class fudai_analyse: def _seek_reservation_room(item: dict) -> bool: try: - return bool(self._seek_reservation_room(item, operation_type="预约")) + return bool( + self._seek_reservation_room(item, operation_type="预约") + ) except Exception: return False @@ -2047,8 +2051,12 @@ class fudai_analyse: analyser=self, revisit_enabled=revisit_enabled, only_current_run=only_current_run, - min_interval_seconds=getattr(self, "high_value_room_revisit_min_interval_seconds", 300), - max_revisit_per_run=getattr(self, "high_value_room_revisit_max_per_run", 5), + min_interval_seconds=getattr( + self, "high_value_room_revisit_min_interval_seconds", 300 + ), + max_revisit_per_run=getattr( + self, "high_value_room_revisit_max_per_run", 5 + ), ) if should_revisit: @@ -2056,8 +2064,12 @@ class fudai_analyse: candidates = douyin_high_value_room.get_revisit_candidates( analyser=self, only_current_run=only_current_run, - min_prize_value=getattr(self, "high_value_room_revisit_min_prize_value", 0.0), - max_age_days=getattr(self, "high_value_room_revisit_max_age_days", 30), + min_prize_value=getattr( + self, "high_value_room_revisit_min_prize_value", 0.0 + ), + max_age_days=getattr( + self, "high_value_room_revisit_max_age_days", 30 + ), ) if candidates: @@ -2523,7 +2535,9 @@ class fudai_analyse: """ return douyin_swipe_handler.SwipeHandler.maybe_reset_after_swipes(self) - def _seek_reservation_room(self, item: dict[str, Any], operation_type: str = "预约") -> bool: + def _seek_reservation_room( + self, item: dict[str, Any], operation_type: str = "预约" + ) -> bool: """根据预约记录里的 pos_seen 与当前 room_pos 进行回退,靠近目标直播间。 说明: @@ -2602,7 +2616,9 @@ class fudai_analyse: self._last_fudai_detail_tuple = detail # 设置当前福袋的 content(使用 cast 帮助静态分析) detail_t: Tuple[Any, ...] = tuple(detail) - self._current_fudai_content = detail_t[0] if len(detail_t) > 0 else "" + self._current_fudai_content = ( + detail_t[0] if len(detail_t) > 0 else "" + ) else: # 使用第一次保存的详情数据,设置当前福袋的倒计时信息 try: @@ -3282,7 +3298,9 @@ class fudai_analyse: elapsed_seconds=round(elapsed, 2), ) return - join_result = douyin_fudai_core.basic_join_decision(self, detail, (skip, skip_reason)) + join_result = douyin_fudai_core.basic_join_decision( + self, detail, (skip, skip_reason) + ) # 检查是否参与成功:如果 _last_successful_attend_ts 刚刚更新,说明参与成功 attend_after_ts = getattr(self, "_last_successful_attend_ts", 0.0) or 0.0 diff --git a/douyin/fudai/core/fudai_attend.py b/douyin/fudai/core/fudai_attend.py index c57bb2d..4a8dfb4 100644 --- a/douyin/fudai/core/fudai_attend.py +++ b/douyin/fudai/core/fudai_attend.py @@ -207,17 +207,19 @@ def attend_choujiang(analyser) -> bool: analyser._log_kv("参与", "关闭福袋详情", action="关闭详情") return True elif attend_button_text and ( - ("活动已结束" in attend_button_text) or - ("活动己结束" in attend_button_text) or - ("福袋超时" in attend_button_text) or - ("活动超时" in attend_button_text) or - ("已超时" in attend_button_text) + ("活动已结束" in attend_button_text) + or ("活动己结束" in attend_button_text) + or ("福袋超时" in attend_button_text) + or ("活动超时" in attend_button_text) + or ("已超时" in attend_button_text) ): # 活动结束/福袋超时:按一次返回键退出详情 analyser.last_attend_fail_reason = "activity_ended" try: analyser._log_kv( - "参与", "活动已结束/福袋超时:按返回键退出详情", result="activity_ended" + "参与", + "活动已结束/福袋超时:按返回键退出详情", + result="activity_ended", ) except Exception: pass diff --git a/douyin/fudai/douyin_fudai_core.py b/douyin/fudai/douyin_fudai_core.py index dc1ad6b..7d1260e 100644 --- a/douyin/fudai/douyin_fudai_core.py +++ b/douyin/fudai/douyin_fudai_core.py @@ -5406,7 +5406,7 @@ def basic_join_decision( r_ft = float(r.get("future_ts") or 0.0) r_content = str(r.get("content") or "") r_room_title = str(r.get("room_title") or "") - + # 检查是否是同一个福袋:开奖时间相同且内容相同 if abs(r_ft - future_ts) < 5.0 and r_content == content: already_reserved = True @@ -5417,7 +5417,9 @@ def basic_join_decision( future_ts=int(future_ts), content=content[:50] if content else "", existing_future_ts=int(r_ft), - existing_content=r_content[:50] if r_content else "", + existing_content=( + r_content[:50] if r_content else "" + ), ) except Exception: pass @@ -5499,7 +5501,9 @@ def basic_join_decision( if stage == "FUDai_DETAIL": # 尝试通过像素检测获取任务数量 try: - from douyin.detection import douyin_pixel + from douyin.detection import ( + douyin_pixel, + ) pic_path = os.path.join( os.path.dirname(__file__), @@ -5548,10 +5552,18 @@ def basic_join_decision( if isinstance(result, tuple): _, detect_info = result detected_task_count = ( - detect_info.get("task_count", 0) + detect_info.get( + "task_count", 0 + ) ) - if detected_task_count in (1, 2, 3): - task_count = detected_task_count + if detected_task_count in ( + 1, + 2, + 3, + ): + task_count = ( + detected_task_count + ) except Exception: pass except Exception: @@ -5649,7 +5661,8 @@ def basic_join_decision( in_lock_period = False try: focus_until = float( - getattr(analyser, "reservation_focus_until_ts", 0.0) or 0.0 + getattr(analyser, "reservation_focus_until_ts", 0.0) + or 0.0 ) now_ts = time.time() if focus_until > 0 and now_ts < focus_until: @@ -5683,11 +5696,15 @@ def basic_join_decision( # 兜底:直接调用底层 swipe(基于 1080x2400 基准坐标) try: rx = int( - getattr(analyser, "resolution_ratio_x", 1080) + getattr( + analyser, "resolution_ratio_x", 1080 + ) or 1080 ) ry = int( - getattr(analyser, "resolution_ratio_y", 2400) + getattr( + analyser, "resolution_ratio_y", 2400 + ) or 2400 ) except Exception: diff --git a/douyin/other/douyin_yanghao.py b/douyin/other/douyin_yanghao.py index 2c57641..faa7a0d 100644 --- a/douyin/other/douyin_yanghao.py +++ b/douyin/other/douyin_yanghao.py @@ -5,6 +5,7 @@ import random import time from typing import Any import cv2 as _cv2 + cv2: Any = _cv2 # pylint: disable=E1101 import numpy as np