Add volume normalization and vimeo workaround
This commit is contained in:
parent
1864cc0b35
commit
e6acf92bdb
8 changed files with 455 additions and 85 deletions
|
|
@ -704,6 +704,87 @@ var Getters = {
|
|||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Function to workaround Vimeo being a dick and blocking my domain from embeds.
|
||||
* Retrieves the player page and extracts the direct links to the MP4 encoded videos.
|
||||
*/
|
||||
function vimeoWorkaround(id, cb) {
|
||||
if (typeof cb !== "function") {
|
||||
return;
|
||||
}
|
||||
|
||||
var failcount = 0;
|
||||
|
||||
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"
|
||||
}
|
||||
};
|
||||
|
||||
var parse = function (data) {
|
||||
var i = data.indexOf("b={");
|
||||
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) {
|
||||
// This shouldn't happen due to the user-agent, but just in case
|
||||
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;
|
||||
} else if (data.indexOf("This video does not exist.") !== -1) {
|
||||
cb({});
|
||||
return;
|
||||
} else if (data.indexOf("Because of its privacy settings, this video cannot be played here.") !== -1) {
|
||||
cb({});
|
||||
}
|
||||
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);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
inner();
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
Getters: Getters,
|
||||
getMedia: function (id, type, callback) {
|
||||
|
|
@ -712,5 +793,7 @@ module.exports = {
|
|||
} else {
|
||||
callback("Unknown media type '" + type + "'", null);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
vimeoWorkaround: vimeoWorkaround
|
||||
};
|
||||
|
|
|
|||
16
lib/media.js
16
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;
|
||||
|
|
|
|||
|
|
@ -9,9 +9,12 @@ The above copyright notice and this permission notice shall be included in all c
|
|||
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.
|
||||
*/
|
||||
|
||||
ULList = require("./ullist").ULList;
|
||||
var ULList = require("./ullist").ULList;
|
||||
var AsyncQueue = require("./asyncqueue");
|
||||
var Media = require("./media").Media;
|
||||
var util = require("./utilities");
|
||||
var vimeoWorkaround = require("./get-info").vimeoWorkaround;
|
||||
var Config = require("./config");
|
||||
var AllPlaylists = {};
|
||||
|
||||
function PlaylistItem(media, uid) {
|
||||
|
|
@ -349,44 +352,47 @@ 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 &&
|
||||
Config.get("vimeo-workaround")) {
|
||||
vimeoWorkaround(self.current.media.id, function (direct) {
|
||||
if (self.current != null && self.current.media != null) {
|
||||
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(!util.isLive(self.current.media.type)) {
|
||||
self._lastUpdate = Date.now();
|
||||
self._leadInterval = setInterval(function() {
|
||||
self._leadLoop();
|
||||
}, 1000);
|
||||
}
|
||||
}
|
||||
|
||||
function isLive(type) {
|
||||
return type == "li" // Livestream.com
|
||||
|| type == "tw" // Twitch.tv
|
||||
|| type == "jt" // Justin.tv
|
||||
|| type == "rt" // RTMP
|
||||
|| type == "jw" // JWPlayer
|
||||
|| type == "us" // Ustream.tv
|
||||
|| type == "im" // Imgur album
|
||||
|| type == "cu";// Custom embed
|
||||
}
|
||||
|
||||
const UPDATE_INTERVAL = 5;
|
||||
|
||||
Playlist.prototype._leadLoop = function() {
|
||||
|
|
|
|||
|
|
@ -189,6 +189,7 @@ module.exports = {
|
|||
case "us":
|
||||
case "rt":
|
||||
case "cu":
|
||||
case "im":
|
||||
case "jw":
|
||||
return true;
|
||||
default:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue