From eaf01f4d8abe34351f6a3b7f4d0c8572fcc7769e Mon Sep 17 00:00:00 2001 From: calzoneman Date: Tue, 7 Jan 2014 00:46:30 -0600 Subject: [PATCH 1/7] Vimeo workaround --- lib/config.js | 1 + lib/get-info.js | 39 ++++++++++++++++++++++++++++-- lib/media.js | 16 +++++++++---- lib/playlist.js | 49 +++++++++++++++++++++++++------------- www/assets/js/callbacks.js | 7 +++++- www/assets/js/player.js | 3 ++- 6 files changed, 91 insertions(+), 24 deletions(-) diff --git a/lib/config.js b/lib/config.js index 13bdea26..4748b25c 100644 --- a/lib/config.js +++ b/lib/config.js @@ -45,6 +45,7 @@ var defaults = { "ytv3apikey" : "", "enable-ytv3" : false, "ytv2devkey" : "", + "vimeo-workaround" : false, "stat-interval" : 3600000, "stat-max-age" : 86400000, "alias-purge-interval" : 3600000, diff --git a/lib/get-info.js b/lib/get-info.js index 5603cc23..0952f310 100644 --- a/lib/get-info.js +++ b/lib/get-info.js @@ -357,7 +357,7 @@ var Getters = { callback("API failure", null); return; } else if(status !== 200) { - callback("YTv2 HTTP " + status, null); + callback("Vimeo HTTP " + status, null); return; } @@ -702,6 +702,40 @@ var Getters = { } }; +function VimeoIsADoucheCopter(id, cb) { + var options = { + host: "player.vimeo.com", + path: "/video/" + id + }; + + var parse = function (data) { + var i = data.indexOf("a={"); + var j = data.indexOf("};", i); + var json = data.substring(i+2, j+1); + try { + json = JSON.parse(json); + var codec = json.request.files.codecs[0]; + var files = json.request.files[codec]; + cb(files); + } catch (e) { + cb({}); + } + }; + + http.get(options, function (res) { + res.setEncoding("utf-8"); + var buffer = ""; + + res.on("data", function (data) { + buffer += data; + }); + + res.on("end", function () { + parse(buffer); + }); + }); +}; + module.exports = { Getters: Getters, getMedia: function (id, type, callback) { @@ -710,5 +744,6 @@ module.exports = { } else { callback("Unknown media type '" + type + "'", null); } - } + }, + VimeoIsADoucheCopter: VimeoIsADoucheCopter }; diff --git a/lib/media.js b/lib/media.js index 407e6735..d394e46e 100644 --- a/lib/media.js +++ b/lib/media.js @@ -1,11 +1,11 @@ /* The MIT License (MIT) Copyright (c) 2013 Calvin Montgomery - + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ @@ -40,7 +40,7 @@ Media.prototype.pack = function() { duration: this.duration, type: this.type, }; - + if (this.object) { x.object = this.object; } @@ -68,6 +68,9 @@ Media.prototype.fullupdate = function() { if (this.params) { x.params = this.params; } + if (this.direct) { + x.direct = this.direct; + } return x; } @@ -79,4 +82,9 @@ Media.prototype.timeupdate = function() { }; } +Media.prototype.reset = function () { + delete this.currentTime; + delete this.direct; +}; + exports.Media = Media; diff --git a/lib/playlist.js b/lib/playlist.js index 36ebe898..5f2119b1 100644 --- a/lib/playlist.js +++ b/lib/playlist.js @@ -13,6 +13,8 @@ ULList = require("./ullist").ULList; var AsyncQueue = require("./asyncqueue"); var Media = require("./media").Media; var AllPlaylists = {}; +var Server = require("./server"); +var VimeoIsADoucheCopter = require("./get-info").VimeoIsADoucheCopter; function PlaylistItem(media, uid) { this.media = media; @@ -212,6 +214,7 @@ Playlist.prototype.addMedia = function (data) { var m = new Media(data.id, data.title, data.seconds, data.type); m.object = data.object; m.params = data.params; + m.direct = data.direct; var item = this.makeItem(m); item.queueby = data.queueby; item.temp = data.temp; @@ -257,6 +260,7 @@ Playlist.prototype.next = function() { return; var it = this.current; + it.media.reset(); if (it.temp) { if (this.remove(it.uid)) { @@ -290,6 +294,7 @@ Playlist.prototype.jump = function(uid) { return false; var it = this.current; + it.media.reset(); this.current = jmp; @@ -338,29 +343,41 @@ Playlist.prototype.lead = function(lead) { } Playlist.prototype.startPlayback = function (time) { - if(!this.current || !this.current.media) + var self = this; + if (!self.current || !self.current.media) { return false; - if (!this.leading) { - this.current.media.paused = false; - this.current.media.currentTime = time || 0; - this.on("changeMedia")(this.current.media); + } + + if (self.current.media.type === "vi" && + !self.current.media.direct && + Server.getServer().cfg["vimeo-workaround"]) { + VimeoIsADoucheCopter(self.current.media.id, function (direct) { + self.current.media.direct = direct; + self.startPlayback(time); + }); + return; + } + + if (!self.leading) { + self.current.media.paused = false; + self.current.media.currentTime = time || 0; + self.on("changeMedia")(self.current.media); return; } time = time || -3; - this.current.media.paused = time < 0; - this.current.media.currentTime = time; + self.current.media.paused = time < 0; + self.current.media.currentTime = time; - var pl = this; - if(this._leadInterval) { - clearInterval(this._leadInterval); - this._leadInterval = false; + if(self._leadInterval) { + clearInterval(self._leadInterval); + self._leadInterval = false; } - this.on("changeMedia")(this.current.media); - if(!isLive(this.current.media.type)) { - this._lastUpdate = Date.now(); - this._leadInterval = setInterval(function() { - pl._leadLoop(); + self.on("changeMedia")(self.current.media); + if(!isLive(self.current.media.type)) { + self._lastUpdate = Date.now(); + self._leadInterval = setInterval(function() { + self._leadLoop(); }, 1000); } } diff --git a/www/assets/js/callbacks.js b/www/assets/js/callbacks.js index b8ed06f3..826797ad 100644 --- a/www/assets/js/callbacks.js +++ b/www/assets/js/callbacks.js @@ -1032,7 +1032,12 @@ Callbacks = { $("#ytapiplayer_wrapper").remove(); } - if(data.type != PLAYER.type) { + if (data.type === "vi" && data.direct) { + data.type = "jw"; + data.id = data.direct.sd.url; + } + + if (data.type != PLAYER.type) { loadMediaPlayer(data); } diff --git a/www/assets/js/player.js b/www/assets/js/player.js index bed857aa..0e8be01f 100644 --- a/www/assets/js/player.js +++ b/www/assets/js/player.js @@ -1086,7 +1086,8 @@ var constructors = { "jw": JWPlayer, "im": ImgurPlayer, "cu": CustomPlayer, - "gd": GoogleDocsPlayer + "gd": GoogleDocsPlayer, + "me": MediaElementsPlayer }; function loadMediaPlayer(data) { From d14ee4f0db7ffc10c2e20e9e93448d4054708280 Mon Sep 17 00:00:00 2001 From: calzoneman Date: Tue, 7 Jan 2014 11:32:48 -0600 Subject: [PATCH 2/7] Add mediaelement player --- lib/get-info.js | 11 +- www/assets/js/callbacks.js | 11 +- www/assets/js/player.js | 68 +- www/assets/mediaelement/background.png | Bin 0 -> 166 bytes www/assets/mediaelement/bigplay.png | Bin 0 -> 3001 bytes www/assets/mediaelement/bigplay.svg | 1 + www/assets/mediaelement/controls-ted.png | Bin 0 -> 1559 bytes www/assets/mediaelement/controls-wmp-bg.png | Bin 0 -> 1960 bytes www/assets/mediaelement/controls-wmp.png | Bin 0 -> 5511 bytes www/assets/mediaelement/controls.png | Bin 0 -> 1892 bytes www/assets/mediaelement/controls.svg | 1 + .../mediaelement/flashmediaelement-cdn.swf | Bin 0 -> 29149 bytes www/assets/mediaelement/flashmediaelement.swf | Bin 0 -> 29142 bytes www/assets/mediaelement/jquery.js | 9597 +++++++++++++++++ www/assets/mediaelement/loading.gif | Bin 0 -> 6224 bytes .../mediaelement/mediaelement-and-player.js | 5097 +++++++++ .../mediaelement-and-player.min.js | 174 + www/assets/mediaelement/mediaelement.js | 1932 ++++ www/assets/mediaelement/mediaelement.min.js | 69 + .../mediaelement/mediaelementplayer.css | 870 ++ www/assets/mediaelement/mediaelementplayer.js | 3163 ++++++ .../mediaelement/mediaelementplayer.min.css | 1 + .../mediaelement/mediaelementplayer.min.js | 103 + www/assets/mediaelement/mejs-skins.css | 289 + .../mediaelement/silverlightmediaelement.xap | Bin 0 -> 12461 bytes www/channel.html | 2 + 26 files changed, 21382 insertions(+), 7 deletions(-) create mode 100644 www/assets/mediaelement/background.png create mode 100644 www/assets/mediaelement/bigplay.png create mode 100644 www/assets/mediaelement/bigplay.svg create mode 100644 www/assets/mediaelement/controls-ted.png create mode 100644 www/assets/mediaelement/controls-wmp-bg.png create mode 100644 www/assets/mediaelement/controls-wmp.png create mode 100644 www/assets/mediaelement/controls.png create mode 100644 www/assets/mediaelement/controls.svg create mode 100755 www/assets/mediaelement/flashmediaelement-cdn.swf create mode 100644 www/assets/mediaelement/flashmediaelement.swf create mode 100644 www/assets/mediaelement/jquery.js create mode 100644 www/assets/mediaelement/loading.gif create mode 100644 www/assets/mediaelement/mediaelement-and-player.js create mode 100644 www/assets/mediaelement/mediaelement-and-player.min.js create mode 100644 www/assets/mediaelement/mediaelement.js create mode 100644 www/assets/mediaelement/mediaelement.min.js create mode 100644 www/assets/mediaelement/mediaelementplayer.css create mode 100644 www/assets/mediaelement/mediaelementplayer.js create mode 100644 www/assets/mediaelement/mediaelementplayer.min.css create mode 100644 www/assets/mediaelement/mediaelementplayer.min.js create mode 100644 www/assets/mediaelement/mejs-skins.css create mode 100644 www/assets/mediaelement/silverlightmediaelement.xap diff --git a/lib/get-info.js b/lib/get-info.js index 0952f310..8329b27a 100644 --- a/lib/get-info.js +++ b/lib/get-info.js @@ -716,9 +716,16 @@ function VimeoIsADoucheCopter(id, cb) { json = JSON.parse(json); var codec = json.request.files.codecs[0]; var files = json.request.files[codec]; - cb(files); + setImmediate(function () { + cb(files); + }); } catch (e) { - cb({}); + Logger.errlog.log("Vimeo workaround error: "); + Logger.errlog.log(e); + Logger.errlog.log(data); + setImmediate(function () { + cb({}); + }); } }; diff --git a/www/assets/js/callbacks.js b/www/assets/js/callbacks.js index 826797ad..cd36f2fa 100644 --- a/www/assets/js/callbacks.js +++ b/www/assets/js/callbacks.js @@ -1030,11 +1030,16 @@ Callbacks = { $("
").attr("id", "ytapiplayer") .insertBefore($("#ytapiplayer_wrapper")); $("#ytapiplayer_wrapper").remove(); + } else if(data.type != "me" && PLAYER.type == "me") { + var mejs = $(".mejs-container"); + $("
").attr("id", "ytapiplayer") + .insertBefore(mejs[0]); + mejs.remove(); } - if (data.type === "vi" && data.direct) { - data.type = "jw"; - data.id = data.direct.sd.url; + if (data.type === "vi" && data.direct && data.direct.sd) { + data.type = "me"; + data.url = data.direct.sd.url; } if (data.type != PLAYER.type) { diff --git a/www/assets/js/player.js b/www/assets/js/player.js index 0e8be01f..c59e2d73 100644 --- a/www/assets/js/player.js +++ b/www/assets/js/player.js @@ -1,4 +1,4 @@ -/* +/*} The MIT License (MIT) Copyright (c) 2013 Calvin Montgomery @@ -990,6 +990,70 @@ var GoogleDocsPlayer = function (data) { self.init(data); }; +function MediaElementsPlayer(data) { + var self = this; + self.init = function (data) { + waitUntilDefined(window, "MediaElementPlayer", function () { + self.videoId = data.id; + self.videoURL = data.url; + var video = $("