# -*- coding: utf-8 -*- """Save six v3 scene outputs to library (project 30) — use actual output ids.""" import json, ssl, pathlib, urllib.request BASE = "https://192.168.31.88:8042" CFG = pathlib.Path(r"C:\Users\admin\.zcode\cli\config.json") pat = json.loads(CFG.read_text(encoding="utf-8-sig"))["mcp"]["servers"]["sorb"]["env"]["SORB_PAT"] ctx = ssl._create_unverified_context() SAVES = [ (13352, "吕布PV_场景v3_S02_虎牢关前关道"), (13353, "吕布PV_场景v3_S04_凤仪亭内帐"), (13354, "吕布PV_场景v3_S05_董卓营帐"), (13355, "吕布PV_场景v3_S06_濮阳城外战场"), (13356, "吕布PV_场景v3_S07_辕门营地"), (13357, "吕布PV_场景v3_S09_游戏古战场"), ] for tid, name in SAVES: # query outputs to get the real output id req = urllib.request.Request(BASE + "/api/external/v1/tasks/" + str(tid), headers={"Authorization": "Bearer " + pat}) o = json.loads(urllib.request.urlopen(req, context=ctx, timeout=60).read().decode("utf-8")) outs = [it for it in (o.get("outputs") or []) if isinstance(it, dict)] if not outs: print(name, "no outputs"); continue oid = outs[0].get("id") already = outs[0].get("media_asset_id") if already: print(name, "already saved:", already); continue payload = json.dumps({"resource_name": name}, ensure_ascii=False).encode("utf-8") req = urllib.request.Request(BASE + "/api/external/v1/tasks/" + str(tid) + "/outputs/" + str(oid) + "/save", data=payload, method="POST", headers={"Authorization": "Bearer " + pat, "Content-Type": "application/json"}) try: with urllib.request.urlopen(req, context=ctx, timeout=60) as r: o2 = json.loads(r.read().decode("utf-8")) outs2 = o2.get("outputs") or [] print(name, "output", oid, "media_asset_id=", outs2[0].get("media_asset_id") if outs2 else None) except urllib.error.HTTPError as e: print(name, "HTTP", e.code, e.read().decode("utf-8")[:300])