YouTube Video Downloader
YouTube Video Downloader
from flask import Flask, request, send_file
from pytube import YouTube
app = Flask(__name__)
@app.route('/')
def index():
return open('index.html').read()
@app.route('/download', methods=['POST'])
def download_video():
video_url = request.form['url'] # Get the URL from the form
yt = YouTube(video_url)
video_stream = yt.streams.filter(file_extension='mp4', res="720p").first()
# Download the video and save it as a file
video_stream.download(output_path='./downloads', filename='video.mp4')
# Send the downloaded video file as a response
return send_file('./downloads/video.mp4', as_attachment=True)
if __name__ == "__main__":
app.run(debug=True)