forked from ncb000gt/node-shoutcast
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshoutcast.js
64 lines (53 loc) · 1.52 KB
/
shoutcast.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
var net = require("net"),
http = require('http'),
fs = require('fs'),
file = require('./lib/file'),
shoutcast = require('./lib/shoutcast');
var config = {
name: 'Node Shoutcasts R Us',
genre: 'Musak',
url: 'http://github.com/ncb000gt/node-shoutcast/',
notice: 'I\'m a little teapot...'
};
var stations = [];
var first = shoutcast.Station(config);
stations.push(first);
var dir = process.argv[2];
console.log('dir: ' + dir);
var stats = fs.statSync(dir);
if (stats.isDirectory()) {
file.walkSync(dir, function(p, dirs, files) {
var len = files.length;
for (var i = 0; i < len; i++) {
var f = files[i];
if (f.indexOf('.mp3') >= 0) {
first.addTrack({file: p+'/'+f});
}
}
});
}
http.createServer(
function (req, res) {
first.connect(req, res, function() {
console.log("Stream ended?");
});
}).listen(7000);
first.start();
setInterval(function() {
var total = 0;
var played = 0;
var connected = 0;
var connections = 0;
var len = stations.length;
for (var idx = 0; idx < len; idx++) {
total += stations[idx].stats.bytesWritten;
played += stations[idx].stats.numPlayed;
connected += stations[idx].stats.connected;
connections += stations[idx].stats.connections;
}
console.log('Total Bytes Written: ' + total);
console.log('Total Tracks Played: ' + played);
console.log('Total Connected: ' + connected);
console.log('Total Connections: ' + connections);
}, 20000);
console.log('Server running at http://0.0.0.0:7000/');