From 00dd092fefd74612b0d7a281ba08de83cf2351bf Mon Sep 17 00:00:00 2001 From: calzoneman Date: Wed, 8 Jan 2014 16:26:52 -0600 Subject: [PATCH] A few minor fixes to the vimeo workaround --- lib/get-info.js | 114 ++++++++++++++++++++++++------------- www/assets/js/callbacks.js | 18 +++++- www/assets/js/data.js | 2 + 3 files changed, 94 insertions(+), 40 deletions(-) diff --git a/lib/get-info.js b/lib/get-info.js index 46560e47..40d85ba2 100644 --- a/lib/get-info.js +++ b/lib/get-info.js @@ -702,51 +702,87 @@ 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) { - var options = { - host: "player.vimeo.com", - path: "/video/" + id - }; + var failcount = 0; - 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]; - setImmediate(function () { - cb(files); - }); - } catch (e) { - if (data.indexOf("crawler") !== -1) { - setImmediate(function () { - VimeoIsADoucheCopter(id, cb); - }); - return; + var inner = function () { + var options = { + host: "player.vimeo.com", + 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" } - Logger.errlog.log("Vimeo workaround error: "); - Logger.errlog.log(e); - Logger.errlog.log(data); - setImmediate(function () { - cb({}); + }; + + 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]; + setImmediate(function () { + cb(files); + }); + } 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) { + 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 () { + cb({}); + }); + } else { + setImmediate(function () { + inner(); + }); + } + return; + } + Logger.errlog.log("Vimeo workaround error: "); + Logger.errlog.log(e); + Logger.errlog.log(data); + setImmediate(function () { + 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); + }); + }); }; - http.get(options, function (res) { - res.setEncoding("utf-8"); - var buffer = ""; - - res.on("data", function (data) { - buffer += data; - }); - - res.on("end", function () { - parse(buffer); - }); - }); + inner(); }; module.exports = { diff --git a/www/assets/js/callbacks.js b/www/assets/js/callbacks.js index 943cc388..34ce5146 100644 --- a/www/assets/js/callbacks.js +++ b/www/assets/js/callbacks.js @@ -1034,12 +1034,28 @@ Callbacks = { $("#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) { data.type = "jw"; } else { 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; } diff --git a/www/assets/js/data.js b/www/assets/js/data.js index 6b6ab972..dcaa3324 100644 --- a/www/assets/js/data.js +++ b/www/assets/js/data.js @@ -136,6 +136,8 @@ var USEROPTS = { var VOLUME = parseFloat(getOrDefault("volume", 1)); 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 = { Guest: 0,