-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisco_stub.py
76 lines (55 loc) · 1.88 KB
/
disco_stub.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
import time
import math
from flask import Flask, render_template, Response
app = Flask(__name__)
times = [3.000979, 3.000000, 3.000000, 3.000000, 3.000000, 3.000000, 3.000000, 2.741417]
seq_no = 0
ref_time = -1
@app.route('/')
def index():
return render_template('index.html')
@app.route('/api/reset')
def api_reset():
global seq_no, ref_time
seq_no = 0
ref_time = -1
return ''
@app.route('/api/get_tracks')
def api_endpoint():
global ref_time, seq_no
if ref_time == -1:
ref_time = time.time()
passed = time.time() - ref_time
if passed >= 4:
seq_no += 1
if seq_no >= len(times):
sample_file = '{'
sample_file += '"segments": []'
sample_file += '}'
else:
segment_offset = 0
for i in range(0, seq_no):
segment_offset += times[i]
m_segment_time = ref_time + segment_offset
print("seq " + str(seq_no) + " start " + "{0:.3f}".format(m_segment_time))
sample_file = "{"
sample_file += '"reference": ' + "{0:.3f}".format(m_segment_time) + ','
sample_file += '"segments": ['
max = seq_no + 3 if seq_no + 3 < len(times) else len(times)
for i in range(seq_no, max):
sample_file += '{"no": ' + str(i) + ','
sample_file += '"duration": ' + "{0:.3f}".format(times[i]) + ' ,'
sample_file += '"url": "/static/media/out00' + str(i) + '.wav"}'
if i < max - 1:
sample_file += ','
sample_file += ']}'
return Response(sample_file, mimetype='application/json')
# No cacheing at all for API endpoints.
@app.after_request
def add_header(response):
# response.cache_control.no_store = True
if 'Cache-Control' not in response.headers:
response.headers['Cache-Control'] = 'no-store'
return response
if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0')