Files
douyi_guaji_main/run_cli.py
T
Your Name ea8d221543 feat: Add runtime overrides for reservation settings and update high value rooms
- Introduced new command-line arguments for runtime configuration:
  - `--reservation-back-swipe-delay`: Adjusts swipe delay after rollback (only effective when rollback verification is disabled).
  - `--reservation-preempt-min-value`: Sets the minimum value for preempting reservations.
  - `--fudai-find-max-attempts`: Limits the maximum attempts to find the 福袋 icon.

- Updated `high_value_rooms.json` to reflect new room entries and updated timestamps.
- Modified `reservations.json` to change the current reservation details and added a new reservation entry.
- Enhanced `web_gui.py` to support new runtime parameters from the GUI.
- Updated `app.js` and `index.html` in the web UI to include new settings for 福袋 attempts, reservation preemption value, and swipe delay.
2025-12-15 20:31:41 +08:00

243 lines
12 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import argparse
import os
import shutil
import sys
# 在导入 PaddleOCR 之前设置,避免每次启动都做连通性检查提示并抑制底层 glog/oneDNN 等噪音
# DISABLE_MODEL_SOURCE_CHECK: 跳过 PaddleOCR 的主机连通性检查(国内网络环境常卡)
# GLOG_minloglevel: 2 -> ERROR 及以上,屏蔽 INFO/WARNING
# OMP_NUM_THREADS: 设为 1,避免 oneDNN 打印线程信息
os.environ.setdefault("DISABLE_MODEL_SOURCE_CHECK", "True")
os.environ.setdefault("GLOG_minloglevel", "2")
os.environ.setdefault("OMP_NUM_THREADS", "1")
from douyin_fudai import fudai_analyse
def ensure_adb_in_path() -> None:
if shutil.which("adb"):
return
localapp = os.environ.get("LOCALAPPDATA") or ""
candidates = []
if localapp:
candidates.append(os.path.join(localapp, "platform-tools"))
userprofile = os.environ.get("USERPROFILE") or ""
if userprofile:
candidates.append(os.path.join(userprofile, "AppData", "Local", "platform-tools"))
for d in candidates:
adb_exe = os.path.join(d, "adb.exe")
if os.path.exists(adb_exe):
os.environ["PATH"] = d + os.pathsep + os.environ.get("PATH", "")
os.environ.setdefault("ADB_EXECUTABLE", adb_exe)
return
def parse_args(argv: list[str]) -> argparse.Namespace:
p = argparse.ArgumentParser(description="Douyin 福袋挂机运行器(供 GUI 调用)")
p.add_argument("--device-id", default="", help="ADB 设备 ID(为空则自动选择)")
p.add_argument("--y-pianyi", type=int, default=0, help="y 轴偏移(通常 -50~50)")
p.add_argument("--needswitch", action="store_true", help="是否允许上划切换直播间")
p.add_argument("--wait-minutes", type=int, default=5, help="倒计时超过该分钟则切换(needswitch 生效)")
p.add_argument("--test-yanghao-flow", action="store_true", help="测试:只执行一次推荐页养号流程并退出")
p.add_argument("--test-yanghao-flow-seconds", type=int, default=10, help="测试:推荐页养号停留秒数")
p.add_argument("--test-comment", action="store_true", help="测试:按配置坐标执行一次评论输入+键盘确认发送并退出")
p.add_argument("--test-comment-text", default="测试评论123", help="测试评论内容")
# 允许从 GUI 覆盖关键配置(不改动 config.json 也能生效)
p.add_argument("--min-prize-value-yuan", type=float, default=None, help="最低奖品价值(元),低于则不参与")
p.add_argument("--min-participants", type=int, default=None, help="最少参与人数(0/空表示不启用)")
p.add_argument("--max-participants", type=int, default=None, help="最多参与人数(0/空表示不启用)")
p.add_argument("--skip-if-countdown-lt-seconds", type=int, default=None, help="倒计时小于该秒数则不参与(needswitch 生效)")
p.add_argument(
"--reset-after-swipes",
type=int,
default=None,
help="切换直播间达到该次数后,在直播间页面下滑回退到本轮第一个直播间(需配合 --reset-after-swipes-enabled)",
)
p.add_argument("--reset-after-swipes-enabled", action="store_true", help="开启切换次数阈值回退到第一个直播间")
p.add_argument("--reset-after-swipes-disabled", action="store_true", help="关闭切换次数阈值回退到第一个直播间")
# 高价值直播间回访运行时开关(GUI 可在启动时传参覆盖)
p.add_argument("--high-value-room-revisit-enabled", action="store_true", help="启用高价值直播间定时回访")
p.add_argument("--high-value-room-revisit-disabled", action="store_true", help="禁用高价值直播间定时回访")
p.add_argument("--high-value-room-revisit-only-current-run", action="store_true", help="仅回访本次运行记录的高价值直播间")
p.add_argument("--reservation-back-verify-enabled", action="store_true", help="启用回退后预约校验(默认启用)")
p.add_argument("--reservation-back-verify-disabled", action="store_true", help="禁用回退后预约校验")
p.add_argument("--reservation-back-swipe-delay", type=float, default=None, help="运行时覆盖:回退后滑动等待(秒),仅在未启用回退校验时生效,可加快回退速度")
p.add_argument("--reservation-preempt-min-value", type=float, default=None, help="运行时覆盖:预约抢占最小价值(元),低于该值的预约不会抢占当前任务")
p.add_argument("--fudai-find-max-attempts", type=int, default=None, help="运行时覆盖:找福袋图标最多尝试次数(整数)")
# 按需求:删除“自动养号/随机等待/轻微扰动”等参数,仅保留“推荐页养号流程”。
# 推荐页养号的动作/概率/阈值等由 config.json 控制(GUI 会保存)。
p.add_argument("--auto-join-fansclub", action="store_true", help="自动尝试加入粉丝团(可能消耗钻石)")
p.add_argument("--fansclub-fail-action", choices=["stay", "switch"], default=None,
help="粉丝团门槛无法处理时:stay=停留当前直播间;switch=切换下一个")
return p.parse_args(argv)
def main(argv: list[str]) -> int:
ensure_adb_in_path()
args = parse_args(argv)
# 让命令行输出更稳定(实时刷新 + UTF-8)
try:
sys.stdout.reconfigure(encoding="utf-8", line_buffering=True)
except Exception:
pass
try:
sys.stderr.reconfigure(encoding="utf-8", line_buffering=True)
except Exception:
pass
if bool(getattr(args, "test_yanghao_flow", False)) or bool(getattr(args, "test_comment", False)):
os.environ.setdefault("SKIP_OCR_INIT", "1")
os.environ.setdefault("NO_TEE_STDOUT", "1")
os.environ.setdefault("FAST_UI", "1")
os.environ.setdefault("YANGHAO_STEP_SCREENSHOT", "1")
analyser = fudai_analyse()
# 测试模式:直接执行一次“评论输入+键盘确认发送”
if bool(getattr(args, "test_comment", 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)
print("[TEST-COMMENT] device_id={} res={}x{}".format(device_id, analyser.resolution_ratio_x, analyser.resolution_ratio_y))
msg = str(getattr(args, "test_comment_text", "测试评论123") or "测试评论123")
# 逐步截图
analyser._save_step_screenshot("test_comment_start")
def _scaled_click(base_x: int, base_y: int) -> None:
sx, sy = analyser._scale_from_base(int(base_x), int(base_y))
analyser.operation.click(device_id, sx, sy)
try:
_scaled_click(analyser.yanghao_comment_btn_x, analyser.yanghao_comment_btn_y)
analyser.operation.delay(1)
analyser._save_step_screenshot("test_comment_after_open")
_scaled_click(analyser.yanghao_comment_input_x, analyser.yanghao_comment_input_y)
analyser.operation.delay(1)
analyser._save_step_screenshot("test_comment_after_focus")
ix, iy = analyser._scale_from_base(int(analyser.yanghao_comment_input_x), int(analyser.yanghao_comment_input_y))
ok_input = bool(analyser.operation.paste_text_at(device_id, ix, iy, msg))
print("[TEST-COMMENT] input {}".format("OK" if ok_input else "FAIL"))
analyser.operation.delay(1)
analyser._save_step_screenshot("test_comment_after_input")
ok_send = bool(analyser.operation.confirm_from_keyboard(device_id))
print("[TEST-COMMENT] send {}".format("OK" if ok_send else "FAIL"))
analyser.operation.delay(1)
analyser._save_step_screenshot("test_comment_after_send")
_scaled_click(analyser.yanghao_comment_close_x, analyser.yanghao_comment_close_y)
analyser.operation.delay(1)
analyser._save_step_screenshot("test_comment_after_close")
except Exception as e:
print("[TEST-COMMENT] failed: {}".format(e))
return 3
print("[TEST-COMMENT] done")
return 0
# 测试模式:直接跑一次“推荐页养号流程”用于验证是否能点到关键按钮
if bool(getattr(args, "test_yanghao_flow", 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.yanghao_use_recommend_flow = True
print("[TEST] device_id={} res={}x{}".format(device_id, analyser.resolution_ratio_x, analyser.resolution_ratio_y))
seconds = int(getattr(args, "test_yanghao_flow_seconds", 10) or 10)
if seconds < 1:
seconds = 1
analyser._yanghao_recommend_flow(seconds)
print("[TEST] 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:
analyser.min_participants = int(args.min_participants or 0)
if args.max_participants is not None:
analyser.max_participants = int(args.max_participants or 0)
if args.skip_if_countdown_lt_seconds is not None:
analyser.skip_if_countdown_lt_seconds = int(args.skip_if_countdown_lt_seconds or 15)
if args.reset_after_swipes is not None:
analyser.reset_after_swipes = max(1, int(args.reset_after_swipes or 0))
analyser.reset_after_swipes_enabled = True
if args.reset_after_swipes_enabled:
analyser.reset_after_swipes_enabled = True
if args.reset_after_swipes_disabled:
analyser.reset_after_swipes_enabled = False
if args.auto_join_fansclub:
analyser.auto_join_fansclub = True
if args.fansclub_fail_action is not None:
analyser.fansclub_fail_action = args.fansclub_fail_action
# 高价值直播间回访开关(优先级:命令行 > config)
if getattr(args, "high_value_room_revisit_enabled", False):
analyser.high_value_room_revisit_enabled = True
if getattr(args, "high_value_room_revisit_disabled", False):
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, "reservation_back_verify_enabled", False):
analyser.reservation_back_verify_enabled = True
if getattr(args, "reservation_back_verify_disabled", False):
analyser.reservation_back_verify_enabled = False
# 运行时覆盖:回退后滑动等待(快速值,仅在未启用回退校验时使用)
if getattr(args, "reservation_back_swipe_delay", None) is not None:
try:
analyser.reservation_back_swipe_delay_fast_seconds = float(args.reservation_back_swipe_delay)
except Exception:
pass
if getattr(args, "reservation_preempt_min_value", None) is not None:
try:
analyser.reservation_preempt_min_value_yuan = max(0.0, float(args.reservation_preempt_min_value))
except Exception:
pass
# 运行时覆盖:找福袋最大尝试次数
if getattr(args, "fudai_find_max_attempts", None) is not None:
try:
analyser.fudai_find_max_attempts = max(1, int(args.fudai_find_max_attempts))
except Exception:
pass
device_id = args.device_id.strip() if args.device_id else ""
if not device_id:
device_id = analyser.operation.select_device()
if not device_id:
print("未检测到设备,退出。")
return 2
analyser.fudai_choujiang(
device_id=device_id,
y_pianyi=args.y_pianyi,
needswitch=bool(args.needswitch),
wait_minutes=int(args.wait_minutes),
)
return 0
if __name__ == "__main__":
try:
from version import print_version_banner
print_version_banner("run_cli")
except Exception:
pass
raise SystemExit(main(sys.argv[1:]))