|
|
@@ -37,17 +37,22 @@ if type(db._LOCK) is not type(threading.RLock()):
|
|
|
|
|
|
logger = logging.getLogger('kuaishou.publish')
|
|
|
|
|
|
-# ── 端点常量(C线 §4 接口清单) ──────────────────────────────────────────
|
|
|
+# ── 端点常量(C线 §4 接口清单 + P1/P3 标定:查询参数实为 caver=2,
|
|
|
+# 镜像原文并非污染;__NS_hxfalcon 签名实测非强制) ─────────────────────
|
|
|
SIGN_URL = ('https://s.kwaixiaodian.com/gateway/pc/shop/material/'
|
|
|
'batch/upload/video/sign/generate')
|
|
|
FRAGMENT_URL = ('https://upload.kuaishouzt.com/api/upload/fragment'
|
|
|
'?upload_token=%s&fragment_id=%d')
|
|
|
COMPLETE_URL = ('https://upload.kuaishouzt.com/api/upload/complete'
|
|
|
'?fragment_count=%d&upload_token=%s')
|
|
|
+REPORT_URL = ('https://s.kwaixiaodian.com/gateway/short/video/b/pc/'
|
|
|
+ 'ownVideo/report?caver=2')
|
|
|
+COVER_LIST_URL = ('https://s.kwaixiaodian.com/gateway/short/video/b/pc/'
|
|
|
+ 'ownVideo/cover/list?caver=2') # P1b标定:body 须带 lingjiPage:true
|
|
|
UPDATE_SLICE_URL = ('https://s.kwaixiaodian.com/gateway/short/video/b/pc/'
|
|
|
- 'ownVideo/update?cover=2') # 镜像混淆 caver=2,真实 cover=2
|
|
|
+ 'ownVideo/update?caver=2')
|
|
|
PUBLISH_URL = ('https://s.kwaixiaodian.com/gateway/short/video/b/pc/'
|
|
|
- 'ownVideo/publish')
|
|
|
+ 'ownVideo/publish?caver=2')
|
|
|
DELETE_URL = ('https://s.kwaixiaodian.com/gateway/short/video/b/pc/'
|
|
|
'ownVideo/delete')
|
|
|
SHELF_SAVE_URL = ('https://cps.kwaixiaodian.com/gateway/distribute/match/' # 镜像污染 ma鹀h
|
|
|
@@ -57,14 +62,14 @@ 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 = 1 # ownVideo/update body 键 updateType 的值(报告未还原,默认1)
|
|
|
-NEED_CONFIRMATION = 0 # ownVideo/publish body 键 needConfirmation 的值(默认0)
|
|
|
+UPDATE_TYPE = 3 # ownVideo/update 键值(P1 标定:真实抓包=3)
|
|
|
+NEED_CONFIRMATION = True # ownVideo/publish 键值(P1 标定:真实抓包=true)
|
|
|
SHELF_BIZ_CODE = 'pcShelfItemSelection' # 挂车 bizCode(原工具常量模板,白盒可配置)
|
|
|
|
|
|
UA_CHROME132 = ('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 '
|
|
|
'(KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36 Edg/132.0.0.0')
|
|
|
-# C线C4 未决污染串:Referer 推断值,待联网比对后修正
|
|
|
-UPLOAD_REFERER = 'https://s.kwaixiaodian.com/zone/les/bp'
|
|
|
+# P3 定案(标定抓包):真实 Referer 为智能发布页
|
|
|
+UPLOAD_REFERER = 'https://s.kwaixiaodian.com/zone/short-video-b/smartRelease'
|
|
|
|
|
|
|
|
|
class PublishError(Exception):
|
|
|
@@ -113,10 +118,12 @@ def _safe_json(resp):
|
|
|
|
|
|
|
|
|
def _err_of(j):
|
|
|
- """提取快手系通用错误键 error_msg/errorMsg/error。"""
|
|
|
+ """提取快手系通用错误键 error_msg/errorMsg/error。
|
|
|
+ 网关怪癖(P1标定):成功响应的 error_msg 为字符串 "SUCCESS",按无错处理。"""
|
|
|
if not isinstance(j, dict):
|
|
|
return ''
|
|
|
- return str(j.get('error_msg') or j.get('errorMsg') or j.get('error') or '')
|
|
|
+ e = str(j.get('error_msg') or j.get('errorMsg') or j.get('error') or '')
|
|
|
+ return '' if e.upper() == 'SUCCESS' else e
|
|
|
|
|
|
|
|
|
def _result_ok(j):
|
|
|
@@ -248,41 +255,76 @@ def upload_complete(client, upload_token, count):
|
|
|
return j
|
|
|
|
|
|
|
|
|
-def submit_slice(client, upload_token):
|
|
|
- """⑤ 提交slice(C线W5):ownVideo/update?cover=2(镜像混淆 caver=2,真实参数 cover)。
|
|
|
- body 键 sliceId/updateType(C线C2:逐键拼装无完整模板,值取白盒默认);
|
|
|
- 响应取 data.sliceIdList[0],缺省回退 data.sliceId → upload_token 兜底。
|
|
|
- 返回 {slice_id, raw}。"""
|
|
|
- body = {'sliceId': upload_token, 'updateType': UPDATE_TYPE}
|
|
|
+def report_slice(client, upload_token):
|
|
|
+ """⑤-0 上报换 sliceId(P1 标定:真实流程 complete→report→update→publish)。
|
|
|
+ POST ownVideo/report?caver=2 body {"uploadTokenList":[tok]};
|
|
|
+ 响应 data.sliceIdList[0] 为数字 sliceId(非 uploadToken!)。
|
|
|
+ 网关怪癖:成功时 error_msg 为字符串 "SUCCESS"(result=1),按成功处理。"""
|
|
|
+ r = client.post(REPORT_URL, json_body={'uploadTokenList': [upload_token]},
|
|
|
+ headers=_shop_headers())
|
|
|
+ j = _safe_json(r)
|
|
|
+ data = j.get('data') if isinstance((j or {}).get('data'), dict) else {}
|
|
|
+ ok = (getattr(r, 'status_code', 0) == 200 and j is not None
|
|
|
+ and (j.get('result') == 1
|
|
|
+ or str(j.get('error_msg', '')).upper() == 'SUCCESS'))
|
|
|
+ slist = data.get('sliceIdList') if isinstance(data.get('sliceIdList'), list) else []
|
|
|
+ if not ok:
|
|
|
+ raise PublishError('上传上报(report)失败:' + (_err_of(j) or _text_head(r)))
|
|
|
+ if not slist:
|
|
|
+ raise PublishError('上报未返回sliceId:' + _text_head(r))
|
|
|
+ return {'slice_id': str(slist[0]),
|
|
|
+ 'cover_image': str(data.get('coverImage') or ''), 'raw': j}
|
|
|
+
|
|
|
+
|
|
|
+def fetch_cover(client, slice_id, timeout_sec=120, interval_sec=4):
|
|
|
+ """取服务端首帧封面(P1b 标定):cover/list body {"sliceId","lingjiPage":true}。
|
|
|
+ data[0].coverImage 由服务端异步生成(首帧转码后出现,实测十几秒),
|
|
|
+ 轮询至非空返回 URL;超时抛 PublishError。"""
|
|
|
+ sid = int(slice_id) if str(slice_id).isdigit() else slice_id
|
|
|
+ end = time.time() + timeout_sec
|
|
|
+ while time.time() < end:
|
|
|
+ r = client.post(COVER_LIST_URL, json_body={'sliceId': sid,
|
|
|
+ 'lingjiPage': True},
|
|
|
+ headers=_shop_headers())
|
|
|
+ j = _safe_json(r)
|
|
|
+ data = j.get('data') if isinstance((j or {}).get('data'), list) else []
|
|
|
+ for c in data:
|
|
|
+ url = str((c or {}).get('coverImage') or '')
|
|
|
+ if url:
|
|
|
+ return url # 首帧封面就绪
|
|
|
+ time.sleep(interval_sec)
|
|
|
+ raise PublishError('封面生成超时(cover/list 始终为空),稍后重试或检查转码')
|
|
|
+
|
|
|
+
|
|
|
+def submit_slice(client, slice_id, cover_image=''):
|
|
|
+ """⑤ 提交slice(P1 标定):ownVideo/update?caver=2。
|
|
|
+ body {"sliceId":<report返回的数字ID>,"coverImage":<封面,可空省略>,
|
|
|
+ "coverImageToken":"","updateType":3}。"""
|
|
|
+ body = {'sliceId': int(slice_id) if str(slice_id).isdigit() else slice_id,
|
|
|
+ 'coverImageToken': '', 'updateType': UPDATE_TYPE}
|
|
|
+ if cover_image:
|
|
|
+ body['coverImage'] = cover_image
|
|
|
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)))
|
|
|
- data = j.get('data') if isinstance(j.get('data'), dict) else {}
|
|
|
- slist = data.get('sliceIdList') if isinstance(data.get('sliceIdList'), list) else []
|
|
|
- if slist:
|
|
|
- slice_id = str(slist[0])
|
|
|
- elif data.get('sliceId'):
|
|
|
- slice_id = str(data['sliceId'])
|
|
|
- else:
|
|
|
- slice_id = str(upload_token) # 服务端未回显时以 token 兜底
|
|
|
- return {'slice_id': slice_id, 'raw': j}
|
|
|
+ return {'slice_id': str(slice_id), 'raw': j}
|
|
|
|
|
|
|
|
|
-def do_publish(client, video_id, title):
|
|
|
- """⑥ 正式发布(C线W6):ownVideo/publish。
|
|
|
- body 键 sliceIdList/needConfirmation/fromUserId/caption=标题。
|
|
|
+def do_publish(client, video_id, title=''):
|
|
|
+ """⑥ 正式发布(P1 标定):ownVideo/publish?caver=2。
|
|
|
+ body 逐键照抓包还原:{"sliceId":<数字>,"needConfirmation":true,"fromUserId":""}
|
|
|
+ (smartRelease 流程不带 caption,标题沿用服务端;title 形参保留待后续标定)。
|
|
|
失败 → ownVideo/delete(body sliceIdList) 回滚,C线W7"发布视频失败-删除发布列表!";
|
|
|
error_msg 含"正在发布中"时不回滚(视频可能实际在发)。
|
|
|
返回 {ok, photo_id, err, limit, banned, in_progress, raw}:
|
|
|
limit = 购物车视频限额/加购上限(C线W6 → 集成方记"已到上限")
|
|
|
banned = 账号被禁用(C线W6 → 集成方置 anchor.rizhi='账号违规异常')"""
|
|
|
body = {
|
|
|
- 'sliceIdList': [video_id],
|
|
|
+ 'sliceId': int(video_id) if str(video_id).isdigit() else video_id,
|
|
|
'needConfirmation': NEED_CONFIRMATION,
|
|
|
'fromUserId': '',
|
|
|
- 'caption': title,
|
|
|
}
|
|
|
r = client.post(PUBLISH_URL, json_body=body, headers=_shop_headers())
|
|
|
j = _safe_json(r)
|
|
|
@@ -413,11 +455,13 @@ def publish_full(cfg, anchor_row, video_path, goods_id=''):
|
|
|
except Exception as e:
|
|
|
res['stage'], res['err'] = 'complete', str(e)
|
|
|
return res
|
|
|
- # ── ⑤ 提交slice ──
|
|
|
+ # ── ⑤ 上报换sliceId(report) → 等首帧封面(cover/list) → 提交slice ──
|
|
|
rand_sleep(*delay)
|
|
|
try:
|
|
|
- s = submit_slice(client, res['upload_token'])
|
|
|
- res['slice_id'] = s['slice_id']
|
|
|
+ rep = report_slice(client, res['upload_token'])
|
|
|
+ res['slice_id'] = rep['slice_id']
|
|
|
+ cover = rep['cover_image'] or fetch_cover(client, rep['slice_id'])
|
|
|
+ submit_slice(client, rep['slice_id'], cover)
|
|
|
except Exception as e:
|
|
|
res['stage'], res['err'] = 'slice', str(e)
|
|
|
return res
|