PrismeFoot commited on
Commit
cf4c7f3
·
verified ·
1 Parent(s): 17b44de

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -58
app.py CHANGED
@@ -1,71 +1,72 @@
1
- import os, uuid, requests, subprocess, random
2
  import streamlit as st
3
 
 
4
  URL_MAKE = "https://make.com"
 
5
 
6
- st.set_page_config(page_title="Prisme Foot - Final", page_icon="⚽")
7
- st.title("⚽ Prisme Foot : Mode Ultra-Stable")
8
 
9
- def recuperer_video_reelle():
10
- # On définit plusieurs mots-clés pour multiplier les chances
11
- api_key = "43306532-38708f59836371360098df240"
12
- queries = ["soccer", "football", "stadium"]
13
-
14
- for q in queries:
15
- try:
16
- url = f"https://pixabay.com{api_key}&q={q}&orientation=vertical&per_page=5"
17
- r = requests.get(url, timeout=10)
18
- data = r.json()
19
- if data.get('hits'):
20
- # On retourne le premier lien valide trouvé
21
- return random.choice(data['hits'])['videos']['medium']['url']
22
- except:
23
- continue
24
- return None
25
 
26
- def executer_publication():
27
- uid = uuid.uuid4().hex[:4]
28
- v_raw, v_final = f"r_{uid}.mp4", f"f_{uid}.mp4"
 
 
 
 
 
 
 
29
 
30
- with st.status("🚀 Traitement en cours...") as status:
31
- # 1. Capture de la source réelle
32
- link = recuperer_video_reelle()
33
- if not link:
34
- st.error("❌ Erreur : Toutes les sources de foot sont occupées. Réessaie dans 1 minute.")
35
- return
 
36
 
37
- # 2. Téléchargement sécurisé
38
- st.write("📥 Récupération d'une séquence de match...")
39
- try:
40
- r = requests.get(link, timeout=20)
41
- with open(v_raw, 'wb') as f: f.write(r.content)
42
- except:
43
- st.error("❌ Echec du téléchargement.")
44
- return
45
 
46
- # 3. Montage Branding
47
- st.write("🎬 Marquage Prisme Foot...")
48
- cmd = (f'ffmpeg -i {v_raw} -t 10 '
49
- f'-vf "scale=720:1280:force_original_aspect_ratio=increase,crop=720:1280,'
50
- f'drawtext=text=\'PRISME FOOT\':fontcolor=white:fontsize=50:x=(w-text_w)/2:y=h-200" '
51
- f'-c:v libx264 -preset superfast {v_final} -y')
 
 
 
 
 
 
52
 
53
- resultat = subprocess.run(cmd, shell=True)
54
 
55
- # 4. Envoi Facebook
56
- if resultat.returncode == 0 and os.path.exists(v_final):
57
- st.write("🚀 Envoi vers Facebook...")
58
- try:
59
- requests.post(URL_MAKE, files={'file': open(v_final, 'rb')}, data={'caption': "⚽ Action de match !"}, timeout=30)
60
- st.success("✅ VIDÉO ENVOYÉE AVEC SUCCÈS !")
61
- except:
62
- st.error("❌ Erreur d'envoi vers Make.")
63
  else:
64
- st.error("❌ Erreur technique de montage.")
65
-
66
- # Nettoyage
67
- for f in [v_raw, v_final]:
68
- if os.path.exists(f): os.remove(f)
69
 
70
- if st.button("🔥 PUBLIER MAINTENANT"):
71
- executer_publication()
 
1
+ import os, uuid, subprocess, random, requests, json
2
  import streamlit as st
3
 
4
+ # --- CONFIGURATION ---
5
  URL_MAKE = "https://make.com"
6
+ DB_FILE = "historique_clips.json" # La mémoire du bot
7
 
8
+ st.set_page_config(page_title="Prisme Foot - Studio Pro", page_icon="⚽")
9
+ st.title("⚽ Prisme Foot : Studio Automatisé")
10
 
11
+ # --- FONCTIONS MÉMOIRE ---
12
+ def charger_memoire():
13
+ if os.path.exists(DB_FILE):
14
+ with open(DB_FILE, "r") as f: return json.load(f)
15
+ return {}
 
 
 
 
 
 
 
 
 
 
 
16
 
17
+ def sauvegarder_memoire(source, depart):
18
+ memoire = charger_memoire()
19
+ if source not in memoire: memoire[source] = []
20
+ memoire[source].append(depart)
21
+ with open(DB_FILE, "w") as f: json.dump(memoire, f)
22
+
23
+ # --- MOTEUR DE PRODUCTION ---
24
+ def produire_reel_unique():
25
+ # 1. Lister les vidéos 1080p que TU as uploadées
26
+ videos_sources = [f for f in os.listdir() if f.endswith('.mp4') and f.startswith('match')]
27
 
28
+ if not videos_sources:
29
+ st.error("⚠️ Esclave de personne ! Ajoute des fichiers 'match1.mp4', 'match2.mp4' dans l'onglet Files.")
30
+ return
31
+
32
+ v_source = random.choice(videos_sources)
33
+ memoire = charger_memoire()
34
+ deja_publie = memoire.get(v_source, [])
35
 
36
+ # 2. Chercher un moment de 10s jamais publié
37
+ tentatives = 0
38
+ depart = 0
39
+ while tentatives < 50:
40
+ depart = random.randint(0, 500) # On cherche entre 0 et 8 minutes
41
+ if depart not in deja_publie:
42
+ break
43
+ tentatives += 1
44
 
45
+ uid = uuid.uuid4().hex[:4]
46
+ v_final = f"PRISME_{uid}.mp4"
47
+
48
+ with st.status(f"🎬 Création d'un Reel unique depuis {v_source}...") as status:
49
+ # 3. LE BOUCLIER ANTI-BANNISSEMENT (Vitesse +2%, Zoom, Couleurs)
50
+ cmd = (
51
+ f'ffmpeg -ss {depart} -t 10 -i "{v_source}" '
52
+ f'-vf "scale=1280:720,setpts=0.98*PTS,crop=405:720:437:0,scale=720:1280,'
53
+ f'eq=brightness=0.06:contrast=1.1:saturation=1.2,'
54
+ f'drawtext=text=\'PRISME FOOT EXCLUSIF\':fontcolor=white:fontsize=35:x=(w-text_w)/2:y=h-200:box=1:boxcolor=black@0.4" '
55
+ f'-c:v libx264 -preset superfast -af "atempo=1.02" {v_final} -y'
56
+ )
57
 
58
+ res = subprocess.run(cmd, shell=True)
59
 
60
+ if res.returncode == 0 and os.path.exists(v_final):
61
+ # 4. ENVOI ET MÉMORISATION
62
+ with open(v_final, 'rb') as f:
63
+ requests.post(URL_MAKE, files={'file': f}, data={'caption': "⚽ Action de match réelle ! #PrismeFoot"})
64
+
65
+ sauvegarder_memoire(v_source, depart)
66
+ st.success(f"✅ Vidéo envoyée ! (Source: {v_source}, Moment: {depart}s)")
67
+ os.remove(v_final)
68
  else:
69
+ st.error("Erreur technique de montage.")
 
 
 
 
70
 
71
+ if st.button("🔥 GÉNÉRER UN REEL UNIQUE ET ORIGINAL"):
72
+ produire_reel_unique()