diff --git a/player/update.coffee b/player/update.coffee
index 0a86c2ec..5504a14d 100644
--- a/player/update.coffee
+++ b/player/update.coffee
@@ -30,6 +30,14 @@ window.loadMediaPlayer = (data) ->
window.PLAYER = new VideoJSPlayer(data)
catch e
console.error e
+ else if data.type is 'gd'
+ try
+ if data.meta.html5hack
+ window.PLAYER = new VideoJSPlayer(data)
+ else
+ window.PLAYER = new GoogleDriveYouTubePlayer(data)
+ catch e
+ console.error e
else if data.type of TYPE_MAP
try
window.PLAYER = TYPE_MAP[data.type](data)
diff --git a/player/videojs.coffee b/player/videojs.coffee
index e73473e6..ff53e35b 100644
--- a/player/videojs.coffee
+++ b/player/videojs.coffee
@@ -53,14 +53,15 @@ window.VideoJSPlayer = class VideoJSPlayer extends Player
.attr(width: '100%', height: '100%')
removeOld(video)
- sources = sortSources(data.meta.direct)
- if sources.length == 0
+ @sources = sortSources(data.meta.direct)
+ if @sources.length == 0
console.error('VideoJSPlayer::constructor(): data.meta.direct
has no sources!')
@mediaType = null
return
- sources.forEach((source) ->
+ @sourceIdx = 0
+ @sources.forEach((source) ->
$('').attr(
src: source.src
type: source.type
@@ -84,6 +85,16 @@ window.VideoJSPlayer = class VideoJSPlayer extends Player
@player = videojs(video[0], autoplay: true, controls: true)
@player.ready(=>
+ @player.on('error', =>
+ err = @player.error()
+ if err and err.code == 4
+ console.error('Caught error, trying next source')
+ @sourceIdx++
+ if @sourceIdx < @sources.length
+ @player.src(@sources[@sourceIdx])
+ else
+ console.error('Out of sources, video will not play')
+ )
@setVolume(VOLUME)
@player.on('ended', ->
if CLIENT.leader
@@ -114,12 +125,13 @@ window.VideoJSPlayer = class VideoJSPlayer extends Player
# not to run until the ready() function returns.
setTimeout(->
$('#ytapiplayer .vjs-subtitles-button .vjs-menu-item').each((i, elem) ->
- if elem.textContent == localStorage.lastSubtitle
+ textNode = elem.childNodes[0]
+ if textNode.textContent == localStorage.lastSubtitle
elem.click()
elem.onclick = ->
- if elem.attributes['aria-selected'].value == 'true'
- localStorage.lastSubtitle = elem.textContent
+ if elem.attributes['aria-checked'].value == 'true'
+ localStorage.lastSubtitle = textNode.textContent
)
, 1)
)
diff --git a/src/config.js b/src/config.js
index e3d0ca82..e328a34a 100644
--- a/src/config.js
+++ b/src/config.js
@@ -120,6 +120,9 @@ var defaults = {
"service-socket": {
enabled: false,
socket: "service.sock"
+ },
+ "google-drive": {
+ "html5-hack-enabled": false
}
};
diff --git a/src/get-info.js b/src/get-info.js
index 24ff6825..08621176 100644
--- a/src/get-info.js
+++ b/src/get-info.js
@@ -12,6 +12,7 @@ var YouTube = require("cytube-mediaquery/lib/provider/youtube");
var Vimeo = require("cytube-mediaquery/lib/provider/vimeo");
var Vidme = require("cytube-mediaquery/lib/provider/vidme");
var Streamable = require("cytube-mediaquery/lib/provider/streamable");
+var GoogleDrive = require("cytube-mediaquery/lib/provider/googledrive");
/*
* Preference map of quality => youtube formats.
@@ -500,6 +501,7 @@ var Getters = {
/* google docs */
gd: function (id, callback) {
+ GoogleDrive.setHTML5HackEnabled(Config.get("google-drive.html5-hack-enabled"));
var data = {
type: "googledrive",
kind: "single",
diff --git a/src/media.js b/src/media.js
index a07416e2..eeeed5c0 100644
--- a/src/media.js
+++ b/src/media.js
@@ -38,7 +38,8 @@ Media.prototype = {
bitrate: this.meta.bitrate,
scuri: this.meta.scuri,
embed: this.meta.embed,
- gdrive_subtitles: this.meta.gdrive_subtitles
+ gdrive_subtitles: this.meta.gdrive_subtitles,
+ html5hack: this.meta.html5hack
}
};
},
diff --git a/www/js/player.js b/www/js/player.js
index 8bfe357d..ef333654 100644
--- a/www/js/player.js
+++ b/www/js/player.js
@@ -510,19 +510,20 @@
VideoJSPlayer.prototype.loadPlayer = function(data) {
return waitUntilDefined(window, 'videojs', (function(_this) {
return function() {
- var sources, video;
+ var video;
video = $('').addClass('video-js vjs-default-skin embed-responsive-item').attr({
width: '100%',
height: '100%'
});
removeOld(video);
- sources = sortSources(data.meta.direct);
- if (sources.length === 0) {
+ _this.sources = sortSources(data.meta.direct);
+ if (_this.sources.length === 0) {
console.error('VideoJSPlayer::constructor(): data.meta.direct has no sources!');
_this.mediaType = null;
return;
}
- sources.forEach(function(source) {
+ _this.sourceIdx = 0;
+ _this.sources.forEach(function(source) {
return $('').attr({
src: source.src,
type: source.type,
@@ -549,6 +550,19 @@
controls: true
});
return _this.player.ready(function() {
+ _this.player.on('error', function() {
+ var err;
+ err = _this.player.error();
+ if (err && err.code === 4) {
+ console.error('Caught error, trying next source');
+ _this.sourceIdx++;
+ if (_this.sourceIdx < _this.sources.length) {
+ return _this.player.src(_this.sources[_this.sourceIdx]);
+ } else {
+ return console.error('Out of sources, video will not play');
+ }
+ }
+ });
_this.setVolume(VOLUME);
_this.player.on('ended', function() {
if (CLIENT.leader) {
@@ -572,12 +586,14 @@
});
return setTimeout(function() {
return $('#ytapiplayer .vjs-subtitles-button .vjs-menu-item').each(function(i, elem) {
- if (elem.textContent === localStorage.lastSubtitle) {
+ var textNode;
+ textNode = elem.childNodes[0];
+ if (textNode.textContent === localStorage.lastSubtitle) {
elem.click();
}
return elem.onclick = function() {
- if (elem.attributes['aria-selected'].value === 'true') {
- return localStorage.lastSubtitle = elem.textContent;
+ if (elem.attributes['aria-checked'].value === 'true') {
+ return localStorage.lastSubtitle = textNode.textContent;
}
};
});
@@ -1310,7 +1326,7 @@
};
window.loadMediaPlayer = function(data) {
- var e, error, error1, error2, error3;
+ var e, error, error1, error2, error3, error4;
try {
if (window.PLAYER) {
window.PLAYER.destroy();
@@ -1326,11 +1342,22 @@
e = error2;
return console.error(e);
}
+ } else if (data.type === 'gd') {
+ try {
+ if (data.meta.html5hack) {
+ return window.PLAYER = new VideoJSPlayer(data);
+ } else {
+ return window.PLAYER = new GoogleDriveYouTubePlayer(data);
+ }
+ } catch (error3) {
+ e = error3;
+ return console.error(e);
+ }
} else if (data.type in TYPE_MAP) {
try {
return window.PLAYER = TYPE_MAP[data.type](data);
- } catch (error3) {
- e = error3;
+ } catch (error4) {
+ e = error4;
return console.error(e);
}
}