diff --git a/server.py b/server.py
index 70b7342c5ff34864fe7bb961fb3092a67f290847..27f095246f484359a8829d6d0e0c900fe0d63496 100755
--- a/server.py
+++ b/server.py
@@ -1,10 +1,30 @@
 #!/bin/python
-from flask import Flask, render_template
+from flask import Flask, render_template, g
+import mysql.connector
+import config
+
 app = Flask(__name__)
 
+def query(operation, *params):
+	if 'db' not in g or not g.db.is_connected():
+		g.db = mysql.connector.connect(user=config.db_user, password=config.db_passwd, host=config.db_host, database=config.db_db)
+	cur = g.db.cursor(dictionary=True)
+	cur.execute(operation, params)
+	return cur.fetchall()
+
 @app.route('/')
 def index():
-	return render_template('index.html', latestvideos=[{'talk':{'title':'talktitle','thumbnail':'https://videoag.fsmpi.rwth-aachen.de/pub/thumbnails/16ss-hyp-160802-Geophysical_models_IV.jpg','id':123,'comment':'comment','date':'date'},'event':{'title':'eventtitle'}},{'talk':{'title':'talktitle','thumbnail':'https://videoag.fsmpi.rwth-aachen.de/pub/thumbnails/16ss-hyp-160802-Geophysical_models_IV.jpg','id':123,'comment':'comment','date':'date'},'event':{'title':'eventtitle'}},{'talk':{'title':'talktitle','thumbnail':'https://videoag.fsmpi.rwth-aachen.de/pub/thumbnails/16ss-hyp-160802-Geophysical_models_IV.jpg','id':123,'comment':'comment','date':'date'},'event':{'title':'eventtitle'}},{'talk':{'title':'talktitle','thumbnail':'https://videoag.fsmpi.rwth-aachen.de/pub/thumbnails/16ss-hyp-160802-Geophysical_models_IV.jpg','id':123,'comment':'comment','date':'date'},'event':{'title':'eventtitle'}}])
+	return render_template('index.html', latestvideos=query('''
+				SELECT lectures.*, max(videos.time_updated) AS lastvidtime, courses.downloadable, courses.title AS coursetitle
+				FROM lectures
+				LEFT JOIN videos ON (videos.lecture_id = lectures.id)
+				LEFT JOIN courses on (courses.id = lectures.course_id)
+				WHERE (videos.time_updated >= SUBDATE(NOW(), 14))
+					AND (%s OR (courses.visible AND courses.listed AND lectures.visible AND videos.visible))
+				GROUP BY videos.lecture_id
+				ORDER BY lastvidtime DESC
+				LIMIT 5
+			''', False))
 
 @app.route('/videos')
 def videos():
diff --git a/templates/index.html b/templates/index.html
index 3b2ec056578c1777bec53ab2345973c6b72f0fdc..55573b45ce0b904b78ca7e7f5a789e28634f69c9 100644
--- a/templates/index.html
+++ b/templates/index.html
@@ -36,7 +36,7 @@
 				<div class="panel-body">
 					<ul class="list-group videopreview">
 						{% for i in latestvideos %}
-							{{ preview(i['talk'],i['event']) }}
+							{{ preview(i) }}
 						{% endfor %}
 					</ul>
 				</div>
diff --git a/templates/macros.html b/templates/macros.html
index c625fa03fb723f4f72de47d12f1885ee1bf94f2d..6312f7a3bf6c125937f09fd9b804a114da2082c8 100644
--- a/templates/macros.html
+++ b/templates/macros.html
@@ -1,16 +1,18 @@
-{% macro preview(talk,event) %}
+{% macro preview(lecture) %}
 <li class="list-group-item">
 	<div class="row">
-		<a href="?view=player&amp;lectureid={{ talk['id'] }}#content" title="{{ event['title'] }}">
-			<img class="col-xs-4" src="{{ talk['thumbnail'] }}" alt="Vorschaubild">
+		<a href="?view=player&amp;lectureid={{ lecture['id'] }}#content" title="{{ lecture['coursetitle'] }}">
+			<img class="col-xs-4" src="https://videoag.fsmpi.rwth-aachen.de/{{ lecture['titlefile'] }}" alt="Vorschaubild">
 			<div class="col-xs-4">
-				<span>{{ event['title'] }}</span>
-				<span>{{ talk['date'] }}</span>
-				<p>{{ talk['title'] }}</p>
+				<span>{{ lecture['coursetitle'] }}</span>
+				<span>{{ lecture['time'] }}</span>
+				<p>{{ lecture['title'] }}</p>
 			</div>
 			<div class="col-xs-4">
-				<div class="comment">{{ talk['comment']  }}</div>
-				<div class="comment">Gehalten von {{ talk['speaker']|default('unbekannt') }} </div>
+				<div class="comment">{{ lecture['comment']  }}</div>
+				{% if lecture['speaker'] %}
+					<div class="comment">Gehalten von {{ lecture['speaker'] }} </div>
+				{% endif %}
 			</div>
 		</a>
 	</div>