-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
51 lines (41 loc) · 1.12 KB
/
server.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
from flask import Flask, request
from video_capture import VideoCapture
import threading
import os
app = Flask(__name__)
vc = VideoCapture()
def remove(f):
try:
os.remove(f)
except:
pass
@app.route('/', methods=['GET'])
def index():
return 'Use /start or /stop!'
@app.route('/configure', methods=['GET'])
def configure():
if request.args.get('url'):
vc.url = request.args.get('url')
if request.args.get('video_source'):
try:
vc.configure(int(request.args.get('video_source')))
except:
vc.configure(request.args.get('video_source'))
return 'configured'
@app.route('/start', methods=['GET'])
def start():
vc.run = True
threading.Thread(target=vc.start).start()
print('started')
return 'started'
@app.route('/stop', methods=['GET'])
def stop():
vc.run = False
print('cleaning up...')
while len(vc.files) > 0:
f = vc.files.pop()
threading.Thread(target=remove, args=(f,)).start()
print('stopped')
return 'stopped'
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5001, debug=True)