diff --git a/server.py b/server.py
index 7f78f610749a3f48e562648a92ae92470573a656..860e9699c7aa99e88f8ed93f99e006a0431c4954 100644
--- a/server.py
+++ b/server.py
@@ -404,7 +404,7 @@ def course(id=None, handle=None):
 			if perm['lecture_id'] == lecture['id']:
 				lecture['perm'].append(perm)
 	videos = query('''
-			SELECT videos.*, (videos.downloadable AND courses.downloadable) as downloadable, formats.description AS format_description, formats.player_prio, formats.prio
+			SELECT videos.*, (videos.downloadable AND courses.downloadable) as downloadable, "formats" AS sep, formats.*
 			FROM videos
 			JOIN lectures ON (videos.lecture_id = lectures.id)
 			JOIN formats ON (videos.video_format = formats.id)
@@ -412,7 +412,7 @@ def course(id=None, handle=None):
 			WHERE lectures.course_id= ? AND (? OR videos.visible)
 			ORDER BY lectures.time, formats.prio DESC
 			''', course['id'], ismod())
-	livestreams = query('''SELECT streams.handle AS livehandle, streams.lecture_id, formats.description AS format_description, formats.player_prio, formats.prio
+	livestreams = query('''SELECT streams.handle AS livehandle, streams.lecture_id, "formats" AS sep, formats.*
 			FROM streams
 			JOIN lectures ON lectures.id = streams.lecture_id
 			JOIN formats ON formats.keywords = "hls"
@@ -434,14 +434,14 @@ def faq():
 def lecture(id, course=None, courseid=None):
 	lecture = query('SELECT * FROM lectures WHERE id = ? AND (? OR visible)', id, ismod())[0]
 	videos = query('''
-			SELECT videos.*, (videos.downloadable AND courses.downloadable) as downloadable, formats.description AS format_description, formats.player_prio, formats.prio, formats.mimetype
+			SELECT videos.*, (videos.downloadable AND courses.downloadable) as downloadable, "formats" AS sep, formats.*
 			FROM videos
 			JOIN formats ON (videos.video_format = formats.id)
 			JOIN courses ON (courses.id = ?)
 			WHERE videos.lecture_id = ? AND (? OR videos.visible)
 			ORDER BY formats.prio DESC
 			''', lecture['course_id'], lecture['id'], ismod())
-	livestreams = query('''SELECT streams.handle AS livehandle, streams.lecture_id, formats.description AS format_description, formats.player_prio, formats.prio, formats.mimetype
+	livestreams = query('''SELECT streams.handle AS livehandle, streams.lecture_id, "formats" AS sep, formats.*
 			FROM streams
 			JOIN lectures ON lectures.id = streams.lecture_id
 			JOIN formats ON formats.keywords = "hls"
diff --git a/static/videojs/videojs-resolution-switcher.js b/static/videojs/videojs-resolution-switcher.js
index eae1c38b579bd397135fdd092f85147b0b26bfdb..fc3647685c5bdcfd5c7c4e093b74774bc3ed887a 100644
--- a/static/videojs/videojs-resolution-switcher.js
+++ b/static/videojs/videojs-resolution-switcher.js
@@ -1,367 +1,406 @@
-/*! videojs-resolution-switcher - 2015-7-26
+/*! videojs-resolution-switcher - 2017-05-20
  * Copyright (c) 2016 Kasper Moskwiak
- * Modified by Pierre Kraft and Derk-Jan Hartman
+ * Modified by Pierre Kraft, Derk-Jan Hartman and Andreas Valder
  * Licensed under the Apache-2.0 license. */
 
 (function() {
-  /* jshint eqnull: true*/
-  /* global require */
-  'use strict';
-  var videojs = null;
-  if(typeof window.videojs === 'undefined' && typeof require === 'function') {
-    videojs = require('video.js');
-  } else {
-    videojs = window.videojs;
-  }
-
-  (function(window, videojs) {
-    var videoJsResolutionSwitcher,
-      defaults = {
-        ui: true
-      };
-
-    /*
-     * Resolution menu item
-     */
-    var MenuItem = videojs.getComponent('MenuItem');
-    var ResolutionMenuItem = videojs.extend(MenuItem, {
-      constructor: function(player, options){
-        options.selectable = true;
-        // Sets this.player_, this.options_ and initializes the component
-        MenuItem.call(this, player, options);
-        this.src = options.src;
-
-        player.on('resolutionchange', videojs.bind(this, this.update));
-      }
-    } );
-    ResolutionMenuItem.prototype.handleClick = function(event){
-      MenuItem.prototype.handleClick.call(this,event);
-      this.player_.currentResolution(this.options_.label);
-    };
-    ResolutionMenuItem.prototype.update = function(){
-      var selection = this.player_.currentResolution();
-      this.selected(this.options_.label === selection.label);
-    };
-    MenuItem.registerComponent('ResolutionMenuItem', ResolutionMenuItem);
-
-    /*
-     * Resolution menu button
-     */
-    var MenuButton = videojs.getComponent('MenuButton');
-    var ResolutionMenuButton = videojs.extend(MenuButton, {
-      constructor: function(player, options){
-        this.label = document.createElement('span');
-        options.label = 'Quality';
-        // Sets this.player_, this.options_ and initializes the component
-        MenuButton.call(this, player, options);
-        this.el().setAttribute('aria-label','Quality');
-        this.controlText('Quality');
-
-        if(options.dynamicLabel){
-          videojs.addClass(this.label, 'vjs-resolution-button-label');
-          this.el().appendChild(this.label);
-        }else{
-          var staticLabel = document.createElement('span');
-          videojs.addClass(staticLabel, 'vjs-menu-icon');
-          this.el().appendChild(staticLabel);
-        }
-        player.on('updateSources', videojs.bind( this, this.update ) );
-      }
-    } );
-    ResolutionMenuButton.prototype.createItems = function(){
-      var menuItems = [];
-      var labels = (this.sources && this.sources.label) || {};
-
-      // FIXME order is not guaranteed here.
-      for (var key in labels) {
-        if (labels.hasOwnProperty(key)) {
-          menuItems.push(new ResolutionMenuItem(
-            this.player_,
-            {
-              label: key,
-              src: labels[key],
-              selected: key === (this.currentSelection ? this.currentSelection.label : false)
-            })
-          );
-        }
-      }
-      return menuItems;
-    };
-    ResolutionMenuButton.prototype.update = function(){
-      this.sources = this.player_.getGroupedSrc();
-      this.currentSelection = this.player_.currentResolution();
-      this.label.innerHTML = this.currentSelection ? this.currentSelection.label : '';
-      return MenuButton.prototype.update.call(this);
-    };
-    ResolutionMenuButton.prototype.buildCSSClass = function(){
-      return MenuButton.prototype.buildCSSClass.call( this ) + ' vjs-resolution-button';
-    };
-    MenuButton.registerComponent('ResolutionMenuButton', ResolutionMenuButton);
-
-    /**
-     * Initialize the plugin.
-     * @param {object} [options] configuration for the plugin
-     */
-    videoJsResolutionSwitcher = function(options) {
-      var settings = videojs.mergeOptions(defaults, options),
-          player = this,
-          groupedSrc = {},
-          currentSources = {},
-          currentResolutionState = {};
-
-      /**
-       * Updates player sources or returns current source URL
-       * @param   {Array}  [src] array of sources [{src: '', type: '', label: '', res: ''}]
-       * @returns {Object|String|Array} videojs player object if used as setter or current source URL, object, or array of sources
-       */
-      player.updateSrc = function(src){
-        //Return current src if src is not given
-        if(!src){ return player.src(); }
-
-        // Only add those sources which we can (maybe) play
-        src = src.filter( function(source) {
-          try {
-            return ( player.canPlayType( source.type ) !== '' );
-          } catch (e) {
-            // If a Tech doesn't yet have canPlayType just add it
-            return true;
-          }
-        });
-        //Sort sources
-        this.currentSources = src.sort(compareResolutions);
-        this.groupedSrc = bucketSources(this.currentSources);
-        // Pick one by default
-        var chosen = chooseSrc(this.groupedSrc, this.currentSources);
-        this.currentResolutionState = {
-          label: chosen.label,
-          sources: chosen.sources
-        };
-
-        player.trigger('updateSources');
-        player.setSourcesSanitized(chosen.sources, chosen.label);
-        player.trigger('resolutionchange');
-        return player;
-      };
-
-      /**
-       * Returns current resolution or sets one when label is specified
-       * @param {String}   [label]         label name
-       * @param {Function} [customSourcePicker] custom function to choose source. Takes 2 arguments: sources, label. Must return player object.
-       * @returns {Object}   current resolution object {label: '', sources: []} if used as getter or player object if used as setter
-       */
-      player.currentResolution = function(label, customSourcePicker){
-        if(label == null) { return this.currentResolutionState; }
-
-        // Lookup sources for label
-        if(!this.groupedSrc || !this.groupedSrc.label || !this.groupedSrc.label[label]){
-          return;
-        }
-        var sources = this.groupedSrc.label[label];
-        // Remember player state
-        var currentTime = player.currentTime();
-        var isPaused = player.paused();
-
-        // Hide bigPlayButton
-        if(!isPaused && this.player_.options_.bigPlayButton){
-          this.player_.bigPlayButton.hide();
-        }
-
-        // Change player source and wait for loadeddata event, then play video
-        // loadedmetadata doesn't work right now for flash.
-        // Probably because of https://github.com/videojs/video-js-swf/issues/124
-        // If player preload is 'none' and then loadeddata not fired. So, we need timeupdate event for seek handle (timeupdate doesn't work properly with flash)
-        var handleSeekEvent = 'loadeddata';
-        if(this.player_.techName_ !== 'Youtube' && this.player_.preload() === 'none' && this.player_.techName_ !== 'Flash') {
-          handleSeekEvent = 'timeupdate';
-        }
-        player
-          .setSourcesSanitized(sources, label, customSourcePicker || settings.customSourcePicker)
-          .one(handleSeekEvent, function() {
-            player.currentTime(currentTime);
-            player.handleTechSeeked_();
-            if(!isPaused){
-              // Start playing and hide loadingSpinner (flash issue ?)
-              player.play().handleTechSeeked_();
-            }
-            player.trigger('resolutionchange');
-          });
-        return player;
-      };
-
-      /**
-       * Returns grouped sources by label, resolution and type
-       * @returns {Object} grouped sources: { label: { key: [] }, res: { key: [] }, type: { key: [] } }
-       */
-      player.getGroupedSrc = function(){
-        return this.groupedSrc;
-      };
-
-      player.setSourcesSanitized = function(sources, label, customSourcePicker) {
-        this.currentResolutionState = {
-          label: label,
-          sources: sources
-        };
-        if(typeof customSourcePicker === 'function'){
-          return customSourcePicker(player, sources, label);
-        }
-        player.src(sources.map(function(src) {
-          return {src: src.src, type: src.type, res: src.res};
-        }));
-        return player;
-      };
-
-      /**
-       * Method used for sorting list of sources
-       * @param   {Object} a - source object with res property
-       * @param   {Object} b - source object with res property
-       * @returns {Number} result of comparation
-       */
-      function compareResolutions(a, b){
-        if(!a.res || !b.res){ return 0; }
-        return (+b.res)-(+a.res);
-      }
-
-      /**
-       * Group sources by label, resolution and type
-       * @param   {Array}  src Array of sources
-       * @returns {Object} grouped sources: { label: { key: [] }, res: { key: [] }, type: { key: [] } }
-       */
-      function bucketSources(src){
-        var resolutions = {
-          label: {},
-          res: {},
-          type: {}
-        };
-        src.map(function(source) {
-          initResolutionKey(resolutions, 'label', source);
-          initResolutionKey(resolutions, 'res', source);
-          initResolutionKey(resolutions, 'type', source);
-
-          appendSourceToKey(resolutions, 'label', source);
-          appendSourceToKey(resolutions, 'res', source);
-          appendSourceToKey(resolutions, 'type', source);
-        });
-        return resolutions;
-      }
-
-      function initResolutionKey(resolutions, key, source) {
-        if(resolutions[key][source[key]] == null) {
-          resolutions[key][source[key]] = [];
-        }
-      }
-
-      function appendSourceToKey(resolutions, key, source) {
-        resolutions[key][source[key]].push(source);
-      }
-
-      /**
-       * Choose src if option.default is specified
-       * @param   {Object} groupedSrc {res: { key: [] }}
-       * @param   {Array}  src Array of sources sorted by resolution used to find high and low res
-       * @returns {Object} {res: string, sources: []}
-       */
-      function chooseSrc(groupedSrc, src){
-        var selectedRes = settings['default']; // use array access as default is a reserved keyword
-        var selectedLabel = '';
-        if (selectedRes === 'high') {
-          selectedRes = src[0].res;
-          selectedLabel = src[0].label;
-        } else if (selectedRes === 'low' || selectedRes == null || !groupedSrc.res[selectedRes]) {
-          // Select low-res if default is low or not set
-          selectedRes = src[src.length - 1].res;
-          selectedLabel = src[src.length -1].label;
-        } else if (groupedSrc.res[selectedRes]) {
-          selectedLabel = groupedSrc.res[selectedRes][0].label;
-        }
-
-        return {res: selectedRes, label: selectedLabel, sources: groupedSrc.res[selectedRes]};
-      }
-
-      function initResolutionForYt(player){
-        // Map youtube qualities names
-        var _yts = {
-          highres: {res: 1080, label: '1080', yt: 'highres'},
-          hd1080: {res: 1080, label: '1080', yt: 'hd1080'},
-          hd720: {res: 720, label: '720', yt: 'hd720'},
-          large: {res: 480, label: '480', yt: 'large'},
-          medium: {res: 360, label: '360', yt: 'medium'},
-          small: {res: 240, label: '240', yt: 'small'},
-          tiny: {res: 144, label: '144', yt: 'tiny'},
-          auto: {res: 0, label: 'auto', yt: 'auto'}
-        };
-        // Overwrite default sourcePicker function
-        var _customSourcePicker = function(_player, _sources, _label){
-          // Note that setPlayebackQuality is a suggestion. YT does not always obey it.
-          player.tech_.ytPlayer.setPlaybackQuality(_sources[0]._yt);
-          player.trigger('updateSources');
-          return player;
-        };
-        settings.customSourcePicker = _customSourcePicker;
-
-        // Init resolution
-        player.tech_.ytPlayer.setPlaybackQuality('auto');
-
-        // This is triggered when the resolution actually changes
-        player.tech_.ytPlayer.addEventListener('onPlaybackQualityChange', function(event){
-          for(var res in _yts) {
-            if(res.yt === event.data) {
-              player.currentResolution(res.label, _customSourcePicker);
-              return;
-            }
-          }
-        });
-
-        // We must wait for play event
-        player.one('play', function(){
-          var qualities = player.tech_.ytPlayer.getAvailableQualityLevels();
-          var _sources = [];
-
-          qualities.map(function(q){
-            _sources.push({
-              src: player.src().src,
-              type: player.src().type,
-              label: _yts[q].label,
-              res: _yts[q].res,
-              _yt: _yts[q].yt
-            });
-          });
-
-          player.groupedSrc = bucketSources(_sources);
-          var chosen = {label: 'auto', res: 0, sources: player.groupedSrc.label.auto};
-
-          this.currentResolutionState = {
-            label: chosen.label,
-            sources: chosen.sources
-          };
-
-          player.trigger('updateSources');
-          player.setSourcesSanitized(chosen.sources, chosen.label, _customSourcePicker);
-        });
-      }
-
-      player.ready(function(){
-        if( settings.ui ) {
-          var menuButton = new ResolutionMenuButton(player, settings);
-          player.controlBar.resolutionSwitcher = player.controlBar.el_.insertBefore(menuButton.el_, player.controlBar.getChild('fullscreenToggle').el_);
-          player.controlBar.resolutionSwitcher.dispose = function(){
-            this.parentNode.removeChild(this);
-          };
-        }
-        if(player.options_.sources.length > 1){
-          // tech: Html5 and Flash
-          // Create resolution switcher for videos form <source> tag inside <video>
-          player.updateSrc(player.options_.sources);
-        }
-
-        if(player.techName_ === 'Youtube'){
-         // tech: YouTube
-         initResolutionForYt(player);
-        }
-      });
-
-    };
-
-    // register the plugin
-    videojs.plugin('videoJsResolutionSwitcher', videoJsResolutionSwitcher);
-  })(window, videojs);
+	/* jshint eqnull: true*/
+	/* global require */
+	'use strict';
+	var videojs = null;
+	if(typeof window.videojs === 'undefined' && typeof require === 'function') {
+		videojs = require('video.js');
+	} else {
+		videojs = window.videojs;
+	}
+
+	(function(window, videojs) {
+		var videoJsResolutionSwitcher,
+			defaults = {
+				ui: true
+			};
+
+		/*
+		 * Resolution menu item
+		 */
+		var MenuItem = videojs.getComponent('MenuItem');
+		var ResolutionMenuItem = videojs.extend(MenuItem, {
+			constructor: function(player, options){
+				options.selectable = true;
+				// Sets this.player_, this.options_ and initializes the component
+				MenuItem.call(this, player, options);
+				this.src = options.src;
+
+				player.on('resolutionchange', videojs.bind(this, this.update));
+			}
+		} );
+		ResolutionMenuItem.prototype.handleClick = function(event){
+			MenuItem.prototype.handleClick.call(this,event);
+			this.player_.currentResolution(this.options_.label);
+		};
+		ResolutionMenuItem.prototype.update = function(){
+			var selection = this.player_.currentResolution();
+			this.selected(this.options_.label === selection.label);
+		};
+		MenuItem.registerComponent('ResolutionMenuItem', ResolutionMenuItem);
+
+		/*
+		 * Resolution menu button
+		 */
+		var MenuButton = videojs.getComponent('MenuButton');
+		var ResolutionMenuButton = videojs.extend(MenuButton, {
+			constructor: function(player, options){
+				this.label = document.createElement('span');
+				options.label = 'Quality';
+				// Sets this.player_, this.options_ and initializes the component
+				MenuButton.call(this, player, options);
+				this.el().setAttribute('aria-label','Quality');
+				this.controlText('Quality');
+
+				if(options.dynamicLabel){
+					videojs.addClass(this.label, 'vjs-resolution-button-label');
+					this.el().appendChild(this.label);
+				}else{
+					var staticLabel = document.createElement('span');
+					videojs.addClass(staticLabel, 'vjs-menu-icon');
+					this.el().appendChild(staticLabel);
+				}
+				player.on('updateSources', videojs.bind( this, this.update ) );
+			}
+		} );
+		ResolutionMenuButton.prototype.createItems = function(){
+			var menuItems = [];
+
+			// one large hack to sort the labels
+			var labels = (this.sources && this.sources.label) || [];
+			var sortable = [];
+			for (var l in labels) {
+				sortable.push({'key': l, 'value': labels[l]});
+			}
+			sortable.sort(function(a,b) {
+				var calcPixel = function(item) {
+					var exp = item.res.replace('x','*');
+					if (exp != item.res) {
+						return eval(exp);
+					} else {
+						return 0;
+					}
+				};
+				if (a.value[0].res && b.value[0].res) {
+					return calcPixel(a.value[0])-calcPixel(b.value[0]);
+				}
+				return 0;
+			});
+			sortable.reverse();
+			var labels = {}
+			for (var i=0; i<sortable.length; i++) {
+				if (! labels[sortable[i].key]) {
+					labels[sortable[i].key] = [];
+				}
+				for (var l=0; l<sortable[i].value.length; l++) {
+					labels[sortable[i].key].push(sortable[i].value[l]);
+				}
+			}
+			labels = labels || {};
+			//hack ends here
+
+			for (var key in labels) {
+				if (labels.hasOwnProperty(key)) {
+					menuItems.push(new ResolutionMenuItem(
+						this.player_,
+						{
+							label: key,
+							src: labels[key],
+							selected: key === (this.currentSelection ? this.currentSelection.label : false)
+						})
+					);
+				}
+			}
+			return menuItems;
+		};
+		ResolutionMenuButton.prototype.update = function(){
+			this.sources = this.player_.getGroupedSrc();
+			this.currentSelection = this.player_.currentResolution();
+			this.label.innerHTML = this.currentSelection ? this.currentSelection.label : '';
+			return MenuButton.prototype.update.call(this);
+		};
+		ResolutionMenuButton.prototype.buildCSSClass = function(){
+			return MenuButton.prototype.buildCSSClass.call( this ) + ' vjs-resolution-button';
+		};
+		MenuButton.registerComponent('ResolutionMenuButton', ResolutionMenuButton);
+
+		/**
+		 * Initialize the plugin.
+		 * @param {object} [options] configuration for the plugin
+		 */
+		videoJsResolutionSwitcher = function(options) {
+			var settings = videojs.mergeOptions(defaults, options),
+				player = this,
+				groupedSrc = {},
+				currentSources = {},
+				currentResolutionState = {};
+
+			/**
+			 * Updates player sources or returns current source URL
+			 * @param   {Array}  [src] array of sources [{src: '', type: '', label: '', res: ''}]
+			 * @returns {Object|String|Array} videojs player object if used as setter or current source URL, object, or array of sources
+			 */
+			player.updateSrc = function(src){
+				//Return current src if src is not given
+				if(!src){ return player.src(); }
+				for (var i=0; i<src.length;i++) {
+					src[i].res = src[i]['data-res'];
+					src[i].label = src[i]['data-label'];
+					src[i].prio = -src[i]['data-player_prio'];
+				}
+
+				// Only add those sources which we can (maybe) play
+				src = src.filter( function(source) {
+					try {
+						return ( player.canPlayType( source.type ) !== '' );
+					} catch (e) {
+						// If a Tech doesn't yet have canPlayType just add it
+						return true;
+					}
+				});
+				//Sort sources
+				this.currentSources = src.sort(compareResolutions);
+				this.groupedSrc = bucketSources(this.currentSources);
+				// Pick one by default
+				var chosen = chooseSrc(this.groupedSrc, this.currentSources);
+				this.currentResolutionState = {
+					label: chosen.label,
+					sources: chosen.sources
+				};
+
+				player.trigger('updateSources');
+				player.setSourcesSanitized(chosen.sources, chosen.label);
+				player.trigger('resolutionchange');
+				return player;
+			};
+
+			/**
+			 * Returns current resolution or sets one when label is specified
+			 * @param {String}   [label]         label name
+			 * @param {Function} [customSourcePicker] custom function to choose source. Takes 2 arguments: sources, label. Must return player object.
+			 * @returns {Object}   current resolution object {label: '', sources: []} if used as getter or player object if used as setter
+			 */
+			player.currentResolution = function(label, customSourcePicker){
+				if(label == null) { return this.currentResolutionState; }
+
+				// Lookup sources for label
+				if(!this.groupedSrc || !this.groupedSrc.label || !this.groupedSrc.label[label]){
+					return;
+				}
+				var sources = this.groupedSrc.label[label];
+				// Remember player state
+				var currentTime = player.currentTime();
+				var isPaused = player.paused();
+
+				// Hide bigPlayButton
+				if(!isPaused && this.player_.options_.bigPlayButton){
+					this.player_.bigPlayButton.hide();
+				}
+
+				// Change player source and wait for loadeddata event, then play video
+				// loadedmetadata doesn't work right now for flash.
+				// Probably because of https://github.com/videojs/video-js-swf/issues/124
+				// If player preload is 'none' and then loadeddata not fired. So, we need timeupdate event for seek handle (timeupdate doesn't work properly with flash)
+				var handleSeekEvent = 'loadeddata';
+				if(this.player_.techName_ !== 'Youtube' && this.player_.preload() === 'none' && this.player_.techName_ !== 'Flash') {
+					handleSeekEvent = 'timeupdate';
+				}
+				player
+					.setSourcesSanitized(sources, label, customSourcePicker || settings.customSourcePicker)
+					.one(handleSeekEvent, function() {
+						player.currentTime(currentTime);
+						player.handleTechSeeked_();
+						if(!isPaused){
+							// Start playing and hide loadingSpinner (flash issue ?)
+							player.play().handleTechSeeked_();
+						}
+						player.trigger('resolutionchange');
+					});
+				return player;
+			};
+
+			/**
+			 * Returns grouped sources by label, resolution and type
+			 * @returns {Object} grouped sources: { label: { key: [] }, res: { key: [] }, type: { key: [] } }
+			 */
+			player.getGroupedSrc = function(){
+				return this.groupedSrc;
+			};
+
+			player.setSourcesSanitized = function(sources, label, customSourcePicker) {
+				this.currentResolutionState = {
+					label: label,
+					sources: sources
+				};
+				if(typeof customSourcePicker === 'function'){
+					return customSourcePicker(player, sources, label);
+				}
+				player.src(sources.map(function(src) {
+					return {src: src.src, type: src.type, res: src.res};
+				}));
+				return player;
+			};
+
+			/**
+			 * Method used for sorting list of sources
+			 * @param   {Object} a - source object with res property
+			 * @param   {Object} b - source object with res property
+			 * @returns {Number} result of comparation
+			 */
+			function compareResolutions(a, b){
+				if(a.prio && b.prio){
+					return (+b.prio)-(+a.prio)
+				}
+				if(!a.res || !b.res){ return 0; }
+				return (+b.res)-(+a.res);
+			}
+
+			/**
+			 * Group sources by label, resolution and type
+			 * @param   {Array}  src Array of sources
+			 * @returns {Object} grouped sources: { label: { key: [] }, res: { key: [] }, type: { key: [] } }
+			 */
+			function bucketSources(src){
+				var resolutions = {
+					label: {},
+					res: {},
+					type: {}
+				};
+				src.map(function(source) {
+					initResolutionKey(resolutions, 'label', source);
+					initResolutionKey(resolutions, 'res', source);
+					initResolutionKey(resolutions, 'type', source);
+
+					appendSourceToKey(resolutions, 'label', source);
+					appendSourceToKey(resolutions, 'res', source);
+					appendSourceToKey(resolutions, 'type', source);
+				});
+				return resolutions;
+			}
+
+			function initResolutionKey(resolutions, key, source) {
+				if(resolutions[key][source[key]] == null) {
+					resolutions[key][source[key]] = [];
+				}
+			}
+
+			function appendSourceToKey(resolutions, key, source) {
+				resolutions[key][source[key]].push(source);
+			}
+
+			/**
+			 * Choose src if option.default is specified
+			 * @param   {Object} groupedSrc {res: { key: [] }}
+			 * @param   {Array}  src Array of sources sorted by resolution used to find high and low res
+			 * @returns {Object} {res: string, sources: []}
+			 */
+			function chooseSrc(groupedSrc, src){
+				var selectedRes = settings['default']; // use array access as default is a reserved keyword
+				var selectedLabel = '';
+				if (selectedRes === 'high') {
+					selectedRes = src[0].res;
+					selectedLabel = src[0].label;
+				} else if (selectedRes === 'low' || selectedRes == null || !groupedSrc.res[selectedRes]) {
+					// Select low-res if default is low or not set
+					selectedRes = src[src.length - 1].res;
+					selectedLabel = src[src.length -1].label;
+				} else if (groupedSrc.res[selectedRes]) {
+					selectedLabel = groupedSrc.res[selectedRes][0].label;
+				}
+
+				return {res: selectedRes, label: selectedLabel, sources: groupedSrc.res[selectedRes]};
+			}
+
+			function initResolutionForYt(player){
+				// Map youtube qualities names
+				var _yts = {
+					highres: {res: 1080, label: '1080', yt: 'highres'},
+					hd1080: {res: 1080, label: '1080', yt: 'hd1080'},
+					hd720: {res: 720, label: '720', yt: 'hd720'},
+					large: {res: 480, label: '480', yt: 'large'},
+					medium: {res: 360, label: '360', yt: 'medium'},
+					small: {res: 240, label: '240', yt: 'small'},
+					tiny: {res: 144, label: '144', yt: 'tiny'},
+					auto: {res: 0, label: 'auto', yt: 'auto'}
+				};
+				// Overwrite default sourcePicker function
+				var _customSourcePicker = function(_player, _sources, _label){
+					// Note that setPlayebackQuality is a suggestion. YT does not always obey it.
+					player.tech_.ytPlayer.setPlaybackQuality(_sources[0]._yt);
+					player.trigger('updateSources');
+					return player;
+				};
+				settings.customSourcePicker = _customSourcePicker;
+
+				// Init resolution
+				player.tech_.ytPlayer.setPlaybackQuality('auto');
+
+				// This is triggered when the resolution actually changes
+				player.tech_.ytPlayer.addEventListener('onPlaybackQualityChange', function(event){
+					for(var res in _yts) {
+						if(res.yt === event.data) {
+							player.currentResolution(res.label, _customSourcePicker);
+							return;
+						}
+					}
+				});
+
+				// We must wait for play event
+				player.one('play', function(){
+					var qualities = player.tech_.ytPlayer.getAvailableQualityLevels();
+					var _sources = [];
+
+					qualities.map(function(q){
+						_sources.push({
+							src: player.src().src,
+							type: player.src().type,
+							label: _yts[q].label,
+							res: _yts[q].res,
+							_yt: _yts[q].yt
+						});
+					});
+
+					player.groupedSrc = bucketSources(_sources);
+					var chosen = {label: 'auto', res: 0, sources: player.groupedSrc.label.auto};
+
+					this.currentResolutionState = {
+						label: chosen.label,
+						sources: chosen.sources
+					};
+
+					player.trigger('updateSources');
+					player.setSourcesSanitized(chosen.sources, chosen.label, _customSourcePicker);
+				});
+			}
+
+			player.ready(function(){
+				if( settings.ui ) {
+					var menuButton = new ResolutionMenuButton(player, settings);
+					player.controlBar.resolutionSwitcher = player.controlBar.el_.insertBefore(menuButton.el_, player.controlBar.getChild('fullscreenToggle').el_);
+					player.controlBar.resolutionSwitcher.dispose = function(){
+						this.parentNode.removeChild(this);
+					};
+				}
+				if(player.options_.sources.length > 1){
+					// tech: Html5 and Flash
+					// Create resolution switcher for videos form <source> tag inside <video>
+					player.updateSrc(player.options_.sources);
+				}
+
+				if(player.techName_ === 'Youtube'){
+					// tech: YouTube
+					initResolutionForYt(player);
+				}
+			});
+
+		};
+
+		// register the plugin
+		videojs.plugin('videoJsResolutionSwitcher', videoJsResolutionSwitcher);
+	})(window, videojs);
 })();
diff --git a/templates/macros.html b/templates/macros.html
index f94bf92437e39c8c862dc114c80381df3af2538c..316c43a9cf7c240fc642ea020ea10c12877399b4 100644
--- a/templates/macros.html
+++ b/templates/macros.html
@@ -50,8 +50,9 @@
 
 {% macro player(lecture, videos, msgs) %}
 <video id="videoplayer" style="width: 100%" class="video-js vjs-default-skin vjs-big-play-centered" width="640" height="320" controls data-wasnotplayed="1"  data-setup='{ "language":"de", "plugins" : {"hotkeys": {"seekStep": 15, "enableVolumeScroll": false, "alwaysCaptureHotkeys": true}, "videoJsResolutionSwitcher": { "ui": true, "default": "720p", "dynamicLabel": false } }, "customControlsOnMobile": true, "playbackRates": [0.5, 0.75, 1, 1.25, 1.5, 1.75, 2, 2.25, 2.5, 2.75, 3, 3.25, 3.5, 3.75, 4] }'>
-	{% for v in videos|sort(attribute='player_prio', reverse=True) %}
-		<source type="{{ v.mimetype }}" src="{{ config.VIDEOPREFIX }}/{{ v.path }}" label="{{ v.format_description }}"/>
+	{% for v in videos|sort(attribute='formats.player_prio', reverse=True) %}
+	<source type="{{ v.formats.mimetype }}" src="{{ config.VIDEOPREFIX }}/{{ v.path }}" data-label="{{ v.formats.description }}" data-res="{{v.formats.resolution}}" data-aspect="{{v.formats.aspect}}" data-player_prio="{{v.formats.player_prio}}"/>
+	{{ v|safe }}
 	{% endfor %}
 	<track srclang="de" kind="chapters" src="{{ url_for('chapters',lectureid=lecture.id) }}" />
 </video>
@@ -162,8 +163,8 @@ $(function() {
 {% if not ismod() %}
 <span class="btn btn-default dropdown-toggle{% if not videos|selectattr('downloadable')|list and not ismod() %} disabled{% endif %}" type="button" data-toggle="dropdown">Download <span class="caret"></span></span>
 <ul class="dropdown-menu">
-	{% for v in videos|sort(attribute='prio', reverse=True) if (v.downloadable or ismod() ) %}
-	<li><a href="{{ config.VIDEOPREFIX }}/{{v.path}}">{{v.format_description}} ({{v.file_size|filesizeformat(true)}})</a></li>
+	{% for v in videos|sort(attribute='formats.prio', reverse=True) if (v.downloadable or ismod() ) %}
+	<li><a href="{{ config.VIDEOPREFIX }}/{{v.path}}">{{v.formats.description}} ({{v.file_size|filesizeformat(true)}})</a></li>
 	{% endfor %}
 </ul>
 {% endif %}
@@ -171,8 +172,8 @@ $(function() {
 	<noscript> 
 {% endif %}
 <ul class="pull-right list-unstyled" style="margin-left:10px;">
-{% for v in videos|sort(attribute='prio', reverse=True) if (v.downloadable or ismod() ) %}
-	<li>{{moderator_delete(['videos',v.id,'deleted'])}} {{ moderator_checkbox(['videos',v.id,'visible'], v.visible) }} <a href="{{ config.VIDEOPREFIX }}/{{v.path}}">{{v.format_description}} ({{v.file_size|filesizeformat(true)}})</a></li>
+{% for v in videos|sort(attribute='formats.prio', reverse=True) if (v.downloadable or ismod() ) %}
+	<li>{{moderator_delete(['videos',v.id,'deleted'])}} {{ moderator_checkbox(['videos',v.id,'visible'], v.visible) }} <a href="{{ config.VIDEOPREFIX }}/{{v.path}}">{{v.formats.description}} ({{v.file_size|filesizeformat(true)}})</a></li>
 {% endfor %}
 </ul>
 {% if not ismod() %}