Skip to content

Instantly share code, notes, and snippets.

View miguelcamposfernandes's full-sized avatar
👋
Hi!

miguelcamposfernandes

👋
Hi!
  • Lisbon, Portugal
View GitHub Profile
@miguelcamposfernandes
miguelcamposfernandes / YTD - Download Function
Created October 17, 2021 20:46
YTD - Download Function
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
@miguelcamposfernandes
miguelcamposfernandes / YTD - Download Form
Created October 17, 2021 20:43
YTD - Download Form
{% extends 'layout.html' %}
{% block content %}
<form method="POST" action="{{ url_for('download_video') }}"> # Linking to a Python function we'll create next
<h3>{{ url.title }}</h5> # The video title
<select name="itag" aria-label="Default select example">
{% for i in url.streams.filter(progressive=True) %}
<option value="{{ i.itag }}"> {{ i.resolution }} </option> # Iterating through the qualities of the video.
{% endfor %}
</select>
<button type="submit">Download</button>
<form method="POST">
<input type="text" placeholder="Enter the YouTube video URL" aria-label="default input example" name="url">
<button type="submit">Convert</button>
</form>
{% extends 'layout.html' %}
{% block content %}
<form method="POST">
<input type="text" placeholder="Enter the YouTube video URL" aria-label="default input example" name="url">
<button type="submit">Convert</button>
</form>
{% endblock content %}