|
|
@@ -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, '完成')
|