Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,71 +1,72 @@
|
|
| 1 |
-
import os, uuid,
|
| 2 |
import streamlit as st
|
| 3 |
|
|
|
|
| 4 |
URL_MAKE = "https://make.com"
|
|
|
|
| 5 |
|
| 6 |
-
st.set_page_config(page_title="Prisme Foot -
|
| 7 |
-
st.title("⚽ Prisme Foot :
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 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
|
| 27 |
-
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
|
|
|
| 36 |
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
-
|
| 54 |
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
else:
|
| 64 |
-
st.error("
|
| 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("🔥
|
| 71 |
-
|
|
|
|
| 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()
|