Node bindings to the libspotify C library
Node bindings for the libspotify C library
This is still very alpha, but you can already play around I suppose
Please note that you must have the libspotify library installed on your system you can get it from here.
You must provide your own spotify application key, because I'm not giving mine away :] You also must provide valid credentials for a spotify account.
Once you cloned the repository run
npm install then test the module with
As there are already a number of spotify bindings or modules for the REST API, the main goal
of this module is not to give access to the artist and tracks catalog. It's main purpose is
to allow for playback of the tracks. The idea is to expose a
Player object in which the user
can load tracks, play them, and get decompressed audio data from it (as provided by the libspotify C library).
What the user can do with the audio stream is up to him/her. As it is raw PCM data, it is easy to pipe to some kind of encoder (like gstreamer) in order to broadcast music or stream it to a web user (as long as it complies with the Spotify terms of service ;).
The main goal is now achieved. Audio data is exposed as the Player object which behaves like a readable stream.
Here is a code snippet of how to play a track from spotify
var sp = require'../lib/libspotify';var cred = require'../spotify_key/passwd';var spawn = require'child_process'spawn;var session =applicationKey: __dirname + '/../spotify_key/spotify_appkey.key';sessionlogincredlogin credpassword;sessiononce'login'iferr thisemit'error' err;var search = 'artist:"rick astley" track:"never gonna give you up"';searchtrackCount = 1; // we're only interested in the first result;searchexecute;searchonce'ready'if!searchtrackslengthconsole.error'there is no track to play :[';sessionlogout;var track = searchtracks0;var player = sessiongetPlayer;playerloadtrack;playerplay;// linuxvar play = spawn'aplay' '-c' 2 '-f' 'S16_LE' '-r' '44100';// osx with `brew install sox`var play = spawn'play' '-r' 44100 '-b' 16 '-L' '-c' 2 '-e' 'signed-integer' '-t' 'raw' '-';playerpipeplaystdin;console.error'playing track. end in %s' trackhumanDuration;playeron'data'// buffer.length// buffer.rate// buffer.channels// 16bit samples;playeronce'track-end'console.error'track ended';playerstop;sessionclose;;;;