Browse Source

feat: UI补发布入口(排队发布选中/立即发布到期任务)

- 标题库页「排队发布选中…」:选中条目排队(账号可指定序号或自动轮转,
  cookie取小店CK优先),成片流转 临存视频→发布中视频,panduan置1
- 队列页「立即发布到期任务」:即时跑一轮调度执行C线8步(带任务面板)
- 全自动(顶栏)仍为托管主入口:排队+调度一体
wubinggen 3 months ago
parent
commit
0bcdbe496a
1 changed files with 61 additions and 0 deletions
  1. 61 0
      白盒重建/kuaishou_tool/ui.py

+ 61 - 0
白盒重建/kuaishou_tool/ui.py

@@ -387,6 +387,7 @@ class App(tk.Tk):
                           ('改标题…', self._edit_biaoti),
                           ('改标题…', self._edit_biaoti),
                           ('成片选中', self._make_selected),
                           ('成片选中', self._make_selected),
                           ('成片全部待处理', self._make_pending),
                           ('成片全部待处理', self._make_pending),
+                          ('排队发布选中…', self._queue_selected),
                           ('删除选中', self._del_biaoti),
                           ('删除选中', self._del_biaoti),
                           ('打开素材夹', lambda: self._open_dir('素材')),
                           ('打开素材夹', lambda: self._open_dir('素材')),
                           ('打开成品夹', lambda: self._open_dir('临存视频'))):
                           ('打开成品夹', lambda: self._open_dir('临存视频'))):
@@ -438,6 +439,48 @@ class App(tk.Tk):
                 db.exe('DELETE FROM biaoti WHERE biaoti1=?', (v,))
                 db.exe('DELETE FROM biaoti WHERE biaoti1=?', (v,))
             self._refresh_biaoti()
             self._refresh_biaoti()
 
 
+    def _queue_selected(self):
+        """排队发布选中条目:成片(临存视频/)→发布队列(发布中视频/)。
+        账号可选指定(序号)或自动分配(等待投递号轮转,排队后即回置)。"""
+        from . import tasks
+        sel = self._tree_biaoti.selection()
+        if not sel:
+            self._set_status('请先选中要发布的条目')
+            return
+        vids = [self._tree_biaoti.item(s, 'values')[0] for s in sel]
+        anchors = db.query('SELECT uid, userName, rizhi, cookie1, cookie2 FROM anchor ORDER BY id')
+        if not anchors:
+            self._set_status('账号库为空,先扫码登录导入账号')
+            return
+        listing = '\n'.join(f'{i + 1}. {r["userName"] or r["uid"]}({r["rizhi"]})'
+                            for i, r in enumerate(anchors[:15]))
+        choice = simpledialog.askstring(
+            '选择发布账号', f'账号序号(1-{len(anchors)}),留空=自动分配:\n{listing}',
+            parent=self)
+        anchor = None
+        if choice and choice.strip().isdigit() and 1 <= int(choice) <= len(anchors):
+            anchor = anchors[int(choice) - 1]
+        n = 0
+        for vid in vids:
+            src = config.dir_of(self.cfg, '临存视频') / f'{vid}.mp4'
+            if not src.exists():
+                continue                      # 无成片(未合成),跳过
+            a = anchor or accounts.next_anchor()
+            if a is None:
+                self._set_status('无可用账号(全部非「等待投递」),排队中止')
+                break
+            tasks.queue_publish(self.cfg, src,
+                                cookie=(a['cookie2'] or a['cookie1']),
+                                video_id=vid, goods_id='')
+            tasks.move(self.cfg, src, '临存视频', '发布中视频')
+            db.exe("UPDATE biaoti SET panduan='1' WHERE biaoti1=?", (vid,))
+            if anchor is None:
+                accounts.release_anchor(a['uid'], True)
+            n += 1
+        self._set_status(f'已排队 {n} 条(「立即发布」或顶栏全自动执行发送)')
+        self._refresh_biaoti()
+        self.refresh_queue()
+
     def _open_dir(self, name):
     def _open_dir(self, name):
         import os
         import os
         d = config.dir_of(self.cfg, name)
         d = config.dir_of(self.cfg, name)
@@ -450,6 +493,7 @@ class App(tk.Tk):
         bar = ttk.Frame(f)
         bar = ttk.Frame(f)
         bar.pack(fill='x', pady=4)
         bar.pack(fill='x', pady=4)
         for text, cmd in (('成片待处理', self._process_pending),
         for text, cmd in (('成片待处理', self._process_pending),
+                          ('立即发布到期任务', self._dispatch_now),
                           ('刷新', self.refresh_queue)):
                           ('刷新', self.refresh_queue)):
             ttk.Button(bar, text=text, command=cmd).pack(side='left', padx=3)
             ttk.Button(bar, text=text, command=cmd).pack(side='left', padx=3)
         ttk.Label(f, text='排队任务由发布调度线程按 liveTime≤now-10min 取走执行',
         ttk.Label(f, text='排队任务由发布调度线程按 liveTime≤now-10min 取走执行',
@@ -917,6 +961,23 @@ class App(tk.Tk):
         self._set_status('解析中…')
         self._set_status('解析中…')
         self._bg(job, done)
         self._bg(job, done)
 
 
+    def _dispatch_now(self):
+        """立即跑一轮发布调度(取到期任务执行 C线8步;结果看队列状态流转)。"""
+        def done(_r, err):
+            self._job_finish()
+            self._set_status('发布调度完成(结果见队列状态列/日志页)'
+                             if err is None else f'发布调度失败:{err}')
+            self.refresh_queue()
+            self.refresh_anchor()
+
+        due = len(db.query("SELECT id FROM publishvideo WHERE state='排队'"))
+        if not due:
+            self._set_status('没有排队中的任务')
+            return
+        self._job_begin('发布调度', 0)
+        self._set_status('发布执行中(步间有延时,详见日志页)…')
+        self._bg(lambda: publish.run_dispatcher(self.cfg, max_rounds=due), done)
+
     # ---------------- 线程启停 ----------------
     # ---------------- 线程启停 ----------------
 
 
     def _toggle_auto(self):
     def _toggle_auto(self):