Add support for Google Docs videos
This commit is contained in:
parent
2730c54344
commit
4198f3ce2c
6 changed files with 158 additions and 3 deletions
|
|
@ -550,6 +550,8 @@ Channel.prototype.getIPRank = function (ip, callback) {
|
|||
|
||||
Channel.prototype.cacheMedia = function(media) {
|
||||
var self = this;
|
||||
if (media.type === "gd")
|
||||
return false;
|
||||
// Prevent the copy in the playlist from messing with this one
|
||||
media = media.dup();
|
||||
if(media.temp) {
|
||||
|
|
|
|||
|
|
@ -615,6 +615,79 @@ var Getters = {
|
|||
id = CustomEmbedFilter(id);
|
||||
var media = new Media(id, "Custom Media", "--:--", "cu");
|
||||
callback(false, media);
|
||||
},
|
||||
|
||||
/* google docs */
|
||||
gd: function (id, callback) {
|
||||
var options = {
|
||||
host: "docs.google.com",
|
||||
path: "/file/d/" + id + "/edit",
|
||||
port: 443
|
||||
};
|
||||
|
||||
urlRetrieve(https, options, function (status, res) {
|
||||
if (status !== 200) {
|
||||
callback("Google Docs rejected: HTTP " + status, false);
|
||||
return;
|
||||
}
|
||||
|
||||
var m = res.match(/main\((.*?)\);<\/script>/);
|
||||
if (m) {
|
||||
try {
|
||||
var data = m[1];
|
||||
data = data.substring(data.indexOf(",") + 1);
|
||||
data = data.replace(/'(.*?)'([:\,\}\]])/g, "\"$1\"$2");
|
||||
data = "[" + data + "]";
|
||||
var js = JSON.parse(data);
|
||||
var title = js[0].title;
|
||||
var seconds = js[1].videodetails.duration / 1000;
|
||||
var med = new Media(id, title, seconds, "gd");
|
||||
|
||||
var fv = js[1].videoplay.flashVars;
|
||||
var fvstr = "";
|
||||
for (var k in fv) {
|
||||
if (k === "autoplay")
|
||||
fv[k] = "1";
|
||||
fvstr += "&" + k + "=" + encodeURIComponent(fv[k]);
|
||||
}
|
||||
fvstr = fvstr.substring(1);
|
||||
|
||||
var url = js[1].videoplay.swfUrl + "&enablejsapi=1";
|
||||
med.object = {
|
||||
type: "application/x-shockwave-flash",
|
||||
allowscriptaccess: "always",
|
||||
allowfullscreen: "true",
|
||||
wmode: "opaque",
|
||||
data: url
|
||||
};
|
||||
|
||||
med.params = [
|
||||
{
|
||||
name: "allowFullScreen",
|
||||
value: "true"
|
||||
},
|
||||
{
|
||||
name: "allowScriptAccess",
|
||||
value: "always"
|
||||
},
|
||||
{
|
||||
name: "wmode",
|
||||
value: "opaque"
|
||||
},
|
||||
{
|
||||
name: "flashvars",
|
||||
value: fvstr
|
||||
}
|
||||
];
|
||||
|
||||
callback(false, med);
|
||||
} catch (e) {
|
||||
callback("Parsing of Google Docs output failed", null);
|
||||
}
|
||||
} else {
|
||||
callback(res, null);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
19
lib/media.js
19
lib/media.js
|
|
@ -33,19 +33,27 @@ Media.prototype.dup = function() {
|
|||
// Returns an object containing the data in this Media but not the
|
||||
// prototype
|
||||
Media.prototype.pack = function() {
|
||||
return {
|
||||
var x = {
|
||||
id: this.id,
|
||||
title: this.title,
|
||||
seconds: this.seconds,
|
||||
duration: this.duration,
|
||||
type: this.type,
|
||||
};
|
||||
|
||||
if (this.object) {
|
||||
x.object = this.object;
|
||||
}
|
||||
if (this.params) {
|
||||
x.params = this.params;
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
// Same as pack() but includes the currentTime variable set by the channel
|
||||
// when the media is being synchronized
|
||||
Media.prototype.fullupdate = function() {
|
||||
return {
|
||||
var x = {
|
||||
id: this.id,
|
||||
title: this.title,
|
||||
seconds: this.seconds,
|
||||
|
|
@ -54,6 +62,13 @@ Media.prototype.fullupdate = function() {
|
|||
currentTime: this.currentTime,
|
||||
paused: this.paused,
|
||||
};
|
||||
if (this.object) {
|
||||
x.object = this.object;
|
||||
}
|
||||
if (this.params) {
|
||||
x.params = this.params;
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
Media.prototype.timeupdate = function() {
|
||||
|
|
|
|||
|
|
@ -126,6 +126,8 @@ Playlist.prototype.load = function(data, callback) {
|
|||
for(var i in data.pl) {
|
||||
var e = data.pl[i].media;
|
||||
var m = new Media(e.id, e.title, e.seconds, e.type);
|
||||
m.object = e.object;
|
||||
m.params = e.params;
|
||||
var it = this.makeItem(m);
|
||||
it.temp = data.pl[i].temp;
|
||||
it.queueby = data.pl[i].queueby;
|
||||
|
|
@ -208,6 +210,8 @@ 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;
|
||||
var item = this.makeItem(m);
|
||||
item.queueby = data.queueby;
|
||||
item.temp = data.temp;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue