forked from night/TwitchStatus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ingests.js
36 lines (30 loc) · 902 Bytes
/
ingests.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
var request = require('request');
module.exports = function(callback) {
request({
url: "https://api.twitch.tv/kraken/ingests",
json: true,
timeout: 10000
}, function(error, response, data) {
if(error || !data.ingests) {
callback([]);
return;
}
var servers = [];
data.ingests.forEach(function(ingest) {
var host = ingest.url_template.split('/')[2],
port = 1935;
var server = {
name: host.replace(/^live/,'Live').replace('.justin.','.twitch.').replace('.twitch.','.Twitch.').replace('.tv','.TV'),
type: "ingest",
description: ingest.name.replace('Midwest', 'Central').replace('Asia', 'AS'),
host: host,
port: port
};
servers.push(server);
});
servers.sort(function(a, b) {
return a.description.localeCompare(b.description);
});
callback(servers);
});
}