From a357d26c03ad73d40587edc91c361775998efd1b Mon Sep 17 00:00:00 2001
From: Julian Rother <julianr@fsmpi.rwth-aachen.de>
Date: Mon, 23 Jul 2018 15:35:10 +0200
Subject: [PATCH] Added live_source thumbnails and changed thumbnail job
 parameters

---
 livestreams.py           | 9 ++++++++-
 sorter.py                | 2 +-
 templates/streaming.html | 2 +-
 3 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/livestreams.py b/livestreams.py
index 52b8f0c..e542e24 100644
--- a/livestreams.py
+++ b/livestreams.py
@@ -8,7 +8,7 @@ import string
 def livestream_thumbnail():
 	livestreams = query('SELECT streams.lecture_id, streams.handle AS livehandle FROM streams WHERE streams.active')
 	for v in genlive(livestreams):
-		schedule_job('thumbnail', {'lectureid': str(v['lecture_id']), 'path': v['path']})
+		schedule_job('thumbnail', {'src': v['path'], 'filename': 'l_%i.jpg'%lecture['id']})
 
 @app.route('/internal/streaming/legacy_auth', methods=['GET', 'POST'])
 @app.route('/internal/streaming/legacy_auth/<server>', methods=['GET', 'POST'])
@@ -113,6 +113,12 @@ def streamdrop(id):
 		return redirect(request.values['ref'])
 	return 'Ok', 200
 
+@sched_func(120)
+def live_source_thumbnail():
+	sources = query('SELECT * FROM live_sources WHERE clientid IS NOT NULL')
+	for source in sources:
+		schedule_job('thumbnail', {'src': 'rtmp://%s/src/%i'%(source['server'], source['id']), 'filename': 's_%i.jpg'%source['id']})
+
 @app.route('/internal/streaming/auth/<server>', methods=['GET', 'POST'])
 def streamauth(server):
 	internal = False
@@ -126,6 +132,7 @@ def streamauth(server):
 		if not sources:
 			return 'Not found', 404
 		modify('UPDATE live_sources SET server = ?, server_public = ?, clientid = ?, last_active = ?, preview_key = ? WHERE id = ?', server, request.args.get('public_ip', server), request.values['clientid'], datetime.now(), gentoken(), sources[0]['id'])
+		live_source_thumbnail()
 		ret = Response('Redirect', 301, {'Location': '%i'%sources[0]['id']})
 		ret.autocorrect_location_header = False
 		return ret
diff --git a/sorter.py b/sorter.py
index e100c24..c8c2f9e 100644
--- a/sorter.py
+++ b/sorter.py
@@ -44,7 +44,7 @@ def schedule_thumbnail(lectureid):
 		JOIN formats ON (videos.video_format = formats.id)
 		WHERE videos.lecture_id = ?
 		ORDER BY formats.prio DESC''', lectureid)
-	return schedule_job('thumbnail', {'lectureid': str(lectureid), 'path': videos[0]['path']})
+	return schedule_job('thumbnail', {'src': videos[0]['path'], 'filename': 'l_%i.jpg'%lectureid})
 
 @app.route('/internal/jobs/add/thumbnail', methods=['GET', 'POST'])
 @mod_required
diff --git a/templates/streaming.html b/templates/streaming.html
index 647f92f..3c65b62 100644
--- a/templates/streaming.html
+++ b/templates/streaming.html
@@ -19,7 +19,7 @@
 			{% for source in sources %}
 			<li class="list-group-item{% if source.clientid %} list-group-item-danger{% endif %}">
 				<div class="row">
-					<div style="background-image: url('{{ config.VIDEOPREFIX }}/hls/preview/{{ source.id }}.jpg')" class="col-sm-2 col-xs-12 thumbnailimg">
+					<div style="background-image: url('{{ config.VIDEOPREFIX }}/thumbnail/s_{{ source.id }}.jpg')" class="col-sm-2 col-xs-12 thumbnailimg">
 					{% if source.clientid %}
 						<a href="#" data-toggle="modal" data-target="#preview-player" data-srcname="{{ source.name }}" data-srcid="{{ source.id }}">
 							<span class="glyphicon glyphicon-play-circle playpreviewbtn"></span>
-- 
GitLab