Files

21 lines
1.9 KiB
Python

import json, re, os, urllib.request
from pathlib import Path
root=Path(__file__).resolve().parent
log=(Path(os.environ['APPDATA'])/'HuobaoDrama/logs/startup.log').read_text(encoding='utf-8')
port=re.findall(r'port=(\d+) userData=',log)[-1]
base='http://127.0.0.1:'+port+'/api/v1'
def request(path,body=None):
req=urllib.request.Request(base+path,data=json.dumps(body).encode() if body else None,headers={'Content-Type':'application/json'})
with urllib.request.urlopen(req,timeout=20) as r: return json.load(r)['data']
styles=request('/style-presets?all=1')
if isinstance(styles,dict): styles=styles.get('items',[])
live=json.loads((root/'style-live-action.json').read_text(encoding='utf-8'))
xianxia={'name':'仙侠风格','value':'xianxia-live-action','description':'真人仙侠影视质感:古装修仙人物、仙山云海、御剑与克制的法术光效。',
'prompt':'Cinematic live-action Chinese xianxia fantasy, photorealistic human actors with natural anatomy and detailed skin texture, elegant traditional Chinese flowing robes with realistic silk fabric and intricate embroidery, ethereal immortal mountains and misty cloud seas, ancient Chinese temples, jade and weathered stone, graceful sword cultivation, restrained luminous magical effects with physically plausible light interaction, atmospheric depth, film-quality practical sets and convincing visual effects, cinematic composition, natural expressive faces, no anime, no cartoon, no game character render, no plastic skin.',
'sort_order':1,'is_active':True}
(root/'style-xianxia.json').write_text(json.dumps(xianxia,ensure_ascii=False,indent=2),encoding='utf-8')
for style in (live,xianxia):
existing=next((s for s in styles if s.get('value')==style['value']),None)
if existing: print('preserved',style['value'],existing['id'])
else: print('added',style['value'],request('/style-presets',style)['id'])