-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.py
37 lines (30 loc) · 1.06 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from flask import Flask,request,render_template,send_file
from pytube import YouTube
from io import BytesIO
app = Flask(__name__)
@app.route("/")
def home():
return render_template('index2.html')
@app.route('/home')
def goback():
return render_template('index2.html')
@app.route("/download",methods=['GET','POST'])
def download():
if(request.method=='POST'):
link = request.form['url']
try:
if link == '':
return render_template('error.html')
else:
buffer = BytesIO()
#link = request.form.get('url')
yt = YouTube(link)
ys = yt.streams.get_highest_resolution()
ys.stream_to_buffer(buffer)
buffer.seek(0)
return send_file(buffer, as_attachment=True, download_name="video.mp4", mimetype="video/mp4")
except:
return render_template('error.html')
return render_template('index2.html')
if __name__ == "__main__":
app.run(debug=True)