Skip to content

Instantly share code, notes, and snippets.

@Anders87x
Created October 3, 2025 14:24
Show Gist options
  • Select an option

  • Save Anders87x/e8adbe17c32ee6fedb63806c11c8e95b to your computer and use it in GitHub Desktop.

Select an option

Save Anders87x/e8adbe17c32ee6fedb63806c11c8e95b to your computer and use it in GitHub Desktop.
App Pytube
from flask import Flask, render_template, request
import yt_dlp
app = Flask(__name__)
@app.route('/', methods=['GET', 'POST'])
def index():
if request.method == 'POST':
# Obtener la URL del formulario
url = request.form['url']
try:
# Opciones de descarga
ydl_opts = {
'outtmpl': '%(title)s.%(ext)s', # nombre archivo = título del video
'format': 'best' # mejor calidad disponible
}
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
info = ydl.extract_info(url, download=True)
filename = ydl.prepare_filename(info)
mensaje = f"¡Descarga completa! Video guardado como {filename}"
return render_template('youtube.html', mensaje=mensaje)
except Exception as e:
mensaje = f"Error: {e}"
return render_template('youtube.html', mensaje=mensaje)
return render_template('youtube.html')
if __name__ == '__main__':
app.run(debug=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment