🎬 Cómo Crear un Descargador de Videos de YouTube con Interfaz Gráfica en Python
🎬 Cómo Crear un Descargador de Videos de YouTube con Interfaz Gráfica en Python
¿Quieres un programa propio para descargar videos de YouTube con solo pegar el enlace y dar clic? En este tutorial aprenderás cómo hacerlo con Python, una interfaz gráfica moderna, y con un toque decorativo de arte ASCII. Usaremos pytubefix, una versión estable para evitar errores al descargar videos.
✅ Paso 1: Instalar dependencias
Abre la terminal o consola y ejecuta:
pip install pytubefix
🧱 Paso 2: Código completo del programa
Crea un archivo llamado descargador_youtube.py y pega el siguiente código:
import tkinter as tk
from tkinter import ttk, messagebox, filedialog
from pytubefix import YouTube
import threading
def descargar_video():
url = entrada_url.get()
carpeta = ruta_descarga.get()
if not url:
messagebox.showwarning("Advertencia", "Por favor, ingresa una URL de YouTube.")
return
try:
boton_descargar.config(state=tk.DISABLED)
estado.set("Descargando video...")
yt = YouTube(url)
video = yt.streams.filter(progressive=True, file_extension='mp4').order_by('resolution').desc().first()
if not video:
raise Exception("No se encontró un stream compatible.")
video.download(output_path=carpeta)
estado.set("¡Descarga completada!")
messagebox.showinfo("Éxito", f"Video descargado: {yt.title}")
except Exception as e:
estado.set("Error en la descarga.")
messagebox.showerror("Error", str(e))
finally:
boton_descargar.config(state=tk.NORMAL)
def elegir_carpeta():
carpeta = filedialog.askdirectory()
if carpeta:
ruta_descarga.set(carpeta)
def iniciar_descarga():
hilo = threading.Thread(target=descargar_video)
hilo.start()
# Crear ventana
ventana = tk.Tk()
ventana.title("Descargador de YouTube")
ventana.geometry("600x460")
ventana.resizable(False, False)
ventana.configure(bg="#ffffff")
# Variables
ruta_descarga = tk.StringVar()
estado = tk.StringVar(value="Esperando URL...")
# Arte ASCII decorativo
ascii_art = r"""
__ __ ______ __ ______ __ __
/\ \ _ \ \ /\ __ \ /\ \ /\ ___\ /\ "-.\ \
\ \ \/ ".\ \ \ \ \/\ \ \ \ \____ \ \ __\ \ \ \-. \
\ \__/".~\_\ \ \_____\ \ \_____\ \ \_____\ \ \_\\"\_\
\/_/ \/_/ \/_____/ \/_____/ \/_____/ \/_/ \/_/
"""
etiqueta_ascii = tk.Label(
ventana,
text=ascii_art,
font=("Courier", 10),
bg="#ffffff",
fg="#cc0000",
justify="left"
)
etiqueta_ascii.pack(pady=(5, 0))
# Estilo
estilo = ttk.Style()
estilo.theme_use("clam")
estilo.configure("TButton", font=("Segoe UI", 10), padding=6)
estilo.configure("TLabel", font=("Segoe UI", 10), background="#ffffff")
estilo.configure("TEntry", font=("Segoe UI", 10))
# Widgets
ttk.Label(ventana, text="URL del video de YouTube:").pack(pady=10)
entrada_url = ttk.Entry(ventana, width=60)
entrada_url.pack(pady=5)
frame_carpeta = ttk.Frame(ventana)
frame_carpeta.pack(pady=10)
ttk.Entry(frame_carpeta, textvariable=ruta_descarga, width=45).pack(side=tk.LEFT, padx=(0, 10))
ttk.Button(frame_carpeta, text="Elegir carpeta", command=elegir_carpeta).pack(side=tk.LEFT)
boton_descargar = ttk.Button(ventana, text="Descargar Video", command=iniciar_descarga)
boton_descargar.pack(pady=15)
ttk.Label(ventana, textvariable=estado, foreground="blue").pack(pady=5)
ventana.mainloop()
🧪 Paso 3: Ejecuta tu aplicación
python descargador_youtube.py
🎨 Resultado final
El programa se verá con un arte decorativo como este:
__ __ ______ __ ______ __ __ /\ \ _ \ \ /\ __ \ /\ \ /\ ___\ /\ "-.\ \ \ \ \/ ".\ \ \ \ \/\ \ \ \ \____ \ \ __\ \ \ \-. \ \ \__/".~\_\ \ \_____\ \ \_____\ \ \_____\ \ \_\\"\_\ \/_/ \/_/ \/_____/ \/_____/ \/_____/ \/_/ \/_/
💡 Mejoras posibles
- Agregar barra de progreso
- Soporte para listas de reproducción
- Conversión directa a MP3
¿Te gustaría que escribiera otro tutorial con alguna de estas mejoras? ¡Déjamelo en los comentarios!


Comentarios
Publicar un comentario