darkmedia-x-api / backend /api /patch_bot.py
cybermedia's picture
Upload folder using huggingface_hub
343eed9 verified
import os
import re
file_path = r"c:\Users\lapet\github-all\darkmedia\.youtube\scripts\firefly_horror_bot.py"
content = open(file_path, 'r', encoding='utf-8').read()
# 1. Fix update_status Prompt assignment
pattern_status = re.escape('if scene: current_status[model_name]["scene"] = scene')
content = re.sub(pattern_status, 'if scene: current_status[model_name]["scene"] = scene\n if prompt: current_status[model_name]["prompt"] = prompt', content)
# 2. Fix Polling delay in wait_for_generation
# We look for the await asyncio.sleep(3) that comes AFTER a True return or loop check
content = content.replace('await asyncio.sleep(3)', 'await asyncio.sleep(1)')
# 3. Fix Move logic Method 2 (direct URL)
# Find the download_video URL direct logic
old_url_logic = """ if response.ok:
content = await response.body()
with open(filepath, "wb") as f:
f.write(content)
log(f"Vidéo téléchargée via URL directe : {filename}", "💾")
return True"""
new_url_logic = """ if response.ok:
content = await response.body()
with open(filepath, "wb") as f:
f.write(content)
log(f"Vidéo téléchargée via URL directe : {filename}", "💾")
# Déplacement vers le dossier de la story si spécifié
if story_folder:
try:
import shutil
from pathlib import Path
videos_dir = Path(story_folder) / "videos"
videos_dir.mkdir(parents=True, exist_ok=True)
if "_S" in str(video_number):
scene_tag = str(video_number).split("_S")[-1]
dest_name = f"S{scene_tag}.mp4"
else:
dest_name = f"{video_number}.mp4"
dest_path = videos_dir / dest_name
log(f" 📂 Tentative de déplacement (Méthode 2) : {filepath.name} -> {dest_path}", "🚚")
shutil.move(str(filepath), str(dest_path))
log(f" ✅ Vidéo déplacée avec succès vers : {dest_path}", "🚚")
except Exception as e:
log(f" ⚠️ Erreur lors du déplacement (Méthode 2) : {e}", "⚠️")
return True"""
content = content.replace(old_url_logic, new_url_logic)
with open(file_path, 'w', encoding='utf-8') as f:
f.write(content)
print("Patch applied successfully.")