-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
108 lines (74 loc) · 2.59 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import os
from flask import (
Flask,
flash,
jsonify,
make_response,
redirect,
render_template,
request,
send_from_directory,
url_for,
)
from werkzeug.utils import secure_filename
from main import main
UPLOAD_FOLDER = "./uploads"
DOWNLOAD_FOLDER = "./downloads"
ALLOWED_EXTENSIONS = {"mp4", "mkv"}
app = Flask(__name__)
app.config["UPLOAD_FOLDER"] = UPLOAD_FOLDER
app.config["DOWNLOAD_FOLDER"] = DOWNLOAD_FOLDER
app.config["SESSION_TYPE"] = "filesystem"
app.config["SECRET_KEY"] = "super secret"
def allowed_file(filename):
return "." in filename and filename.rsplit(".", 1)[1].lower() in ALLOWED_EXTENSIONS
@app.route("/", methods=["GET", "POST"])
def Home():
if not os.path.isdir(UPLOAD_FOLDER):
os.mkdir(UPLOAD_FOLDER)
if not os.path.isdir(DOWNLOAD_FOLDER):
os.mkdir(DOWNLOAD_FOLDER)
if request.method == "POST":
file = request.files["file"]
print("File uploaded")
print(file)
if file and allowed_file(file.filename):
filename = secure_filename(file.filename)
file.save(os.path.join(app.config["UPLOAD_FOLDER"], filename))
res = make_response(jsonify({"message": "File uploaded"}), 200)
return res
else:
res = make_response(jsonify({"message": "Invalid Video"}), 400)
return res
return render_template("home.html")
@app.route("/game/<filename>/", methods=["GET", "POST"])
def Game(filename):
if request.method == "POST":
video_name = main(os.path.join(UPLOAD_FOLDER, filename), DOWNLOAD_FOLDER, use_gpu=False)
return redirect(url_for("Download", filename=video_name))
return render_template("game.html", filename=filename)
@app.route("/tour")
def Tour():
return render_template("tour.html")
@app.route("/upgrade")
def Upgrade():
return render_template("upgrade.html")
@app.route("/help")
def Help():
return render_template("help.html")
@app.route("/explore")
def Explore():
return render_template("explore.html")
@app.route("/profile")
def Profile():
return render_template("profile.html")
@app.route("/download/<filename>/")
def Download(filename):
return render_template("download.html", name=filename)
@app.route("/downloads/<path:filename>", methods=["GET", "POST"])
def download_video(filename):
downloads = os.path.join(app.root_path, app.config["DOWNLOAD_FOLDER"])
return send_from_directory(directory=downloads, filename=filename, as_attachment=True)
if __name__ == "__main__":
app.debug = True
app.run(host='0.0.0.0', port=int(os.environ.get('PORT', 5000)))