From ea77c0b50125f1e0daaa65a7b7bdf9f21f6352ff Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 15 Jan 2026 00:20:17 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E6=A0=BC=E5=BC=8F=EF=BC=8C=E6=8F=90=E5=8D=87=E5=8F=AF?= =?UTF-8?q?=E8=AF=BB=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Underlying_Operations.py | 24 +++++++++--- config/config.json | 2 +- douyin/core/douyin_fudai.py | 8 +++- douyin/other/douyin_yanghao.py | 68 +++++++++++++++++++++++----------- 4 files changed, 71 insertions(+), 31 deletions(-) diff --git a/Underlying_Operations.py b/Underlying_Operations.py index 0c70d43..e3ec6a0 100644 --- a/Underlying_Operations.py +++ b/Underlying_Operations.py @@ -797,7 +797,9 @@ class underlying_operations: # 优先走 exec-out:只需 1 次 adb 调用;不在手机端落盘,减少 I/O 与卡顿 # 为避免被并发读取到"半写入文件",写入 tmp 后再原子替换。 execout_timeout_sec = float(os.environ.get("ADB_EXECOUT_TIMEOUT_SEC", "10")) - execout_warn_after_sec = float(os.environ.get("ADB_EXECOUT_WARN_AFTER_SEC", "3")) + execout_warn_after_sec = float( + os.environ.get("ADB_EXECOUT_WARN_AFTER_SEC", "3") + ) execout_heartbeat_interval_sec = float( os.environ.get("ADB_EXECOUT_HEARTBEAT_INTERVAL_SEC", "5") ) @@ -3098,14 +3100,18 @@ class underlying_operations: # 先确保输入框获得焦点 try: try: - print(f"[Underlying] paste_text_at: clicking to focus device_id={device_id} coord=({x},{y})") + print( + f"[Underlying] paste_text_at: clicking to focus device_id={device_id} coord=({x},{y})" + ) except Exception: pass self.click(device_id, int(x), int(y)) time_module.sleep(0.2) # 有些输入框第一次点不进,补一次轻点 try: - print(f"[Underlying] paste_text_at: clicking again to ensure focus device_id={device_id} coord=({x},{y})") + print( + f"[Underlying] paste_text_at: clicking again to ensure focus device_id={device_id} coord=({x},{y})" + ) except Exception: pass self.click(device_id, int(x), int(y)) @@ -3118,11 +3124,15 @@ class underlying_operations: try: ok_adbkb = False try: - ok_adbkb = bool(self.input_text_adbkeyboard(device_id, t, restore_prev=False)) + ok_adbkb = bool( + self.input_text_adbkeyboard(device_id, t, restore_prev=False) + ) except Exception: ok_adbkb = False try: - print(f"[Underlying] paste_text_at: input_text_adbkeyboard -> {ok_adbkb}") + print( + f"[Underlying] paste_text_at: input_text_adbkeyboard -> {ok_adbkb}" + ) except Exception: pass if ok_adbkb: @@ -3157,7 +3167,9 @@ class underlying_operations: # 2) 兜底:adb input text(中文可能不稳定) try: - print(f"[Underlying] paste_text_at: falling back to input_text for device_id={device_id}") + print( + f"[Underlying] paste_text_at: falling back to input_text for device_id={device_id}" + ) except Exception: pass return self.input_text(device_id, t) diff --git a/config/config.json b/config/config.json index f6d331f..5596bdc 100644 --- a/config/config.json +++ b/config/config.json @@ -220,4 +220,4 @@ "high_value_room_revisit_max_per_run": 9999, "high_value_room_revisit_min_prize_value": 1000.0, "high_value_room_revisit_max_age_days": 1 -} +} \ No newline at end of file diff --git a/douyin/core/douyin_fudai.py b/douyin/core/douyin_fudai.py index 9913a8e..221c478 100644 --- a/douyin/core/douyin_fudai.py +++ b/douyin/core/douyin_fudai.py @@ -431,7 +431,9 @@ class fudai_analyse: # method directly cannot bypass the main on/off setting. if not bool(getattr(self, "yanghao_enabled", True)): try: - self._log_kv("养号", "_yanghao_recommend_flow skipped - yanghao_enabled=0") + self._log_kv( + "养号", "_yanghao_recommend_flow skipped - yanghao_enabled=0" + ) except Exception: print("[养号] _yanghao_recommend_flow skipped - yanghao_enabled=0") return @@ -503,7 +505,9 @@ class fudai_analyse: pass try: - reservation_focus_until = float(getattr(self, "reservation_focus_until_ts", 0.0) or 0.0) + reservation_focus_until = float( + getattr(self, "reservation_focus_until_ts", 0.0) or 0.0 + ) if reservation_focus_until > time.time(): # 当前处于预约焦点期,跳过养号 return diff --git a/douyin/other/douyin_yanghao.py b/douyin/other/douyin_yanghao.py index b001138..79b193d 100644 --- a/douyin/other/douyin_yanghao.py +++ b/douyin/other/douyin_yanghao.py @@ -322,10 +322,12 @@ def yanghao_idle(analyser, total_seconds: int) -> None: # 仅在爱心和收藏都实际触发(都被点击)时才考虑评论 # 记录评论是否实际执行 did_comment = False - if did_like and did_fav and float( - getattr(analyser, "yanghao_comment_prob", 0) or 0 - ) > 0 and random.random() < float( - getattr(analyser, "yanghao_comment_prob", 0) or 0 + if ( + did_like + and did_fav + and float(getattr(analyser, "yanghao_comment_prob", 0) or 0) > 0 + and random.random() + < float(getattr(analyser, "yanghao_comment_prob", 0) or 0) ): _do_comment(analyser) did_comment = True @@ -392,14 +394,22 @@ def yanghao_idle(analyser, total_seconds: int) -> None: analyser.operation.delay(2) # 点击直播按钮(备用坐标) - fallback_x = int(getattr(analyser, "yanghao_fallback_live_x", 540) or 540) - fallback_y = int(getattr(analyser, "yanghao_fallback_live_y", 2000) or 2000) + fallback_x = int( + getattr(analyser, "yanghao_fallback_live_x", 540) or 540 + ) + fallback_y = int( + getattr(analyser, "yanghao_fallback_live_y", 2000) or 2000 + ) analyser.operation.click(analyser.device_id, fallback_x, fallback_y) analyser.operation.delay(1.5) # 点击进入直播间(备用坐标) - enter_x = int(getattr(analyser, "yanghao_fallback_enter_live_x", 540) or 540) - enter_y = int(getattr(analyser, "yanghao_fallback_enter_live_y", 1200) or 1200) + enter_x = int( + getattr(analyser, "yanghao_fallback_enter_live_x", 540) or 540 + ) + enter_y = int( + getattr(analyser, "yanghao_fallback_enter_live_y", 1200) or 1200 + ) analyser.operation.click(analyser.device_id, enter_x, enter_y) analyser.operation.delay(0.6) analyser.operation.click(analyser.device_id, enter_x, enter_y) @@ -493,48 +503,62 @@ def yanghao_idle(analyser, total_seconds: int) -> None: try: # 获取前台包名 top_pkg = analyser.operation.get_top_package(analyser.device_id) or "" - + # 检查是否在抖音前台 is_douyin_pkg = top_pkg and ( "aweme" in top_pkg or "douyin" in top_pkg or "com.ss.android.ugc" in top_pkg ) - + if top_pkg and not is_douyin_pkg: print(f"[养号] 自救: 检测到不在抖音前台,前台包名={top_pkg}") - + # 执行自救操作 try: # 点击桌面图标 desktop_x = int(getattr(analyser, "desktop_icon_x", 153) or 153) desktop_y = int(getattr(analyser, "desktop_icon_y", 260) or 260) - analyser.operation.click(analyser.device_id, desktop_x, desktop_y) + analyser.operation.click( + analyser.device_id, desktop_x, desktop_y + ) analyser.operation.delay(2) - + # 点击直播按钮(备用坐标) - fallback_x = int(getattr(analyser, "yanghao_fallback_live_x", 540) or 540) - fallback_y = int(getattr(analyser, "yanghao_fallback_live_y", 2000) or 2000) - analyser.operation.click(analyser.device_id, fallback_x, fallback_y) + fallback_x = int( + getattr(analyser, "yanghao_fallback_live_x", 540) or 540 + ) + fallback_y = int( + getattr(analyser, "yanghao_fallback_live_y", 2000) or 2000 + ) + analyser.operation.click( + analyser.device_id, fallback_x, fallback_y + ) analyser.operation.delay(1.5) - + # 点击进入直播间(备用坐标) - enter_x = int(getattr(analyser, "yanghao_fallback_enter_live_x", 540) or 540) - enter_y = int(getattr(analyser, "yanghao_fallback_enter_live_y", 1200) or 1200) + enter_x = int( + getattr(analyser, "yanghao_fallback_enter_live_x", 540) + or 540 + ) + enter_y = int( + getattr(analyser, "yanghao_fallback_enter_live_y", 1200) + or 1200 + ) analyser.operation.click(analyser.device_id, enter_x, enter_y) analyser.operation.delay(0.6) analyser.operation.click(analyser.device_id, enter_x, enter_y) analyser.operation.delay(2.0) - + print("[养号] 自救: 恢复操作完成") return True - + except Exception as e: print(f"[养号] 自救: 恢复操作失败: {e}") return False else: return False - + except Exception as e: print(f"[养号] 自救: 桌面检测异常: {e}") return False