Install via npm (node) or bower (browser):
$ npm install spotify.js
$ bower install spotify
Spotify search capabilities with the following features:
- Operate in the browser (direct inclusion or requirejs) or node
- Throttle requests as per the Spotify terms of service
- Automatically traverse multi-page results
- Tested.
spotify.artists('pixies', function(err, artists) {
console.log('Artists results:', artists);
spotify.albums('Doolittle', function(err, albums) {
console.log('Album results:', albums);
spotify.tracks('Debaser', function(err, tracks) {
console.log('Track results:', tracks);
});
});
});
// Or, stream results as they arrive ...
spotify.tracks('love').forEach(function(track) {
if (track === null) {
// finished
} else {
console.log('Track result:', track);
}
});
Use with either requirejs or raw include.
jQuery is required, so use the require-jquery approach:
<script data-main="/path/to/spotify.js" src="/path/to/require-jquery.js"></script>
<script>
require(['spotify'], function(spotify) {
spotify.albums('doolittle', function(err, albums) {
console.log(albums);
});
});
</script>
<script src="jquery.min.js" type="text/javascript"></script>
<script src="/path/to/spotify.js" type="text/javascript"></script>
<script type="text/javascript">
spotify.albums('doolittle', function(err, albums) {
console.log(albums);
});
</script>
var spotify = require('spotify.js');
spotify.albums(query, function(err, albums) {
console.log(albums);
});
- @gyllstromk
- @tusbar