🎬 Cómo Crear un Descargador de Videos de YouTube con Interfaz Gráfica en Python

¿Quieres tu propia app para descargar videos de YouTube de forma sencilla? Aquí te explico cómo hacerlo con Python, usando una interfaz gráfica moderna y arte ASCII decorativo. Usaremos pytubefix para evitar errores comunes como el 400 Bad Request.


✅ Paso 1: Instala las dependencias

Abre la terminal y escribe:


pip install pytubefix

🧱 Paso 2: Código completo del programa

Crea un archivo llamado descargador_youtube.py y copia el siguiente contenido:


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 del arte ASCII


 __     __     ______     __         ______     __   __    
/\ \  _ \ \   /\  __ \   /\ \       /\  ___\   /\ "-.\ \   
\ \ \/ ".\ \  \ \ \/\ \  \ \ \____  \ \  __\   \ \ \-.  \  
 \ \__/".~\_\  \ \_____\  \ \_____\  \ \_____\  \ \_\\"\_\ 
  \/_/   \/_/   \/_____/   \/_____/   \/_____/   \/_/ \/_/ 

💡 Siguientes pasos sugeridos

  • Agregar barra de progreso visual
  • Soporte para listas de reproducción
  • Conversión a MP3 automática

¿Te gustaría que publique otra guía con alguna de estas mejoras? ¡Déjame un comentario! 🚀