Просмотр исходного кода

fix: 作品描述走 ownVideo/update(updateType=2),删除 publish 无效 caption 字段

- 挖 smartRelease 前端 kmi.js handleVideoCaptionChange 定位真实通道:
  描述=独立 update 调用 {sliceId,title,updateType:2}(封面=type3)
- publish.py 新增 set_caption(),publish_full 第⑥步内先封面后描述
- do_publish 删除实测无效的 caption body 键,title 形参保留兼容
- 测试:新增 set_caption 3 用例;publish_full 调用顺序断言改双 update
- 真机验证:发布 3xheigpu73dsx6s 后快手 App 显示标题✓(联调清单 P6)
- 136 测试全绿
wubinggen 3 месяцев назад
Родитель
Сommit
a18b8910e8

+ 22 - 5
白盒重建/kuaishou_tool/publish.py

@@ -81,7 +81,8 @@ SHELF_SAVE_URL = ('https://cps.kwaixiaodian.com/gateway/distribute/match/'   # 
 FRAGMENT_MB_DEFAULT = 8      # 分片大小,I线§3-1 定案 8MB(0x800000)
 FRAGMENT_RETRIES = 3         # 单片失败重试次数(C线未还原具体值,白盒默认3)
 DISPATCHER_IDLE_SEC = 30     # 调度线程空转休眠秒数
-UPDATE_TYPE = 3              # ownVideo/update 键值(P1 标定:真实抓包=3)
+UPDATE_TYPE = 3              # ownVideo/update 封面键值(P1 标定:真实抓包=3)
+CAPTION_UPDATE_TYPE = 2      # ownVideo/update 描述键值(前端kmi.js标定:updateType=2)
 NEED_CONFIRMATION = True     # ownVideo/publish 键值(P1 标定:真实抓包=true)
 SHELF_BIZ_CODE = 'pcShelfItemSelection'   # 挂车 bizCode(原工具常量模板,白盒可配置)
 
@@ -331,11 +332,28 @@ def submit_slice(client, slice_id, cover_image=''):
     return {'slice_id': str(slice_id), 'raw': j}
 
 
+def set_caption(client, slice_id, title):
+    """⑤b 写作品描述(前端源码标定):ownVideo/update?caver=2。
+    body {"sliceId":<数字>,"title":<描述>,"updateType":2}。
+    smartRelease 页 kmi.js 的 handleVideoCaptionChange 调 updateSliceInfo
+    {videoId, title, updateType:2}——描述不走 publish 的 caption(实测无效字段),
+    而是独立 update 调用(updateType:2=描述,3=封面)。videoId 即 sliceId。"""
+    if not title:
+        return {'slice_id': str(slice_id), 'raw': None}
+    body = {'sliceId': int(slice_id) if str(slice_id).isdigit() else slice_id,
+            'title': str(title), 'updateType': CAPTION_UPDATE_TYPE}
+    r = client.post(UPDATE_SLICE_URL, json_body=body, headers=_shop_headers())
+    j = _safe_json(r)
+    err = _err_of(j)
+    if getattr(r, 'status_code', 0) != 200 or j is None or err:
+        raise PublishError('作品描述提交失败:' + (err or _text_head(r)))
+    return {'slice_id': str(slice_id), 'raw': j}
+
+
 def do_publish(client, video_id, title=''):
     """⑥ 正式发布(P1 标定):ownVideo/publish?caver=2。
     body {"sliceId":<数字>,"needConfirmation":true,"fromUserId":""};
-    title 非空时附 caption(C线W6:caption=标题;抓包无此键因手动上传未填标题,
-    实测带回后验证)。
+    描述已由 set_caption(updateType:2)先行写入,title 形参仅为兼容旧签名。
     失败 → ownVideo/delete(body sliceIdList) 回滚,C线W7"发布视频失败-删除发布列表!";
     error_msg 含"正在发布中"时不回滚(视频可能实际在发)。
     返回 {ok, photo_id, err, limit, banned, in_progress, raw}:
@@ -346,8 +364,6 @@ def do_publish(client, video_id, title=''):
         'needConfirmation': NEED_CONFIRMATION,
         'fromUserId': '',
     }
-    if title:
-        body['caption'] = title
     r = client.post(PUBLISH_URL, json_body=body, headers=_shop_headers())
     j = _safe_json(r)
     res = {'ok': False, 'photo_id': '', 'err': '', 'limit': False, 'banned': False,
@@ -499,6 +515,7 @@ def publish_full(cfg, anchor_row, video_path, goods_id='', progress=None):
         cover = rep['cover_image'] or fetch_cover(client, rep['slice_id'])
         _p('提交信息', 6)
         submit_slice(client, rep['slice_id'], cover)
+        set_caption(client, rep['slice_id'], res['title'])
     except Exception as e:
         res['stage'], res['err'] = 'slice', str(e)
         return res

+ 41 - 5
白盒重建/tests/test_publish.py

@@ -19,7 +19,7 @@ sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
 from kuaishou_tool import config, db, tasks, publish
 from kuaishou_tool.publish import (
     PublishError, upload_sign, upload_fragment, upload_complete,
-    report_slice, submit_slice, do_publish, add_goods,
+    report_slice, submit_slice, set_caption, do_publish, add_goods,
 )
 
 logging.disable(logging.CRITICAL)   # 静音调度日志,保持测试输出干净
@@ -347,6 +347,37 @@ def test_submit_slice_fail():
         assert '提交上传视频失败' in str(e)
 
 
+# ═══════════════ ④b set_caption(前端kmi.js标定:updateType=2) ═══════════════
+
+def test_set_caption_ok():
+    fc = FakeClient()
+    fc.script = ok_script()
+    set_caption(fc, '496010274615', '和我一起走进光遇的世界吧~')
+    c = fc.calls[0]
+    assert c['url'] == ('https://s.kwaixiaodian.com/gateway/short/video/b/pc/'
+                        'ownVideo/update?caver=2')
+    b = c['json']
+    assert b == {'sliceId': 496010274615, 'title': '和我一起走进光遇的世界吧~',
+                 'updateType': 2}          # 前端handleVideoCaptionChange原样键
+
+
+def test_set_caption_empty_skip():
+    fc = FakeClient()
+    fc.script = ok_script()
+    set_caption(fc, '123', '')             # 空标题不发请求
+    assert fc.calls == []
+
+
+def test_set_caption_fail():
+    fc = FakeClient()
+    fc.script = {'ownVideo/update': FakeResp({'error_msg': '描述被拒'})}
+    try:
+        set_caption(fc, '123', 't')
+        raise AssertionError('失败应抛 PublishError')
+    except PublishError as e:
+        assert '作品描述提交失败' in str(e)
+
+
 # ═══════════════ ⑤ do_publish ═══════════════
 
 def test_do_publish_ok():
@@ -357,7 +388,7 @@ def test_do_publish_ok():
     assert 'ownVideo/publish?caver=2' in c['url']
     b = c['json']
     assert b == {'sliceId': 496010274615, 'needConfirmation': True,
-                 'fromUserId': '', 'caption': '爆款标题'}   # P1标定+C线W6 caption
+                 'fromUserId': ''}         # P1标定:描述不走publish的caption(无效字段)
     assert r['ok'] is True and r['photo_id'] == 'PHOTO_777'
     assert not fc.by('ownVideo/delete')          # 成功不回滚
 
@@ -472,7 +503,8 @@ def test_publish_full_ok_with_goods():
     assert res['photo_id'] == 'PHOTO_777'
     assert res['goods'] and res['goods']['ok'] is True
     assert len(sleeps) == 5 and sleeps[0] == (0, 0)  # 相邻步骤间延时5次
-    # 调用顺序(P1标定):sign → fragment → complete → report → update → publish → item/save
+    # 调用顺序(P1标定+描述update):sign→fragment→complete→report→update(封面)→
+    # update(描述updateType=2)→publish→item/save
     order = []
     marks = ('sign/generate', 'upload/fragment', 'upload/complete', 'ownVideo/report',
              'ownVideo/update', 'ownVideo/publish', 'ownVideo/delete', 'item/save')
@@ -482,8 +514,12 @@ def test_publish_full_ok_with_goods():
                 order.append(m)
                 break
     assert order == ['sign/generate', 'upload/fragment', 'upload/complete',
-                     'ownVideo/report', 'ownVideo/update', 'ownVideo/publish',
-                     'item/save'], order
+                     'ownVideo/report', 'ownVideo/update', 'ownVideo/update',
+                     'ownVideo/publish', 'item/save'], order
+    ups = fc.by('ownVideo/update')
+    assert ups[0]['json']['updateType'] == 3          # 先封面
+    assert ups[1]['json']['updateType'] == 2          # 后描述
+    assert ups[1]['json']['title'] == '测试标题ABC'   # 描述=biaoti标题
 
 
 def test_publish_full_no_goods_and_title_fallback():

+ 4 - 1
白盒重建/联调清单.md

@@ -24,6 +24,7 @@
 | P3 | `UPLOAD_REFERER` | ✅ 真实 Referer=`https://s.kwaixiaodian.com/zone/short-video-b/smartRelease`(智能发布页)。已回填 | ✅ |
 | P4 | 挂车 remind 两端点 | 未实现(`pontus/shelf/reminder/save` 参数已知;`remind/<x>/save?bizType=6&remindType=3` 原名未还原) | 挂车成功但需提醒时抓 cps 域请求 | ☐ |
 | P5 | `_result_ok` 宽容判定 | fragment/complete 响应无 `result` 键即视为成功 | 抓分片响应确认实际键名 | ☐ |
+| P6 | 作品描述(标题)落库 | ✅ 2026-08-16 标定:描述**不走** publish 的 caption(无效字段),走 `ownVideo/update` body `{sliceId,title,updateType:2}`(封面=type3,描述=type2)。证据:smartRelease 前端 kmi.js `handleVideoCaptionChange→updateSliceInfo{videoId,title,updateType:2}`。已实现 `set_caption()` 并插入 publish_full;实测发布后快手 App 显示标题「宝宝们明天游园会我还在~#渔女…」✓ | ✅ |
 
 ## 三、采集线(collect.py,E线)
 
@@ -55,4 +56,6 @@
 
 | 日期 | 项 | 结论(实际值/改动) |
 |------|----|-------------------|
-| — | — | — |
+| 2026-08-16 | P6 描述通道 | 挖 smartRelease 前端 kmi.e91fd5a1.js 定位 `handleVideoCaptionChange`:描述=独立 `ownVideo/update{sliceId,title,updateType:2}`;publish body 的 caption 是无效字段已删。真机发布 3xheigpu73dsx6s 验证描述上片 ✓ |
+| 2026-08-16 | C6(原计划) | ~~cp.kuaishou.com 创作者平台自动化~~ 描述+封面均已走 smartRelease 通道解决,该路线搁置 |
+