Update main.py
Browse files
main.py
CHANGED
|
@@ -491,6 +491,8 @@ EXEMPLOS
|
|
| 491 |
|
| 492 |
# Se for vídeo, chamar a API de video export
|
| 493 |
if 'image' not in content_type and title_text:
|
|
|
|
|
|
|
| 494 |
try:
|
| 495 |
# Usar o vídeo cortado se disponível, senão o original
|
| 496 |
video_for_export = cropped_video_path if cropped_video_path and os.path.exists(cropped_video_path) else temp_file.name
|
|
@@ -551,9 +553,26 @@ EXEMPLOS
|
|
| 551 |
|
| 552 |
canvas_width = 1080
|
| 553 |
image_height = 616
|
| 554 |
-
|
| 555 |
video_template = "horizontal" if crop_w > crop_h else "vertical"
|
| 556 |
print(f"📐 Dimensões do vídeo: {crop_w}x{crop_h} | Template: {video_template}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 557 |
|
| 558 |
# 5. Montar title_url
|
| 559 |
import urllib.parse
|
|
@@ -573,7 +592,7 @@ EXEMPLOS
|
|
| 573 |
"cut_start": 0,
|
| 574 |
"cut_end": video_duration,
|
| 575 |
"video_x": video_x,
|
| 576 |
-
"video_y":
|
| 577 |
"video_width": crop_w,
|
| 578 |
"video_height": crop_h,
|
| 579 |
"video_template": video_template
|
|
|
|
| 491 |
|
| 492 |
# Se for vídeo, chamar a API de video export
|
| 493 |
if 'image' not in content_type and title_text:
|
| 494 |
+
# Título de vídeo sempre começa com maiúscula
|
| 495 |
+
title_text = title_text[0].upper() + title_text[1:] if title_text else title_text
|
| 496 |
try:
|
| 497 |
# Usar o vídeo cortado se disponível, senão o original
|
| 498 |
video_for_export = cropped_video_path if cropped_video_path and os.path.exists(cropped_video_path) else temp_file.name
|
|
|
|
| 553 |
|
| 554 |
canvas_width = 1080
|
| 555 |
image_height = 616
|
| 556 |
+
video_dest_height = 1920 - image_height # 1304px
|
| 557 |
video_template = "horizontal" if crop_w > crop_h else "vertical"
|
| 558 |
print(f"📐 Dimensões do vídeo: {crop_w}x{crop_h} | Template: {video_template}")
|
| 559 |
+
|
| 560 |
+
# Para vídeo vertical: calcular video_y para centralizar o crop verticalmente
|
| 561 |
+
# O videoexport escala o vídeo para largura=1080 mantendo proporção,
|
| 562 |
+
# depois faz crop de cima. Precisamos passar o offset Y correto.
|
| 563 |
+
if video_template == "vertical":
|
| 564 |
+
# Altura escalada quando width=1080
|
| 565 |
+
if crop_w > 0:
|
| 566 |
+
scaled_h = int(crop_h * canvas_width / crop_w)
|
| 567 |
+
else:
|
| 568 |
+
scaled_h = crop_h
|
| 569 |
+
video_x = 0
|
| 570 |
+
video_y = max(0, (scaled_h - video_dest_height) // 2)
|
| 571 |
+
else:
|
| 572 |
+
# Horizontal: centralizado horizontalmente, sem offset vertical relevante
|
| 573 |
+
video_x = 0
|
| 574 |
+
video_y = 0
|
| 575 |
+
print(f" → video_y (crop offset): {video_y}px")
|
| 576 |
|
| 577 |
# 5. Montar title_url
|
| 578 |
import urllib.parse
|
|
|
|
| 592 |
"cut_start": 0,
|
| 593 |
"cut_end": video_duration,
|
| 594 |
"video_x": video_x,
|
| 595 |
+
"video_y": video_y,
|
| 596 |
"video_width": crop_w,
|
| 597 |
"video_height": crop_h,
|
| 598 |
"video_template": video_template
|