|
@@ -0,0 +1,744 @@
|
|
|
|
|
+# -*- coding: utf-8 -*-
|
|
|
|
|
+"""Tkinter 桌面操作台(可选界面,零第三方依赖)。
|
|
|
|
|
+
|
|
|
|
|
+布局参照 J线界面功能映射还原原工具主窗口的信息结构(原工具为易语言窗体,
|
|
|
|
|
+白盒取其面板语义:账号库/监控池/发布队列/金牛面板 + 线程启停 + 日志)。
|
|
|
|
|
+
|
|
|
|
|
+用法:python -m kuaishou_tool.ui 或 python -m kuaishou_tool.cli ui
|
|
|
|
|
+
|
|
|
|
|
+线程模型:
|
|
|
|
|
+- 所有网络/ffmpeg 操作在后台 daemon 线程执行,结果经队列回填主线程(不卡界面);
|
|
|
|
|
+- 「全自动」= 发布调度线程 + auto_round 循环线程,共用 stop_event 一起停;
|
|
|
|
|
+- 「金牛托管」默认只读(写操作仍由 config.json 的 ads 开关控制,界面不提供
|
|
|
|
|
+ 任何直接动钱的入口;充值只会出现二维码,付款必须人工扫码)。
|
|
|
|
|
+"""
|
|
|
|
|
+import json
|
|
|
|
|
+import logging
|
|
|
|
|
+import queue
|
|
|
|
|
+import re
|
|
|
|
|
+import shutil
|
|
|
|
|
+import sys
|
|
|
|
|
+import threading
|
|
|
|
|
+import tkinter as tk
|
|
|
|
|
+from tkinter import filedialog, messagebox, simpledialog, ttk
|
|
|
|
|
+
|
|
|
|
|
+from . import accounts, collect, config, db, media, niu, publish, scheduler
|
|
|
|
|
+
|
|
|
|
|
+# 日志捕获目标(media 单独关了 propagate,需逐个挂)
|
|
|
|
|
+_LOGGERS = ('kuaishou_tool', 'kuaishou_tool.media', 'kuaishou_tool.publish',
|
|
|
|
|
+ 'kuaishou_tool.niu')
|
|
|
|
|
+_LOG_MAX_LINES = 3000
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+# --------------------------------------------------------------------------
|
|
|
|
|
+# 数据供给(与界面解离的纯查询,便于无窗口测试)
|
|
|
|
|
+# --------------------------------------------------------------------------
|
|
|
|
|
+
|
|
|
|
|
+def anchor_rows():
|
|
|
|
|
+ """账号库行(展示列含金牛回写的 yue/ciliroi 与三把CK的持有状态)。"""
|
|
|
|
|
+ rows = []
|
|
|
|
|
+ for r in db.query(
|
|
|
|
|
+ 'SELECT uid, userName, rizhi, yue, ciliroi, jrfb, fenlei, '
|
|
|
|
|
+ 'length(cookie1) AS n1, length(cookie2) AS n2, length(cookie3) AS n3 '
|
|
|
|
|
+ 'FROM anchor ORDER BY id'):
|
|
|
|
|
+ d = dict(r)
|
|
|
|
|
+ d['ck'] = '/'.join('✓' if d[f'n{i}'] else '–' for i in (1, 2, 3))
|
|
|
|
|
+ rows.append(d)
|
|
|
|
|
+ return rows
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def monitoring_rows(fenlei=None):
|
|
|
|
|
+ """监控池行;fenlei 非空时按分类过滤(对齐原工具「加载监控分类账号」)。"""
|
|
|
|
|
+ if fenlei:
|
|
|
|
|
+ return [dict(r) for r in db.query(
|
|
|
|
|
+ 'SELECT name, uid, fensishu, zuopinshu, shangpinshu, shangcitime, fenlei '
|
|
|
|
|
+ 'FROM monitoring WHERE fenlei=? ORDER BY id', (fenlei,))]
|
|
|
|
|
+ return [dict(r) for r in db.query(
|
|
|
|
|
+ 'SELECT name, uid, fensishu, zuopinshu, shangpinshu, shangcitime, fenlei '
|
|
|
|
|
+ 'FROM monitoring ORDER BY id')]
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+# --------------------------------------------------------------------------
|
|
|
|
|
+# 设置面板(J线 §1.2 筛选条件/§1.4 文字封面/§1.5 自动调整ROI/§1.1 设置带的
|
|
|
|
|
+# 白盒等价:config.json 的表单化)。字段声明驱动,读写为可测试的纯函数。
|
|
|
|
|
+# --------------------------------------------------------------------------
|
|
|
|
|
+
|
|
|
|
|
+SETTINGS_FIELDS = [
|
|
|
|
|
+ # (分组, config键路径, 标签, 类型, 默认值)
|
|
|
|
|
+ ('采集过滤', 'collect.filters.min_likes', '最低点赞', 'int', 0),
|
|
|
|
|
+ ('采集过滤', 'collect.filters.min_plays', '最低播放', 'int', 0),
|
|
|
|
|
+ ('采集过滤', 'collect.filters.max_age_hours', '最大发布时长(小时,0不限)', 'float', 0),
|
|
|
|
|
+ ('采集过滤', 'collect.filters.keywords_block', '违禁词(逗号分隔)', 'list', []),
|
|
|
|
|
+ ('采集过滤', 'collect.filters.min_commission', '最低佣金(0不限)', 'float', 0),
|
|
|
|
|
+ ('采集过滤', 'collect.filters.max_price', '最高客单价(0不限)', 'float', 0),
|
|
|
|
|
+ ('采集过滤', 'collect.filters.need_goods', '需挂车(无商品则过滤)', 'bool', True),
|
|
|
|
|
+ ('采集', 'collect.poll_interval_sec', '轮询间隔(秒)', 'int', 300),
|
|
|
|
|
+ ('发布', 'publish.fragment_mb', '分片大小(MB)', 'int', 8),
|
|
|
|
|
+ ('发布', 'publish.daily_limit_per_account', '单账号日发布上限', 'int', 5),
|
|
|
|
|
+ ('AI生图', 'ai.model', '模型', 'str', 'cogview-3-flash'),
|
|
|
|
|
+ ('AI生图', 'ai.image_size', '生图尺寸(WxH)', 'str', '1024x1024'),
|
|
|
|
|
+ ('AI生图', 'ai.pollinations_fallback', 'pollinations 兜底', 'bool', True),
|
|
|
|
|
+ ('AI生图', 'ai.key_cooldown_sec', 'key 失败冷却(秒)', 'int', 300),
|
|
|
|
|
+ ('翻译', 'translate.baidu_appid', '百度 APPID', 'str', ''),
|
|
|
|
|
+ ('翻译', 'translate.baidu_key', '百度密钥', 'str', ''),
|
|
|
|
|
+ ('文字封面', 'caption.font_size', '字体大小', 'int', 32),
|
|
|
|
|
+ ('文字封面', 'caption.font_color', '字体颜色', 'str', 'white'),
|
|
|
|
|
+ ('文字封面', 'caption.box', '文字背景框', 'bool', True),
|
|
|
|
|
+ ('文字封面', 'caption.box_color', '背景颜色', 'str', 'black'),
|
|
|
|
|
+ ('文字封面', 'caption.box_opacity', '背景透明度(0~1)', 'float', 0.5),
|
|
|
|
|
+ ('文字封面', 'caption.border_w', '描边大小(0=无)', 'int', 0),
|
|
|
|
|
+ ('文字封面', 'caption.border_color', '描边颜色', 'str', 'black'),
|
|
|
|
|
+ ('文字封面', 'caption.shadow_color', '阴影颜色(空=无)', 'str', ''),
|
|
|
|
|
+ ('金牛托管', 'ads.enabled', '总开关(关=只读)', 'bool', False),
|
|
|
|
|
+ ('金牛托管', 'ads.stop_enabled', '自动停计划', 'bool', True),
|
|
|
|
|
+ ('金牛托管', 'ads.stop_cost_threshold', '停计划消耗阈值(元)', 'float', 10.0),
|
|
|
|
|
+ ('金牛托管', 'ads.bid_enabled', '自动调ROI', 'bool', True),
|
|
|
|
|
+ ('金牛托管', 'ads.roi_target', '目标ROI(0=不调)', 'float', 0.0),
|
|
|
|
|
+ ('金牛托管', 'ads.roi_tolerance', 'ROI 容差', 'float', 0.0),
|
|
|
|
|
+ ('金牛托管', 'ads.recharge_enabled', '充值下单(付款须人工扫码)', 'bool', False),
|
|
|
|
|
+ ('金牛托管', 'ads.recharge_threshold', '充值触发余额(元,0=不触发)', 'float', 0.0),
|
|
|
|
|
+ ('金牛托管', 'ads.recharge_amount', '单次充值金额(元)', 'float', 0.0),
|
|
|
|
|
+]
|
|
|
|
|
+_LIST_SPLIT_RE = re.compile(r'[,,、]')
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def _dig(cfg, path):
|
|
|
|
|
+ cur = cfg
|
|
|
|
|
+ for k in path.split('.'):
|
|
|
|
|
+ cur = cur.get(k) if isinstance(cur, dict) else None
|
|
|
|
|
+ if cur is None:
|
|
|
|
|
+ return None
|
|
|
|
|
+ return cur
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def _bury(cfg, path, value):
|
|
|
|
|
+ keys = path.split('.')
|
|
|
|
|
+ cur = cfg
|
|
|
|
|
+ for k in keys[:-1]:
|
|
|
|
|
+ cur = cur.setdefault(k, {})
|
|
|
|
|
+ cur[keys[-1]] = value
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def form_values(cfg):
|
|
|
|
|
+ """cfg → 表单初值 {键路径: 字符串值}(缺失项取字段默认)。"""
|
|
|
|
|
+ vals = {}
|
|
|
|
|
+ for _group, path, _label, typ, default in SETTINGS_FIELDS:
|
|
|
|
|
+ v = _dig(cfg, path)
|
|
|
|
|
+ if v is None:
|
|
|
|
|
+ v = default
|
|
|
|
|
+ if typ == 'bool':
|
|
|
|
|
+ vals[path] = '1' if v else '0'
|
|
|
|
|
+ elif typ == 'list':
|
|
|
|
|
+ vals[path] = ','.join(v)
|
|
|
|
|
+ else:
|
|
|
|
|
+ vals[path] = str(v)
|
|
|
|
|
+ return vals
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def apply_form(cfg, vals):
|
|
|
|
|
+ """表单字符串值写回 cfg(原地);bool/int/float/list 按类型解析。"""
|
|
|
|
|
+ for _group, path, _label, typ, _default in SETTINGS_FIELDS:
|
|
|
|
|
+ raw = str(vals.get(path, '')).strip()
|
|
|
|
|
+ if typ == 'bool':
|
|
|
|
|
+ _bury(cfg, path, raw.lower() in ('1', 'true', 'yes', '是'))
|
|
|
|
|
+ elif typ == 'int':
|
|
|
|
|
+ _bury(cfg, path, int(float(raw or 0)))
|
|
|
|
|
+ elif typ == 'float':
|
|
|
|
|
+ _bury(cfg, path, float(raw or 0))
|
|
|
|
|
+ elif typ == 'list':
|
|
|
|
|
+ _bury(cfg, path, [x.strip() for x in _LIST_SPLIT_RE.split(raw) if x.strip()])
|
|
|
|
|
+ else:
|
|
|
|
|
+ _bury(cfg, path, raw)
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def queue_rows():
|
|
|
|
|
+ """发布队列行。"""
|
|
|
|
|
+ return [dict(r) for r in db.query(
|
|
|
|
|
+ 'SELECT videoId, state, liveTime, goodsId FROM publishvideo ORDER BY id')]
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+# --------------------------------------------------------------------------
|
|
|
|
|
+# 日志/输出捕获(scheduler 用 print,各模块用 logging,两者都进日志页)
|
|
|
|
|
+# --------------------------------------------------------------------------
|
|
|
|
|
+
|
|
|
|
|
+class _QueueLogHandler(logging.Handler):
|
|
|
|
|
+ def __init__(self, q):
|
|
|
|
|
+ super().__init__()
|
|
|
|
|
+ self.q = q
|
|
|
|
|
+
|
|
|
|
|
+ def emit(self, record):
|
|
|
|
|
+ try:
|
|
|
|
|
+ self.q.put_nowait(f'[{record.levelname}] {record.getMessage()}')
|
|
|
|
|
+ except Exception:
|
|
|
|
|
+ pass
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+class _StdoutProxy:
|
|
|
|
|
+ """把 print 输出(scheduler._log 等)镜像进日志页,同时保留原控制台。"""
|
|
|
|
|
+
|
|
|
|
|
+ def __init__(self, q, orig):
|
|
|
|
|
+ self.q, self.orig = q, orig
|
|
|
|
|
+
|
|
|
|
|
+ def write(self, s):
|
|
|
|
|
+ if s and s.strip():
|
|
|
|
|
+ self.q.put_nowait(s.rstrip('\n'))
|
|
|
|
|
+ try:
|
|
|
|
|
+ self.orig.write(s)
|
|
|
|
|
+ except Exception:
|
|
|
|
|
+ pass
|
|
|
|
|
+
|
|
|
|
|
+ def flush(self):
|
|
|
|
|
+ try:
|
|
|
|
|
+ self.orig.flush()
|
|
|
|
|
+ except Exception:
|
|
|
|
|
+ pass
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+class App(tk.Tk):
|
|
|
|
|
+ def __init__(self, cfg):
|
|
|
|
|
+ super().__init__()
|
|
|
|
|
+ self.cfg = cfg
|
|
|
|
|
+ self.title('快手矩阵工具 · 白盒重建操作台')
|
|
|
|
|
+ self.geometry('1020x660')
|
|
|
|
|
+ self._logq = queue.Queue() # 日志行(任意线程 put,主线程定时取)
|
|
|
|
|
+ self._callq = queue.Queue() # 后台线程→主线程回调
|
|
|
|
|
+ self._stop_auto = threading.Event()
|
|
|
|
|
+ self._stop_niu = threading.Event()
|
|
|
|
|
+ self._auto_t = None
|
|
|
|
|
+ self._niu_t = None
|
|
|
|
|
+ self._orig_stdout = sys.stdout
|
|
|
|
|
+ self._build()
|
|
|
|
|
+ self._install_log_capture()
|
|
|
|
|
+ self.refresh_all()
|
|
|
|
|
+ self.protocol('WM_DELETE_WINDOW', self._on_close)
|
|
|
|
|
+ self.after(200, self._drain)
|
|
|
|
|
+
|
|
|
|
|
+ # ---------------- 布局 ----------------
|
|
|
|
|
+
|
|
|
|
|
+ def _build(self):
|
|
|
|
|
+ top = ttk.Frame(self)
|
|
|
|
|
+ top.pack(fill='x', padx=8, pady=6)
|
|
|
|
|
+ self._btn_auto = ttk.Button(top, text='全自动:启动', width=14,
|
|
|
|
|
+ command=self._toggle_auto)
|
|
|
|
|
+ self._btn_auto.pack(side='left')
|
|
|
|
|
+ self._btn_niu = ttk.Button(top, text='金牛托管:启动', width=14,
|
|
|
|
|
+ command=self._toggle_niu)
|
|
|
|
|
+ self._btn_niu.pack(side='left', padx=6)
|
|
|
|
|
+ ttk.Label(top, text='(金牛默认只读;写操作由 config.json ads 开关控制,充值须人工扫码)',
|
|
|
|
|
+ foreground='#888').pack(side='left')
|
|
|
|
|
+ self._status = ttk.Label(self, text='就绪', anchor='w', relief='sunken')
|
|
|
|
|
+ self._status.pack(side='bottom', fill='x')
|
|
|
|
|
+ nb = ttk.Notebook(self)
|
|
|
|
|
+ nb.pack(fill='both', expand=True, padx=6, pady=4)
|
|
|
|
|
+ self._tab_anchor(nb)
|
|
|
|
|
+ self._tab_monitor(nb)
|
|
|
|
|
+ self._tab_queue(nb)
|
|
|
|
|
+ self._tab_settings(nb)
|
|
|
|
|
+ self._tab_log(nb)
|
|
|
|
|
+
|
|
|
|
|
+ def _table(self, parent, cols):
|
|
|
|
|
+ wrap = ttk.Frame(parent)
|
|
|
|
|
+ wrap.pack(fill='both', expand=True)
|
|
|
|
|
+ tree = ttk.Treeview(wrap, columns=[k for k, _, _ in cols], show='headings')
|
|
|
|
|
+ for k, label, w in cols:
|
|
|
|
|
+ tree.heading(k, text=label)
|
|
|
|
|
+ tree.column(k, width=w, anchor='w')
|
|
|
|
|
+ ysb = ttk.Scrollbar(wrap, orient='vertical', command=tree.yview)
|
|
|
|
|
+ tree.configure(yscrollcommand=ysb.set)
|
|
|
|
|
+ tree.pack(side='left', fill='both', expand=True)
|
|
|
|
|
+ ysb.pack(side='right', fill='y')
|
|
|
|
|
+ return tree
|
|
|
|
|
+
|
|
|
|
|
+ def _tab_anchor(self, nb):
|
|
|
|
|
+ f = ttk.Frame(nb)
|
|
|
|
|
+ nb.add(f, text=' 账号库 ')
|
|
|
|
|
+ bar1 = ttk.Frame(f)
|
|
|
|
|
+ bar1.pack(fill='x', pady=(4, 0))
|
|
|
|
|
+ ttk.Label(bar1, text='扫码登录:').pack(side='left')
|
|
|
|
|
+ for site, label in (('web', '网页CK'), ('shop', '小店CK'), ('fenxiao', '分销CK')):
|
|
|
|
|
+ ttk.Button(bar1, text=label,
|
|
|
|
|
+ command=lambda s=site: self._login_site(s)).pack(side='left', padx=3)
|
|
|
|
|
+ ttk.Label(bar1, text='(内嵌浏览器,登录成功自动抓取入库;验证码在窗口里人工过)',
|
|
|
|
|
+ foreground='#888').pack(side='left')
|
|
|
|
|
+ bar = ttk.Frame(f)
|
|
|
|
|
+ bar.pack(fill='x', pady=4)
|
|
|
|
|
+ for text, cmd in (('导入CK…', self._import_ck), ('校验全部', self._check_all),
|
|
|
|
|
+ ('删除账号', self._del_anchor), ('导出CK…', self._export_ck)):
|
|
|
|
|
+ ttk.Button(bar, text=text, command=cmd).pack(side='left', padx=3)
|
|
|
|
|
+ ttk.Button(bar, text='导入小店CK…',
|
|
|
|
|
+ command=lambda: self._import_shop_ck('cookie2')).pack(side='left', padx=3)
|
|
|
|
|
+ ttk.Button(bar, text='导入分销CK…',
|
|
|
|
|
+ command=lambda: self._import_shop_ck('cookie3')).pack(side='left', padx=3)
|
|
|
|
|
+ ttk.Button(bar, text='刷新', command=self.refresh_anchor).pack(side='left', padx=3)
|
|
|
|
|
+ self._tree_anchor = self._table(f, [
|
|
|
|
|
+ ('uid', 'UID', 110), ('userName', '名称', 120), ('rizhi', '状态', 90),
|
|
|
|
|
+ ('ck', 'CK 网/店/分', 90), ('yue', '余额', 70), ('ciliroi', '金牛ROI', 75),
|
|
|
|
|
+ ('jrfb', '最近发布', 140), ('fenlei', '分类', 70)])
|
|
|
|
|
+
|
|
|
|
|
+ def _login_site(self, site):
|
|
|
|
|
+ """内嵌浏览器扫码登录抓CK(独立子进程跑 pywebview,避免与 Tk 事件循环冲突),
|
|
|
|
|
+ 成功后自动入库:网页CK→import_cookie,小店/分销→import_shop_cookie。"""
|
|
|
|
|
+ from . import login as login_mod
|
|
|
|
|
+ conf = login_mod.SITES[site]
|
|
|
|
|
+ col = conf['column']
|
|
|
|
|
+
|
|
|
|
|
+ def job():
|
|
|
|
|
+ import subprocess as sp
|
|
|
|
|
+ r = sp.run([sys.executable, '-X', 'utf8', '-m', 'kuaishou_tool.login', site],
|
|
|
|
|
+ capture_output=True, text=True, encoding='utf-8',
|
|
|
|
|
+ cwd=str(config.ROOT), timeout=login_mod.WAIT_SEC + 120)
|
|
|
|
|
+ lines = (r.stdout or '').strip().splitlines()
|
|
|
|
|
+ last = lines[-1] if lines else ''
|
|
|
|
|
+ if not last.startswith('CK_OK '):
|
|
|
|
|
+ # 带出末尾诊断行(DEBUG poll=.../get_cookies异常等)便于定位
|
|
|
|
|
+ raise RuntimeError(' | '.join(lines[-3:])
|
|
|
|
|
+ or f'登录进程退出码 {r.returncode}')
|
|
|
|
|
+ return last[len('CK_OK '):]
|
|
|
|
|
+
|
|
|
|
|
+ def done(ck, err):
|
|
|
|
|
+ self.deiconify() # 登录流程结束,恢复主窗口
|
|
|
|
|
+ if err is not None:
|
|
|
|
|
+ self._set_status(f'扫码登录失败:{err}')
|
|
|
|
|
+ return
|
|
|
|
|
+ if col == 'cookie1':
|
|
|
|
|
+ n = accounts.import_cookie(ck, update=True)
|
|
|
|
|
+ self._set_status(f'网页CK已抓取并导入/更新(新账号 {n} 个,已存在者已覆盖续期)')
|
|
|
|
|
+ else:
|
|
|
|
|
+ u, s = accounts.import_shop_cookie(ck, col)
|
|
|
|
|
+ self._set_status(f'CK已抓取,回填 {u} 条,跳过 {s} 条'
|
|
|
|
|
+ '(小店/分销CK需先有网页CK账号行)')
|
|
|
|
|
+ self.refresh_anchor()
|
|
|
|
|
+
|
|
|
|
|
+ self._set_status(f'已弹出「{site}」登录窗口,完成扫码后自动抓取…')
|
|
|
|
|
+ self.iconify() # 最小化主窗,登录窗口不再被遮挡
|
|
|
|
|
+ self._bg(job, done)
|
|
|
|
|
+
|
|
|
|
|
+ def _tab_monitor(self, nb):
|
|
|
|
|
+ f = ttk.Frame(nb)
|
|
|
|
|
+ nb.add(f, text=' 监控池 ')
|
|
|
|
|
+ bar = ttk.Frame(f)
|
|
|
|
|
+ bar.pack(fill='x', pady=4)
|
|
|
|
|
+ for text, cmd in (('添加…', self._monitor_add), ('批量导入…', self._monitor_batch),
|
|
|
|
|
+ ('解析作品…', self._resolve_dialog),
|
|
|
|
|
+ ('删除选中', self._monitor_del), ('刷新资料', self._monitor_refresh),
|
|
|
|
|
+ ('采集一轮', self._poll_once)):
|
|
|
|
|
+ ttk.Button(bar, text=text, command=cmd).pack(side='left', padx=3)
|
|
|
|
|
+ self._fenlei_var = tk.StringVar(value='全部分类')
|
|
|
|
|
+ self._fenlei_combo = ttk.Combobox(bar, textvariable=self._fenlei_var,
|
|
|
|
|
+ width=10, state='readonly')
|
|
|
|
|
+ self._fenlei_combo.pack(side='left', padx=3)
|
|
|
|
|
+ ttk.Button(bar, text='刷新', command=self.refresh_monitor).pack(side='left', padx=3)
|
|
|
|
|
+ self._tree_monitor = self._table(f, [
|
|
|
|
|
+ ('name', '名称', 130), ('uid', 'UID', 110), ('fensishu', '粉丝', 70),
|
|
|
|
|
+ ('zuopinshu', '作品', 70), ('shangpinshu', '商品', 70),
|
|
|
|
|
+ ('shangcitime', '最近轮询', 140), ('fenlei', '分类', 80)])
|
|
|
|
|
+
|
|
|
|
|
+ def _tab_queue(self, nb):
|
|
|
|
|
+ f = ttk.Frame(nb)
|
|
|
|
|
+ nb.add(f, text=' 发布队列 ')
|
|
|
|
|
+ bar = ttk.Frame(f)
|
|
|
|
|
+ bar.pack(fill='x', pady=4)
|
|
|
|
|
+ for text, cmd in (('成片待处理', self._process_pending),
|
|
|
|
|
+ ('刷新', self.refresh_queue)):
|
|
|
|
|
+ ttk.Button(bar, text=text, command=cmd).pack(side='left', padx=3)
|
|
|
|
|
+ ttk.Label(f, text='排队任务由发布调度线程按 liveTime≤now-10min 取走执行',
|
|
|
|
|
+ foreground='#888').pack(anchor='w')
|
|
|
|
|
+ self._tree_queue = self._table(f, [
|
|
|
|
|
+ ('videoId', 'videoId', 150), ('state', '状态', 80),
|
|
|
|
|
+ ('liveTime', '定时时间', 150), ('goodsId', '商品ID', 120)])
|
|
|
|
|
+
|
|
|
|
|
+ def _tab_log(self, nb):
|
|
|
|
|
+ f = ttk.Frame(nb)
|
|
|
|
|
+ nb.add(f, text=' 日志 ')
|
|
|
|
|
+ self._log_text = tk.Text(f, height=10, state='disabled', wrap='none',
|
|
|
|
|
+ font=('Consolas', 9))
|
|
|
|
|
+ ysb = ttk.Scrollbar(f, orient='vertical', command=self._log_text.yview)
|
|
|
|
|
+ xsb = ttk.Scrollbar(f, orient='horizontal', command=self._log_text.xview)
|
|
|
|
|
+ self._log_text.configure(yscrollcommand=ysb.set, xscrollcommand=xsb.set)
|
|
|
|
|
+ self._log_text.pack(side='left', fill='both', expand=True)
|
|
|
|
|
+ ysb.pack(side='right', fill='y')
|
|
|
|
|
+ xsb.pack(side='bottom', fill='x')
|
|
|
|
|
+
|
|
|
|
|
+ # ---------------- 刷新(主线程直接查库,本地 sqlite 足够快) ----------------
|
|
|
|
|
+
|
|
|
|
|
+ @staticmethod
|
|
|
|
|
+ def _fill(tree, rows, keys):
|
|
|
|
|
+ tree.delete(*tree.get_children())
|
|
|
|
|
+ for r in rows:
|
|
|
|
|
+ tree.insert('', 'end', values=[str(r.get(k) or '') for k in keys])
|
|
|
|
|
+
|
|
|
|
|
+ def refresh_anchor(self):
|
|
|
|
|
+ self._fill(self._tree_anchor, anchor_rows(),
|
|
|
|
|
+ ('uid', 'userName', 'rizhi', 'ck', 'yue', 'ciliroi', 'jrfb', 'fenlei'))
|
|
|
|
|
+
|
|
|
|
|
+ def refresh_monitor(self):
|
|
|
|
|
+ cur = self._fenlei_var.get()
|
|
|
|
|
+ rows = monitoring_rows(None if cur in ('', '全部分类') else cur)
|
|
|
|
|
+ self._fill(self._tree_monitor, rows,
|
|
|
|
|
+ ('name', 'uid', 'fensishu', 'zuopinshu', 'shangpinshu',
|
|
|
|
|
+ 'shangcitime', 'fenlei'))
|
|
|
|
|
+ cats = sorted({r['fenlei'] for r in monitoring_rows() if r['fenlei']})
|
|
|
|
|
+ self._fenlei_combo['values'] = ['全部分类'] + cats
|
|
|
|
|
+ if cur not in self._fenlei_combo['values']:
|
|
|
|
|
+ self._fenlei_var.set('全部分类')
|
|
|
|
|
+
|
|
|
|
|
+ def refresh_queue(self):
|
|
|
|
|
+ self._fill(self._tree_queue, queue_rows(),
|
|
|
|
|
+ ('videoId', 'state', 'liveTime', 'goodsId'))
|
|
|
|
|
+
|
|
|
|
|
+ def refresh_all(self):
|
|
|
|
|
+ self.refresh_anchor()
|
|
|
|
|
+ self.refresh_monitor()
|
|
|
|
|
+ self.refresh_queue()
|
|
|
|
|
+
|
|
|
|
|
+ # ---------------- 后台执行器 ----------------
|
|
|
|
|
+
|
|
|
|
|
+ def _bg(self, job, done=None):
|
|
|
|
|
+ """job 在后台线程跑;done(res, err) 回主线程(经 _callq 队列)。"""
|
|
|
|
|
+ def run():
|
|
|
|
|
+ try:
|
|
|
|
|
+ res, err = job(), None
|
|
|
|
|
+ except Exception as e: # noqa: BLE001 界面层兜底展示
|
|
|
|
|
+ res, err = None, e
|
|
|
|
|
+ if done is not None:
|
|
|
|
|
+ self._callq.put(lambda: done(res, err))
|
|
|
|
|
+ threading.Thread(target=run, daemon=True).start()
|
|
|
|
|
+
|
|
|
|
|
+ def _drain(self):
|
|
|
|
|
+ """主线程定时泵:日志行入 Text + 执行后台回调。"""
|
|
|
|
|
+ n = 0
|
|
|
|
|
+ try:
|
|
|
|
|
+ while True:
|
|
|
|
|
+ line = self._logq.get_nowait()
|
|
|
|
|
+ self._log_text.configure(state='normal')
|
|
|
|
|
+ self._log_text.insert('end', line + '\n')
|
|
|
|
|
+ self._log_text.see('end')
|
|
|
|
|
+ self._log_text.configure(state='disabled')
|
|
|
|
|
+ n += 1
|
|
|
|
|
+ except queue.Empty:
|
|
|
|
|
+ pass
|
|
|
|
|
+ if n and float(self._log_text.index('end-1c').split('.')[0]) > _LOG_MAX_LINES:
|
|
|
|
|
+ self._log_text.delete('1.0', f'{_LOG_MAX_LINES // 3}.0')
|
|
|
|
|
+ try:
|
|
|
|
|
+ while True:
|
|
|
|
|
+ cb = self._callq.get_nowait()
|
|
|
|
|
+ try:
|
|
|
|
|
+ cb()
|
|
|
|
|
+ except Exception:
|
|
|
|
|
+ pass
|
|
|
|
|
+ except queue.Empty:
|
|
|
|
|
+ pass
|
|
|
|
|
+ self.after(200, self._drain)
|
|
|
|
|
+
|
|
|
|
|
+ def _set_status(self, text):
|
|
|
|
|
+ self._status.configure(text=text)
|
|
|
|
|
+
|
|
|
|
|
+ # ---------------- 账号页动作 ----------------
|
|
|
|
|
+
|
|
|
|
|
+ def _import_ck(self):
|
|
|
|
|
+ p = filedialog.askopenfilename(title='选择CK文件',
|
|
|
|
|
+ filetypes=[('文本', '*.txt'), ('全部', '*.*')])
|
|
|
|
|
+ if not p:
|
|
|
|
|
+ return
|
|
|
|
|
+ text = open(p, encoding='utf-8', errors='replace').read()
|
|
|
|
|
+
|
|
|
|
|
+ def done(n, err):
|
|
|
|
|
+ self._set_status(f'导入 {n} 条CK' if err is None else f'导入失败:{err}')
|
|
|
|
|
+ self.refresh_anchor()
|
|
|
|
|
+
|
|
|
|
|
+ self._bg(lambda: accounts.import_cookie(text), done)
|
|
|
|
|
+
|
|
|
|
|
+ def _import_shop_ck(self, column):
|
|
|
|
|
+ """导入小店/分销CK(按 UID 回填 anchor.cookie2/cookie3,已有账号行)。"""
|
|
|
|
|
+ title = '小店CK' if column == 'cookie2' else '分销CK'
|
|
|
|
|
+ p = filedialog.askopenfilename(title=f'选择{title}文件(每行: UID,CK 或 用户名,UID,CK)',
|
|
|
|
|
+ filetypes=[('文本', '*.txt'), ('全部', '*.*')])
|
|
|
|
|
+ if not p:
|
|
|
|
|
+ return
|
|
|
|
|
+ text = open(p, encoding='utf-8', errors='replace').read()
|
|
|
|
|
+
|
|
|
|
|
+ def done(res, err):
|
|
|
|
|
+ if err is not None:
|
|
|
|
|
+ self._set_status(f'{title}导入失败:{err}')
|
|
|
|
|
+ return
|
|
|
|
|
+ updated, skipped = res
|
|
|
|
|
+ self._set_status(f'{title}回填 {updated} 条,跳过 {skipped} 条'
|
|
|
|
|
+ '(无身份键/无对应账号行——网页CK需先导入)')
|
|
|
|
|
+ self.refresh_anchor()
|
|
|
|
|
+
|
|
|
|
|
+ self._bg(lambda: accounts.import_shop_cookie(text, column), done)
|
|
|
|
|
+
|
|
|
|
|
+ def _check_all(self):
|
|
|
|
|
+ def job():
|
|
|
|
|
+ out = []
|
|
|
|
|
+ for r in db.query('SELECT uid, userName FROM anchor ORDER BY id'):
|
|
|
|
|
+ out.append((r['userName'] or r['uid'], accounts.check_anchor(r['uid'])))
|
|
|
|
|
+ return out
|
|
|
|
|
+
|
|
|
|
|
+ def done(res, err):
|
|
|
|
|
+ if err is not None:
|
|
|
|
|
+ self._set_status(f'校验失败:{err}')
|
|
|
|
|
+ return
|
|
|
|
|
+ bad = [n for n, ok in res if not ok]
|
|
|
|
|
+ self._set_status(f'CK校验完成:{len(res)} 个账号,有效 {len(res) - len(bad)}')
|
|
|
|
|
+ if bad:
|
|
|
|
|
+ messagebox.showwarning('CK校验', '以下账号CK无效:\n' + '\n'.join(bad[:20]),
|
|
|
|
|
+ parent=self)
|
|
|
|
|
+ self.refresh_anchor()
|
|
|
|
|
+
|
|
|
|
|
+ self._bg(job, done)
|
|
|
|
|
+
|
|
|
|
|
+ # ---------------- 监控页动作 ----------------
|
|
|
|
|
+
|
|
|
|
|
+ def _monitor_add(self):
|
|
|
|
|
+ name = simpledialog.askstring('添加监控', '名称:', parent=self)
|
|
|
|
|
+ if name is None:
|
|
|
|
|
+ return
|
|
|
|
|
+ uid = simpledialog.askstring('添加监控', 'UID:', parent=self)
|
|
|
|
|
+ if not uid:
|
|
|
|
|
+ return
|
|
|
|
|
+ ok = collect.add_monitor(name, uid)
|
|
|
|
|
+ self._set_status('已添加监控' if ok else '记录已存在')
|
|
|
|
|
+ self.refresh_monitor()
|
|
|
|
|
+
|
|
|
|
|
+ def _monitor_batch(self):
|
|
|
|
|
+ p = filedialog.askopenfilename(title='选择UID列表(每行一个,#注释)',
|
|
|
|
|
+ filetypes=[('文本', '*.txt'), ('全部', '*.*')])
|
|
|
|
|
+ if not p:
|
|
|
|
|
+ return
|
|
|
|
|
+ fenlei = simpledialog.askstring('批量导入', '分类(可空):', parent=self) or ''
|
|
|
|
|
+ uids = [ln.strip() for ln in open(p, encoding='utf-8', errors='replace')
|
|
|
|
|
+ if ln.strip() and not ln.lstrip().startswith('#')]
|
|
|
|
|
+
|
|
|
|
|
+ def done(res, err):
|
|
|
|
|
+ if err is not None:
|
|
|
|
|
+ self._set_status(f'批量导入失败:{err}')
|
|
|
|
|
+ return
|
|
|
|
|
+ added, skipped = res
|
|
|
|
|
+ self._set_status(f'批量导入:新增 {added},跳过 {skipped}')
|
|
|
|
|
+ self.refresh_monitor()
|
|
|
|
|
+
|
|
|
|
|
+ self._bg(lambda: collect.batch_add(uids, fenlei=fenlei), done)
|
|
|
|
|
+
|
|
|
|
|
+ def _monitor_del(self):
|
|
|
|
|
+ sel = self._tree_monitor.selection()
|
|
|
|
|
+ if not sel:
|
|
|
|
|
+ self._set_status('请先选中要删除的监控账号')
|
|
|
|
|
+ return
|
|
|
|
|
+ uid = self._tree_monitor.item(sel[0], 'values')[1]
|
|
|
|
|
+ if messagebox.askyesno('删除监控', f'确定删除监控账号 {uid}?', parent=self) \
|
|
|
|
|
+ and collect.delete_monitor(uid):
|
|
|
|
|
+ self._set_status(f'已删除 {uid}')
|
|
|
|
|
+ self.refresh_monitor()
|
|
|
|
|
+
|
|
|
|
|
+ def _monitor_refresh(self):
|
|
|
|
|
+ def done(n, err):
|
|
|
|
|
+ self._set_status(f'资料刷新 {n} 个账号' if err is None else f'资料刷新失败:{err}')
|
|
|
|
|
+ self.refresh_monitor()
|
|
|
|
|
+
|
|
|
|
|
+ self._bg(lambda: collect.refresh_monitor_stats(self.cfg), done)
|
|
|
|
|
+
|
|
|
|
|
+ def _poll_once(self):
|
|
|
|
|
+ def done(n, err):
|
|
|
|
|
+ self._set_status(f'采集完成:新增通过过滤 {n} 条'
|
|
|
|
|
+ if err is None else f'采集失败:{err}')
|
|
|
|
|
+
|
|
|
|
|
+ self._bg(lambda: collect.poll_all(self.cfg), done)
|
|
|
|
|
+
|
|
|
|
|
+ # ---------------- 队列页动作 ----------------
|
|
|
|
|
+
|
|
|
|
|
+ def _process_pending(self):
|
|
|
|
|
+ def job():
|
|
|
|
|
+ cfg, n = self.cfg, 0
|
|
|
|
|
+ for row in db.query("SELECT biaoti1 FROM biaoti WHERE panduan='0'"):
|
|
|
|
|
+ vid = row['biaoti1']
|
|
|
|
|
+ if media._find_source(cfg, vid) is None:
|
|
|
|
|
+ continue
|
|
|
|
|
+ if media.process_full(cfg, vid):
|
|
|
|
|
+ n += 1
|
|
|
|
|
+ return n
|
|
|
|
|
+
|
|
|
|
|
+ def done(n, err):
|
|
|
|
|
+ self._set_status(f'成片完成 {n} 个' if err is None else f'成片失败:{err}')
|
|
|
|
|
+ self.refresh_queue()
|
|
|
|
|
+
|
|
|
|
|
+ self._set_status('成片处理中(后台线程,详见日志页)…')
|
|
|
|
|
+ self._bg(job, done)
|
|
|
|
|
+
|
|
|
|
|
+ # ---------------- 设置页(J线参数面板的白盒等价) ----------------
|
|
|
|
|
+
|
|
|
|
|
+ def _tab_settings(self, nb):
|
|
|
|
|
+ f = ttk.Frame(nb)
|
|
|
|
|
+ nb.add(f, text=' 设置 ')
|
|
|
|
|
+ bar = ttk.Frame(f)
|
|
|
|
|
+ bar.pack(fill='x', pady=4)
|
|
|
|
|
+ ttk.Button(bar, text='保存设置', command=self._save_settings).pack(side='left', padx=3)
|
|
|
|
|
+ ttk.Button(bar, text='环境自检', command=self._env_check).pack(side='left', padx=3)
|
|
|
|
|
+ ttk.Label(bar, text='保存写入 config.json,对之后启动的线程/轮次生效',
|
|
|
|
|
+ foreground='#888').pack(side='left')
|
|
|
|
|
+ cols = (ttk.Frame(f), ttk.Frame(f))
|
|
|
|
|
+ for c in cols: # 与上方 bar.pack 同用 pack,不混 grid
|
|
|
|
|
+ c.pack(side='left', fill='both', expand=True, padx=6)
|
|
|
|
|
+ col_of = {'采集过滤': 0, '金牛托管': 0} # 左列放两个大组,其余右列
|
|
|
|
|
+ init = form_values(self.cfg)
|
|
|
|
|
+ self._settings_vars = {}
|
|
|
|
|
+ groups = {}
|
|
|
|
|
+ for group, path, label, typ, _default in SETTINGS_FIELDS:
|
|
|
|
|
+ groups.setdefault(group, []).append((path, label, typ))
|
|
|
|
|
+ for group, fields in groups.items():
|
|
|
|
|
+ lf = ttk.Labelframe(cols[col_of.get(group, 1)], text=group, padding=6)
|
|
|
|
|
+ lf.pack(fill='x', pady=4)
|
|
|
|
|
+ for i, (path, label, typ) in enumerate(fields):
|
|
|
|
|
+ if typ == 'bool':
|
|
|
|
|
+ var = tk.BooleanVar(value=init[path] == '1')
|
|
|
|
|
+ ttk.Checkbutton(lf, text=label, variable=var).grid(
|
|
|
|
|
+ row=i, column=0, columnspan=2, sticky='w')
|
|
|
|
|
+ else:
|
|
|
|
|
+ ttk.Label(lf, text=label).grid(row=i, column=0, sticky='w',
|
|
|
|
|
+ padx=(0, 6))
|
|
|
|
|
+ var = tk.StringVar(value=init[path])
|
|
|
|
|
+ ttk.Entry(lf, textvariable=var, width=24).grid(
|
|
|
|
|
+ row=i, column=1, sticky='w')
|
|
|
|
|
+ self._settings_vars[path] = var
|
|
|
|
|
+
|
|
|
|
|
+ def _save_settings(self):
|
|
|
|
|
+ vals = {}
|
|
|
|
|
+ for path, var in self._settings_vars.items():
|
|
|
|
|
+ v = var.get()
|
|
|
|
|
+ vals[path] = ('1' if v else '0') if isinstance(v, bool) else str(v)
|
|
|
|
|
+ try:
|
|
|
|
|
+ apply_form(self.cfg, vals)
|
|
|
|
|
+ config.DEFAULT_CFG.write_text(
|
|
|
|
|
+ json.dumps(self.cfg, ensure_ascii=False, indent=2), encoding='utf-8')
|
|
|
|
|
+ except Exception as e: # noqa: BLE001 界面层兜底展示
|
|
|
|
|
+ messagebox.showerror('保存失败', str(e), parent=self)
|
|
|
|
|
+ return
|
|
|
|
|
+ self._set_status('设置已保存到 config.json(对之后启动的线程/轮次生效)')
|
|
|
|
|
+
|
|
|
|
|
+ def _env_check(self):
|
|
|
|
|
+ """运行环境自检(对齐原工具启动流程的 ffmpeg/mkvmerge 检测)。"""
|
|
|
|
|
+ lines = []
|
|
|
|
|
+ for name in ('ffmpeg', 'ffprobe'):
|
|
|
|
|
+ p = shutil.which(name)
|
|
|
|
|
+ lines.append(f'{name}: {"OK " + p if p else "未找到(合成/去重不可用)"}')
|
|
|
|
|
+ lines.append(f'python: {sys.version.split()[0]}')
|
|
|
|
|
+ messagebox.showinfo('环境自检', '\n'.join(lines), parent=self)
|
|
|
|
|
+
|
|
|
|
|
+ # ---------------- 账号页补充动作 ----------------
|
|
|
|
|
+
|
|
|
|
|
+ def _del_anchor(self):
|
|
|
|
|
+ sel = self._tree_anchor.selection()
|
|
|
|
|
+ if not sel:
|
|
|
|
|
+ self._set_status('请先选中要删除的账号')
|
|
|
|
|
+ return
|
|
|
|
|
+ uid = self._tree_anchor.item(sel[0], 'values')[0]
|
|
|
|
|
+ if messagebox.askyesno('删除账号', f'确定删除账号 {uid}?(排队中的任务不受影响)',
|
|
|
|
|
+ parent=self):
|
|
|
|
|
+ db.exe('DELETE FROM anchor WHERE uid=?', (uid,))
|
|
|
|
|
+ self._set_status(f'已删除账号 {uid}')
|
|
|
|
|
+ self.refresh_anchor()
|
|
|
|
|
+
|
|
|
|
|
+ def _export_ck(self):
|
|
|
|
|
+ with_user = messagebox.askyesno(
|
|
|
|
|
+ '导出CK', '导出格式带用户名吗?\n(是: 用户名,UID,CK / 否: 纯CK)', parent=self)
|
|
|
|
|
+
|
|
|
|
|
+ def done(p, err):
|
|
|
|
|
+ self._set_status(f'CK 已导出: {p}' if err is None else f'导出失败:{err}')
|
|
|
|
|
+
|
|
|
|
|
+ self._bg(lambda: accounts.export_cookies(self.cfg, with_user), done)
|
|
|
|
|
+
|
|
|
|
|
+ def _resolve_dialog(self):
|
|
|
|
|
+ """单作品解析(对齐原工具「开始解析」入口):分享文本→解析→可下载入库。"""
|
|
|
|
|
+ text = simpledialog.askstring('解析作品', '粘贴分享文本/链接/photoId:', parent=self)
|
|
|
|
|
+ if not text:
|
|
|
|
|
+ return
|
|
|
|
|
+
|
|
|
|
|
+ def job():
|
|
|
|
|
+ return collect.resolve_photo(self.cfg, text)
|
|
|
|
|
+
|
|
|
|
|
+ def done(item, err):
|
|
|
|
|
+ if err is not None or not item:
|
|
|
|
|
+ messagebox.showwarning('解析', '解析失败或作品已失效', parent=self)
|
|
|
|
|
+ return
|
|
|
|
|
+ msg = (f"标题: {item['biaoti']}\n点赞 {item['likes']} 播放 {item['plays']}\n"
|
|
|
|
|
+ f"商品: {item['itemId'] or '无'}\nvideoId: {item['videoId']}")
|
|
|
|
|
+ if not messagebox.askyesno('解析成功', msg + '\n\n下载视频并入标题库?', parent=self):
|
|
|
|
|
+ return
|
|
|
|
|
+
|
|
|
|
|
+ def job2():
|
|
|
|
|
+ collect.download(self.cfg, item)
|
|
|
|
|
+ collect.save_biaoti(item)
|
|
|
|
|
+
|
|
|
|
|
+ self._bg(job2, lambda _r, e: self._set_status(
|
|
|
|
|
+ '已下载并入库' if e is None else f'下载失败:{e}'))
|
|
|
|
|
+
|
|
|
|
|
+ self._set_status('解析中…')
|
|
|
|
|
+ self._bg(job, done)
|
|
|
|
|
+
|
|
|
|
|
+ # ---------------- 线程启停 ----------------
|
|
|
|
|
+
|
|
|
|
|
+ def _toggle_auto(self):
|
|
|
|
|
+ if self._auto_t is not None and self._auto_t.is_alive():
|
|
|
|
|
+ self._stop_auto.set()
|
|
|
|
|
+ self._btn_auto.configure(text='全自动:启动')
|
|
|
|
|
+ self._set_status('全自动已停止(采集/成片/发布调度线程一并退出)')
|
|
|
|
|
+ return
|
|
|
|
|
+ self._stop_auto = threading.Event()
|
|
|
|
|
+ self._auto_t = threading.Thread(
|
|
|
|
|
+ target=scheduler.run_auto,
|
|
|
|
|
+ kwargs={'cfg': self.cfg, 'stop_event': self._stop_auto}, daemon=True)
|
|
|
|
|
+ self._auto_t.start()
|
|
|
|
|
+ self._btn_auto.configure(text='全自动:停止')
|
|
|
|
|
+ self._set_status('全自动运行中(采集→成片→排队 + 发布调度),详见日志页')
|
|
|
|
|
+
|
|
|
|
|
+ def _toggle_niu(self):
|
|
|
|
|
+ if self._niu_t is not None and self._niu_t.is_alive():
|
|
|
|
|
+ self._stop_niu.set()
|
|
|
|
|
+ self._btn_niu.configure(text='金牛托管:启动')
|
|
|
|
|
+ self._set_status('金牛托管已停止')
|
|
|
|
|
+ return
|
|
|
|
|
+ enabled = (self.cfg.get('ads') or {}).get('enabled')
|
|
|
|
|
+ if not enabled and not messagebox.askyesno(
|
|
|
|
|
+ '金牛托管', 'ads.enabled 未开启,将以只读模式运行(仅刷余额/报表)。\n'
|
|
|
|
|
+ '继续?', parent=self):
|
|
|
|
|
+ return
|
|
|
|
|
+ self._stop_niu = threading.Event()
|
|
|
|
|
+ self._niu_t = threading.Thread(
|
|
|
|
|
+ target=niu.run_auto, kwargs={'cfg': self.cfg, 'stop_event': self._stop_niu},
|
|
|
|
|
+ daemon=True)
|
|
|
|
|
+ self._niu_t.start()
|
|
|
|
|
+ self._btn_niu.configure(text='金牛托管:停止')
|
|
|
|
|
+ self._set_status('金牛托管运行中(' + ('写操作已启用,见 config.json ads 开关'
|
|
|
|
|
+ if enabled else '只读') + ')')
|
|
|
|
|
+
|
|
|
|
|
+ # ---------------- 日志捕获与退出 ----------------
|
|
|
|
|
+
|
|
|
|
|
+ def _install_log_capture(self):
|
|
|
|
|
+ h = _QueueLogHandler(self._logq)
|
|
|
|
|
+ h.setLevel(logging.INFO)
|
|
|
|
|
+ for name in _LOGGERS:
|
|
|
|
|
+ lg = logging.getLogger(name)
|
|
|
|
|
+ lg.addHandler(h)
|
|
|
|
|
+ if lg.level == logging.NOTSET:
|
|
|
|
|
+ lg.setLevel(logging.INFO)
|
|
|
|
|
+ if self._orig_stdout is not None:
|
|
|
|
|
+ sys.stdout = _StdoutProxy(self._logq, self._orig_stdout)
|
|
|
|
|
+
|
|
|
|
|
+ def _on_close(self):
|
|
|
|
|
+ self._stop_auto.set()
|
|
|
|
|
+ self._stop_niu.set()
|
|
|
|
|
+ sys.stdout = self._orig_stdout
|
|
|
|
|
+ self.destroy()
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def main():
|
|
|
|
|
+ cfg = config.load()
|
|
|
|
|
+ App(cfg).mainloop()
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+if __name__ == '__main__':
|
|
|
|
|
+ try:
|
|
|
|
|
+ sys.stdout.reconfigure(encoding='utf-8')
|
|
|
|
|
+ except Exception:
|
|
|
|
|
+ pass
|
|
|
|
|
+ main()
|