Explorar el Código

feat: 发布8步进度条(准备→签名→分片→合并→上报→封面→提交→发布→完成)

- publish_full 增 progress(vid,stage,step)回调,8步刻度逐级上报
- run_dispatcher 透传;UI立即发布/排队直通的进度条改为 N条×8步确定型,
  当前条目+阶段名实时显示('3xabc…:封面生成')
wubinggen hace 3 meses
padre
commit
5f3a8030cd
Se han modificado 2 ficheros con 34 adiciones y 6 borrados
  1. 21 3
      白盒重建/kuaishou_tool/publish.py
  2. 13 3
      白盒重建/kuaishou_tool/ui.py

+ 21 - 3
白盒重建/kuaishou_tool/publish.py

@@ -425,7 +425,7 @@ def add_goods(client, goods_id):
 
 # ═══════════════ 步骤⑧:编排与调度 ═══════════════
 
-def publish_full(cfg, anchor_row, video_path, goods_id=''):
+def publish_full(cfg, anchor_row, video_path, goods_id='', progress=None):
     """编排②~⑦(C线8步;①鉴权由 anchor 行的 cookie2 提供)。
     相邻网络步骤之间随机延时 cfg['publish']['delay_sec']=[a,b]。
     标题来源(C线W1):biaoti 表 biaoti1=视频名(stem) → biaoti2;查不到用文件名。
@@ -438,7 +438,16 @@ def publish_full(cfg, anchor_row, video_path, goods_id=''):
     res = {'ok': False, 'stage': '准备', 'err': '', 'title': '',
            'upload_token': '', 'fragment_count': 0, 'slice_id': '', 'photo_id': '',
            'goods': None, 'limit': False, 'banned': False}
+    def _p(stage, step):
+        """进度回调:8步刻度(0准备~8结束),UI进度条用。"""
+        if progress:
+            try:
+                progress(video.stem, stage, step)
+            except Exception:
+                pass
+
     video = Path(video_path)
+    _p('准备', 0)
     if not video.exists():
         res['err'] = f'视频文件不存在:{video}'
         return res
@@ -456,6 +465,7 @@ def publish_full(cfg, anchor_row, video_path, goods_id=''):
                       proxy=_resolve_proxy(cfg, anchor_row))
 
     # ── ② 取上传签名/token ──
+    _p('签名', 1)
     try:
         sign = upload_sign(client, video.name, video.stat().st_size)
         res['upload_token'] = sign['upload_token']
@@ -463,6 +473,7 @@ def publish_full(cfg, anchor_row, video_path, goods_id=''):
         res['stage'], res['err'] = 'sign', str(e)
         return res
     # ── ③ 分片上传(8MB) ──
+    _p('分片上传', 2)
     rand_sleep(*delay)
     try:
         res['fragment_count'] = upload_fragment(client, video, res['upload_token'],
@@ -471,6 +482,7 @@ def publish_full(cfg, anchor_row, video_path, goods_id=''):
         res['stage'], res['err'] = 'fragment', str(e)
         return res
     # ── ④ complete ──
+    _p('合并完成', 3)
     rand_sleep(*delay)
     try:
         upload_complete(client, res['upload_token'], res['fragment_count'])
@@ -478,16 +490,20 @@ def publish_full(cfg, anchor_row, video_path, goods_id=''):
         res['stage'], res['err'] = 'complete', str(e)
         return res
     # ── ⑤ 上报换sliceId(report) → 等首帧封面(cover/list) → 提交slice ──
+    _p('上报', 4)
     rand_sleep(*delay)
     try:
         rep = report_slice(client, res['upload_token'])
         res['slice_id'] = rep['slice_id']
+        _p('封面生成', 5)
         cover = rep['cover_image'] or fetch_cover(client, rep['slice_id'])
+        _p('提交信息', 6)
         submit_slice(client, rep['slice_id'], cover)
     except Exception as e:
         res['stage'], res['err'] = 'slice', str(e)
         return res
     # ── ⑥ 正式发布(失败已在 do_publish 内回滚 ownVideo/delete) ──
+    _p('发布', 7)
     rand_sleep(*delay)
     try:
         p = do_publish(client, res['slice_id'], res['title'])
@@ -512,6 +528,7 @@ def publish_full(cfg, anchor_row, video_path, goods_id=''):
             res['stage'], res['err'] = 'goods', g.get('msg', '挂车失败')
             return res
     res['ok'], res['stage'] = True, '完成'
+    _p('完成', 8)
     return res
 
 
@@ -570,7 +587,7 @@ def _writeback_anchor(anchor_row, res):
         db.exe('UPDATE anchor SET jrfb=? WHERE uid=?', (db.now(), uid))
 
 
-def run_dispatcher(cfg, max_rounds=None, stop_event=None):
+def run_dispatcher(cfg, max_rounds=None, stop_event=None, progress=None):
     """⑧ 定时发布调度线程(C线F3):循环取到期任务(liveTime<=now-10min,即
     tasks.take_due)→ 组装 anchor/代理 → publish_full → 成功置'完成'、失败置'失败'
     (tasks.mark_state)。无任务空转 sleep DISPATCHER_IDLE_SEC 秒;单线程。
@@ -609,7 +626,8 @@ def run_dispatcher(cfg, max_rounds=None, stop_event=None):
                 tasks.mark_state(vid, '失败')
                 continue
             anchor = _anchor_for(cfg, row)
-            res = publish_full(cfg, anchor, video, row['goodsId'] or '')
+            res = publish_full(cfg, anchor, video, row['goodsId'] or '',
+                               progress=progress)
             _writeback_anchor(anchor, res)
             if res.get('ok'):
                 tasks.mark_state(vid, '完成')

+ 13 - 3
白盒重建/kuaishou_tool/ui.py

@@ -1135,9 +1135,19 @@ class App(tk.Tk):
             self.refresh_queue()
             self.refresh_anchor()
 
-        self._job_begin('发布调度', len(due) or 1)
-        self._set_status(f'发布执行中({len(due)} 条,步间有随机延时防风控,详见日志页)…')
-        self._bg(lambda: publish.run_dispatcher(self.cfg, max_rounds=len(due) or 1), done)
+        n = len(due)
+        order = {r['videoId']: i for i, r in enumerate(due)}
+        total_steps = n * 8
+
+        def prog(vid, stage, step):
+            cum = order.get(vid, 0) * 8 + step
+            self._callq.put(lambda c=cum, v=vid, st=stage, t=total_steps:
+                            self._job_progress(c, t, f'{v[:16]}:{st}'))
+
+        self._job_begin('发布调度', total_steps or 1)
+        self._set_status(f'发布执行中({n} 条×8步,随机延时防风控,进度见下方条)…')
+        self._bg(lambda: publish.run_dispatcher(self.cfg, max_rounds=n or 1,
+                                                 progress=prog if n else None), done)
 
     # ---------------- 线程启停 ----------------