Update app.py
Browse files
app.py
CHANGED
|
@@ -1,19 +1,25 @@
|
|
| 1 |
from fastapi import FastAPI
|
| 2 |
import subprocess
|
| 3 |
import json
|
|
|
|
| 4 |
|
| 5 |
app = FastAPI()
|
| 6 |
|
| 7 |
@app.get("/extraer-audios")
|
| 8 |
def extraer_audios(url: str):
|
| 9 |
-
# Comando FFprobe para leer la URL del MP4
|
| 10 |
comando = [
|
| 11 |
"ffprobe", "-v", "quiet", "-print_format", "json",
|
| 12 |
"-show_streams", url
|
| 13 |
]
|
| 14 |
|
| 15 |
resultado = subprocess.run(comando, capture_output=True, text=True)
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
audios = []
|
| 19 |
if "streams" in datos:
|
|
@@ -24,4 +30,8 @@ def extraer_audios(url: str):
|
|
| 24 |
"idioma": stream.get("tags", {}).get("language", "Desconocido")
|
| 25 |
})
|
| 26 |
|
| 27 |
-
return {"audios": audios}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from fastapi import FastAPI
|
| 2 |
import subprocess
|
| 3 |
import json
|
| 4 |
+
import uvicorn
|
| 5 |
|
| 6 |
app = FastAPI()
|
| 7 |
|
| 8 |
@app.get("/extraer-audios")
|
| 9 |
def extraer_audios(url: str):
|
| 10 |
+
# Comando FFprobe para leer la URL del MP4
|
| 11 |
comando = [
|
| 12 |
"ffprobe", "-v", "quiet", "-print_format", "json",
|
| 13 |
"-show_streams", url
|
| 14 |
]
|
| 15 |
|
| 16 |
resultado = subprocess.run(comando, capture_output=True, text=True)
|
| 17 |
+
|
| 18 |
+
# Manejo de errores por si ffprobe falla al leer la URL
|
| 19 |
+
try:
|
| 20 |
+
datos = json.loads(resultado.stdout)
|
| 21 |
+
except json.JSONDecodeError:
|
| 22 |
+
return {"error": "No se pudo leer el video. Verifica que la URL sea pública y directa al MP4."}
|
| 23 |
|
| 24 |
audios = []
|
| 25 |
if "streams" in datos:
|
|
|
|
| 30 |
"idioma": stream.get("tags", {}).get("language", "Desconocido")
|
| 31 |
})
|
| 32 |
|
| 33 |
+
return {"audios": audios}
|
| 34 |
+
|
| 35 |
+
# FALTABA ESTA PARTE: Mantener el servidor encendido en el puerto correcto
|
| 36 |
+
if __name__ == "__main__":
|
| 37 |
+
uvicorn.run(app, host="0.0.0.0", port=7860)
|