Files
douyi_guaji_main/gui/dashboard_app/page_config.py
T

202 lines
15 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.
from __future__ import annotations
import os
import tkinter as tk
from douyin.license.license_manager import get_license_status_payload
from . import theme
from .data import DashboardData, cfg_get
from .page_context import PageContext
from .page_helpers import pack_fields, pack_switches, select_spec, spin_spec, text_box
from .widgets import button, card, section
def build_run_settings(parent: tk.Misc, data: DashboardData, ctx: PageContext) -> None:
section(parent, "运行设置", "保持旧入口运行参数")
box = card(parent, "基本运行参数")
box.pack(fill="x")
pack_switches(box, ctx, [
("允许切换直播间", "needswitch_var", bool(cfg_get(data.cfg, "needswitch"))),
("无限循环模式", "infinite_loop_var", bool(cfg_get(data.cfg, "infinite_loop_enabled"))),
("切换N次后回到第一个", "reset_after_swipes_enabled_var", False),
("启用返回键回退", "enable_back_on_misses_var", True),
("启用下滑回退直播间", "swipe_down_back_enabled_var", False),
])
pack_fields(box, ctx, [
spin_spec("运行时长(分钟)", "wait_minutes_var", cfg_get(data.cfg, "wait_minutes"), from_=1, to=60),
spin_spec("倒计时大于(秒)时不参与", "skip_gt_seconds_var", cfg_get(data.cfg, "skip_if_countdown_gt_seconds"), from_=0, to=3600),
spin_spec("次数", "reset_after_swipes_var", cfg_get(data.cfg, "reset_after_swipes"), from_=1, to=9999),
select_spec("滑动重置回退方式", "reset_after_swipes_action_var", cfg_get(data.cfg, "reset_after_swipes_action"), ["swipe", "back"]),
select_spec("进入直播间坐标模式", "reenter_live_entry_mode_var", cfg_get(data.cfg, "reenter_live_entry_mode"), ["follow_list", "screen_center"]),
spin_spec("下滑回退次数", "swipe_down_back_count_var", cfg_get(data.cfg, "swipe_down_back_count"), from_=1, to=9999),
spin_spec("连续无福袋退出阈值", "fudai_exit_after_misses_var", cfg_get(data.cfg, "fudai_exit_after_misses"), from_=1, to=99999),
])
def build_filter_settings(parent: tk.Misc, data: DashboardData, ctx: PageContext) -> None:
section(parent, "筛选设置", "价值 / 人数 / 倒计时 / 粉丝团")
box = card(parent, "福袋筛选条件")
box.pack(fill="x")
pack_switches(box, ctx, [("自动加入粉丝团(谨慎:可能消耗钻石)", "auto_join_var", False)], columns=1)
pack_fields(box, ctx, [
spin_spec("最低价值(元)", "min_value_var", cfg_get(data.cfg, "min_prize_value_yuan"), from_=0, to=99999, increment=0.01),
spin_spec("参与人数最小", "min_participants_var", cfg_get(data.cfg, "min_participants"), from_=0, to=99999999),
spin_spec("参与人数最大", "max_participants_var", cfg_get(data.cfg, "max_participants"), from_=0, to=99999999),
spin_spec("倒计时小于(秒)时不参与", "skip_lt_seconds_var", cfg_get(data.cfg, "skip_if_countdown_lt_seconds"), from_=0, to=300),
select_spec("粉丝团失败策略", "fansclub_action_var", cfg_get(data.cfg, "fansclub_fail_action"), ["stay", "switch"]),
spin_spec("粉丝团点击延迟(s)", "fansclub_click_delay_var", cfg_get(data.cfg, "fansclub_click_delay"), from_=0.1, to=5.0, increment=0.1),
spin_spec("自动加入等待(s)", "fansclub_auto_wait_var", cfg_get(data.cfg, "fansclub_auto_join_wait_seconds"), from_=0.5, to=10.0, increment=0.5),
spin_spec("手动加入等待(s)", "fansclub_manual_wait_var", cfg_get(data.cfg, "fansclub_manual_wait_seconds"), from_=0.5, to=10.0, increment=0.5),
])
def build_reservation_settings(parent: tk.Misc, data: DashboardData, ctx: PageContext) -> None:
section(parent, "高价值预约", "预约参与 / 房间回访 / 回退校验")
box = card(parent, "高价值福袋预约参与")
box.pack(fill="x")
pack_switches(box, ctx, [
("启用预约(价值≥阈值)", "high_value_fudai_enabled_var", False),
("启用高价值房间回访", "high_value_room_revisit_enabled_var", True),
("仅当前运行", "high_value_room_revisit_only_current_run_var", False),
("预约回退校验", "reservation_back_verify_enabled_var", True),
])
pack_fields(box, ctx, [
spin_spec("价值阈值(元)", "high_value_fudai_threshold_yuan_var", cfg_get(data.cfg, "high_value_fudai_threshold_yuan"), from_=0, to=99999, increment=100),
spin_spec("提前参与(秒)", "high_value_fudai_join_ahead_seconds_var", cfg_get(data.cfg, "high_value_fudai_join_ahead_seconds"), from_=5, to=900, increment=10),
spin_spec("最多回退直播间次数", "high_value_fudai_max_swipe_back_var", cfg_get(data.cfg, "high_value_fudai_max_swipe_back"), from_=0, to=300, increment=5),
spin_spec("最多记录数量", "high_value_fudai_max_reservations_var", cfg_get(data.cfg, "high_value_fudai_max_reservations"), from_=1, to=50),
select_spec("完成后策略", "high_value_fudai_after_action_var", cfg_get(data.cfg, "high_value_fudai_after_action"), ["continue", "stay"]),
spin_spec("重访最小间隔(秒)", "high_value_room_revisit_min_interval_seconds_var", cfg_get(data.cfg, "high_value_room_revisit_min_interval_seconds"), from_=60, to=3600),
spin_spec("每次运行最大次数", "high_value_room_revisit_max_per_run_var", cfg_get(data.cfg, "high_value_room_revisit_max_per_run"), from_=1, to=20),
spin_spec("最低奖品价值(元)", "high_value_room_revisit_min_prize_value_var", cfg_get(data.cfg, "high_value_room_revisit_min_prize_value"), from_=0.0, to=10000.0),
spin_spec("最大年龄(天)", "high_value_room_revisit_max_age_days_var", cfg_get(data.cfg, "high_value_room_revisit_max_age_days"), from_=1, to=365),
spin_spec("开奖前轮询时间(秒)", "high_value_fudai_poll_before_seconds_var", cfg_get(data.cfg, "high_value_fudai_poll_before_seconds"), from_=0.0, to=60.0),
spin_spec("回退滑延迟(秒)", "reservation_back_swipe_delay_var", cfg_get(data.cfg, "reservation_back_swipe_delay"), from_=0.0, to=10.0, increment=0.1),
spin_spec("校验等待时间(秒)", "reservation_back_verify_wait_seconds_var", cfg_get(data.cfg, "reservation_back_verify_wait_seconds"), from_=0.1, to=10.0, increment=0.1),
])
def build_yanghao_settings(parent: tk.Misc, data: DashboardData, ctx: PageContext) -> None:
section(parent, "养号设置", "推荐页养号 / 互动动作 / 定时禁抢")
box = card(parent, "推荐页养号(爱心/收藏/评论)")
box.pack(fill="x", pady=(0, 12))
pack_switches(box, ctx, [
("养号总开关(关闭则跳过推荐页养号)", "yg_enabled_var", True),
("启用养号动作(爱心/收藏/评论)", "yg_actions_enabled_var", True),
("只养号(仅执行推荐页养号,跳过抽奖/参与)", "yg_only_var", False),
("逐步截图(调试用,生成 pic/*/latest.png)", "yg_step_screenshot_var", False),
("启用定时禁抢", "fudai_quiet_hours_enabled_var", True),
])
pack_fields(box, ctx, [
spin_spec("养号时长(秒)", "yg_recommend_duration_var", cfg_get(data.cfg, "yanghao_recommend_duration_seconds"), from_=1, to=3600, increment=5),
spin_spec("养号间隔(秒)", "yg_recommend_interval_var", cfg_get(data.cfg, "yanghao_recommend_interval_seconds"), from_=0, to=3600, increment=10),
spin_spec("爱心概率", "yg_like_prob_var", cfg_get(data.cfg, "yanghao_like_prob"), from_=0.0, to=1.0, increment=0.05),
spin_spec("收藏概率", "yg_fav_prob_var", cfg_get(data.cfg, "yanghao_fav_prob"), from_=0.0, to=1.0, increment=0.05),
spin_spec("评论概率", "yg_comment_prob_var", cfg_get(data.cfg, "yanghao_comment_prob"), from_=0.0, to=1.0, increment=0.05),
spin_spec("检测动作后停留最小(秒)", "yg_dwell_on_action_min_var", cfg_get(data.cfg, "yanghao_dwell_on_action_min_seconds"), from_=0.0, to=120.0),
spin_spec("检测动作后停留最大(秒)", "yg_dwell_on_action_max_var", cfg_get(data.cfg, "yanghao_dwell_on_action_max_seconds"), from_=0.0, to=120.0),
spin_spec("图标ROI大小(px)", "yg_icon_roi_size_var", cfg_get(data.cfg, "yanghao_icon_roi_size"), from_=80, to=600, increment=10),
spin_spec("匹配阈值", "yg_icon_match_threshold_var", cfg_get(data.cfg, "yanghao_icon_match_threshold"), from_=0.0, to=1.0, increment=0.01),
spin_spec("开始小时", "fudai_quiet_start_hour_var", cfg_get(data.cfg, "fudai_quiet_start_hour"), from_=0, to=23),
spin_spec("结束小时", "fudai_quiet_end_hour_var", cfg_get(data.cfg, "fudai_quiet_end_hour"), from_=0, to=23),
])
texts = tk.Frame(parent, bg=theme.BG)
texts.pack(fill="both", expand=True)
texts.grid_columnconfigure(0, weight=1)
texts.grid_columnconfigure(1, weight=1)
left = tk.Frame(texts, bg=theme.BG)
right = tk.Frame(texts, bg=theme.BG)
left.grid(row=0, column=0, sticky="nsew", padx=(0, 8))
right.grid(row=0, column=1, sticky="nsew", padx=(8, 0))
text_box(left, ctx, "yg_comment_texts", "评论文案库(每行一条)", data.cfg.get("yanghao_comment_texts", []) or [], height=7)
text_box(right, ctx, "yg_like_keywords_text", "爱心关键词(每行一条)", data.cfg.get("yanghao_like_keywords", []) or [], height=3)
text_box(right, ctx, "yg_fav_keywords_text", "收藏关键词(每行一条)", data.cfg.get("yanghao_fav_keywords", []) or [], height=3)
def build_logging(parent: tk.Misc, data: DashboardData, ctx: PageContext) -> None:
section(parent, "日志配置", "日志格式、保留策略、实时状态刷新")
box = card(parent, "日志与界面")
box.pack(fill="x")
pack_switches(box, ctx, [
("启用日志美化", "logging_beautify_var", True),
("启用颜色显示", "logging_color_var", True),
("显示时间戳", "logging_show_timestamps_var", True),
("启用日志监控(超限告警/触发清理)", "logging_enable_monitor_var", True),
("按日期拆分日志", "logging_use_dated_logs_var", True),
("写入统一日志", "log_unified_enabled_var", True),
("压缩旧日志", "logging_compress_logs_var", True),
("启用性能追踪", "logging_performance_enabled_var", True),
("追踪函数调用", "logging_track_functions_var", True),
("流式后台截图(加速但可能导致并发读取)", "streaming_enabled_var", True),
("详细阶段诊断日志", "stage_diag_verbose_var", False),
])
pack_fields(box, ctx, [
select_spec("日志格式模式", "logging_format_mode_var", cfg_get(data.cfg, "logging", "log_format_mode"), ["simple", "detailed"]),
("统一日志路径", "log_unified_path_var", cfg_get(data.cfg, "log_unified_path")),
spin_spec("保留天数", "logging_keep_days_var", cfg_get(data.cfg, "logging", "keep_days"), from_=1, to=365),
spin_spec("总量上限(GB)", "logging_max_total_size_gb_var", cfg_get(data.cfg, "logging", "max_total_size_gb"), from_=0.1, to=100.0, increment=0.1),
spin_spec("压缩阈值(天)", "logging_compress_after_days_var", cfg_get(data.cfg, "logging", "compress_after_days"), from_=0, to=365),
spin_spec("日志总大小警告阈值(MB)", "logging_monitor_warning_mb_var", cfg_get(data.cfg, "logging", "monitor_warning_mb"), from_=50, to=20000, increment=50),
spin_spec("严重阈值(MB)", "logging_monitor_critical_mb_var", cfg_get(data.cfg, "logging", "monitor_critical_mb"), from_=100, to=100000, increment=100),
("日志调试详细度", "logging_debug_level_var", cfg_get(data.cfg, "logging", "debug_detail_level")),
("错误详细度", "logging_error_level_var", cfg_get(data.cfg, "logging", "error_detail_level")),
("行为日志格式", "logging_action_format_var", cfg_get(data.cfg, "logging", "action_log_format")),
select_spec("界面主题", "gui_theme_var", cfg_get(data.cfg, "gui", "theme"), ["litera", "flatly", "journal", "minty", "cosmo", "darkly"]),
spin_spec("实时状态刷新(ms)", "gui_realtime_refresh_interval_ms_var", cfg_get(data.cfg, "gui", "realtime_status", "refresh_interval_ms"), from_=200, to=10000, increment=100),
spin_spec("实时状态条数", "gui_realtime_tail_items_var", cfg_get(data.cfg, "gui", "realtime_status", "tail_items"), from_=10, to=500, increment=10),
])
row = tk.Frame(box, bg=theme.SURFACE)
row.pack(fill="x", padx=20, pady=(0, 16))
button(row, "保存日志配置", ctx.action("save_config"), kind="primary").pack(side="left")
def build_keywords(parent: tk.Misc, data: DashboardData, ctx: PageContext) -> None:
section(parent, "关键词", "白名单与黑名单")
body = tk.Frame(parent, bg=theme.BG)
body.pack(fill="both", expand=True)
body.grid_columnconfigure(0, weight=1)
body.grid_columnconfigure(1, weight=1)
left = tk.Frame(body, bg=theme.BG)
right = tk.Frame(body, bg=theme.BG)
left.grid(row=0, column=0, sticky="nsew", padx=(0, 8))
right.grid(row=0, column=1, sticky="nsew", padx=(8, 0))
text_box(left, ctx, "want_text", "想要 contains_want(白名单,空=不限制)", data.cfg.get("contains_want", []) or [], height=18)
text_box(right, ctx, "not_want_text", "不想要 contains_not_want(黑名单)", data.cfg.get("contains_not_want", []) or [], height=18)
def build_license(parent: tk.Misc, data: DashboardData, ctx: PageContext) -> None:
section(parent, "授权", "输入卡密后自动联网验证")
box = card(parent, "卡密验证")
box.pack(fill="x")
if "license_key_var" not in ctx.vars:
ctx.vars["license_key_var"] = tk.StringVar(value="")
pack_fields(box, ctx, [("输入卡密", "license_key_var", "")], columns=1)
try:
os.environ["DOUYIN_LICENSE_REQUIRED"] = "1"
payload = get_license_status_payload()
except Exception as exc:
payload = {"ok": False, "message": f"读取授权状态失败:{exc}", "reason": "status_error"}
ok = bool(payload.get("ok"))
message = str(payload.get("message") or payload.get("reason") or "未知状态")
status = tk.Frame(box, bg=theme.GREEN_SOFT if ok else theme.AMBER_SOFT)
status.pack(fill="x", padx=20, pady=(0, 12))
tk.Label(
status,
text=("当前授权有效" if ok else "当前授权未通过"),
bg=status["bg"],
fg=theme.GREEN if ok else theme.AMBER,
font=("Microsoft YaHei UI", 12, "bold"),
).pack(side="left", padx=12, pady=8)
tk.Label(
status,
text=message,
bg=status["bg"],
fg=theme.TEXT,
font=theme.FONT_SMALL,
).pack(side="left", padx=(8, 12), pady=8)
row = tk.Frame(box, bg=theme.SURFACE)
row.pack(fill="x", padx=20, pady=(0, 16))
button(row, "验证卡密", ctx.action("verify_license"), kind="primary").pack(side="left", padx=(0, 8))
button(row, "上传诊断日志", ctx.action("upload_logs"), kind="soft").pack(side="left", padx=(0, 8))