-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
110 lines (94 loc) · 3.14 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
109
110
import os
import sys
import site
if getattr(sys, "frozen", False) and hasattr(sys, "_MEIPASS"):
sys.stdout = sys.stderr = open(os.devnull, 'w')
ffmpeg_dir = os.path.join(sys._MEIPASS, "bin")
os.environ["PATH"] = os.pathsep.join([os.environ["PATH"], ffmpeg_dir])
site.addsitedir(ffmpeg_dir)
from flask import (
Flask,
render_template,
send_file,
after_this_request,
request,
redirect,
)
from flask_socketio import SocketIO
from video_processing.final_video import generate_video, get_exported_video_path
from window import MainWindow
from PySide6.QtWidgets import QApplication
from PySide6.QtCore import QThread
from engineio.async_drivers import threading
import multiprocessing
app = Flask(__name__)
app.config["SECRET_KEY"] = "secret!"
socketio = SocketIO(app)
links = []
is_loggedin = False
# Fix for macOS crash
os.environ["no_proxy"] = "*"
@app.route("/", methods=["GET", "POST"])
def login():
global is_loggedin
if is_loggedin:
return redirect("/dashboard")
if request.method == "POST":
is_loggedin = True
return redirect("/dashboard")
"""
email = request.form["email"]
password = request.form["password"]
try:
auth = firebase.auth()
user = auth.sign_in_with_email_and_password(email, password)
if auth.get_account_info(user["idToken"]) is not None:
# If authentication succeeds, redirect the user to their account page
is_loggedin = True
return redirect("/dashboard")
else:
# If authentication fails, render the login page with a message
return render_template("login.html", message="Login failed")
except:
# If the password is invalid, render the login page with a message
return render_template("login.html", message="Invalid email or password")
"""
return render_template("login.html")
@app.route("/dashboard")
def index():
if is_loggedin:
return render_template("dashboard.html")
return redirect("/")
@socketio.on("submit")
def handle_submit(data):
if is_loggedin:
global links
links = data["inputs"]
generate_video(links, mode=data["mode"])
@app.route("/video")
def get_video():
if is_loggedin:
exported_video_path = get_exported_video_path(links[0])
if len(links) and os.path.isfile(exported_video_path):
@after_this_request
def delete_video(response):
try:
os.remove(exported_video_path)
except Exception as ex:
pass
return response
return send_file(exported_video_path, as_attachment=True)
return "No video to download"
return redirect("/")
if __name__ == "__main__":
multiprocessing.freeze_support()
flask_thread = QThread()
flask_thread.run = lambda: socketio.run(
app, debug=False, use_reloader=False, port=5001, allow_unsafe_werkzeug=True
)
flask_thread.start()
app_qt = QApplication([])
w = MainWindow()
w.show()
app_qt.exec()
flask_thread.terminate()