Vimeo workaround

This commit is contained in:
calzoneman 2014-01-07 00:46:30 -06:00
parent 6d6bf69828
commit eaf01f4d8a
6 changed files with 91 additions and 24 deletions

View File

@ -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,

View File

@ -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
};

View File

@ -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;

View File

@ -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);
}
}

View File

@ -1032,6 +1032,11 @@ Callbacks = {
$("#ytapiplayer_wrapper").remove();
}
if (data.type === "vi" && data.direct) {
data.type = "jw";
data.id = data.direct.sd.url;
}
if (data.type != PLAYER.type) {
loadMediaPlayer(data);
}

View File

@ -1086,7 +1086,8 @@ var constructors = {
"jw": JWPlayer,
"im": ImgurPlayer,
"cu": CustomPlayer,
"gd": GoogleDocsPlayer
"gd": GoogleDocsPlayer,
"me": MediaElementsPlayer
};
function loadMediaPlayer(data) {