Adblock Radio client SDK
This is a JS Node & browser library to connect to adblockradio.com API servers.
It provides live information about the nature of broadcast contents: either ads, talk or music.
It also gives the average volume gain of radio streams so that channel-hopping between stations does not lead to volume variations.
Installation
$ npm install
Usage in browser:
The demo script demo.js
requires libabr.js
. To test it in a browser, you need to use browserify.
$ browserify demo.js -o bundle.js
or
$ npm run build
Then launch a local web server at http://localhost:5000
:
$ serve -s
The demo has no UI, everything happens in the web console (F12 to display it in Firefox & Chrome).
Usage in Node:
Put a valid token in a token
file. Then:
$ nodejs demo_node.js
How to get an API token
A token is required to use this API. To get one:
Documentation
The workflow is to call connectServer
, then get the list of available streams with getSupportedRadios
. You create a list of desired radios and send it to the server with sendPlaylist
. You register to a prediction callback with setPredictionCallback
. It will give you live updates about the streams status.
If a prediction is incorrect, use sendFlag
to help improve the system.
If you want to send some feedback with the API, use sendFeedback
.
Demo usage
var abrsdk = require("./libabr.js")();
var token = "change me";
var onConnectionEvent = function(err, isConnected) {
if (err) return console.log("connection error: " + err);
if (!isConnected) return console.log("disconnected");
abrsdk.getSupportedRadios(function(data) {
console.log("supported radios: " + JSON.stringify(data));
abrsdk.sendPlaylist(data.supportedRadios.slice(0, data.maxPlaylistLen), token, function(err, validatedPlaylist) {
if (err) {
console.log("sendPlaylist error = " + err);
} else {
console.log("validated playlist = " + JSON.stringify(validatedPlaylist));
abrsdk.setPredictionCallback(onPrediction);
}
});
});
}
var onPrediction = function(predictions) {
var status, volume;
for (var i=0; i<predictions.radios.length; i++) {
switch (predictions.status[i]) {
case abrsdk.statusList.STATUS_AD: status = "AD"; break;
case abrsdk.statusList.STATUS_SPEECH: status = "SPEECH"; break;
case abrsdk.statusList.STATUS_MUSIC: status = "MUSIC"; break;
default: status = "not available";
}
volume = Math.pow(10, (Math.min(abrsdk.GAIN_REF-predictions.gain[i],0))/20);
console.log(predictions.radios[i] + " has status " + status + " and volume " + Math.round(volume*100)/100);
}
}
abrsdk.connectServer(onConnectionEvent);
Licence
MIT