CenaForge: primeira versão pública
Gerador de vídeos narrativos (Godot + FFmpeg), painel Next.js, serviço de voz, Clipador de lives e Publicador para YouTube, TikTok e Instagram. Inclui a leitura das visualizações dos posts para o Dashboard e o botão "Publicar no <rede>" nos cartões das publicações. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,318 @@
|
||||
"""Formato do corte (vertical 9:16 / horizontal 16:9), durações padrão novas (60–90 s, volta até 2 min) e tempo da
|
||||
legenda com fala rápida (pedidos do dono, 16/11/2026)."""
|
||||
import hashlib
|
||||
import json
|
||||
import re
|
||||
import shutil
|
||||
import sqlite3
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from app import db as db_module
|
||||
from app import editor, editor_render, layout, subtitles
|
||||
from app.scoring import ChatMessage, Word
|
||||
|
||||
from .test_editor import KEY, _lavfi_segments, api, make_project, validate # noqa: F401 - api é fixture
|
||||
|
||||
FFMPEG = shutil.which("ffmpeg")
|
||||
FFPROBE = shutil.which("ffprobe")
|
||||
HORIZONTAL = {"format": {"aspect": "horizontal"}}
|
||||
CAM = {"layout": {"cam": {"x": 0.02, "y": 0.45, "w": 0.2, "h": 0.25}}}
|
||||
|
||||
|
||||
# ---------------------------------------------------------------- configuração: format e duration
|
||||
def test_format_validate_and_merge():
|
||||
assert layout.DEFAULTS["format"] == {"aspect": "vertical"}
|
||||
assert layout.merge()["format"]["aspect"] == "vertical"
|
||||
assert layout.validate({"format": {"aspect": "horizontal"}}) == {"format": {"aspect": "horizontal"}}
|
||||
assert layout.validate({"format": {}}) == {"format": {}}
|
||||
for bad in ({"format": {"aspect": "quadrado"}}, {"format": "horizontal"}):
|
||||
with pytest.raises(layout.LayoutError):
|
||||
layout.validate(bad)
|
||||
# padrão ← canal ← sessão ← projeto: a camada de cima vence; sem `format` (config antiga) = vertical.
|
||||
cfg = layout.merge({"format": {"aspect": "horizontal"}}, {"caption": {"size": 90}})
|
||||
assert layout.aspect(cfg) == "horizontal" and layout.frame_size(cfg) == (1920, 1080)
|
||||
assert layout.aspect(layout.merge(cfg, {"format": {"aspect": "vertical"}})) == "vertical"
|
||||
assert layout.aspect({"layout": {}}) == "vertical" and layout.frame_size(layout.merge()) == (1080, 1920)
|
||||
|
||||
|
||||
def test_duration_defaults_and_limits():
|
||||
assert layout.DEFAULTS["duration"] == {"minS": 60, "maxS": 90, "backtrackS": 120}
|
||||
assert layout.validate({"duration": {"minS": 120, "maxS": 180, "backtrackS": 120}})["duration"]["minS"] == 120
|
||||
for bad in ({"minS": 121}, {"minS": 4}, {"maxS": 181}, {"maxS": 14}, {"backtrackS": 121}, {"minS": 90, "maxS": 90},
|
||||
{"minS": 100, "maxS": 90}):
|
||||
with pytest.raises(layout.LayoutError):
|
||||
layout.validate({"duration": bad})
|
||||
|
||||
|
||||
def test_settings_routes_carry_format(api): # noqa: F811
|
||||
client, engine, _root = api
|
||||
h = {"X-Service-Key": KEY}
|
||||
r = client.put("/v1/sessions/1/settings", headers=h, json={"format": {"aspect": "horizontal"}})
|
||||
assert r.status_code == 200, r.text
|
||||
body = r.json()
|
||||
assert body["own"] == {"format": {"aspect": "horizontal"}} and body["effective"]["format"]["aspect"] == "horizontal"
|
||||
assert body["defaults"]["format"]["aspect"] == "vertical" and body["defaults"]["duration"]["maxS"] == 90
|
||||
assert body["aspects"] == ["vertical", "horizontal"] and body["frames"]["horizontal"]["width"] == 1920
|
||||
assert client.put("/v1/sessions/1/settings", headers=h, json={"format": {"aspect": "x"}}).status_code == 400
|
||||
|
||||
|
||||
# ---------------------------------------------------------------- layout horizontal
|
||||
def test_horizontal_layout_modes():
|
||||
plain = layout.merge(HORIZONTAL)
|
||||
for mode in ("auto", "blur", "cam_top", "game_only"):
|
||||
cfg = layout.merge(HORIZONTAL, CAM, {"layout": {"mode": mode}})
|
||||
assert layout.resolved_mode(cfg) == "full"
|
||||
chain = layout.layout_chain(cfg, "in", "out")
|
||||
assert "vstack" not in chain and "boxblur" not in chain and "pad=1920:1080" in chain # quadro inteiro
|
||||
cam_only = layout.merge(HORIZONTAL, CAM, {"layout": {"mode": "cam_only"}})
|
||||
chain = layout.layout_chain(cam_only, "in", "out")
|
||||
assert layout.resolved_mode(cam_only) == "cam_only" and "crop=iw*0.2:ih*0.25:iw*0.02:ih*0.45" in chain
|
||||
assert "crop=1920:1080" in chain # câmera preenche 1920×1080 sem distorcer
|
||||
# cam_only sem câmera marcada: quadro inteiro; região do jogo marcada: recorta e preenche.
|
||||
assert layout.resolved_mode(layout.merge(HORIZONTAL, {"layout": {"mode": "cam_only"}})) == "full"
|
||||
game = layout.merge(HORIZONTAL, {"layout": {"game": {"x": 0.1, "y": 0.1, "w": 0.8, "h": 0.8}}})
|
||||
assert "crop=iw*0.8:ih*0.8:iw*0.1:ih*0.1,scale=1920:1080:force_original_aspect_ratio=increase,crop=1920:1080" in \
|
||||
layout.layout_chain(game, "in", "out")
|
||||
# troca de layout por trecho (editor) também respeita o formato
|
||||
assert "crop=iw*0.2" in layout.layout_chain(layout.merge(HORIZONTAL, CAM), "in", "out", mode="cam_only")
|
||||
assert layout.layout_chain(plain, "in", "out").startswith("[in]scale=1920:1080:force_original_aspect_ratio=decrease")
|
||||
|
||||
|
||||
def test_horizontal_ass_positions_and_sizes(tmp_path):
|
||||
data = make_project(settings=HORIZONTAL, chat={"enabled": True, "x": 0.02, "y": 0.9, "width": 0.3, "lines": 3})
|
||||
p = validate(data, tmp_path)
|
||||
cfg = editor.effective_settings(layout.merge(), p)
|
||||
assert layout.aspect(cfg) == "horizontal"
|
||||
ass = editor_render.build_project_ass(p, cfg, "twitch.tv/x", chat=[ChatMessage(11.0, "KKKK", "ana")])
|
||||
assert "PlayResX: 2560" in ass and "PlayResY: 1440" in ass # quadro lógico (textos a 75 % no 1920×1080)
|
||||
assert "\\pos(1280,1224)" in ass # legenda automática: centro, 85 % da altura
|
||||
assert f"\\pos(1280,{int(1440 * 0.2)})" in ass # gancho (y relativo)
|
||||
assert f"\\an1\\pos({int(2560 * 0.02)},{int(1440 * 0.9)})" in ass # chat (x/y relativos)
|
||||
assert "m 0 0 l 2560 0 2560 12 0 12" in ass # barra de progresso na largura toda
|
||||
credit = next(line for line in ass.splitlines() if line.startswith("Style: Credit"))
|
||||
assert credit.endswith(",9,48,48,36,1") # crédito no canto superior direito
|
||||
graph = editor_render.build_filter(p, cfg, editor.pieces(p["cuts"]), 10.0, "e.ass", [], cover_input=1)
|
||||
assert "s=1920x1080" in graph and "[1:v]scale=1920:1080" in graph # zoom e capa no tamanho do formato
|
||||
# legenda com y escolhido: fração da altura do quadro lógico
|
||||
q = validate(make_project(settings={**HORIZONTAL, "caption": {"y": 0.5}}), tmp_path)
|
||||
assert "\\pos(1280,720)" in editor_render.build_project_ass(q, editor.effective_settings(layout.merge(), q), "")
|
||||
|
||||
|
||||
def _golden_values() -> dict:
|
||||
"""Mesmas entradas usadas para gravar tests/data/vertical_golden_sha256.json com o código de ANTES do formato."""
|
||||
cam = {"layout": {"cam": {"x": 0.02, "y": 0.45, "w": 0.2, "h": 0.25}, "game": {"x": 0.3, "y": 0.1, "w": 0.6, "h": 0.8}}}
|
||||
g = {}
|
||||
for base_name, base in (("nocam", {}), ("cam", cam)):
|
||||
for mode in layout.MODES:
|
||||
cfg = layout.merge(base, {"layout": {"mode": mode}})
|
||||
g[f"chain-{base_name}-{mode}"] = layout.layout_chain(cfg, "in", "out", ",setsar=1", "_0")
|
||||
g[f"vf-{base_name}-{mode}"] = layout.video_filter(cfg, "a.ass")
|
||||
g[f"capy-{base_name}-{mode}"] = layout.caption_y(cfg)
|
||||
return g, cam
|
||||
|
||||
|
||||
def test_vertical_output_is_unchanged(tmp_path):
|
||||
"""O vertical continua idêntico ao de antes do formato (filtergraph, legenda, textos, chat, capa)."""
|
||||
expected = json.loads((Path(__file__).parent / "data" / "vertical_golden_sha256.json").read_text(encoding="utf-8"))
|
||||
g, cam = _golden_values()
|
||||
p = validate(make_project(chat={"enabled": True, "lines": 3}), tmp_path)
|
||||
chat = [ChatMessage(11.0, "KKKKKK", "ana"), ChatMessage(13.0, "server chinês", "beto")]
|
||||
for base_name, base in (("nocam", {}), ("cam", cam)):
|
||||
for preset in editor.CAPTION_PRESETS:
|
||||
q = json.loads(json.dumps(p))
|
||||
q["captions"]["preset"] = preset
|
||||
g[f"ass-{base_name}-{preset}"] = editor_render.build_project_ass(
|
||||
q, editor.effective_settings(layout.merge(base), q), "twitch.tv/x", chat=chat)
|
||||
cfg = editor.effective_settings(layout.merge(base), p)
|
||||
g[f"filter-{base_name}"] = editor_render.build_filter(p, cfg, editor.pieces(p["cuts"]), 10.0, "e.ass", [], cover_input=1)
|
||||
words = [Word(1.0, 1.3, "olha"), Word(1.4, 1.8, "isso"), Word(1.9, 2.3, "aqui"), Word(3.5, 3.9, "caiu"), Word(4.0, 4.6, "mano")]
|
||||
g[f"subs-{base_name}"] = subtitles.build_ass(words, 0.5, 6.0, "twitch.tv/x", layout.merge(base))
|
||||
got = {k: hashlib.sha256(str(v).encode("utf-8")).hexdigest() for k, v in g.items()}
|
||||
assert set(got) == set(expected)
|
||||
assert [k for k in expected if got[k] != expected[k]] == []
|
||||
|
||||
|
||||
def test_old_project_without_format_stays_vertical(tmp_path):
|
||||
p = validate(make_project(settings={"caption": {"size": 90}}), tmp_path)
|
||||
assert "format" not in p["settings"]
|
||||
cfg = editor.effective_settings(layout.merge(), p)
|
||||
assert layout.aspect(cfg) == "vertical" and "PlayResY: 1920" in editor_render.build_project_ass(p, cfg, "")
|
||||
# o projeto escolhe o formato por corte, por cima do canal/sessão
|
||||
q = validate(make_project(settings={"format": {"aspect": "vertical"}}), tmp_path)
|
||||
assert layout.aspect(editor.effective_settings(layout.merge(HORIZONTAL), q)) == "vertical"
|
||||
with pytest.raises(editor.EditError):
|
||||
validate(make_project(settings={"format": {"aspect": "4:3"}}), tmp_path)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------- render real
|
||||
def _dark_segment(folder: Path, seconds: int = 8) -> Path:
|
||||
"""Bloco de vídeo escuro (texto claro aparece com clareza) com tom de teste."""
|
||||
seg = folder / "dark.ts"
|
||||
subprocess.run([FFMPEG, "-v", "error", "-f", "lavfi", "-i", f"color=c=0x202020:size=640x360:rate=30:duration={seconds}",
|
||||
"-f", "lavfi", "-i", f"sine=frequency=440:duration={seconds}", "-c:v", "libx264", "-preset", "ultrafast",
|
||||
"-g", "15", "-c:a", "aac", "-shortest", str(seg)], check=True)
|
||||
return seg
|
||||
|
||||
|
||||
def _gray_frame(video: Path, at: float, w: int, h: int) -> bytes:
|
||||
return subprocess.run([FFMPEG, "-v", "error", "-ss", f"{at:.2f}", "-i", str(video), "-frames:v", "1", "-f", "rawvideo",
|
||||
"-pix_fmt", "gray", "-"], capture_output=True, check=True).stdout[: w * h]
|
||||
|
||||
|
||||
def _bright(frame: bytes, w: int, x0: float, x1: float, y0: float, y1: float, h: int) -> int:
|
||||
return sum(1 for y in range(int(y0 * h), int(y1 * h)) for x in range(int(x0 * w), int(x1 * w), 2)
|
||||
if frame[y * w + x] > 200)
|
||||
|
||||
|
||||
@pytest.mark.skipif(not (FFMPEG and FFPROBE), reason="FFmpeg não instalado")
|
||||
def test_real_horizontal_render(tmp_path):
|
||||
"""Render de verdade em 1920×1080: legenda, gancho, chat, zoom, barra, crédito e capa no início."""
|
||||
seg = _dark_segment(tmp_path)
|
||||
words = [{"s": 1.2 + i * 0.3, "e": 1.45 + i * 0.3, "w": w} for i, w in enumerate("olha isso aqui caiu mano".split())]
|
||||
data = make_project(source={"sessionId": 1, "lo": 0, "hi": 8}, settings=HORIZONTAL,
|
||||
cuts=[{"start": 1, "end": 4, "mode": None}, {"start": 4, "end": 7, "mode": "cam_only"}],
|
||||
overlays=[{"id": "hook", "kind": "hook", "text": "ELE NÃO ACREDITOU", "start": 0, "end": 2, "y": 0.2,
|
||||
"size": 70, "color": "#FFFFFF", "box": "#E11D48", "anim": "none"},
|
||||
{"id": "z", "kind": "zoom", "start": 5, "end": 6.5, "scale": 1.3, "x": 0.5, "y": 0.5, "ramp": 0.2}],
|
||||
captions={"enabled": True, "preset": "classic", "style": {}, "emphColor": "#22E36B", "words": words},
|
||||
cover={"enabled": True, "t": 2, "text": "CAPA", "atStart": True},
|
||||
chat={"enabled": True, "x": 0.02, "y": 0.6, "width": 0.3, "lines": 3, "size": 40})
|
||||
p = validate(data, tmp_path, duration=8.0)
|
||||
base = layout.merge(CAM)
|
||||
segments = [(seg, 0.0, 8.0)]
|
||||
cover = editor_render.render_cover(FFMPEG, segments, p, base, "twitch.tv/x", tmp_path / "cover.jpg")
|
||||
out = tmp_path / "out.mp4"
|
||||
editor_render.render_project(FFMPEG, FFPROBE, ["-c:v", "libx264", "-preset", "ultrafast"], segments, p, base, "twitch.tv/x",
|
||||
out, tmp_path, chat=[ChatMessage(1.5, "KKKK", "ana"), ChatMessage(5.0, "F", "beto")],
|
||||
cover_file=cover)
|
||||
probe = subprocess.run([FFPROBE, "-v", "error", "-show_entries", "format=duration:stream=width,height", "-of", "csv=p=0",
|
||||
str(out)], capture_output=True, text=True, check=True).stdout
|
||||
assert "1920,1080" in probe and abs(float(probe.strip().splitlines()[-1]) - 6.0) < 0.2
|
||||
cover_probe = subprocess.run([FFPROBE, "-v", "error", "-show_entries", "stream=width,height", "-of", "csv=p=0", str(cover)],
|
||||
capture_output=True, text=True, check=True).stdout
|
||||
assert cover_probe.strip() == "1920,1080"
|
||||
w, h = 1920, 1080
|
||||
frame = _gray_frame(out, 1.0, w, h) # 1 s de saída = 2 s da sessão: gancho, legenda e chat na tela
|
||||
assert _bright(frame, w, 0.25, 0.75, 0.15, 0.25, h) > 200 # gancho em cima
|
||||
assert _bright(frame, w, 0.25, 0.75, 0.80, 0.90, h) > 200 # legenda no terço de baixo
|
||||
assert _bright(frame, w, 0.0, 0.3, 0.50, 0.60, h) > 50 # chat à esquerda
|
||||
assert _bright(frame, w, 0.7, 1.0, 0.0, 0.08, h) > 50 # crédito no canto de cima à direita
|
||||
assert _bright(frame, w, 0.0, 1.0, 0.30, 0.45, h) < 50 # o meio do jogo fica limpo
|
||||
|
||||
|
||||
# ---------------------------------------------------------------- aspect no corte + migração v8
|
||||
def test_migration_v8_marks_old_clips_vertical(tmp_path):
|
||||
path = tmp_path / "old.db"
|
||||
conn = sqlite3.connect(path)
|
||||
for script in db_module.SCHEMA[:7]:
|
||||
for statement in db_module._split(script):
|
||||
conn.execute(statement)
|
||||
conn.execute("PRAGMA user_version = 7")
|
||||
conn.execute("INSERT INTO sessions (id, platform, kind, url, status, dir, started_at) VALUES (1, 'twitch', 'live', 'u', 'done', 'd', 'x')")
|
||||
conn.execute("INSERT INTO clips (session_id, peak_s, start_s, end_s, score, source, status, created_at, updated_at) "
|
||||
"VALUES (1, 5, 0, 10, 1, 'chat', 'ready', 'x', 'x')")
|
||||
conn.commit()
|
||||
conn.close()
|
||||
database = db_module.Database(path)
|
||||
assert database.get("PRAGMA user_version")["user_version"] == len(db_module.SCHEMA) >= 8 # v9 (capture_json) em cima
|
||||
assert database.get("SELECT aspect FROM clips")["aspect"] == "vertical"
|
||||
with pytest.raises(sqlite3.IntegrityError):
|
||||
database.run("UPDATE clips SET aspect = 'quadrado'")
|
||||
database.close()
|
||||
|
||||
|
||||
@pytest.mark.skipif(not FFMPEG, reason="FFmpeg não instalado")
|
||||
def test_clip_reports_rendered_aspect(api): # noqa: F811
|
||||
client, engine, root = api
|
||||
h = {"X-Service-Key": KEY}
|
||||
assert client.get("/v1/clips/7", headers=h).json()["aspect"] == "vertical" # antes do render: padrão
|
||||
_lavfi_segments(root / "data" / "s1")
|
||||
client.put("/v1/sessions/1/settings", headers=h, json={"format": {"aspect": "horizontal"}})
|
||||
engine.db.run("UPDATE clips SET status = 'pending' WHERE id = 7")
|
||||
engine.render_pending()
|
||||
clip = client.get("/v1/clips/7", headers=h).json()
|
||||
assert clip["status"] == "ready", clip["error"]
|
||||
assert clip["aspect"] == "horizontal"
|
||||
assert any(c["aspect"] == "horizontal" for c in client.get("/v1/clips", headers=h).json()["clips"])
|
||||
probe = subprocess.run([FFPROBE or "ffprobe", "-v", "error", "-select_streams", "v", "-show_entries", "stream=width,height",
|
||||
"-of", "csv=p=0", str(root / clip["file"])], capture_output=True, text=True, check=True).stdout
|
||||
assert probe.strip() == "1920,1080"
|
||||
# Prévia real do começo com capa no início: a capa é gerada também para a prévia.
|
||||
project = client.get("/v1/clips/7/edit", headers=h).json()
|
||||
project["project"]["cover"]["atStart"] = True
|
||||
assert client.put("/v1/clips/7/edit", headers=h, json=project).status_code == 200
|
||||
prev = client.post("/v1/clips/7/preview-render", headers=h, json={"fromS": 0, "durationS": 2})
|
||||
assert prev.status_code == 200, prev.text
|
||||
assert (root / "output" / "clipper" / "1" / "edit-7" / "preview-cover.jpg").is_file()
|
||||
# O projeto escolhe o formato por corte: vertical por cima da sessão horizontal.
|
||||
project = client.get("/v1/clips/7/edit", headers=h).json()
|
||||
project["project"]["settings"] = {"format": {"aspect": "vertical"}}
|
||||
assert client.put("/v1/clips/7/edit", headers=h, json=project).status_code == 200
|
||||
client.post("/v1/clips/7/export", headers=h)
|
||||
engine.render_pending()
|
||||
assert client.get("/v1/clips/7", headers=h).json()["aspect"] == "vertical"
|
||||
|
||||
|
||||
# ---------------------------------------------------------------- legenda com fala rápida
|
||||
def _fast_words() -> list[Word]:
|
||||
"""~7 palavras/s, com sobreposição (fim depois do início da seguinte), duração zero e duas no mesmo instante."""
|
||||
out, t = [], 0.3
|
||||
for i, text in enumerate("e aí mano olha isso que ele fez cara não acredito vai vai vai pega ele agora sim kkkk".split()):
|
||||
dur = 0.0 if i % 5 == 3 else 0.22 # algumas de 0 s (Whisper)
|
||||
out.append(Word(round(t, 3), round(t + dur, 3), text))
|
||||
t += 0.14
|
||||
out.append(Word(out[-1].start, out[-1].start + 0.2, "boa")) # mesmo instante da anterior
|
||||
return out
|
||||
|
||||
|
||||
def _caption_events(ass: str) -> list[tuple[float, float]]:
|
||||
def ts(s: str) -> float:
|
||||
hh, mm, ss = s.split(":")
|
||||
return int(hh) * 3600 + int(mm) * 60 + float(ss)
|
||||
rows = [line.split(",") for line in ass.splitlines() if re.match(r"Dialogue: 0,.*,(Caption|Karaoke),", line)]
|
||||
return sorted((ts(r[1]), ts(r[2])) for r in rows)
|
||||
|
||||
|
||||
def test_fast_speech_captions_never_overlap_and_stay_in_sync(tmp_path):
|
||||
raw = _fast_words()
|
||||
clean = subtitles.clean_words(raw)
|
||||
assert all(b.start > a.start and a.end <= b.start + 1e-9 for a, b in zip(clean, clean[1:])) # ordem, sem sobreposição
|
||||
assert all(w.end - w.start > 0 for w in clean)
|
||||
assert subtitles.clean_words(clean) == clean # idempotente
|
||||
# só a palavra que começava junto com a anterior foi empurrada (e no máximo 40 ms)
|
||||
shifts = [round(c.start - r.start, 3) for r, c in zip(sorted(raw, key=lambda w: (w.start, w.end)), clean)]
|
||||
assert [s for s in shifts if s] == [0.04]
|
||||
blocks = subtitles.caption_blocks(raw, 3)
|
||||
assert all(len(g) <= 4 for g, _ in blocks) and any(len(g) == 4 for g, _ in blocks) # fala rápida: +1 palavra
|
||||
for (g1, end1), (g2, _) in zip(blocks, blocks[1:]):
|
||||
assert end1 <= g2[0].start # um bloco sai antes do próximo entrar
|
||||
|
||||
# Render do editor (todos os presets, nos dois formatos) e do worker: nenhum par de eventos ao mesmo tempo, e
|
||||
# cada bloco entra no início da sua 1ª palavra (no centésimo do ASS).
|
||||
words = [{"s": w.start + 10, "e": w.end + 10, "w": w.word} for w in raw]
|
||||
starts = {round(w.start, 2) for w in clean}
|
||||
for settings in ({}, HORIZONTAL):
|
||||
for preset in editor.CAPTION_PRESETS:
|
||||
p = validate(make_project(settings=settings, cuts=[{"start": 10, "end": 20, "mode": None}], overlays=[],
|
||||
captions={"enabled": True, "preset": preset, "style": {}, "emphColor": "#22E36B",
|
||||
"words": words}), tmp_path)
|
||||
events = _caption_events(editor_render.build_project_ass(p, editor.effective_settings(layout.merge(), p), ""))
|
||||
assert len(events) >= 5, preset
|
||||
assert all(b[0] >= a[1] - 1e-6 for a, b in zip(events, events[1:])), preset
|
||||
assert all(round(s, 2) in starts or any(abs(s - x) <= 0.011 for x in starts) for s, _ in events), preset
|
||||
events = _caption_events(subtitles.build_ass(raw, 0.0, 10.0, "", layout.merge(settings)))
|
||||
assert all(b[0] >= a[1] - 1e-6 for a, b in zip(events, events[1:]))
|
||||
|
||||
|
||||
def test_emphasis_and_highlight_survive_word_cleaning(tmp_path):
|
||||
words = [{"s": 11.0, "e": 11.3, "w": "olha"}, {"s": 11.0, "e": 11.2, "w": "isso", "emph": True},
|
||||
{"s": 11.25, "e": 11.25, "w": "aqui"}]
|
||||
p = validate(make_project(cuts=[{"start": 10, "end": 15, "mode": None}], overlays=[],
|
||||
captions={"enabled": True, "preset": "classic", "style": {}, "emphColor": "#22E36B", "words": words}),
|
||||
tmp_path)
|
||||
ass = editor_render.build_project_ass(p, editor.effective_settings(layout.merge(), p), "")
|
||||
assert "&H6BE322&" in ass # ênfase ainda casada com a palavra certa depois do saneamento
|
||||
assert len(_caption_events(ass)) == 3
|
||||
Reference in New Issue
Block a user