-
Notifications
You must be signed in to change notification settings - Fork 3
/
app.py
48 lines (35 loc) · 1 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
38
39
40
41
42
43
44
45
46
47
48
from flask import Flask, render_template, request, redirect
import youtube_dl
app = Flask(__name__)
@app.route('/')
def home():
return render_template('index.html')
@app.route('/how-to')
def how_to():
return render_template('how-to.html')
@app.route('/about')
def about():
return render_template('about.html')
@app.route('/terms-conditions')
def terms():
return render_template('terms-conditions.html')
@app.route('/download', methods=["POST", "GET"])
def download():
try:
url = request.form["url"]
with youtube_dl.YoutubeDL() as ydl:
url = ydl.extract_info(url, download=False)
try:
download_link = url["entries"][-1]["formats"][-1]["url"]
except:
download_link = url["formats"][-1]["url"]
if ".mp4" in download_link:
return redirect(download_link)
else:
return redirect(download_link+"&dl=1")
except:
return render_template('error.html')
if __name__ == '__main__':
# Use this for local testing
# app.run(port=80, debug=False)
app.run(debug=False, host='0.0.0.0')