-
Notifications
You must be signed in to change notification settings - Fork 13
/
ingests.js
50 lines (44 loc) · 1.17 KB
/
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
var request = require("request");
var config = require("./config.json");
module.exports = function (callback) {
request(
{
url: "https://ingest.twitch.tv/ingests",
headers: {
"Client-ID": config.irc.client_id,
},
json: true,
timeout: 60000,
},
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")
.replace("Australia", "AU"),
host: host,
port: port,
};
servers.push(server);
});
servers.sort(function (a, b) {
return a.description.localeCompare(b.description);
});
callback(servers);
}
);
};