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>
85 lines
3.7 KiB
GDScript
85 lines
3.7 KiB
GDScript
extends RefCounted
|
|
## Contrato das cenas do documentário:
|
|
## { "id": "...", "kind": "doc2d" | "doc3d",
|
|
## "video": { "width": 1080, "height": 1920, "fps": 30, "durationSeconds": 6.2 },
|
|
## "template": <modelo do tipo>, "params": { ... } }
|
|
## doc2d (motion graphics, doc2d_canvas.gd): "title" | "counter" | "map"
|
|
## doc3d (cena 3D da biblioteca): o nome de uma pasta em godot/library/ ("island", ...)
|
|
## A duração vem do áudio do trecho: a cena dura exatamente o que a narração dura.
|
|
## params.variant (inteiro, opcional): variação de layout/câmera para "gerar de novo".
|
|
|
|
const TEMPLATES_2D := ["title", "counter", "map"]
|
|
const LIBRARY_DIR := "res://library"
|
|
|
|
|
|
## Script da cena 3D da biblioteca: res://library/<id>/template.gd.
|
|
static func library_script(id: String) -> String:
|
|
return "%s/%s/template.gd" % [LIBRARY_DIR, id]
|
|
|
|
|
|
## Cenas 3D disponíveis (pastas da biblioteca com template.gd).
|
|
static func library_templates() -> Array:
|
|
var out := []
|
|
var dir := DirAccess.open(LIBRARY_DIR)
|
|
if dir == null:
|
|
return out
|
|
for name in dir.get_directories():
|
|
if ResourceLoader.exists(library_script(name)):
|
|
out.append(name)
|
|
return out
|
|
|
|
|
|
static func load_file(path: String) -> Dictionary:
|
|
if not FileAccess.file_exists(path):
|
|
return {"ok": false, "errors": ["arquivo não encontrado: %s" % path]}
|
|
var parsed = JSON.parse_string(FileAccess.get_file_as_string(path))
|
|
if typeof(parsed) != TYPE_DICTIONARY:
|
|
return {"ok": false, "errors": ["JSON inválido ou não é objeto"]}
|
|
return validate(parsed)
|
|
|
|
|
|
static func validate(raw: Dictionary) -> Dictionary:
|
|
var errors := []
|
|
if typeof(raw.get("id")) != TYPE_STRING or str(raw.id).is_empty():
|
|
errors.append("id: texto obrigatório")
|
|
var kind := str(raw.get("kind", ""))
|
|
if not (kind in ["doc2d", "doc3d"]):
|
|
errors.append("kind: \"doc2d\" ou \"doc3d\"")
|
|
var video = raw.get("video")
|
|
if typeof(video) != TYPE_DICTIONARY:
|
|
errors.append("video: objeto obrigatório")
|
|
return {"ok": false, "errors": errors}
|
|
for key in ["width", "height", "fps", "durationSeconds"]:
|
|
if not (typeof(video.get(key)) in [TYPE_INT, TYPE_FLOAT]) or float(video.get(key)) <= 0.0:
|
|
errors.append("video.%s: número positivo obrigatório" % key)
|
|
if errors.is_empty():
|
|
if float(video.durationSeconds) > 120.0:
|
|
errors.append("video.durationSeconds: máximo 120 s por cena")
|
|
if int(video.fps) < 1 or int(video.fps) > 60:
|
|
errors.append("video.fps: entre 1 e 60")
|
|
var template = raw.get("template")
|
|
if kind == "doc2d" and not (template in TEMPLATES_2D):
|
|
errors.append("template: um de %s para doc2d" % [TEMPLATES_2D])
|
|
if kind == "doc3d" and not (typeof(template) == TYPE_STRING and ResourceLoader.exists(library_script(template))):
|
|
errors.append("template: cena 3D \"%s\" não existe na biblioteca (godot/library/). Disponíveis: %s" % [template, library_templates()])
|
|
var params = raw.get("params", {})
|
|
if typeof(params) != TYPE_DICTIONARY:
|
|
errors.append("params: objeto")
|
|
elif template == "counter" and not (typeof(params.get("value")) in [TYPE_INT, TYPE_FLOAT]):
|
|
errors.append("params.value: número obrigatório no modelo counter")
|
|
elif template == "title" and str(params.get("title", "")).strip_edges().is_empty():
|
|
errors.append("params.title: texto obrigatório no modelo title")
|
|
elif template == "map" and typeof(params.get("markers", [])) != TYPE_ARRAY:
|
|
errors.append("params.markers: lista")
|
|
if not errors.is_empty():
|
|
return {"ok": false, "errors": errors}
|
|
var cfg := raw.duplicate(true)
|
|
cfg.video.fps = int(video.fps)
|
|
cfg.video.width = int(video.width)
|
|
cfg.video.height = int(video.height)
|
|
cfg.video.duration = float(video.durationSeconds)
|
|
cfg.video.total_frames = int(round(float(video.durationSeconds) * float(video.fps)))
|
|
if not cfg.has("params"):
|
|
cfg.params = {}
|
|
return {"ok": true, "config": cfg}
|