node-internet-radio

Node.js module to get Now Playing information from an internet radio stream in the form of the following object:

{ listeners: '89',
  bitrate: '128',
  title: 'Die Antwoord - I Fink U Freaky',
  fetchsource: 'SHOUTCAST_V1' }

The syntax is simple:

getStationInfo(url, callback, [method]);

Install

npm install node-internet-radio

This Node.js module supports three different methods to fetch the station details of an internet radio stream. All but fetching details from the raw audio stream give you the currently playing track, bitrate, and listener count.

MethodStreamSourceTrackBitrateListenersHeaders
Shoutcast V1StreamSource.SHOUTCAST_V1X
Shoutcast V2StreamSource.SHOUTCAST_V2X
IcecastStreamSource.ICECASTX
Raw Stream (icy metadata)StreamSource.STREAMXX
Radionomy ScrapingStreamSource.RADIONOMYXXX

Examples

If you have an audio stream and don’t know what approach to take then simply omit the last method parameter and it will use all available options and return the first one that completes. At the very least the stream method will return something from a valid stream, but it will not support the Bitrate and Listener count.

var internetradio = require('node-internet-radio');
var testStream = "http://23.27.51.2:6699";
internetradio.getStationInfo(testStream, function(error, station) {
  console.log(station);
});

While this approach is easy, it’s not efficient. You should not be hitting invalid resources and slurping down the raw audio feed each time if you don’t need to.

The approach you should take is to find out what source method you want to utilize, cache it, and then only use that going forward. Think about going through each method in order of preference (probably V1, V2, Icecast, Stream) and take note of that for next time.

To fetch the station details using a specific method simply pass it as the last argument using one of the StreamSource constants above.

internetradio.getStationInfo("http://coolstream.net/", function(error, station) {
  console.log(station);
}, internetradio.StreamSource.SHOUTCAST_V1);

Radionomy Support

Because Radionomy begins an ad each time you connect directly to the audio stream you’ll never know what is actually playing. Because of this the option of Radionomy.com scraping to get the track name has been added. This is likely to break in the future any time Radionomy updates their web site.

Server headers

If you are interested in the server headers instead of just the now-playing information use StreamSource.STREAM and you’ll get the server headers from the stream.

{ title: 'Tosca - Zuri',
  fetchsource: 'STREAM',
  headers:
   { 'icy-br': '128',
     'icy-genre': 'Ambient Chill',
     'icy-name': 'Groove Salad',
     'icy-notice1': '<BR>This stream requires <a href="http',
     'icy-notice2': 'SHOUTcast Distributed Network Audio Server/Linux v1.9.5<BR>',
     'icy-pub': '0',
     'icy-metaint': '45000' } }