-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
136 lines (118 loc) · 3.95 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import os
import codecs
import requests
import pytube
import random
import shutil
from flask import Flask , render_template , request , Response,send_file
from pytube import YouTube
from Video import Video
from VideoHandler import VideoHandler
from VideoCamera import VideoCamera
from flask_sockets import Sockets
app=Flask(__name__)
sockets = Sockets(app)
videoHandler = VideoHandler()
global webSocket
APP_ROOT = os.path.dirname(os.path.abspath(__file__))
@app.route('/')
def home():
id= random.randint(1,1000)
return render_template('home.html',user_id=id)
@sockets.route('/echo')
def echo_socket(ws):
webSocket = ws;
while True:
message = ws.receive()
print(message)
for i in range(4):
ws.send("Charith");
@app.route('/documentation')
def documentation():
return render_template('documentation.html')
@app.route('/contact')
def contact():
return render_template('contact.html')
@app.route('/about')
def about():
return render_template('about.html')
@app.route('/uploadVideo-storage')
def uploadVideo_storage():
return render_template('uploadVideo_storage.html')
@app.route('/uploadVideo-link')
def uploadVideo_link():
return render_template('uploadVideo_link.html')
@app.route('/upload' , methods = ["POST"])
def upload():
user_id= request.form['user_id']
target=os.path.join(APP_ROOT, 'videos/')
if not os.path.isdir(target):
os.mkdir(target)
for file in request.files.getlist("file"):
filename=file.filename
destination = "/".join([target,filename])
file.save(destination)
video = Video(filename,destination,user_id)
videoHandler.addVideo(video)
return render_template("generateText.html",variable=video.user)
@app.route('/uploadByLink' , methods = ["POST"])
def uploadByLink():
#user_id= request.form['user_id']
target=os.path.join(APP_ROOT, 'videos/')
if not os.path.isdir(target):
os.mkdir(target)
url = request.form['url']
yt = YouTube(url)
filename=yt.title
destination="/".join([target,filename])
stream=yt.streams.first()
stream.download(target)
video = Video(filename,destination)
videoHandler.addVideo(video)
return render_template("generateText.html",variable=video.path)
@app.route("/generateTextFile" , methods=["POST"])
def generateTextFile():
user_id = request.form['user_id']
print(user_id)
video=videoHandler.getVideoByUserId(user_id)
name=video.name;
print(name);
print(video);
videoHandler.splitVideo(video)
videoHandler.compareImages()
text = videoHandler.generateTextFile(video)
print(text)
return render_template('editText.html', variable=user_id, name=name, textData = text)
@app.route("/editTextFile" , methods=["POST"])
def editTextFile():
editedText=request.form['text']
userId = request.form['user']
shutil.rmtree("data/"+userId)
print (editedText)
videoHandler.object_array =[]
videoHandler.similarFrames =[]
videoHandler.images =[]
videoHandler.videos=[]
f= open(userId+".txt","w")
f.write(editedText)
f.close()
return send_file(userId+".txt",mimetype='text/plain',as_attachment=True)
def gen(camera):
while True:
frame = camera.get_frame()
yield (b'--frame\r\n'
b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n\r\n')
@app.route('/video_feed',methods=['GET'])
def video_feed():
video = videoHandler.getVideoByUserId(request.args.get("id"))
return send_file(video.path,as_attachment=True)
@app.route('/video_text',methods=['GET'])
def video_text():
textId = request.args.get("id")
return send_file("text/"+textId+".vtt", attachment_filename=textId+".vtt", mimetype='text/vtt', as_attachment=True)
if __name__ == '__main__':
# from gevent import pywsgi
# from geventwebsocket.handler import WebSocketHandler
# server = pywsgi.WSGIServer(('', 5000), app, handler_class=WebSocketHandler)
# server.serve_forever()
app.run(debug=True)