• Stars
    star
    103
  • Rank 325,755 (Top 7 %)
  • Language
    C++
  • Created over 11 years ago
  • Updated almost 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Node bindings for the libspotify C library

Build Status

node-libspotify

Node bindings for the libspotify C library

This is still very alpha, but you can already play around I suppose

Install & test

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 npm test.

Main objectives

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 user can also choose to play the song locally with a node module like speaker or pipe the audio data to another process like aplay.

The main goal is now achieved. Audio data is exposed as the Player object which behaves like a readable stream.

Snippet

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 = new sp.Session({
    applicationKey: __dirname + '/../spotify_key/spotify_appkey.key'
});
session.login(cred.login, cred.password);
session.once('login', function(err) {
    if(err) this.emit('error', err);

    var search = new sp.Search('artist:"rick astley" track:"never gonna give you up"');
    search.trackCount = 1; // we're only interested in the first result;
    search.execute();
    search.once('ready', function() {
        if(!search.tracks.length) {
            console.error('there is no track to play :[');
            session.logout();
        }

        var track = search.tracks[0];
        var player = session.getPlayer();
        player.load(track);
        player.play();

        // linux
        var 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', '-']);

        player.pipe(play.stdin);

        console.error('playing track. end in %s', track.humanDuration);
        player.on('data', function(buffer) {
            // buffer.length
            // buffer.rate
            // buffer.channels
            // 16bit samples
        });
        player.once('track-end', function() {
            console.error('track ended');
            player.stop();
            session.close();
        });
    });
});

TODO

  • Bind to the rest of the API...

Credits

Thanks to IainCole for his help on the playlist subsystem. Thanks to LinusU and swissmanu for their help on album cover retreivals

More Repositories

1

node-tokenizer

A tokenizer that looks like a stream for JavaScript and node.js
JavaScript
100
star
2

node-json-streams

Streams for parsing and stringifying large JSON objects without buffering
JavaScript
79
star
3

node-url-assembler

Assemble urls from route-like templates (/path/:param)
JavaScript
39
star
4

node-parser

a generic parser to parse whatever you want in node.js
JavaScript
25
star
5

node-stream-stream

A stream of streams in order to concatenate the contents of several streams
JavaScript
21
star
6

konga-cli

Command-line client for the Kong admin (http://getkong.org)
JavaScript
18
star
7

node-blue

JSP-like, streamed template engine
JavaScript
14
star
8

node-envie

A tiny module to read and document environment configuration
JavaScript
12
star
9

vim-config

My vim config
Vim Script
11
star
10

node-stream-sink

Collect all data piped to this stream when it closes
JavaScript
11
star
11

node-stream-json-stringify

JSON.stringify, streaming, non-blocking, for real this time.
JavaScript
10
star
12

node-lines

tiny utility to process streams line per line
JavaScript
9
star
13

node-sse-writer

Creates a text/event-stream stream as specified by the WD-eventsource W3C recommendation
JavaScript
8
star
14

node-meme

Generate memes from http://memegenerator.net - largely inspired by drbrain/meme
JavaScript
8
star
15

node-umzug-dynamodb-storage

A storage backend for migrating dynamoDB tables with umzug
JavaScript
5
star
16

node-json-tokenizer

A streaming JSON tokenizer
JavaScript
5
star
17

node-disect

Bisection helper for Javascript
JavaScript
4
star
18

node-duplex-maker

Create a duplex stream from a writable and a readable
JavaScript
3
star
19

node-stream-blackhole

A silly writable stream that eats all data
JavaScript
3
star
20

hashtag-influenceur

Un jeu de carte oรน l'on incarne un influenceur linkedin
JavaScript
3
star
21

node-catstream

Filenames go in, contents come out. You can't explain that.
JavaScript
3
star
22

node-voice

A bit of code to make my computer speak remotely
JavaScript
3
star
23

node-object-iterator

A module to walk through an object with an iterator
JavaScript
3
star
24

git-split

yet another script to split subtrees apart in submodules
Shell
3
star
25

Drupal-Semaine-CMS

Projet CMS Hetic
PHP
2
star
26

node-microauth2

Minimal tool to start securing your API with OAuth2
JavaScript
2
star
27

node-services-as-promised

A DI container using promises
JavaScript
2
star
28

lambda-left-pad

left-pad as a service
JavaScript
2
star
29

Purple

Apache Module for Server-Side JavaScript
C++
2
star
30

mocha-rest-interface

Specify your REST endpoints behaviours like a pro and generate their docs
JavaScript
2
star
31

node-exist

eXist XML database REST API wrapper
JavaScript
2
star
32

node-ka-ching

A caching module for streams
JavaScript
2
star
33

node-http-measuring-client

Like the http module, except with stats
JavaScript
2
star
34

node-deep-getset

Utilities to get and set stuff on deeply nested structures
JavaScript
1
star
35

npmake

Make with all your local npm modules
JavaScript
1
star
36

nigel

Proof of concept of a prototype-oriented CMS
JavaScript
1
star
37

questionnaire-snapcity

JavaScript
1
star
38

Node-Websockets-Test

JavaScript
1
star
39

node-prophet

CLI Wizard utility, with promises
JavaScript
1
star
40

jest-expect-error

missing `expect.error()` from jest as `expectError()`
JavaScript
1
star
41

article-les-statuts-ca-pue

CSS
1
star
42

node-cache-depend

A utility function to detect when you should invalidate your cached data
JavaScript
1
star
43

node-geste

A small module with an executable that calls a requirable jest-cli
JavaScript
1
star
44

dumbal.flo.by

A website / mobile app to keep the score when playing Dumbal.
JavaScript
1
star
45

npm2dock

Convert any npm package into a runnable container
Shell
1
star
46

node-sse-reader

reads a text/event-stream stream as specified by the WD-eventsource W3C recommendation
JavaScript
1
star
47

shi-flo-by

Online real-time shi fu mi with leapmotion support.
JavaScript
1
star
48

floby.github.com

JavaScript
1
star
49

centurion-module-search

Wide purpose search module for Centurion CMS
1
star
50

nodejsparis-addons

Les addons natifs binaires en node.js avec libspotify
JavaScript
1
star
51

node-office-music

A small local webapp to play music in an openspace office
1
star
52

node-stream-write-read

Write to a file, read when it's done
JavaScript
1
star
53

node-dummy-streaming-array-parser

A stream for getting each line of a JSON array
JavaScript
1
star
54

mosic

Mocha + Sinon + Chai as a single setup + other stuff maybe
JavaScript
1
star
55

Echo

A P2P decentralized Instant Messenger
JavaScript
1
star