Spaces:
Sleeping
Sleeping
Update src/capsule_builder.py
Browse files- src/capsule_builder.py +39 -7
src/capsule_builder.py
CHANGED
|
@@ -80,17 +80,49 @@ def build_capsule(titre, sous_titre, texte_voix, texte_ecran, theme,
|
|
| 80 |
clips.append(bg)
|
| 81 |
|
| 82 |
if video_presentateur and os.path.exists(video_presentateur):
|
| 83 |
-
|
| 84 |
-
v_presentateur =
|
| 85 |
-
|
| 86 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
if v_presentateur:
|
| 88 |
-
print(f"[Capsule] ✅
|
| 89 |
clips.append(v_presentateur)
|
| 90 |
else:
|
| 91 |
-
print(f"[Capsule] ❌ Échec préparation
|
| 92 |
else:
|
| 93 |
-
print(f"[Capsule] Aucune vidéo présentateur: {video_presentateur}")
|
|
|
|
| 94 |
|
| 95 |
final = CompositeVideoClip(clips).set_audio(audio.set_fps(44100))
|
| 96 |
name = safe_name(f"{titre}_{langue}")
|
|
|
|
| 80 |
clips.append(bg)
|
| 81 |
|
| 82 |
if video_presentateur and os.path.exists(video_presentateur):
|
| 83 |
+
ext = os.path.splitext(video_presentateur)[1].lower()
|
| 84 |
+
v_presentateur = None
|
| 85 |
+
|
| 86 |
+
# --- Vidéo ---
|
| 87 |
+
if ext in [".mp4", ".mov", ".avi", ".mkv"]:
|
| 88 |
+
print(f"[Capsule] Vidéo présentateur trouvée: {video_presentateur}")
|
| 89 |
+
v_presentateur = prepare_video_presentateur(
|
| 90 |
+
video_presentateur, dur, position_presentateur, plein
|
| 91 |
+
)
|
| 92 |
+
|
| 93 |
+
# --- Image ---
|
| 94 |
+
elif ext in [".jpg", ".jpeg", ".png", ".bmp", ".webp"]:
|
| 95 |
+
from moviepy.editor import ImageClip
|
| 96 |
+
print(f"[Capsule] Image présentateur trouvée: {video_presentateur}")
|
| 97 |
+
try:
|
| 98 |
+
img_clip = ImageClip(video_presentateur).set_duration(dur)
|
| 99 |
+
if plein:
|
| 100 |
+
img_clip = img_clip.resize((W, H)).set_position(("center", "center"))
|
| 101 |
+
print("[Capsule] Image plein écran")
|
| 102 |
+
else:
|
| 103 |
+
img_clip = img_clip.resize(width=520)
|
| 104 |
+
pos_map = {
|
| 105 |
+
"bottom-right": ("right", "bottom"),
|
| 106 |
+
"bottom-left": ("left", "bottom"),
|
| 107 |
+
"top-right": ("right", "top"),
|
| 108 |
+
"top-left": ("left", "top"),
|
| 109 |
+
"center": ("center", "center"),
|
| 110 |
+
}
|
| 111 |
+
img_clip = img_clip.set_position(pos_map.get(position_presentateur, ("right", "bottom")))
|
| 112 |
+
print(f"[Capsule] Image positionnée : {position_presentateur}")
|
| 113 |
+
v_presentateur = img_clip
|
| 114 |
+
except Exception as e:
|
| 115 |
+
print(f"[Capsule] ❌ Erreur image présentateur : {e}")
|
| 116 |
+
|
| 117 |
+
# --- Ajout final ---
|
| 118 |
if v_presentateur:
|
| 119 |
+
print(f"[Capsule] ✅ Présentateur ajouté (image ou vidéo)")
|
| 120 |
clips.append(v_presentateur)
|
| 121 |
else:
|
| 122 |
+
print(f"[Capsule] ❌ Échec préparation présentateur")
|
| 123 |
else:
|
| 124 |
+
print(f"[Capsule] Aucune vidéo/image présentateur: {video_presentateur}")
|
| 125 |
+
|
| 126 |
|
| 127 |
final = CompositeVideoClip(clips).set_audio(audio.set_fps(44100))
|
| 128 |
name = safe_name(f"{titre}_{langue}")
|