A few minor fixes to the vimeo workaround

This commit is contained in:
calzoneman 2014-01-08 16:26:52 -06:00
parent 73235e5fbb
commit 00dd092fef
3 changed files with 94 additions and 40 deletions

View File

@ -702,10 +702,30 @@ var Getters = {
} }
}; };
/**
* A function name like this deserves an explanation.
*
* Vimeo blocked my domain from using their embed API, citing "volume of abuse" as the
* reason. After attempts to reach a compromise, Vimeo refused to unblock my domain.
*
* This function downloads the HTML for the embedded player and extracts direct links
* to the h264 encoded MP4 video files (with a session hash required for downloading it).
*
* This rivals the Google Drive playback functionality as quite possibly the hackiest code
* in CyTube. Thanks Vimeo, and may you never see a dime in advertising revenue from a
* CyTube client again.
*/
function VimeoIsADoucheCopter(id, cb) { function VimeoIsADoucheCopter(id, cb) {
var failcount = 0;
var inner = function () {
var options = { var options = {
host: "player.vimeo.com", host: "player.vimeo.com",
path: "/video/" + id path: "/video/" + id,
headers: {
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:29.0) Gecko/20100101 Firefox/29.0",
"Referrer": "player.vimeo.com"
}
}; };
var parse = function (data) { var parse = function (data) {
@ -720,10 +740,23 @@ function VimeoIsADoucheCopter(id, cb) {
cb(files); cb(files);
}); });
} catch (e) { } catch (e) {
// Not sure why the response sometimes differs. Trying to weed out
// search engines perhaps?
// Maybe adding the User-Agent above will fix this, I dunno
if (data.indexOf("crawler") !== -1) { if (data.indexOf("crawler") !== -1) {
Logger.syslog.log("Warning: VimeoIsADoucheCopter got crawler response");
failcount++;
if (failcount > 4) {
Logger.errlog.log("VimeoIsADoucheCopter got bad response 5 times!"+
" Giving up.");
setImmediate(function () { setImmediate(function () {
VimeoIsADoucheCopter(id, cb); cb({});
}); });
} else {
setImmediate(function () {
inner();
});
}
return; return;
} }
Logger.errlog.log("Vimeo workaround error: "); Logger.errlog.log("Vimeo workaround error: ");
@ -747,6 +780,9 @@ function VimeoIsADoucheCopter(id, cb) {
parse(buffer); parse(buffer);
}); });
}); });
};
inner();
}; };
module.exports = { module.exports = {

View File

@ -1034,12 +1034,28 @@ Callbacks = {
$("#ytapiplayer_wrapper").remove(); $("#ytapiplayer_wrapper").remove();
} }
if (data.type === "vi" && data.direct && data.direct.sd) { /*
VIMEO SIMULATOR 2014
Vimeo decided to block my domain. After repeated emails, they refused to
unblock it. Rather than give in to their demands, there is a serverside
option which extracts direct links to the h264 encoded MP4 video files.
These files can be loaded in a custom player to allow Vimeo playback without
triggering their dumb API domain block.
It's a little bit hacky, but my only other option is to keep buying new
domains every time one gets blocked. No thanks to Vimeo, who were of no help
and unwilling to compromise on the issue.
*/
if (NO_VIMEO && data.type === "vi" && data.direct && data.direct.sd) {
// For browsers that don't support native h264 playback
if (USEROPTS.no_h264) { if (USEROPTS.no_h264) {
data.type = "jw"; data.type = "jw";
} else { } else {
data.type = "rv"; data.type = "rv";
} }
// Right now only plays standard definition.
// In the future, I may add a quality selector for mobile/standard/HD
data.url = data.direct.sd.url; data.url = data.direct.sd.url;
} }

View File

@ -136,6 +136,8 @@ var USEROPTS = {
var VOLUME = parseFloat(getOrDefault("volume", 1)); var VOLUME = parseFloat(getOrDefault("volume", 1));
var NO_WEBSOCKETS = USEROPTS.altsocket; var NO_WEBSOCKETS = USEROPTS.altsocket;
// Change this to include your own domain if you enable Vimeo fallback
var NO_VIMEO = Boolean(location.host.match("cytu.be"));
var Rank = { var Rank = {
Guest: 0, Guest: 0,