Created
October 17, 2021 20:46
-
-
Save miguelcamposfernandes/bd2d3f23d28e8c262e34c8ab9d41060e to your computer and use it in GitHub Desktop.
YTD - Download Function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import redirect, send_file | |
from io import BytesIO | |
@app.route("/download", methods = ["GET", "POST"]) | |
def download_video(): | |
if request.method == "POST": | |
buffer = BytesIO() # Declaring the buffer | |
url = YouTube(session['link']) # Getting the URL | |
itag = request.form.get("itag") # Get the video resolution | |
video = url.streams.get_by_itag(itag) # Store the video into a variable | |
video.stream_to_buffer(buffer) | |
buffer.seek(0) | |
return send_file(buffer, as_attachment=True, download_name="Video - YT2Video.mp4", mimetype="video/mp4") | |
return redirect(url_for("home")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment