Ver código fonte

feat: 发布全周期状态可视+防重发保险

- dispatcher 取走任务即置「发布中」→完成/失败,队列与标题库状态列
  实时联动(发布中5~15分钟不再显示'排队'假死)
- biaoti_rows LEFT JOIN publishvideo,状态列直读队列实况
- 排队发布选中防重发:已入队/发布中/完成的条目自动跳过并提示
  (失败的可重试);132测全绿
wubinggen 3 meses atrás
pai
commit
446b173d2a

+ 1 - 0
白盒重建/kuaishou_tool/publish.py

@@ -572,6 +572,7 @@ def run_dispatcher(cfg, max_rounds=None, stop_event=None):
             continue
             continue
         row = rows[0]
         row = rows[0]
         vid = row['videoId']
         vid = row['videoId']
+        tasks.mark_state(vid, '发布中')      # 取走即标记,表格可见+防并发重取
         try:
         try:
             video = _find_video(cfg, vid)
             video = _find_video(cfg, vid)
             if video is None:
             if video is None:

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

@@ -51,12 +51,17 @@ def anchor_rows(group=None):
 
 
 
 
 def biaoti_rows(cfg):
 def biaoti_rows(cfg):
-    """标题库行:videoId/标题/panduan状态(待处理|已排队)/素材是否已下载/商品ID。"""
+    """标题库行:状态列联动发布队列(发布中/完成/失败实时可见);
+    未入队的按 panduan 显示 待处理/已排队。"""
     mat = config.dir_of(cfg, '素材')
     mat = config.dir_of(cfg, '素材')
     rows = []
     rows = []
-    for r in db.query('SELECT biaoti1, biaoti2, panduan, goodsId FROM biaoti ORDER BY id'):
+    q = ('SELECT b.biaoti1, b.biaoti2, b.panduan, b.goodsId, p.state AS pstate '
+         'FROM biaoti b LEFT JOIN publishvideo p ON p.videoId = b.biaoti1 '
+         'ORDER BY b.id')
+    for r in db.query(q):
         d = dict(r)
         d = dict(r)
-        d['panduan'] = '已排队' if str(d['panduan']) == '1' else '待处理'
+        d['panduan'] = (d.pop('pstate') or '') \
+            or ('已排队' if str(d['panduan']) == '1' else '待处理')
         has = False
         has = False
         if mat.exists():
         if mat.exists():
             try:
             try:
@@ -503,6 +508,15 @@ class App(tk.Tk):
             self._set_status('请先选中要发布的条目')
             self._set_status('请先选中要发布的条目')
             return
             return
         vids = [self._tree_biaoti.item(s, 'values')[0] for s in sel]
         vids = [self._tree_biaoti.item(s, 'values')[0] for s in sel]
+        # 防重发:已在队列/发布中/完成的跳过(失败的可重试)
+        existing = {r['videoId']: r['state'] for r in db.query(
+            'SELECT videoId, state FROM publishvideo')}
+        blocked = ('排队', '发布中', '完成')
+        skip = [v for v in vids if existing.get(v) in blocked]
+        vids = [v for v in vids if existing.get(v) not in blocked]
+        if skip:
+            self._set_status(f'跳过 {len(skip)} 条已入队/已发布(不重复发):'
+                             + ','.join(skip[:5]))
         anchors = db.query('SELECT uid, userName, rizhi, cookie1, cookie2 FROM anchor ORDER BY id')
         anchors = db.query('SELECT uid, userName, rizhi, cookie1, cookie2 FROM anchor ORDER BY id')
         if not anchors:
         if not anchors:
             self._set_status('账号库为空,先扫码登录导入账号')
             self._set_status('账号库为空,先扫码登录导入账号')

+ 8 - 2
白盒重建/tests/test_ui.py

@@ -74,11 +74,17 @@ def test_biaoti_rows(_biaoti_cfg):
            "VALUES ('v1','标题一','0','')")
            "VALUES ('v1','标题一','0','')")
     db.exe("INSERT INTO biaoti (biaoti1, biaoti2, panduan, goodsId) "
     db.exe("INSERT INTO biaoti (biaoti1, biaoti2, panduan, goodsId) "
            "VALUES ('v2','标题二','1','g9')")
            "VALUES ('v2','标题二','1','g9')")
+    db.exe("INSERT INTO biaoti (biaoti1, biaoti2, panduan, goodsId) "
+           "VALUES ('v3','标题三','1','')")
+    db.exe("INSERT INTO publishvideo (videoId, state, liveTime) "
+           "VALUES ('v2','完成','2026-01-01 00:00:00')")
+    db.exe("INSERT INTO publishvideo (videoId, state, liveTime) "
+           "VALUES ('v3','发布中','2026-01-01 00:00:00')")
     (Path(_biaoti_cfg['dirs']['素材']) / 'v1.mp4').write_bytes(b'x')   # v1 有素材
     (Path(_biaoti_cfg['dirs']['素材']) / 'v1.mp4').write_bytes(b'x')   # v1 有素材
     rows = ui.biaoti_rows(_biaoti_cfg)
     rows = ui.biaoti_rows(_biaoti_cfg)
     assert rows[0]['panduan'] == '待处理' and rows[0]['has_mat'] == '有'
     assert rows[0]['panduan'] == '待处理' and rows[0]['has_mat'] == '有'
-    assert rows[1]['panduan'] == '已排队' and rows[1]['has_mat'] == '无'
-    assert rows[1]['goodsId'] == 'g9'
+    assert rows[1]['panduan'] == '完成' and rows[1]['goodsId'] == 'g9'   # 联动队列状态
+    assert rows[2]['panduan'] == '发布中'
 
 
 
 
 @pytest.fixture()
 @pytest.fixture()