Update app.py
Browse files
app.py
CHANGED
|
@@ -1,31 +1,35 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import
|
|
|
|
| 3 |
|
| 4 |
-
def
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
f"
|
| 20 |
-
|
| 21 |
-
|
| 22 |
|
|
|
|
| 23 |
iface = gr.Interface(
|
| 24 |
-
fn=
|
| 25 |
-
inputs=
|
| 26 |
-
outputs="
|
| 27 |
-
title="
|
| 28 |
-
description="
|
| 29 |
)
|
| 30 |
|
| 31 |
-
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from pytube import YouTube
|
| 3 |
+
import os
|
| 4 |
|
| 5 |
+
def download_youtube_video(url):
|
| 6 |
+
try:
|
| 7 |
+
# Crea el objeto YouTube a partir de la URL
|
| 8 |
+
yt = YouTube(url)
|
| 9 |
+
# Selecciona el stream progresivo con extensi贸n mp4, ordenado de mayor a menor resoluci贸n
|
| 10 |
+
stream = yt.streams.filter(progressive=True, file_extension='mp4').order_by('resolution').desc().first()
|
| 11 |
+
if stream is None:
|
| 12 |
+
return "No se encontr贸 un stream adecuado para descargar."
|
| 13 |
+
|
| 14 |
+
# Define un directorio de descarga y aseg煤rate de que exista
|
| 15 |
+
download_folder = "downloads"
|
| 16 |
+
os.makedirs(download_folder, exist_ok=True)
|
| 17 |
+
|
| 18 |
+
# Descarga el video en el directorio especificado
|
| 19 |
+
output_path = stream.download(output_path=download_folder)
|
| 20 |
+
return f"Video descargado: {output_path}"
|
| 21 |
+
except Exception as e:
|
| 22 |
+
return f"Error al descargar el v铆deo: {str(e)}"
|
| 23 |
|
| 24 |
+
# Crea la interfaz Gradio
|
| 25 |
iface = gr.Interface(
|
| 26 |
+
fn=download_youtube_video,
|
| 27 |
+
inputs=gr.Textbox(label="URL del v铆deo de YouTube", placeholder="Ingresa la URL aqu铆..."),
|
| 28 |
+
outputs=gr.Textbox(label="Resultado"),
|
| 29 |
+
title="Descargador de V铆deos de YouTube",
|
| 30 |
+
description="Ingresa la URL de un v铆deo de YouTube y descarga la versi贸n en MP4 de mayor resoluci贸n disponible."
|
| 31 |
)
|
| 32 |
|
| 33 |
+
if __name__ == "__main__":
|
| 34 |
+
iface.launch()
|
| 35 |
+
|