From 748b42cff0689c605b5dec2daec8f8a5a5a35c00 Mon Sep 17 00:00:00 2001 From: reality Date: Mon, 17 Feb 2014 20:00:31 +0000 Subject: [PATCH 1/6] radio --- modules/radio/config.json | 5 ++++ modules/radio/radio.js | 50 ++++++++++++++++++++++++++++++++++++++ modules/radio/strings.json | 8 ++++++ 3 files changed, 63 insertions(+) create mode 100644 modules/radio/config.json create mode 100644 modules/radio/radio.js create mode 100644 modules/radio/strings.json diff --git a/modules/radio/config.json b/modules/radio/config.json new file mode 100644 index 0000000..3cb4868 --- /dev/null +++ b/modules/radio/config.json @@ -0,0 +1,5 @@ +{ + "stream": "", + "announce": [ { "server": "aberwiki", "name": "#dbot" } ], + "outputPrefix": "\u00033radio\u000f" +} diff --git a/modules/radio/radio.js b/modules/radio/radio.js new file mode 100644 index 0000000..dd1e2df --- /dev/null +++ b/modules/radio/radio.js @@ -0,0 +1,50 @@ +/** + * Module Name: Radio + * Description: Various icecast functionality. + */ + +var _ = require('underscore')._, + icecast = require('icecast-stack'); + +var radio = function(dbot) { + this.listening = false; + this.data = false; + this.internalAPI = { + 'startRadio': function() { + var stream = icecast.createReadStream(this.config.stream); + + stream.on('connect', function() { + this.listening = true; + }.bind(this)); + + stream.on('response', function(res) { + this.data = res.headers; + _.each(this.config.announce, function(a) { + dbot.say(a.server, a.name, dbot.t('now_online', { + 'name': res.headers['icy-name'], + 'desc': res.headers['icy-description'], + 'url': res.headers['icy-url'] + })); + }); + }.bind(this)); + + stream.on('metadata', function(metadata) { + var title = icecast.parseMetadata(metadata).StreamTitle; + _.each(this.config.announce, function(a) { + dbot.say(a.server, a.name, dbot.t('now_playing', { + 'name': this.data['icy-name'], + 'song': title, + 'url': this.data['icy-url'] + })); + }, this); + }.bind(this)); + }.bind(this) + }; + this.onLoad = function() { + this.internalAPI.startRadio(); + }.bind(this); +}; + +exports.fetch = function(dbot) { + return new radio(dbot); +}; diff --git a/modules/radio/strings.json b/modules/radio/strings.json new file mode 100644 index 0000000..ecd3157 --- /dev/null +++ b/modules/radio/strings.json @@ -0,0 +1,8 @@ +{ + "now_online": { + "en": "Now Online: {name} - {desc} - {url}" + }, + "now_playing": { + "en": "Now Playing: {name} - {song} - {url}" + } +} From 21eab082bf2fda36a57d60841e10c15a2cc275d1 Mon Sep 17 00:00:00 2001 From: reality Date: Mon, 17 Feb 2014 20:11:11 +0000 Subject: [PATCH 2/6] fuck lag --- modules/radio/radio.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/modules/radio/radio.js b/modules/radio/radio.js index dd1e2df..a214248 100644 --- a/modules/radio/radio.js +++ b/modules/radio/radio.js @@ -38,10 +38,22 @@ var radio = function(dbot) { })); }, this); }.bind(this)); - }.bind(this) + + stream.on('end', function() { + this.listening = false; + }.bind(this)); + }.bind(this), + + 'getRadio': function() { + dbot.api.timers.addTimer(20000, function() { + if(this.listening == false) { + this.internalAPI.startRadio(); + } + }.bind(this)); + } }; this.onLoad = function() { - this.internalAPI.startRadio(); + this.internalAPI.getRadio(); }.bind(this); }; From 0913f382d73602fba9e16576bb0207e27d5e8bd5 Mon Sep 17 00:00:00 2001 From: reality Date: Mon, 17 Feb 2014 20:13:29 +0000 Subject: [PATCH 3/6] missing bing --- modules/radio/radio.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/radio/radio.js b/modules/radio/radio.js index a214248..aeaa868 100644 --- a/modules/radio/radio.js +++ b/modules/radio/radio.js @@ -50,7 +50,7 @@ var radio = function(dbot) { this.internalAPI.startRadio(); } }.bind(this)); - } + }.bind(this) }; this.onLoad = function() { this.internalAPI.getRadio(); From e4997cd9152e905ba27b91c8823a8a3c5a43e405 Mon Sep 17 00:00:00 2001 From: reality Date: Mon, 17 Feb 2014 20:31:20 +0000 Subject: [PATCH 4/6] fuck timers --- modules/radio/radio.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/modules/radio/radio.js b/modules/radio/radio.js index aeaa868..aaa8853 100644 --- a/modules/radio/radio.js +++ b/modules/radio/radio.js @@ -9,9 +9,11 @@ var _ = require('underscore')._, var radio = function(dbot) { this.listening = false; this.data = false; + this.stream = false; this.internalAPI = { 'startRadio': function() { var stream = icecast.createReadStream(this.config.stream); + this.stream = stream; stream.on('connect', function() { this.listening = true; @@ -40,6 +42,7 @@ var radio = function(dbot) { }.bind(this)); stream.on('end', function() { + this.stream.close(); this.listening = false; }.bind(this)); }.bind(this), @@ -55,6 +58,9 @@ var radio = function(dbot) { this.onLoad = function() { this.internalAPI.getRadio(); }.bind(this); + this.onDestroy = function() { + this.stream.close(); + }.bind(this); }; exports.fetch = function(dbot) { From a38f8df657b30b2fa50c91d0872b6e6a098ed1c9 Mon Sep 17 00:00:00 2001 From: reality Date: Mon, 17 Feb 2014 20:42:24 +0000 Subject: [PATCH 5/6] whoops --- modules/radio/radio.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/radio/radio.js b/modules/radio/radio.js index aaa8853..163eef2 100644 --- a/modules/radio/radio.js +++ b/modules/radio/radio.js @@ -42,7 +42,7 @@ var radio = function(dbot) { }.bind(this)); stream.on('end', function() { - this.stream.close(); + this.stream.end(); this.listening = false; }.bind(this)); }.bind(this), @@ -59,7 +59,7 @@ var radio = function(dbot) { this.internalAPI.getRadio(); }.bind(this); this.onDestroy = function() { - this.stream.close(); + this.stream.end(); }.bind(this); }; From 2c1acab7618833cd2c5b5d7b51c417a513d7cc79 Mon Sep 17 00:00:00 2001 From: reality Date: Mon, 17 Feb 2014 20:51:20 +0000 Subject: [PATCH 6/6] try abort --- modules/radio/radio.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/radio/radio.js b/modules/radio/radio.js index 163eef2..38ce3c0 100644 --- a/modules/radio/radio.js +++ b/modules/radio/radio.js @@ -42,7 +42,7 @@ var radio = function(dbot) { }.bind(this)); stream.on('end', function() { - this.stream.end(); + this.stream.end(); this.listening = false; }.bind(this)); }.bind(this), @@ -59,7 +59,7 @@ var radio = function(dbot) { this.internalAPI.getRadio(); }.bind(this); this.onDestroy = function() { - this.stream.end(); + this.stream.abort(); }.bind(this); };