livestreams.py 1.64 KB
Newer Older
1
2
3
4
from server import *

@sched_func(30)
def livestream_thumbnail():
Andreas Valder's avatar
Andreas Valder committed
5
	livestreams = query('SELECT streams.lecture_id, streams.handle AS livehandle FROM streams WHERE streams.active')
Andreas Valder's avatar
Andreas Valder committed
6

7
	for v in genlive(livestreams):
Andreas Valder's avatar
Andreas Valder committed
8
		sorter.schedule_thumbnail(v['lecture_id'], v['path'])
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
@app.route('/internal/streaming/legacy_auth', methods=['GET', 'POST'])
def streamauth():
	internal = False
	for net in config.get('FSMPI_IP_RANGES', []):
		if ip_address(request.headers['X-Real-IP']) in ip_network(net):
			internal = True
	if request.values['app'] != 'live':
		return 'Bad request', 400
	if not internal:
		return 'Forbidden', 403
	if request.values['pass'] != 'caisoh8aht0wuSu':
		return 'Forbidden', 403
	if request.values['call'] == 'publish':
		matches = query("SELECT lectures.* FROM lectures JOIN courses ON lectures.course_id = courses.id WHERE courses.handle = ? ORDER BY lectures.time DESC", request.values['name'])
		now = datetime.now()
		match = {'id': -1}
		for lecture in matches:
			if lecture['time']-timedelta(minutes=30) <= now and \
				now <= lecture['time']+timedelta(minutes=lecture['duration']):
				match = lecture
				break
		if 'lecture' in request.values:
			match = {'id': request.values['lecture']}
		try:
			modify("INSERT INTO streams (handle, active, visible, lecture_id, description, poster) VALUES (?, 0, 1, -1, "", "")", request.values['name'])
		except:
			pass
		modify("UPDATE streams SET active = 1, lecture_id = ? WHERE handle = ?", match['id'], request.values['name'])
	elif request.values['call'] == 'publish_done':
		modify("UPDATE streams SET active = 0 WHERE handle = ?", request.values['name'])
	else:
		return 'Bad request', 400
	return 'OK', 200