Add twitch clip support (#659)

This commit is contained in:
Calvin Montgomery 2017-05-27 11:49:27 -07:00
parent 995ab142e3
commit e9c519c6e2
6 changed files with 36 additions and 1 deletions

View File

@ -18,6 +18,7 @@ TYPE_MAP =
vm: VideoJSPlayer vm: VideoJSPlayer
hl: HLSPlayer hl: HLSPlayer
sb: VideoJSPlayer sb: VideoJSPlayer
tc: VideoJSPlayer
window.loadMediaPlayer = (data) -> window.loadMediaPlayer = (data) ->
try try

View File

@ -385,6 +385,8 @@ function preprocessConfig(cfg) {
if (cfg["twitch-client-id"]) { if (cfg["twitch-client-id"]) {
require("cytube-mediaquery/lib/provider/twitch-vod").setClientID( require("cytube-mediaquery/lib/provider/twitch-vod").setClientID(
cfg["twitch-client-id"]); cfg["twitch-client-id"]);
require("cytube-mediaquery/lib/provider/twitch-clip").setClientID(
cfg["twitch-client-id"]);
} else { } else {
LOGGER.warn("No Twitch Client ID set. Twitch VOD links will " + LOGGER.warn("No Twitch Client ID set. Twitch VOD links will " +
"not work. See twitch-client-id in config.template.yaml and " + "not work. See twitch-client-id in config.template.yaml and " +

View File

@ -12,6 +12,7 @@ var Vidme = require("cytube-mediaquery/lib/provider/vidme");
var Streamable = require("cytube-mediaquery/lib/provider/streamable"); var Streamable = require("cytube-mediaquery/lib/provider/streamable");
var GoogleDrive = require("cytube-mediaquery/lib/provider/googledrive"); var GoogleDrive = require("cytube-mediaquery/lib/provider/googledrive");
var TwitchVOD = require("cytube-mediaquery/lib/provider/twitch-vod"); var TwitchVOD = require("cytube-mediaquery/lib/provider/twitch-vod");
var TwitchClip = require("cytube-mediaquery/lib/provider/twitch-clip");
import { LoggerFactory } from '@calzoneman/jsli'; import { LoggerFactory } from '@calzoneman/jsli';
const LOGGER = LoggerFactory.getLogger('get-info'); const LOGGER = LoggerFactory.getLogger('get-info');
@ -391,6 +392,25 @@ var Getters = {
}); });
}, },
/* twitch clip */
tc: function (id, callback) {
var m = id.match(/^([A-Za-z]+)$/);
if (m) {
id = m[1];
} else {
process.nextTick(callback, "Invalid Twitch VOD ID");
return;
}
TwitchClip.lookup(id).then(video => {
const media = new Media(video.id, video.title, video.duration,
"tc", video.meta);
process.nextTick(callback, false, media);
}).catch(function (err) {
callback(err.message || err, null);
});
},
/* ustream.tv */ /* ustream.tv */
us: function (id, callback) { us: function (id, callback) {
/** /**

View File

@ -244,6 +244,8 @@
return id; return id;
case "sb": case "sb":
return "https://streamable.com/" + id; return "https://streamable.com/" + id;
case "tc":
return "https://clips.twitch.tv/" + id;
default: default:
return ""; return "";
} }

View File

@ -1519,7 +1519,8 @@
im: ImgurPlayer, im: ImgurPlayer,
vm: VideoJSPlayer, vm: VideoJSPlayer,
hl: HLSPlayer, hl: HLSPlayer,
sb: VideoJSPlayer sb: VideoJSPlayer,
tc: VideoJSPlayer
}; };
window.loadMediaPlayer = function(data) { window.loadMediaPlayer = function(data) {

View File

@ -54,6 +54,8 @@ function formatURL(data) {
return data.id; return data.id;
case "sb": case "sb":
return "https://streamable.com/" + data.id; return "https://streamable.com/" + data.id;
case "tc":
return "https://clips.twitch.tv/" + data.id;
default: default:
return "#"; return "#";
} }
@ -1284,6 +1286,13 @@ function parseMediaLink(url) {
}; };
} }
if ((m = url.match(/clips\.twitch\.tv\/([A-Za-z]+)/))) {
return {
id: m[1],
type: "tc"
};
}
if((m = url.match(/twitch\.tv\/(?:.*?)\/([cv])\/(\d+)/))) { if((m = url.match(/twitch\.tv\/(?:.*?)\/([cv])\/(\d+)/))) {
return { return {
id: m[1] + m[2], id: m[1] + m[2],