2013-03-24 17:23:48 +00:00
|
|
|
var http = require("http");
|
|
|
|
var https = require("https");
|
2015-02-13 13:11:28 +00:00
|
|
|
var cheerio = require('cheerio');
|
2013-03-27 19:28:51 +00:00
|
|
|
var Logger = require("./logger.js");
|
2014-05-21 02:30:14 +00:00
|
|
|
var Media = require("./media");
|
2013-08-03 15:12:53 +00:00
|
|
|
var CustomEmbedFilter = require("./customembed").filter;
|
2013-10-11 21:31:40 +00:00
|
|
|
var Server = require("./server");
|
2014-01-22 23:11:26 +00:00
|
|
|
var Config = require("./config");
|
2014-06-01 18:43:18 +00:00
|
|
|
var ffmpeg = require("./ffmpeg");
|
2015-05-15 05:03:05 +00:00
|
|
|
var mediaquery = require("cytube-mediaquery");
|
2015-03-27 23:44:46 +00:00
|
|
|
var YouTube = require("cytube-mediaquery/lib/provider/youtube");
|
2013-10-11 21:31:40 +00:00
|
|
|
|
2014-09-07 03:59:28 +00:00
|
|
|
/*
|
|
|
|
* Preference map of quality => youtube formats.
|
|
|
|
* see https://en.wikipedia.org/wiki/Youtube#Quality_and_codecs
|
|
|
|
*
|
|
|
|
* Prefer WebM over MP4, ignore other codecs (e.g. FLV)
|
|
|
|
*/
|
|
|
|
const GOOGLE_PREFERENCE = {
|
2015-03-06 06:23:06 +00:00
|
|
|
"hd1080": [37, 46],
|
|
|
|
"hd720": [22, 45],
|
|
|
|
"large": [59, 44],
|
|
|
|
"medium": [18, 43, 34] // 34 is 360p FLV as a last-ditch
|
2014-09-07 03:59:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const CONTENT_TYPES = {
|
|
|
|
43: "webm",
|
|
|
|
44: "webm",
|
|
|
|
45: "webm",
|
|
|
|
46: "webm",
|
|
|
|
18: "mp4",
|
|
|
|
22: "mp4",
|
|
|
|
37: "mp4",
|
|
|
|
59: "mp4",
|
|
|
|
34: "flv"
|
|
|
|
};
|
|
|
|
|
2013-10-11 21:31:40 +00:00
|
|
|
var urlRetrieve = function (transport, options, callback) {
|
2014-12-26 15:39:47 +00:00
|
|
|
var req = transport.request(options, function (res) {
|
2015-01-06 15:54:14 +00:00
|
|
|
res.on("error", function (err) {
|
|
|
|
Logger.errlog.log("HTTP response " + options.host + options.path + " failed: "+
|
|
|
|
err);
|
|
|
|
callback(503, "");
|
|
|
|
});
|
|
|
|
|
2014-12-26 15:39:47 +00:00
|
|
|
var buffer = "";
|
|
|
|
res.setEncoding("utf-8");
|
|
|
|
res.on("data", function (chunk) {
|
|
|
|
buffer += chunk;
|
2014-12-04 06:42:25 +00:00
|
|
|
});
|
2014-12-26 15:39:47 +00:00
|
|
|
res.on("end", function () {
|
|
|
|
callback(res.statusCode, buffer);
|
2013-08-17 02:35:21 +00:00
|
|
|
});
|
2014-12-26 15:39:47 +00:00
|
|
|
});
|
2013-08-03 14:52:24 +00:00
|
|
|
|
2014-12-26 15:39:47 +00:00
|
|
|
req.on("error", function (err) {
|
|
|
|
Logger.errlog.log("HTTP request " + options.host + options.path + " failed: " +
|
|
|
|
err);
|
|
|
|
callback(503, "");
|
2013-10-11 21:31:40 +00:00
|
|
|
});
|
2014-12-26 15:39:47 +00:00
|
|
|
|
|
|
|
req.end();
|
2013-10-11 21:31:40 +00:00
|
|
|
};
|
|
|
|
|
2015-05-15 05:03:05 +00:00
|
|
|
var mediaTypeMap = {
|
|
|
|
"youtube": "yt",
|
|
|
|
"googledrive": "gd",
|
|
|
|
"google+": "gp"
|
|
|
|
};
|
|
|
|
|
|
|
|
function convertMedia(media) {
|
|
|
|
return new Media(media.id, media.title, media.duration, mediaTypeMap[media.type],
|
|
|
|
media.meta);
|
|
|
|
}
|
|
|
|
|
2013-10-11 21:31:40 +00:00
|
|
|
var Getters = {
|
|
|
|
/* youtube.com */
|
|
|
|
yt: function (id, callback) {
|
2015-03-27 23:44:46 +00:00
|
|
|
if (!Config.get("youtube-v3-key")) {
|
2015-06-07 15:45:23 +00:00
|
|
|
return callback("The YouTube API now requires an API key. Please see the " +
|
|
|
|
"documentation for youtube-v3-key in config.template.yaml");
|
2013-10-11 21:31:40 +00:00
|
|
|
}
|
2013-09-04 03:23:05 +00:00
|
|
|
|
2013-08-03 14:58:21 +00:00
|
|
|
|
2015-03-27 23:44:46 +00:00
|
|
|
YouTube.lookup(id).then(function (video) {
|
|
|
|
var meta = {};
|
|
|
|
if (video.meta.blocked) {
|
|
|
|
meta.restricted = video.meta.blocked;
|
2013-08-03 20:13:19 +00:00
|
|
|
}
|
2014-04-04 16:37:30 +00:00
|
|
|
|
2015-03-27 23:44:46 +00:00
|
|
|
var media = new Media(video.id, video.title, video.duration, "yt", meta);
|
|
|
|
callback(false, media);
|
|
|
|
}).catch(function (err) {
|
2015-04-07 20:42:24 +00:00
|
|
|
callback(err.message || err, null);
|
2013-10-11 21:31:40 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
/* youtube.com playlists */
|
2015-03-27 23:44:46 +00:00
|
|
|
yp: function (id, callback) {
|
|
|
|
if (!Config.get("youtube-v3-key")) {
|
2015-06-07 15:45:23 +00:00
|
|
|
return callback("The YouTube API now requires an API key. Please see the " +
|
|
|
|
"documentation for youtube-v3-key in config.template.yaml");
|
2013-10-11 21:31:40 +00:00
|
|
|
}
|
2013-08-01 14:27:32 +00:00
|
|
|
|
2015-03-27 23:44:46 +00:00
|
|
|
YouTube.lookupPlaylist(id).then(function (videos) {
|
|
|
|
videos = videos.map(function (video) {
|
|
|
|
var meta = {};
|
|
|
|
if (video.meta.blocked) {
|
|
|
|
meta.restricted = video.meta.blocked;
|
2013-08-01 14:27:32 +00:00
|
|
|
}
|
|
|
|
|
2015-03-27 23:44:46 +00:00
|
|
|
return new Media(video.id, video.title, video.duration, "yt", meta);
|
|
|
|
});
|
2013-08-03 14:58:21 +00:00
|
|
|
|
2015-03-27 23:44:46 +00:00
|
|
|
callback(null, videos);
|
|
|
|
}).catch(function (err) {
|
2015-04-07 20:42:24 +00:00
|
|
|
callback(err.message || err, null);
|
2013-10-11 21:31:40 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
/* youtube.com search */
|
2015-03-27 23:44:46 +00:00
|
|
|
ytSearch: function (query, callback) {
|
|
|
|
if (!Config.get("youtube-v3-key")) {
|
2015-06-07 15:45:23 +00:00
|
|
|
return callback("The YouTube API now requires an API key. Please see the " +
|
|
|
|
"documentation for youtube-v3-key in config.template.yaml");
|
2014-05-21 02:30:14 +00:00
|
|
|
}
|
2013-10-11 21:31:40 +00:00
|
|
|
|
2015-03-27 23:44:46 +00:00
|
|
|
YouTube.search(query).then(function (res) {
|
|
|
|
var videos = res.results;
|
|
|
|
videos = videos.map(function (video) {
|
|
|
|
var meta = {};
|
|
|
|
if (video.meta.blocked) {
|
|
|
|
meta.restricted = video.meta.blocked;
|
2013-08-03 14:58:21 +00:00
|
|
|
}
|
|
|
|
|
2015-03-27 23:44:46 +00:00
|
|
|
var media = new Media(video.id, video.title, video.duration, "yt", meta);
|
|
|
|
media.thumb = { url: video.meta.thumbnail };
|
|
|
|
return media;
|
|
|
|
});
|
|
|
|
|
|
|
|
callback(null, videos);
|
|
|
|
}).catch(function (err) {
|
2015-04-07 20:42:24 +00:00
|
|
|
callback(err.message || err, null);
|
2013-10-11 21:31:40 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
/* vimeo.com */
|
|
|
|
vi: function (id, callback) {
|
|
|
|
var m = id.match(/([\w-]+)/);
|
|
|
|
if (m) {
|
|
|
|
id = m[1];
|
|
|
|
} else {
|
|
|
|
callback("Invalid ID", null);
|
|
|
|
return;
|
|
|
|
}
|
2014-04-04 16:37:30 +00:00
|
|
|
|
|
|
|
if (Config.get("vimeo-oauth.enabled")) {
|
|
|
|
return Getters.vi_oauth(id, callback);
|
|
|
|
}
|
|
|
|
|
2013-10-11 21:31:40 +00:00
|
|
|
var options = {
|
|
|
|
host: "vimeo.com",
|
|
|
|
port: 443,
|
|
|
|
path: "/api/v2/video/" + id + ".json",
|
|
|
|
method: "GET",
|
|
|
|
dataType: "jsonp",
|
|
|
|
timeout: 1000
|
|
|
|
};
|
|
|
|
|
|
|
|
urlRetrieve(https, options, function (status, data) {
|
2014-05-21 02:30:14 +00:00
|
|
|
switch (status) {
|
|
|
|
case 200:
|
|
|
|
break; /* Request is OK, skip to handling data */
|
|
|
|
case 400:
|
|
|
|
return callback("Invalid request", null);
|
|
|
|
case 403:
|
|
|
|
return callback("Private video", null);
|
|
|
|
case 404:
|
|
|
|
return callback("Video not found", null);
|
|
|
|
case 500:
|
|
|
|
case 503:
|
|
|
|
return callback("Service unavailable", null);
|
|
|
|
default:
|
|
|
|
return callback("HTTP " + status, null);
|
2013-09-04 03:23:05 +00:00
|
|
|
}
|
2013-08-01 03:26:11 +00:00
|
|
|
|
2013-10-11 21:31:40 +00:00
|
|
|
try {
|
|
|
|
data = JSON.parse(data);
|
|
|
|
data = data[0];
|
|
|
|
var seconds = data.duration;
|
|
|
|
var title = data.title;
|
|
|
|
var media = new Media(id, title, seconds, "vi");
|
|
|
|
callback(false, media);
|
|
|
|
} catch(e) {
|
|
|
|
var err = e;
|
2014-05-21 02:30:14 +00:00
|
|
|
/**
|
|
|
|
* This should no longer be necessary as the outer handler
|
|
|
|
* checks for HTTP 404
|
|
|
|
*/
|
|
|
|
if (buffer.match(/not found/))
|
2013-10-11 21:31:40 +00:00
|
|
|
err = "Video not found";
|
|
|
|
|
|
|
|
callback(err, null);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2014-04-04 16:37:30 +00:00
|
|
|
vi_oauth: function (id, callback) {
|
|
|
|
var OAuth = require("oauth");
|
|
|
|
var oa = new OAuth.OAuth(
|
|
|
|
"https://vimeo.com/oauth/request_token",
|
|
|
|
"https://vimeo.com/oauth/access_token",
|
|
|
|
Config.get("vimeo-oauth.consumer-key"),
|
|
|
|
Config.get("vimeo-oauth.secret"),
|
|
|
|
"1.0",
|
|
|
|
null,
|
|
|
|
"HMAC-SHA1"
|
|
|
|
);
|
|
|
|
|
|
|
|
oa.get("https://vimeo.com/api/rest/v2?format=json" +
|
|
|
|
"&method=vimeo.videos.getInfo&video_id=" + id,
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
function (err, data, res) {
|
2014-04-05 01:03:34 +00:00
|
|
|
if (err) {
|
|
|
|
return callback(err, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
data = JSON.parse(data);
|
|
|
|
|
|
|
|
if (data.stat !== "ok") {
|
|
|
|
return callback(data.err.msg, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
var video = data.video[0];
|
|
|
|
|
|
|
|
if (video.embed_privacy !== "anywhere") {
|
|
|
|
return callback("Embedding disabled", null);
|
|
|
|
}
|
|
|
|
|
|
|
|
var id = video.id;
|
|
|
|
var seconds = parseInt(video.duration);
|
|
|
|
var title = video.title;
|
|
|
|
callback(null, new Media(id, title, seconds, "vi"));
|
|
|
|
} catch (e) {
|
|
|
|
callback("Error handling Vimeo response", null);
|
|
|
|
}
|
2014-04-04 16:37:30 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2013-10-11 21:31:40 +00:00
|
|
|
/* dailymotion.com */
|
|
|
|
dm: function (id, callback) {
|
|
|
|
var m = id.match(/([\w-]+)/);
|
|
|
|
if (m) {
|
2015-02-16 08:50:15 +00:00
|
|
|
id = m[1].split("_")[0];
|
2013-10-11 21:31:40 +00:00
|
|
|
} else {
|
|
|
|
callback("Invalid ID", null);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var options = {
|
|
|
|
host: "api.dailymotion.com",
|
|
|
|
port: 443,
|
|
|
|
path: "/video/" + id + "?fields=duration,title",
|
|
|
|
method: "GET",
|
|
|
|
dataType: "jsonp",
|
|
|
|
timeout: 1000
|
|
|
|
};
|
|
|
|
|
|
|
|
urlRetrieve(https, options, function (status, data) {
|
2014-05-21 02:30:14 +00:00
|
|
|
switch (status) {
|
|
|
|
case 200:
|
|
|
|
break; /* Request is OK, skip to handling data */
|
|
|
|
case 400:
|
|
|
|
return callback("Invalid request", null);
|
|
|
|
case 403:
|
|
|
|
return callback("Private video", null);
|
|
|
|
case 404:
|
|
|
|
return callback("Video not found", null);
|
|
|
|
case 500:
|
|
|
|
case 503:
|
|
|
|
return callback("Service unavailable", null);
|
|
|
|
default:
|
|
|
|
return callback("HTTP " + status, null);
|
2013-09-04 03:23:05 +00:00
|
|
|
}
|
2013-08-01 03:26:11 +00:00
|
|
|
|
2013-10-11 21:31:40 +00:00
|
|
|
try {
|
|
|
|
data = JSON.parse(data);
|
|
|
|
var title = data.title;
|
|
|
|
var seconds = data.duration;
|
2014-05-21 02:30:14 +00:00
|
|
|
/**
|
|
|
|
* This is a rather hacky way to indicate that a video has
|
|
|
|
* been deleted...
|
|
|
|
*/
|
|
|
|
if (title === "Deleted video" && seconds === 10) {
|
2013-10-07 05:10:16 +00:00
|
|
|
callback("Video not found", null);
|
|
|
|
return;
|
2013-08-01 03:26:11 +00:00
|
|
|
}
|
2013-10-11 21:31:40 +00:00
|
|
|
var media = new Media(id, title, seconds, "dm");
|
|
|
|
callback(false, media);
|
|
|
|
} catch(e) {
|
2014-06-25 20:13:54 +00:00
|
|
|
callback(e, null);
|
2013-10-11 21:31:40 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
/* soundcloud.com */
|
|
|
|
sc: function (id, callback) {
|
2014-05-21 02:30:14 +00:00
|
|
|
/* TODO: require server owners to register their own API key, put in config */
|
2013-10-11 21:31:40 +00:00
|
|
|
const SC_CLIENT = "2e0c82ab5a020f3a7509318146128abd";
|
|
|
|
|
|
|
|
var m = id.match(/([\w-\/\.:]+)/);
|
|
|
|
if (m) {
|
|
|
|
id = m[1];
|
|
|
|
} else {
|
|
|
|
callback("Invalid ID", null);
|
|
|
|
return;
|
|
|
|
}
|
2013-08-01 03:26:11 +00:00
|
|
|
|
2013-10-11 21:31:40 +00:00
|
|
|
var options = {
|
|
|
|
host: "api.soundcloud.com",
|
|
|
|
port: 443,
|
|
|
|
path: "/resolve.json?url=" + id + "&client_id=" + SC_CLIENT,
|
|
|
|
method: "GET",
|
|
|
|
dataType: "jsonp",
|
|
|
|
timeout: 1000
|
|
|
|
};
|
|
|
|
|
|
|
|
urlRetrieve(https, options, function (status, data) {
|
2014-05-21 02:30:14 +00:00
|
|
|
switch (status) {
|
|
|
|
case 200:
|
2014-05-22 03:53:13 +00:00
|
|
|
case 302:
|
2014-05-21 02:30:14 +00:00
|
|
|
break; /* Request is OK, skip to handling data */
|
|
|
|
case 400:
|
|
|
|
return callback("Invalid request", null);
|
|
|
|
case 403:
|
|
|
|
return callback("Private sound", null);
|
|
|
|
case 404:
|
|
|
|
return callback("Sound not found", null);
|
|
|
|
case 500:
|
|
|
|
case 503:
|
|
|
|
return callback("Service unavailable", null);
|
|
|
|
default:
|
|
|
|
return callback("HTTP " + status, null);
|
2013-10-11 21:31:40 +00:00
|
|
|
}
|
2013-08-01 14:12:22 +00:00
|
|
|
|
2013-10-11 21:31:40 +00:00
|
|
|
var track = null;
|
|
|
|
try {
|
|
|
|
data = JSON.parse(data);
|
|
|
|
track = data.location;
|
|
|
|
} catch(e) {
|
|
|
|
callback(e, null);
|
2013-09-04 03:23:05 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-10-11 21:31:40 +00:00
|
|
|
var options2 = {
|
2013-08-03 14:58:21 +00:00
|
|
|
host: "api.soundcloud.com",
|
|
|
|
port: 443,
|
2013-10-11 21:31:40 +00:00
|
|
|
path: track,
|
2013-08-03 14:58:21 +00:00
|
|
|
method: "GET",
|
|
|
|
dataType: "jsonp",
|
|
|
|
timeout: 1000
|
|
|
|
};
|
|
|
|
|
2014-05-21 02:30:14 +00:00
|
|
|
/**
|
|
|
|
* There has got to be a way to directly get the data I want without
|
|
|
|
* making two requests to Soundcloud...right?
|
|
|
|
* ...right?
|
|
|
|
*/
|
2013-10-11 21:31:40 +00:00
|
|
|
urlRetrieve(https, options2, function (status, data) {
|
2014-05-21 02:30:14 +00:00
|
|
|
switch (status) {
|
|
|
|
case 200:
|
|
|
|
break; /* Request is OK, skip to handling data */
|
|
|
|
case 400:
|
|
|
|
return callback("Invalid request", null);
|
|
|
|
case 403:
|
|
|
|
return callback("Private sound", null);
|
|
|
|
case 404:
|
|
|
|
return callback("Sound not found", null);
|
|
|
|
case 500:
|
|
|
|
case 503:
|
|
|
|
return callback("Service unavailable", null);
|
|
|
|
default:
|
|
|
|
return callback("HTTP " + status, null);
|
2013-08-03 14:58:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
data = JSON.parse(data);
|
2013-10-11 21:31:40 +00:00
|
|
|
var seconds = data.duration / 1000;
|
|
|
|
var title = data.title;
|
2015-01-11 18:10:09 +00:00
|
|
|
var meta = {};
|
|
|
|
if (data.sharing === "private" && data.embeddable_by === "all") {
|
|
|
|
meta.scuri = data.uri;
|
|
|
|
}
|
|
|
|
var media = new Media(id, title, seconds, "sc", meta);
|
2013-10-11 21:31:40 +00:00
|
|
|
callback(false, media);
|
2013-08-03 14:58:21 +00:00
|
|
|
} catch(e) {
|
2013-10-07 05:10:16 +00:00
|
|
|
callback(e, null);
|
2013-08-03 14:58:21 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-10-11 21:31:40 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
/* livestream.com */
|
|
|
|
li: function (id, callback) {
|
|
|
|
var m = id.match(/([\w-]+)/);
|
|
|
|
if (m) {
|
|
|
|
id = m[1];
|
|
|
|
} else {
|
|
|
|
callback("Invalid ID", null);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var title = "Livestream.com - " + id;
|
|
|
|
var media = new Media(id, title, "--:--", "li");
|
|
|
|
callback(false, media);
|
|
|
|
},
|
|
|
|
|
|
|
|
/* twitch.tv */
|
|
|
|
tw: function (id, callback) {
|
|
|
|
var m = id.match(/([\w-]+)/);
|
|
|
|
if (m) {
|
|
|
|
id = m[1];
|
|
|
|
} else {
|
|
|
|
callback("Invalid ID", null);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var title = "Twitch.tv - " + id;
|
|
|
|
var media = new Media(id, title, "--:--", "tw");
|
|
|
|
callback(false, media);
|
|
|
|
},
|
|
|
|
|
|
|
|
/* ustream.tv */
|
|
|
|
us: function (id, callback) {
|
2014-05-21 02:30:14 +00:00
|
|
|
/**
|
|
|
|
*2013-09-17
|
|
|
|
* They couldn't fucking decide whether channels should
|
|
|
|
* be at http://www.ustream.tv/channel/foo or just
|
|
|
|
* http://www.ustream.tv/foo so they do both.
|
|
|
|
* [](/cleese)
|
|
|
|
*/
|
2013-10-11 21:31:40 +00:00
|
|
|
var m = id.match(/([^\?&#]+)|(channel\/[^\?&#]+)/);
|
|
|
|
if (m) {
|
|
|
|
id = m[1];
|
|
|
|
} else {
|
|
|
|
callback("Invalid ID", null);
|
|
|
|
return;
|
|
|
|
}
|
2014-05-21 02:30:14 +00:00
|
|
|
|
2013-10-11 21:31:40 +00:00
|
|
|
var options = {
|
|
|
|
host: "www.ustream.tv",
|
|
|
|
port: 80,
|
|
|
|
path: "/" + id,
|
|
|
|
method: "GET",
|
|
|
|
timeout: 1000
|
|
|
|
};
|
|
|
|
|
|
|
|
urlRetrieve(http, options, function (status, data) {
|
|
|
|
if(status !== 200) {
|
|
|
|
callback("Ustream HTTP " + status, null);
|
2013-09-04 03:23:05 +00:00
|
|
|
return;
|
|
|
|
}
|
2013-08-03 14:58:21 +00:00
|
|
|
|
2014-05-21 02:30:14 +00:00
|
|
|
/**
|
|
|
|
* Regexing the ID out of the HTML because
|
|
|
|
* Ustream's API is so horribly documented
|
|
|
|
* I literally could not figure out how to retrieve
|
|
|
|
* this information.
|
|
|
|
*
|
|
|
|
* [](/eatadick)
|
|
|
|
*/
|
2015-03-23 23:10:00 +00:00
|
|
|
var m = data.match(/https:\/\/www\.ustream\.tv\/embed\/(\d+)/);
|
|
|
|
if (m) {
|
2013-10-11 21:31:40 +00:00
|
|
|
var title = "Ustream.tv - " + id;
|
|
|
|
var media = new Media(m[1], title, "--:--", "us");
|
|
|
|
callback(false, media);
|
2013-09-04 03:23:05 +00:00
|
|
|
} else {
|
2015-03-23 23:10:00 +00:00
|
|
|
callback("Channel ID not found", null);
|
2013-09-04 03:23:05 +00:00
|
|
|
}
|
2013-10-11 21:31:40 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
/* JWPlayer */
|
|
|
|
jw: function (id, callback) {
|
|
|
|
var title = "JWPlayer - " + id;
|
|
|
|
var media = new Media(id, title, "--:--", "jw");
|
|
|
|
callback(false, media);
|
|
|
|
},
|
|
|
|
|
|
|
|
/* rtmp stream */
|
|
|
|
rt: function (id, callback) {
|
|
|
|
var title = "Livestream";
|
|
|
|
var media = new Media(id, title, "--:--", "rt");
|
|
|
|
callback(false, media);
|
|
|
|
},
|
|
|
|
|
|
|
|
/* imgur.com albums */
|
|
|
|
im: function (id, callback) {
|
2014-05-21 02:30:14 +00:00
|
|
|
/**
|
|
|
|
* TODO: Consider deprecating this in favor of custom embeds
|
|
|
|
*/
|
2013-10-11 21:31:40 +00:00
|
|
|
var m = id.match(/([\w-]+)/);
|
|
|
|
if (m) {
|
|
|
|
id = m[1];
|
|
|
|
} else {
|
|
|
|
callback("Invalid ID", null);
|
|
|
|
return;
|
2013-08-03 14:58:21 +00:00
|
|
|
}
|
2013-10-11 21:31:40 +00:00
|
|
|
var title = "Imgur Album - " + id;
|
|
|
|
var media = new Media(id, title, "--:--", "im");
|
|
|
|
callback(false, media);
|
|
|
|
},
|
|
|
|
|
|
|
|
/* custom embed */
|
|
|
|
cu: function (id, callback) {
|
2015-06-18 22:46:33 +00:00
|
|
|
var media;
|
|
|
|
try {
|
|
|
|
media = CustomEmbedFilter(id);
|
|
|
|
} catch (e) {
|
|
|
|
if (/invalid embed/i.test(e.message)) {
|
|
|
|
return callback(e.message);
|
|
|
|
} else {
|
|
|
|
Logger.errlog.log(e.stack);
|
|
|
|
return callback("Unknown error processing embed");
|
|
|
|
}
|
|
|
|
}
|
2013-10-11 21:31:40 +00:00
|
|
|
callback(false, media);
|
2013-11-07 23:19:36 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/* google docs */
|
|
|
|
gd: function (id, callback) {
|
2015-05-15 05:03:05 +00:00
|
|
|
var data = {
|
|
|
|
type: "googledrive",
|
|
|
|
kind: "single",
|
|
|
|
id: id
|
2013-11-07 23:19:36 +00:00
|
|
|
};
|
|
|
|
|
2015-05-15 05:03:05 +00:00
|
|
|
mediaquery.lookup(data).then(function (video) {
|
|
|
|
callback(null, convertMedia(video));
|
|
|
|
}).catch(function (err) {
|
|
|
|
callback(err.message || err);
|
2013-11-07 23:19:36 +00:00
|
|
|
});
|
2014-06-01 18:43:18 +00:00
|
|
|
},
|
|
|
|
|
2015-05-15 06:19:08 +00:00
|
|
|
/* Google+ videos */
|
|
|
|
gp: function (id, callback) {
|
|
|
|
var data = {
|
|
|
|
type: "google+",
|
|
|
|
kind: "single",
|
|
|
|
id: id
|
|
|
|
};
|
|
|
|
|
|
|
|
mediaquery.lookup(data).then(function (video) {
|
|
|
|
callback(null, convertMedia(video));
|
|
|
|
}).catch(function (err) {
|
|
|
|
callback(err.message || err);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2014-06-01 18:43:18 +00:00
|
|
|
/* ffmpeg for raw files */
|
|
|
|
fi: function (id, cb) {
|
|
|
|
ffmpeg.query(id, function (err, data) {
|
|
|
|
if (err) {
|
|
|
|
return cb(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
var m = new Media(id, data.title, data.duration, "fi", {
|
|
|
|
bitrate: data.bitrate,
|
|
|
|
codec: data.codec
|
|
|
|
});
|
|
|
|
cb(null, m);
|
|
|
|
});
|
2014-07-10 03:41:11 +00:00
|
|
|
},
|
|
|
|
|
2015-01-23 05:21:31 +00:00
|
|
|
/* hitbox.tv */
|
|
|
|
hb: function (id, callback) {
|
|
|
|
var m = id.match(/([\w-]+)/);
|
|
|
|
if (m) {
|
|
|
|
id = m[1];
|
|
|
|
} else {
|
|
|
|
callback("Invalid ID", null);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var title = "Hitbox.tv - " + id;
|
|
|
|
var media = new Media(id, title, "--:--", "hb");
|
|
|
|
callback(false, media);
|
|
|
|
},
|
2013-10-11 21:31:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
Getters: Getters,
|
|
|
|
getMedia: function (id, type, callback) {
|
|
|
|
if(type in this.Getters) {
|
|
|
|
this.Getters[type](id, callback);
|
|
|
|
} else {
|
|
|
|
callback("Unknown media type '" + type + "'", null);
|
2013-08-03 14:58:21 +00:00
|
|
|
}
|
2015-06-28 16:42:21 +00:00
|
|
|
}
|
2013-10-11 21:31:40 +00:00
|
|
|
};
|