PrismeFoot commited on
Commit
f4d3ff1
·
verified ·
1 Parent(s): 557486a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +80 -0
app.py CHANGED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os, random, uuid, json, subprocess, asyncio, requests
2
+ import edge_tts
3
+
4
+ # --- CONFIGURATION (À REMPLIR) ---
5
+ PEXELS_API_KEY = "TA_CLE_PEXELS_ICI"
6
+ VOIX_FR = "fr-FR-RemyNeural"
7
+ DB_FILE = "memoire_prisme.json"
8
+ DOSSIER_SECOURS = "images_actu"
9
+
10
+ # --- FONCTIONS DE MÉMOIRE (ANTI-RÉPÉTITION) ---
11
+ def deja_traite(sujet):
12
+ if not os.path.exists(DB_FILE): return False
13
+ with open(DB_FILE, "r", encoding="utf-8") as f:
14
+ return sujet in json.load(f)
15
+
16
+ def sauvegarder_sujet(sujet):
17
+ memoire = []
18
+ if os.path.exists(DB_FILE):
19
+ with open(DB_FILE, "r", encoding="utf-8") as f: memoire = json.load(f)
20
+ memoire.append(sujet)
21
+ with open(DB_FILE, "w", encoding="utf-8") as f: json.dump(memoire, f)
22
+
23
+ # --- RECHERCHE D'IMAGE DYNAMIQUE (PEXELS) ---
24
+ def obtenir_image_fond(sujet):
25
+ url = f"https://pexels.com{sujet} football&per_page=1"
26
+ headers = {"Authorization": PEXELS_API_KEY}
27
+ try:
28
+ r = requests.get(url, headers=headers, timeout=10)
29
+ if r.status_code == 200 and r.json()['photos']:
30
+ img_url = r.json()['photos'][0]['src']['large2x']
31
+ with open("fond_temp.jpg", 'wb') as f:
32
+ f.write(requests.get(img_url).content)
33
+ return "fond_temp.jpg"
34
+ except: pass
35
+ # Secours : image aléatoire du dossier
36
+ fonds = [f for f in os.listdir(DOSSIER_SECOURS) if f.endswith(('.jpg', '.png'))]
37
+ return os.path.join(DOSSIER_SECOURS, random.choice(fonds))
38
+
39
+ # --- MOTEUR DE PRODUCTION ---
40
+ async def creer_video_expert(joueur, news_brute):
41
+ if deja_traite(news_brute):
42
+ print(f"🚫 Déjà publié : {joueur}")
43
+ return
44
+
45
+ # 1. Construction du Script
46
+ hooks = ["ALERTE INFO ! 🚨", "INCROYABLE REBONDISSEMENT ! 😱", "DERNIÈRE MINUTE ! 🔥"]
47
+ script = f"{random.choice(hooks)} On parle de {joueur}. {news_brute} Abonne-toi pour ne rien rater sur Prisme Foot ! ⚽"
48
+
49
+ audio_file = f"audio_{uuid.uuid4().hex[:4]}.mp3"
50
+ video_final = f"PRISME_{uuid.uuid4().hex[:6]}.mp4"
51
+
52
+ # 2. Génération de la Voix Humaine
53
+ communicate = edge_tts.Communicate(script, VOIX_FR)
54
+ await communicate.save(audio_file)
55
+
56
+ # 3. Récupération de l'image
57
+ image_path = obtenir_image_fond(joueur)
58
+
59
+ # 4. Montage FFmpeg (Signature Unique + Zoom + Texte)
60
+ flip = ",hflip" if random.random() > 0.5 else ""
61
+ cmd = (
62
+ f'ffmpeg -loop 1 -i "{image_path}" -i {audio_file} '
63
+ f'-vf "scale=720:1280,zoompan=z=\'min(zoom+0.0015,1.5)\':d=500:s=720x1280'
64
+ f'{flip},hue=h={random.randint(-5,5)},noise=alls=5:allf=t+u,' # Anti-Ban
65
+ f'drawtext=text=\'PRISME FOOT\':fontcolor=yellow:fontsize=40:x=(w-text_w)/2:y=150:box=1:boxcolor=black@0.6,'
66
+ f'drawtext=text=\'{joueur.upper()}\':fontcolor=white:fontsize=60:x=(w-text_w)/2:y=(h-text_h)/2:box=1:boxcolor=red@0.8" '
67
+ f'-c:v libx264 -preset superfast -tune stillimage -c:a aac -shortest {video_final} -y'
68
+ )
69
+
70
+ subprocess.run(cmd, shell=True)
71
+
72
+ # 5. Finalisation
73
+ sauvegarder_sujet(news_brute)
74
+ if os.path.exists(audio_file): os.remove(audio_file)
75
+ print(f"✅ Vidéo terminée avec succès : {video_final}")
76
+
77
+ # --- LANCEMENT ---
78
+ if __name__ == "__main__":
79
+ # Test avec une actu
80
+ asyncio.run(creer_video_expert("Vinicius Jr", "Il vient de recevoir une offre monumentale d'Arabie Saoudite !"))