diff --git a/config/config.json b/config/config.json index 8034e14..b451504 100644 --- a/config/config.json +++ b/config/config.json @@ -75,7 +75,46 @@ "yanghao_comment_send_y": -1, "yanghao_comment_close_x": 0, "yanghao_comment_close_y": 0, - "yanghao_comment_texts": [], + "yanghao_comment_texts": [ + "好看!", + "赞一个", + "真不错", + "喜欢这个风格", + "太棒了", + "很有创意", + "支持一下", + "笑死我了", + "学习了", + "被圈粉了", + "期待更多", + "必须收藏", + "这也太治愈了", + "质量很高", + "简直绝了", + "画面太美了", + "配色好舒服", + "氛围感满分", + "做得很用心", + "好想试试这个", + "安利给朋友", + "收藏备用", + "太有意思了", + "这音乐选得太绝", + "太会了", + "入坑了", + "好惊喜", + "真有参考价值", + "好暖心的一条", + "笑哭,我服了", + "细节处理得很好", + "太有才了", + "看着就治愈", + "学习到新方法", + "大家都来看看", + "点赞支持", + "完美", + "好看到不行" + ], "yanghao_like_keywords": [], "yanghao_fav_keywords": [], "stage_diag_max_time": 1.0, diff --git a/douyin/core/douyin_fudai.py b/douyin/core/douyin_fudai.py index 80bb561..2b24d40 100644 --- a/douyin/core/douyin_fudai.py +++ b/douyin/core/douyin_fudai.py @@ -216,6 +216,38 @@ class fudai_analyse: self.yanghao_fallback_enter_live_x: int = 540 # 养号备用进入直播间 X 坐标 self.yanghao_fallback_enter_live_y: int = 1200 # 养号备用进入直播间 Y 坐标 + # 推荐页养号默认配置(若 config.json 未设置则使用这些默认值) + self.yanghao_enabled: bool = True + self.yanghao_enable_actions: bool = True + self.yanghao_step_screenshot: bool = False + self.yanghao_recommend_duration_seconds: int = 60 + self.yanghao_recommend_interval_seconds: int = 0 + self.yanghao_like_prob: float = 0.15 + self.yanghao_fav_prob: float = 0.05 + self.yanghao_comment_prob: float = 0.0 + self.yanghao_icon_roi_size: int = 180 + self.yanghao_icon_match_threshold: float = 0.72 + # icon 坐标(基于 1080x2400) + self.yanghao_like_icon_x: int = 0 + self.yanghao_like_icon_y: int = 0 + self.yanghao_fav_icon_x: int = 0 + self.yanghao_fav_icon_y: int = 0 + # roi 偏移 + self.yanghao_like_roi_offset_x: int = 0 + self.yanghao_like_roi_offset_y: int = 0 + self.yanghao_fav_roi_offset_x: int = 0 + self.yanghao_fav_roi_offset_y: int = 0 + # 评论相关默认坐标与文案列表 + self.yanghao_comment_btn_x: int = 0 + self.yanghao_comment_btn_y: int = 0 + self.yanghao_comment_input_x: int = 0 + self.yanghao_comment_input_y: int = 0 + self.yanghao_comment_send_x: int = 0 + self.yanghao_comment_send_y: int = 0 + self.yanghao_comment_close_x: int = 0 + self.yanghao_comment_close_y: int = 0 + self.yanghao_comment_texts: list[str] = [] + # —— 预约运行时状态(单次运行内有效) —— # 高价值福袋预约队列 self.reservations: list[dict[str, Any]] = [] @@ -288,6 +320,44 @@ class fudai_analyse: """从 config.json 加载与福袋筛选/节流相关的关键参数(精简版)。""" douyin_config.ConfigManager.load_config_from_file(self) # type: ignore[attr-defined] + # ===== 推荐页养号封装 ===== + def _yanghao_recommend_flow(self, seconds: int) -> None: + """封装调用 douyin.other.douyin_yanghao.yanghao_recommend_flow。""" + try: + from douyin.other import douyin_yanghao + + douyin_yanghao.yanghao_recommend_flow(self, int(seconds or 0)) + except Exception: + # 兜底:若模块不可用则快速返回 + try: + self._log_kv("养号", "_yanghao_recommend_flow 未能执行 - 模块缺失或异常") + except Exception: + pass + + def _yanghao_wait(self, seconds: int) -> None: + """封装调用 douyin.other.douyin_yanghao.yanghao_wait(可由主流程在等待阶段调用)。""" + try: + from douyin.other import douyin_yanghao + + douyin_yanghao.yanghao_wait(self, int(seconds or 0)) + except Exception: + try: + self._log_kv("养号", "_yanghao_wait 未能执行 - 模块缺失或异常") + except Exception: + pass + + def _yanghao_get_recommend_seconds(self) -> int: + """返回配置或默认的推荐页停留时长(秒)。""" + try: + from douyin.other import douyin_yanghao + + return int(douyin_yanghao.yanghao_get_recommend_seconds(self)) + except Exception: + try: + return int(getattr(self, "yanghao_recommend_duration_seconds", 60) or 60) + except Exception: + return 60 + # ========== 兼容旧入口:主循环 ========== def fudai_choujiang( self, diff --git a/douyin/utils/douyin_config.py b/douyin/utils/douyin_config.py index de1c8cf..9bdc1f0 100644 --- a/douyin/utils/douyin_config.py +++ b/douyin/utils/douyin_config.py @@ -272,3 +272,109 @@ class ConfigManager: if "enable_whole_detail_ocr" in config: analyser.enable_whole_detail_ocr = bool(config["enable_whole_detail_ocr"]) + + # ===== 推荐页养号相关配置 ===== + if "yanghao_enabled" in config: + analyser.yanghao_enabled = bool(config["yanghao_enabled"]) + + if "yanghao_enable_actions" in config: + analyser.yanghao_enable_actions = bool(config["yanghao_enable_actions"]) + + if "yanghao_step_screenshot" in config: + analyser.yanghao_step_screenshot = bool(config["yanghao_step_screenshot"]) + + if "yanghao_recommend_duration_seconds" in config: + analyser.yanghao_recommend_duration_seconds = int( + config["yanghao_recommend_duration_seconds"] or 60 + ) + + if "yanghao_recommend_interval_seconds" in config: + analyser.yanghao_recommend_interval_seconds = int( + config["yanghao_recommend_interval_seconds"] or 0 + ) + + if "yanghao_like_prob" in config: + analyser.yanghao_like_prob = float(config["yanghao_like_prob"] or 0.0) + + if "yanghao_fav_prob" in config: + analyser.yanghao_fav_prob = float(config["yanghao_fav_prob"] or 0.0) + + if "yanghao_comment_prob" in config: + analyser.yanghao_comment_prob = float( + config["yanghao_comment_prob"] or 0.0 + ) + + # icon 坐标/偏移/模板路径 + if "yanghao_like_icon_x" in config: + analyser.yanghao_like_icon_x = int(config["yanghao_like_icon_x"] or 0) + if "yanghao_like_icon_y" in config: + analyser.yanghao_like_icon_y = int(config["yanghao_like_icon_y"] or 0) + if "yanghao_fav_icon_x" in config: + analyser.yanghao_fav_icon_x = int(config["yanghao_fav_icon_x"] or 0) + if "yanghao_fav_icon_y" in config: + analyser.yanghao_fav_icon_y = int(config["yanghao_fav_icon_y"] or 0) + + if "yanghao_like_roi_offset_x" in config: + analyser.yanghao_like_roi_offset_x = int( + config["yanghao_like_roi_offset_x"] or 0 + ) + if "yanghao_like_roi_offset_y" in config: + analyser.yanghao_like_roi_offset_y = int( + config["yanghao_like_roi_offset_y"] or 0 + ) + if "yanghao_fav_roi_offset_x" in config: + analyser.yanghao_fav_roi_offset_x = int( + config["yanghao_fav_roi_offset_x"] or 0 + ) + if "yanghao_fav_roi_offset_y" in config: + analyser.yanghao_fav_roi_offset_y = int( + config["yanghao_fav_roi_offset_y"] or 0 + ) + + if "yanghao_icon_roi_size" in config: + analyser.yanghao_icon_roi_size = int(config["yanghao_icon_roi_size"] or 180) + if "yanghao_icon_match_threshold" in config: + analyser.yanghao_icon_match_threshold = float( + config["yanghao_icon_match_threshold"] or 0.72 + ) + + # 评论相关坐标与文案 + if "yanghao_comment_btn_x" in config: + analyser.yanghao_comment_btn_x = int(config["yanghao_comment_btn_x"] or 0) + if "yanghao_comment_btn_y" in config: + analyser.yanghao_comment_btn_y = int(config["yanghao_comment_btn_y"] or 0) + if "yanghao_comment_input_x" in config: + analyser.yanghao_comment_input_x = int( + config["yanghao_comment_input_x"] or 0 + ) + if "yanghao_comment_input_y" in config: + analyser.yanghao_comment_input_y = int( + config["yanghao_comment_input_y"] or 0 + ) + if "yanghao_comment_send_x" in config: + analyser.yanghao_comment_send_x = int( + config["yanghao_comment_send_x"] or 0 + ) + if "yanghao_comment_send_y" in config: + analyser.yanghao_comment_send_y = int( + config["yanghao_comment_send_y"] or 0 + ) + if "yanghao_comment_close_x" in config: + analyser.yanghao_comment_close_x = int( + config["yanghao_comment_close_x"] or 0 + ) + if "yanghao_comment_close_y" in config: + analyser.yanghao_comment_close_y = int( + config["yanghao_comment_close_y"] or 0 + ) + + if "yanghao_comment_texts" in config: + # 支持配置为字符串数组或以换行分隔的长文本 + raw = config.get("yanghao_comment_texts") or [] + if isinstance(raw, list): + analyser.yanghao_comment_texts = [str(x) for x in raw if str(x).strip()] + else: + # 按行拆分并过滤空行 + analyser.yanghao_comment_texts = [ + line.strip() for line in str(raw or "").splitlines() if line.strip() + ] diff --git a/gui/gui_app.py b/gui/gui_app.py index e1775b0..110345f 100644 --- a/gui/gui_app.py +++ b/gui/gui_app.py @@ -447,6 +447,7 @@ def main(): yg_actions_enabled_var = tk.BooleanVar( value=bool(cfg.get("yanghao_enable_actions", True)) ) + yg_only_var = tk.BooleanVar(value=bool(cfg.get("yanghao_only", False))) yg_recommend_duration_var = tk.IntVar( value=int(cfg.get("yanghao_recommend_duration_seconds", 60) or 60) ) @@ -930,6 +931,11 @@ def main(): text="启用养号动作(爱心/收藏/评论)", variable=yg_actions_enabled_var, ).pack(side=LEFT, padx=(10, 0)) + ttk.Checkbutton( + yg_switch, + text="只养号(仅执行推荐页养号,跳过抽奖/参与)", + variable=yg_only_var, + ).pack(side=LEFT, padx=(10, 0)) yg0 = ttk.Frame(yg_box) yg0.pack(fill=X, padx=10, pady=(0, 8)) @@ -1536,6 +1542,7 @@ def main(): wait_minutes_var.set(int(cfg.get("wait_minutes", 5) or 5)) yg_enabled_var.set(bool(cfg.get("yanghao_enabled", True))) yg_actions_enabled_var.set(bool(cfg.get("yanghao_enable_actions", True))) + yg_only_var.set(bool(cfg.get("yanghao_only", False))) yg_recommend_duration_var.set( int(cfg.get("yanghao_recommend_duration_seconds", 60) or 60) ) @@ -1932,6 +1939,7 @@ def main(): cfg2["yanghao_enabled"] = bool(yg_enabled_var.get()) cfg2["yanghao_enable_actions"] = bool(yg_actions_enabled_var.get()) + cfg2["yanghao_only"] = bool(yg_only_var.get()) cfg2["yanghao_recommend_duration_seconds"] = int( yg_recommend_duration_var.get() or 60 ) @@ -2977,6 +2985,9 @@ def main(): fudai_template_match_threshold=float( fudai_template_match_threshold_var.get() or 0.7 ), + # 只养号模式与养号时长 + yanghao_only=bool(yg_only_var.get()), + yanghao_seconds=int(yg_recommend_duration_var.get() or 0), ) def start_run(): diff --git a/gui/gui_core.py b/gui/gui_core.py index 9694db0..72e82ee 100644 --- a/gui/gui_core.py +++ b/gui/gui_core.py @@ -95,6 +95,10 @@ class RunParams: enable_ocr_mode1: bool fudai_template_match_enabled: bool fudai_template_match_threshold: float + # 只养号模式(仅执行推荐页养号) + yanghao_only: bool + # 只养号时的养号时长(秒),会传给 --yanghao-seconds + yanghao_seconds: int class Runner: @@ -865,6 +869,17 @@ class Runner: ["--fudai-template-threshold", str(params.fudai_template_match_threshold)] ) + # 只养号模式:如果启用则传递到 run_cli.py + try: + if getattr(params, "yanghao_only", False): + cmd.append("--yanghao-only") + # 若指定时长,传给 --yanghao-seconds + if int(getattr(params, "yanghao_seconds", 0) or 0) > 0: + cmd += ["--yanghao-seconds", str(int(params.yanghao_seconds))] + except Exception: + # 忽略,保证兼容旧参数集合 + pass + # 继承当前环境,并确保 adb 在 PATH(即使用户没手动刷新 PATH) env = os.environ.copy() env.setdefault("PYTHONIOENCODING", "utf-8") diff --git a/run_cli.py b/run_cli.py index c3b1802..81d21ed 100644 --- a/run_cli.py +++ b/run_cli.py @@ -266,6 +266,19 @@ def parse_args(argv: list[str]) -> argparse.Namespace: help="禁用福袋模板匹配(默认已禁用)", ) + p.add_argument( + "--yanghao-only", + action="store_true", + help="只执行推荐页养号流程(运行完成后退出)", + ) + + p.add_argument( + "--yanghao-seconds", + type=int, + default=None, + help="仅在 --yanghao-only 时有效:覆盖推荐页养号停留秒数", + ) + return p.parse_args(argv) @@ -386,6 +399,31 @@ def main(argv: list[str]) -> int: print("[TEST] done") return 0 + # 命令行:只运行推荐页养号并退出(用于纯养号场景) + if getattr(args, "yanghao_only", False): + device_id = (args.device_id or "").strip() or analyser.operation.select_device() + if not device_id: + print("未检测到设备,退出。") + return 2 + analyser.device_id = device_id + analyser.y_pianyi = int(args.y_pianyi or 0) + analyser.resolution_ratio_x, analyser.resolution_ratio_y = ( + analyser.operation.get_device_resolution(device_id) + ) + # 重新加载配置以确保养号配置生效 + analyser.load_config() + print( + "[YANGHAO-ONLY] device_id={} res={}x{}".format( + device_id, analyser.resolution_ratio_x, analyser.resolution_ratio_y + ) + ) + seconds = int(args.yanghao_seconds) if getattr(args, "yanghao_seconds", None) else analyser._yanghao_get_recommend_seconds() + if seconds < 1: + seconds = 1 + getattr(analyser, "_yanghao_recommend_flow", lambda _: None)(seconds) # type: ignore[attr-defined] + print("[YANGHAO-ONLY] done") + return 0 + if args.min_prize_value_yuan is not None: analyser.min_prize_value_yuan = float(args.min_prize_value_yuan) if args.min_participants is not None: