Files
unicut/scripts/e2e_quickvideo_fx.py
T
jinghui 59241af720 本地化改造:免登录 + 本机 AI + 离线可用
在上游 gitee.com/676015863/unicut 基础上做的自托管改造,使其可脱离官方账号体系
与 CDN 独立运行。详见 CHANGELOG.md。

主要能力
- 免登录:GUEST_USER 直接使用核心功能,checkAuth 不再拦截
- 本机 AI:对话 mimo-v2.6-flash(同源 /newapi/v1)、视觉 deepseek-v4-flash-vision-exp、
  生图 /omniai、生视频 /civideo;密钥仅存服务端(nginx 占位符 + entrypoint 注入)
- AI 一键出片:图片+标题 → AI 文案 → 人声/语速/情绪 → 确认生成直接排时间轴,
  并支持转场、图片运镜、字幕位置/大小/配色/入场动画
- 离线可用:工程数据 IndexedDB + 项目文件 JSON 双写;官方素材走同源 /cdn/ 反代;
  无 OPFS 时素材回落 IndexedDB files 表

修复
- 账号类接口本地短路,不再反复弹「Header parameter [authorization] cannot be empty」
- isFSApiSupported 改取值判断,修 OPFS 判定错误导致卡在文件夹引导页
- 模板素材统一 /cdn/ 改写 + nginx 兜底转发,修缩略图全裂
- 剔除素材已失效的模板(上游 CDN 已删,点开必卡 loading 50%)
- 补齐 SDK 内置 4 张滤镜贴图,修画布卡 loading 0%
- 封面上传失败不再中断整次保存

品牌与页面
- 「云剪」改为 UniCut
- 首页删除收费标准栏目;顶部菜单移除 GitHub/Gitee;底部栏整体下线

安全
- .env 与 public/local-ai.json(含密钥)已在 .gitignore,不入库
- public/local-ai.json.example 仅含占位符
2026-10-26 18:18:41 +08:00

379 lines
19 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""一键出片 端到端:真实跑完向导 4 步,然后断言时间轴里真的有转场/运镜关键帧/字幕效果。
依赖:系统 chromium + playwright(与 scripts/e2e_template.py 相同)。
用法:python3 scripts/e2e_quickvideo_fx.py
"""
import sys, time, json, re
from playwright.sync_api import sync_playwright
BASE = "https://127.0.0.1:3005"
APPID = "qv_fx_%d" % int(time.time())
STAMP = time.strftime("%H:%M:%S")
def log(msg):
print("[%s] %s" % (STAMP, msg), flush=True)
GUARD = """async () => {
try {
const root = await navigator.storage.getDirectory();
const db = await new Promise((res, rej) => {
const rq = indexedDB.open('H5VideoLocalDB');
rq.onupgradeneeded = () => rq.result.createObjectStore('folderHandles');
rq.onsuccess = () => res(rq.result);
rq.onerror = () => rej(rq.error);
});
const done = await new Promise((res, rej) => {
const tx = db.transaction('folderHandles', 'readwrite');
const st = tx.objectStore('folderHandles');
const rec = { id: 'root', handle: root };
// 应用自己建的 store 用内联键(keyPath='id'),我们脚本建的是外置键,两种都兼容
if (st.keyPath) st.put(rec); else st.put(rec, 'root');
tx.oncomplete = () => res(true);
tx.onerror = () => rej(tx.error);
});
db.close();
return done;
} catch (e) { return String(e); }
}"""
def js_click(page, expr, desc):
ok = page.evaluate("() => { const e = %s; if (e) { e.click(); return true; } return false; }" % expr)
log("点 %s: %s" % (desc, ok))
return ok
def wait_text(page, text, seconds=120, label=""):
"""等页面出现某个文案 —— 用它当『到第几步了』的唯一判据,别用会撞车的按钮片段。"""
for _ in range(seconds):
page.wait_for_timeout(1000)
if page.evaluate("() => document.body.innerText.includes(%s)" % json.dumps(text)):
log("到位[%s]: %s" % (label, text))
return True
log("等待超时[%s]: %s" % (label, text))
return False
def pick(page, shows, option, desc):
"""打开 semi Select 并选一项:shows=当前可见文案(定位哪个下拉),option=要选的文案"""
opened = page.evaluate(
"() => { const s=[...document.querySelectorAll('.semi-select')].find(x=>x.innerText.includes('%s'));"
" if(s){s.click();return true;} return false; }" % shows
)
if not opened:
log("下拉没找到:%s" % desc)
return False
page.wait_for_timeout(600)
ok = page.evaluate(
"() => { const o=[...document.querySelectorAll('.semi-select-option')].find(x=>x.innerText.trim()==='%s');"
" if(o){o.click();return true;} return false; }" % option
)
log("选 %s -> %s: %s" % (desc, option, ok))
return ok
def make_images():
from PIL import Image, ImageDraw
out = []
for i, color in enumerate([(200, 60, 60), (60, 140, 200), (80, 170, 90)], 1):
p = "/tmp/qv_img%d.png" % i
im = Image.new("RGB", (960, 720), color)
d = ImageDraw.Draw(im)
d.text((40, 40), "QV FX TEST %d" % i, fill=(255, 255, 255))
d.rectangle([20, 20, 940, 700], outline=(255, 255, 255), width=6)
im.save(p)
out.append(p)
return out
def main():
imgs = make_images()
log("测试图片: %s" % imgs)
with sync_playwright() as p:
browser = p.chromium.launch(
executable_path="/usr/bin/chromium",
headless=True,
args=["--no-sandbox", "--disable-gpu", "--disable-dev-shm-usage", "--mute-audio",
"--autoplay-policy=no-user-gesture-required"],
)
ctx = browser.new_context(ignore_https_errors=True)
page = ctx.new_page()
errors = []
bad = []
page.on("pageerror", lambda e: errors.append(str(e)))
page.on("console", lambda m: errors.append("console:" + m.text[:200]) if m.type == "error" else None)
# 把向导自己的收尾日志打出来(里面有统一轨道/转场计数)
page.on("console", lambda m: log("页面日志 %s" % m.text[:220]) if "[qv]" in m.text else None)
page.on("response", lambda r: bad.append("%d %s" % (r.status, r.url[:120])) if r.status >= 400 else None)
log("打开工程 %s" % APPID)
page.goto("%s/editor/%s" % (BASE, APPID), wait_until="domcontentloaded", timeout=120000)
page.wait_for_timeout(4000)
log("守卫: %s" % page.evaluate(GUARD))
page.reload(wait_until="domcontentloaded")
# 等编辑器真正起来(侧栏是纯文本,没有 aria-label,只能等文案出现)
page.wait_for_selector('#h5dsCanvas', timeout=90000)
try:
page.wait_for_function("() => document.body.innerText.includes('AI创作')", timeout=90000)
log("侧栏已就绪")
except Exception as e:
log("侧栏等待超时: %s" % e)
page.wait_for_timeout(3000)
# 打开 AI 面板 -> 一键出片(入口是文本叶子,aria-label 不可用)
js_click(page, """(() => {
const w = document.createTreeWalker(document.body, NodeFilter.SHOW_TEXT);
let n;
while (n = w.nextNode()) {
const t = (n.textContent || '').trim();
if (t === 'AI创作' && n.parentElement) return n.parentElement;
}
return null;
})()""", "AI创作")
page.wait_for_timeout(2500)
js_click(page, "[...document.querySelectorAll('button')].find(x => (x.innerText||'').trim() === '开始一键出片') "
"|| [...document.querySelectorAll('button')].find(x => (x.innerText||'').includes('一键出片'))",
"开始一键出片")
page.wait_for_timeout(3000)
# 步骤1:上传 3 张图 + 标题
fi = page.query_selector("div.semi-modal input[type=file]")
if not fi:
fi = page.query_selector("input[type=file][accept='image/*']")
if not fi:
log("ERROR: 找不到向导的图片输入框")
print(json.dumps({"ok": False, "why": "no-file-input", "errors": errors[-5:]}, ensure_ascii=False))
return 1
fi.set_input_files(imgs)
page.wait_for_timeout(2500)
page.fill("input[placeholder*='三步搞定']", "测试标题效果验证")
page.wait_for_timeout(500)
js_click(page, "[...document.querySelectorAll('button')].find(x=>(x.innerText||'').includes('① 识别图片'))", "生成文案")
# 到第 2 步的唯一标志:第 1 步的「下一步:配置声音」按钮出现(最长 180s)
got = wait_text(page, "下一步:配置声音", 180, "第2步")
log("文案生成完成: %s" % got)
if not got:
# 兜底:手动加 3 段
log("AI 文案没出来,改用手动加段")
for i in range(3):
js_click(page, "[...document.querySelectorAll('button')].find(x=>(x.innerText||'').trim()==='加一段')", "加一段")
page.wait_for_timeout(500)
tas = page.query_selector_all(".semi-modal textarea")
for i, ta in enumerate(tas[:3]):
ta.fill("第%d段测试口播内容" % (i + 1))
page.wait_for_timeout(500)
js_click(page, "[...document.querySelectorAll('button')].find(x=>(x.innerText||'').includes('下一步:配置声音'))", "下一步")
page.wait_for_timeout(2000)
# 步骤3:合成全部配音
js_click(page, "[...document.querySelectorAll('button')].find(x=>(x.innerText||'').includes('合成全部配音'))", "合成全部配音")
# 合成完会自动跳到第 4 步;只认效果面板的特征文案「图片转场」,
# 不能用「确认生成」——第 3 步的「下一步:确认生成」也含这几个字,会误判。
done = wait_text(page, "图片转场", 300, "第4步效果面板")
log("配音合成完成(自动进入确认页): %s" % done)
page.wait_for_timeout(1500)
# 步骤4:设置画面/字幕效果(全部用非默认值,证明控件真的生效)
body_before = page.inner_text(".semi-modal-body")
log("确认页含效果面板: %s" % ("图片转场" in body_before and "字幕效果" in body_before))
pick(page, "自动轮换", "左侧擦除", "转场")
pick(page, "缓慢推近", "左右平移", "图片动效")
pick(page, "底部", "居中", "字幕位置")
pick(page, "黄字黑边", "白字黑边", "字幕配色")
pick(page, "放大弹入", "放大 + 淡入", "字幕入场")
# 大小滑块:聚焦后按右键 5 次(0.6 -> 1.1)
moved = page.evaluate("""() => {
const h = document.querySelector('.semi-modal .semi-slider-handle');
if (!h) return 'no-handle';
h.focus(); return 'focused';
}""")
if moved == "focused":
for _ in range(5):
page.keyboard.press("ArrowRight")
page.wait_for_timeout(400)
log("字幕大小滑块: %s" % moved)
page.wait_for_timeout(800)
log("确认页摘要: %s" % page.inner_text(".semi-modal .semi-modal-body").split("\n")[0:14])
# 生成
js_click(page, "[...document.querySelectorAll('button')].find(x=>(x.innerText||'').includes('③ 确认生成视频'))", "确认生成视频")
page.wait_for_timeout(12000)
# 断言:读回工程数据
res = page.evaluate("""() => {
const ed = window.__editor && window.__editor.movie;
if (!ed) return {err:'no-editor'};
const d = ed.data || {};
const els = d.elements || [];
const imgs = els.filter(e => e.type === 'image');
const trs = d.transitions || [];
const caps = d.captions || [];
// 转场有效性:startElementId 必须存在,且同轨道相邻
const byId = {};
els.forEach(e => byId[e.id] = e);
const check = trs.map(t => {
const a = byId[t.startElementId];
if (!a) return {name: t.name, ok: false, why: 'startElementId 不存在'};
// 注意:不要用 e !== a 排除自身 —— indexOf(a) 会永远返回 -1,next 就会取错
const same = els.filter(e => e.trackIndex === a.trackIndex)
.sort((m, n) => m.startTime - n.startTime);
const i = same.indexOf(a);
const next = same[i + 1];
const gap = next ? Number((a.startTime + a.duration - next.startTime).toFixed(3)) : null;
return { name: t.name, tname: t.transitionName, dur: t.duration, gap,
ok: !!next && Math.abs(gap) < 0.01 };
});
return {
imgCount: imgs.length,
sameTrack: imgs.length ? new Set(imgs.map(e => e.trackIndex)).size : 0,
elementsFull: els.map(e => ({ id: e.id, type: e.type, t: e.startTime, d: e.duration,
track: e.trackIndex })),
transitionsFull: trs.map(t => ({ id: t.id, startElementId: t.startElementId,
tname: t.transitionName, dur: t.duration })),
imgs: imgs.map(e => ({ t: e.startTime, d: e.duration, track: e.trackIndex,
frames: (e.frames || []).length,
f0: (e.frames || [])[0] || null,
f1: (e.frames || [])[(e.frames || []).length - 1] || null,
style: { x: e.style && e.style.x, y: e.style && e.style.y,
w: e.style && e.style.width, h: e.style && e.style.height } })),
transitionCount: trs.length,
transitionChecks: check,
captionCount: caps.length,
caption0: caps[0] ? {
x: caps[0].style.x, y: caps[0].style.y, textScale: caps[0].textScale,
fill: caps[0].textStyle && caps[0].textStyle.fill,
stroke: caps[0].textStyle && caps[0].textStyle.stroke && caps[0].textStyle.stroke.color,
frames: (caps[0].frames || []).length,
f0: (caps[0].frames || [])[0] || null,
f1: (caps[0].frames || [])[(caps[0].frames || []).length - 1] || null,
} : null,
canvas: { w: d.width, h: d.height },
};
}""")
log("元素明细: " + json.dumps(res.get('elementsFull'), ensure_ascii=False))
log("转场明细: " + json.dumps(res.get('transitionsFull'), ensure_ascii=False))
log("工程数据: " + json.dumps(res, ensure_ascii=False)[:2400])
# 播一下确认渲染
play = page.evaluate("""() => {
const m = window.__editor && window.__editor.movie;
if (!m) return 'no-movie';
try { m.currentTime = 1.5; if (typeof m.play === 'function') m.play(); return 'playing'; }
catch (e) { return 'err:' + e.message; }
}""")
page.wait_for_timeout(4000)
after = page.evaluate("""() => {
const m = window.__editor && window.__editor.movie;
const st = document.querySelector('#h5dsCanvas') && document.querySelector('#h5dsCanvas').innerText || '';
return { time: m ? m.currentTime : null, loading: /loading\\s+\\d/.test(st) };
}""")
log("播放: %s -> %s" % (play, json.dumps(after, ensure_ascii=False)))
page.screenshot(path="/tmp/qv_fx.png", full_page=False)
log("截图: /tmp/qv_fx.png")
# 转场区间内截一帧,确认转场真的在渲染(而不是只有数据)
mid = page.evaluate("""() => {
const st = window.__editor;
const m = st && st.movie;
if (!m) return 'no-movie';
const trs = (m.data && m.data.transitions) || [];
if (!trs.length) return 'no-transitions';
const tr = trs[0];
const el = (m.data.elements || []).find(e => e.id === tr.startElementId);
if (!el) return 'no-start-element';
const t = el.startTime + el.duration - 0.5;
m.pause();
if (typeof st.updateMovie === 'function') st.updateMovie(t); else m.currentTime = t;
return 'seek=' + Math.round(t * 100) / 100;
}""")
page.wait_for_timeout(2500)
log("转场区间定位: %s" % mid)
page.screenshot(path="/tmp/qv_fx_transition.png", full_page=False)
log("转场截图: /tmp/qv_fx_transition.png")
# 转场窗口内多点采样,看是不是渐变过渡(红->蓝中间应出现混合色)而不是硬切
samples = page.evaluate("""() => {
const m = window.__editor && window.__editor.movie;
const trs = (m && m.data && m.data.transitions) || [];
if (!trs.length) return null;
const el = m.data.elements.find(e => e.id === trs[0].startElementId);
const end = el.startTime + el.duration;
const win = trs[0].duration || 1;
const pts = [];
for (let k = 1; k <= 4; k++) pts.push(Number((end - win + (win * k) / 5).toFixed(2)));
return pts;
}""")
if samples:
log("转场窗口采样点: %s" % samples)
for idx, tt in enumerate(samples):
# 必须先暂停再跳帧;跳帧要用 Store 的 updateMovie(t)(内部是 movie.step),
# 直接赋 movie.currentTime 不会驱动渲染,四个采样点会停在同一帧。
page.evaluate(
"(t) => { const st = window.__editor;"
" if (st && st.movie && st.movie.pause) st.movie.pause();"
" if (st && st.updateMovie) st.updateMovie(t);"
" else if (st && st.movie) st.movie.currentTime = t; }",
tt,
)
page.wait_for_timeout(1200)
# 确认跳帧真的生效(currentTime 赋值未必驱动渲染)
cur = page.evaluate("""() => {
const m = window.__editor.movie;
const tc = (document.body.innerText.split('\\n').join(' ').match(/\\d{2}:\\d{2}:\\d{2}/g) || []).slice(0, 3);
return { movieTime: Math.round(m.currentTime * 100) / 100, timecodes: tc };
}""")
page.locator("#h5dsCanvas").screenshot(path="/tmp/qv_tr_%d.png" % idx)
log("采样 t=%.2f -> %s" % (tt, json.dumps(cur, ensure_ascii=False)))
# 暂停态 step() 可能不渲染转场滤镜,所以再做一次「边播边截帧」的验证
capinfo = page.evaluate("""() => {
const m = window.__editor.movie;
const trs = (m.data && m.data.transitions) || [];
if (!trs.length) return null;
const el = m.data.elements.find(e => e.id === trs[0].startElementId);
const end = el.startTime + el.duration;
return { start: Number((end - (trs[0].duration || 1) - 0.5).toFixed(2)), boundary: end };
}""")
if capinfo:
page.evaluate("(t) => { const s=window.__editor; if (s.movie.pause) s.movie.pause(); s.updateMovie(t); }",
capinfo["start"])
page.wait_for_timeout(900)
page.evaluate("() => window.__editor.movie.play()")
pts = []
for i in range(18):
page.locator("#h5dsCanvas").screenshot(path="/tmp/qvp_%02d.png" % i)
pts.append(page.evaluate("() => Math.round(window.__editor.movie.currentTime * 100) / 100"))
log("播放采样起点=%.2f 边界=%.2f 时刻表=%s" % (capinfo["start"], capinfo["boundary"], pts))
# 保存 + 刷新,确认一键出片的结果不会丢
saved = page.evaluate("""() => {
const s = window.__editor;
if (typeof s.saveApp === 'function') { s.saveApp(() => {}); return 'saveApp 已调用'; }
return '没有 saveApp';
}""")
log("手动保存: %s" % saved)
page.wait_for_timeout(8000)
page.reload(wait_until="domcontentloaded")
page.wait_for_selector("#h5dsCanvas", timeout=90000)
page.wait_for_timeout(12000)
after_reload = page.evaluate("""() => {
const d = (window.__editor && window.__editor.movie && window.__editor.movie.data) || {};
return { els: (d.elements || []).length, caps: (d.captions || []).length,
trans: (d.transitions || []).length };
}""")
log("刷新后工程数据: %s" % json.dumps(after_reload, ensure_ascii=False))
log("JS 错误: %s" % (errors[-4:] if errors else "无"))
log("非2xx请求: %s" % (bad[:8] if bad else "无"))
browser.close()
return 0
if __name__ == "__main__":
sys.exit(main())