Merge pull request #616 from calzoneman/gd-html5-hack

Gd html5 hack
This commit is contained in:
Calvin Montgomery 2016-08-11 21:32:44 -07:00 committed by GitHub
commit d51722c466
6 changed files with 70 additions and 17 deletions

View File

@ -30,6 +30,14 @@ window.loadMediaPlayer = (data) ->
window.PLAYER = new VideoJSPlayer(data) window.PLAYER = new VideoJSPlayer(data)
catch e catch e
console.error 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 else if data.type of TYPE_MAP
try try
window.PLAYER = TYPE_MAP[data.type](data) window.PLAYER = TYPE_MAP[data.type](data)

View File

@ -53,14 +53,15 @@ window.VideoJSPlayer = class VideoJSPlayer extends Player
.attr(width: '100%', height: '100%') .attr(width: '100%', height: '100%')
removeOld(video) removeOld(video)
sources = sortSources(data.meta.direct) @sources = sortSources(data.meta.direct)
if sources.length == 0 if @sources.length == 0
console.error('VideoJSPlayer::constructor(): data.meta.direct console.error('VideoJSPlayer::constructor(): data.meta.direct
has no sources!') has no sources!')
@mediaType = null @mediaType = null
return return
sources.forEach((source) -> @sourceIdx = 0
@sources.forEach((source) ->
$('<source/>').attr( $('<source/>').attr(
src: source.src src: source.src
type: source.type type: source.type
@ -84,6 +85,16 @@ window.VideoJSPlayer = class VideoJSPlayer extends Player
@player = videojs(video[0], autoplay: true, controls: true) @player = videojs(video[0], autoplay: true, controls: true)
@player.ready(=> @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) @setVolume(VOLUME)
@player.on('ended', -> @player.on('ended', ->
if CLIENT.leader if CLIENT.leader
@ -114,12 +125,13 @@ window.VideoJSPlayer = class VideoJSPlayer extends Player
# not to run until the ready() function returns. # not to run until the ready() function returns.
setTimeout(-> setTimeout(->
$('#ytapiplayer .vjs-subtitles-button .vjs-menu-item').each((i, elem) -> $('#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.click()
elem.onclick = -> elem.onclick = ->
if elem.attributes['aria-selected'].value == 'true' if elem.attributes['aria-checked'].value == 'true'
localStorage.lastSubtitle = elem.textContent localStorage.lastSubtitle = textNode.textContent
) )
, 1) , 1)
) )

View File

@ -120,6 +120,9 @@ var defaults = {
"service-socket": { "service-socket": {
enabled: false, enabled: false,
socket: "service.sock" socket: "service.sock"
},
"google-drive": {
"html5-hack-enabled": false
} }
}; };

View File

@ -12,6 +12,7 @@ var YouTube = require("cytube-mediaquery/lib/provider/youtube");
var Vimeo = require("cytube-mediaquery/lib/provider/vimeo"); var Vimeo = require("cytube-mediaquery/lib/provider/vimeo");
var Vidme = require("cytube-mediaquery/lib/provider/vidme"); var Vidme = require("cytube-mediaquery/lib/provider/vidme");
var Streamable = require("cytube-mediaquery/lib/provider/streamable"); var Streamable = require("cytube-mediaquery/lib/provider/streamable");
var GoogleDrive = require("cytube-mediaquery/lib/provider/googledrive");
/* /*
* Preference map of quality => youtube formats. * Preference map of quality => youtube formats.
@ -500,6 +501,7 @@ var Getters = {
/* google docs */ /* google docs */
gd: function (id, callback) { gd: function (id, callback) {
GoogleDrive.setHTML5HackEnabled(Config.get("google-drive.html5-hack-enabled"));
var data = { var data = {
type: "googledrive", type: "googledrive",
kind: "single", kind: "single",

View File

@ -38,7 +38,8 @@ Media.prototype = {
bitrate: this.meta.bitrate, bitrate: this.meta.bitrate,
scuri: this.meta.scuri, scuri: this.meta.scuri,
embed: this.meta.embed, embed: this.meta.embed,
gdrive_subtitles: this.meta.gdrive_subtitles gdrive_subtitles: this.meta.gdrive_subtitles,
html5hack: this.meta.html5hack
} }
}; };
}, },

View File

@ -510,19 +510,20 @@
VideoJSPlayer.prototype.loadPlayer = function(data) { VideoJSPlayer.prototype.loadPlayer = function(data) {
return waitUntilDefined(window, 'videojs', (function(_this) { return waitUntilDefined(window, 'videojs', (function(_this) {
return function() { return function() {
var sources, video; var video;
video = $('<video/>').addClass('video-js vjs-default-skin embed-responsive-item').attr({ video = $('<video/>').addClass('video-js vjs-default-skin embed-responsive-item').attr({
width: '100%', width: '100%',
height: '100%' height: '100%'
}); });
removeOld(video); removeOld(video);
sources = sortSources(data.meta.direct); _this.sources = sortSources(data.meta.direct);
if (sources.length === 0) { if (_this.sources.length === 0) {
console.error('VideoJSPlayer::constructor(): data.meta.direct has no sources!'); console.error('VideoJSPlayer::constructor(): data.meta.direct has no sources!');
_this.mediaType = null; _this.mediaType = null;
return; return;
} }
sources.forEach(function(source) { _this.sourceIdx = 0;
_this.sources.forEach(function(source) {
return $('<source/>').attr({ return $('<source/>').attr({
src: source.src, src: source.src,
type: source.type, type: source.type,
@ -549,6 +550,19 @@
controls: true controls: true
}); });
return _this.player.ready(function() { 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.setVolume(VOLUME);
_this.player.on('ended', function() { _this.player.on('ended', function() {
if (CLIENT.leader) { if (CLIENT.leader) {
@ -572,12 +586,14 @@
}); });
return setTimeout(function() { return setTimeout(function() {
return $('#ytapiplayer .vjs-subtitles-button .vjs-menu-item').each(function(i, elem) { 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(); elem.click();
} }
return elem.onclick = function() { return elem.onclick = function() {
if (elem.attributes['aria-selected'].value === 'true') { if (elem.attributes['aria-checked'].value === 'true') {
return localStorage.lastSubtitle = elem.textContent; return localStorage.lastSubtitle = textNode.textContent;
} }
}; };
}); });
@ -1310,7 +1326,7 @@
}; };
window.loadMediaPlayer = function(data) { window.loadMediaPlayer = function(data) {
var e, error, error1, error2, error3; var e, error, error1, error2, error3, error4;
try { try {
if (window.PLAYER) { if (window.PLAYER) {
window.PLAYER.destroy(); window.PLAYER.destroy();
@ -1326,11 +1342,22 @@
e = error2; e = error2;
return console.error(e); 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) { } else if (data.type in TYPE_MAP) {
try { try {
return window.PLAYER = TYPE_MAP[data.type](data); return window.PLAYER = TYPE_MAP[data.type](data);
} catch (error3) { } catch (error4) {
e = error3; e = error4;
return console.error(e); return console.error(e);
} }
} }