sortSources = (sources) -> if not sources console.error('sortSources() called with null source list') return [] qualities = ['2160', '1440', '1080', '720', '540', '480', '360', '240'] pref = String(USEROPTS.default_quality) if USEROPTS.default_quality == 'best' pref = '2160' idx = qualities.indexOf(pref) if idx < 0 idx = 5 # 480p qualityOrder = qualities.slice(idx).concat(qualities.slice(0, idx).reverse()) qualityOrder.unshift('auto') sourceOrder = [] flvOrder = [] for quality in qualityOrder if quality of sources flv = [] nonflv = [] sources[quality].forEach((source) -> source.quality = quality if source.contentType == 'video/flv' flv.push(source) else nonflv.push(source) ) sourceOrder = sourceOrder.concat(nonflv) flvOrder = flvOrder.concat(flv) return sourceOrder.concat(flvOrder).map((source) -> type: source.contentType src: source.link res: source.quality label: getSourceLabel(source) ) getSourceLabel = (source) -> if source.res is 'auto' return 'auto' else return "#{source.quality}p #{source.contentType.split('/')[1]}" hasAnyTextTracks = (data) -> ntracks = data?.meta?.textTracks?.length ? 0 return ntracks > 0 window.VideoJSPlayer = class VideoJSPlayer extends Player constructor: (data) -> if not (this instanceof VideoJSPlayer) return new VideoJSPlayer(data) @load(data) loadPlayer: (data) -> waitUntilDefined(window, 'videojs', => attrs = width: '100%' height: '100%' if @mediaType == 'cm' and hasAnyTextTracks(data) attrs.crossorigin = 'anonymous' video = $('