GithubHelp home page GithubHelp logo

floby / node-libspotify Goto Github PK

View Code? Open in Web Editor NEW
103.0 17.0 66.0 1.39 MB

Node bindings for the libspotify C library

Home Page: projects.flo.by/node-libspotify/

Python 0.48% JavaScript 37.61% Shell 0.35% C++ 48.23% C 13.33%

node-libspotify's Introduction

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

node-libspotify's People

Contributors

19h avatar facekapow avatar floby avatar iaincole avatar linusu avatar ronaldevers avatar tcr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

node-libspotify's Issues

[Feature Request] Playlist subsystem support

One feature most of the libspotify binding libraries are missing are bindings into the Playlist subsystem. I have an app, for example, that pulls in random tracks off of specified playlists.

I'd send you a pull request to add this myself, but my lack of C knowledge seems to be holding me back.

'track-end' event sent early

Hi @Floby - awesome work on this project, it's perfect for what I'm doing. I know you haven't touched this in a long while, but I was wondering if you had any thoughts on what might cause the track-end event to be sent early, before the track has played all the way through. From how I understand it, this comes directly from sp_session_callbacks::end_of_track in libspotify. I suppose there could be a bug in libspotify, but it happens probably around a third of the time in my experience.

Compiling Issue

Hey Guys,

Not sure what the issue might be but i can't appear to build the npm on Arch (With raspberry pi hardware) Any Ideas? The build report is below:

Hey Guys,

Having an issue compiling on Arch any ideas?

[email protected] install /home/node/node_modules/libspotify
node-gyp configure build

make: Entering directory '/home/node/node_modules/libspotify/build'
CXX(target) Release/obj.target/libspotify/src/album.o
CXX(target) Release/obj.target/libspotify/src/artist.o
CXX(target) Release/obj.target/libspotify/src/audio.o
CXX(target) Release/obj.target/libspotify/src/binding.o
CXX(target) Release/obj.target/libspotify/src/link.o
In file included from ../src/link.cc:21:0:
../src/playlistcallbacks.cc:105:39: warning: 'nsp_playlistcontainer_callbacks' defined but not used [-Wunused-variable]
CXX(target) Release/obj.target/libspotify/src/player.o
CXX(target) Release/obj.target/libspotify/src/search.o
CXX(target) Release/obj.target/libspotify/src/session.o
../src/session.cc:290:1: error: invalid conversion from 'void ()(sp_session, sp_error)' to 'void ()(sp_session)' [-fpermissive]
../src/session.cc:290:1: error: invalid conversion from 'void ()(sp_session, bool)' to 'void ()(sp_session, sp_error)' [-fpermissive]
../src/session.cc:290:1: warning: missing initializer for member 'sp_session_callbacks::private_session_mode_changed' [-Wmissing-field-initializers]
In file included from ../src/session.cc:20:0:
../src/playlistcallbacks.cc:234:30: warning: 'nsp_playlist_callbacks' defined but not used [-Wunused-variable]
libspotify.target.mk:90: recipe for target 'Release/obj.target/libspotify/src/session.o' failed
make: *** [Release/obj.target/libspotify/src/session.o] Error 1
make: Leaving directory '/home/node/node_modules/libspotify/build'
gyp ERR! build error
gyp ERR! stack Error: make failed with exit code: 2
gyp ERR! stack at ChildProcess.onExit (/usr/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:267:23)
gyp ERR! stack at ChildProcess.EventEmitter.emit (events.js:98:17)
gyp ERR! stack at Process.ChildProcess._handle.onexit (child_process.js:789:12)
gyp ERR! System Linux 3.6.11-14-ARCH+
gyp ERR! command "node" "/usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "configure" "build"
gyp ERR! cwd /home/node/node_modules/libspotify
gyp ERR! node -v v0.10.22
gyp ERR! node-gyp -v v0.11.0
gyp ERR! not ok

Segmentation fault when delivering music

[../deps/mpg123/src/output/coreaudio.c:81] warning: Didn't have any audio data in callback (buffer underflow)

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0x0000000000000000
0x000008c4719245b9 in ?? ()
(gdb) bt
#0  0x000008c4719245b9 in ?? ()
#1  0x000008c4719118b7 in ?? ()
#2  0x000000010018a28c in v8::internal::Invoke ()
#3  0x0000000100146364 in v8::Function::Call ()
#4  0x00000001021055b4 in read_delivered_music (handle=<value temporarily unavailable, due to optimizations>, status=<value temporarily unavailable, due to optimizations>) at ../src/player.cc:132
#5  0x000000010012f60c in uv__run_timers ()
#6  0x0000000100125f7e in uv_run ()
#7  0x000000010000c6e3 in node::Start ()
#8  0x00000001000039f4 in start ()
(gdb) 

Installing as module

it might be obvious, but where do i have to place the "official" libspotify files when installing your library as module in my own app?
trying to install node-libspotify with a plain npm install libspotify --save command and tried various locations for the offical files with no succes.

thanks in advance & thanks for your work!
cheers,
manu

Segmentation fault when loading PlaylistContainer

If you try to use getPlaylistcontainer() on a session before receiving the login callback you'll trigger a segmentation fault. This is of course low prio but I still think that we never should segfault. I'll try to submit a pull request as well.

console.log('This gets printed');
pc = this.session.getPlaylistcontainer();
console.log('This will not...');
Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0x0000000000000028
0x000000010222ffd5 in sp_image_add_load_callback ()
(gdb) bt
#0  0x000000010222ffd5 in sp_image_add_load_callback ()
#1  0x00000001022300c3 in sp_playlistcontainer_add_callbacks ()
#2  0x00000001009de52d in Session_PlaylistContainer (args=<value temporarily unavailable, due to optimizations>) at ../src/session.cc:482
#3  0x000000010016665c in v8::internal::Builtin_HandleApiCall ()
#4  0x00003e4f82e0618e in ?? ()
#5  0x00003e4f8307cf33 in ?? ()
#6  0x00003e4f8306a397 in ?? ()
#7  0x00003e4f82e636f7 in ?? ()
#8  0x00003e4f82e2851e in ?? ()
#9  0x00003e4f82e62fb0 in ?? ()
#10 0x00003e4f82e5de25 in ?? ()
#11 0x00003e4f82e59f16 in ?? ()
#12 0x00003e4f82e492e7 in ?? ()
#13 0x00003e4f82e48cab in ?? ()
#14 0x00003e4f82e2d119 in ?? ()
#15 0x00003e4f82e2c6a5 in ?? ()
#16 0x00003e4f82e245e7 in ?? ()
#17 0x00003e4f82e118b7 in ?? ()
#18 0x000000010018abd7 in v8::internal::Invoke ()
#19 0x0000000100147104 in v8::Function::Call ()
#20 0x000000010000b2f5 in node::Load ()
#21 0x000000010000bdf4 in node::Start ()
#22 0x0000000100003034 in start ()
(gdb) 

Error when trying to retrieve playlists

Hi again! You guys are probably going to quite bored with my 'issues'.

I'm trying to get the users playlists, but all I keep getting is an empty error when I run my script.

Output:

➜  spode git:(master) ✗ node src/server.js

Error:

My script looks like this:

// Skip all the require stuff
session.login(cred.login, cred.password);

session.once('login', function (err) {
    if(err) this.emit('error', err);

    // I'm logged in, now what?!
    // Let's get a list of playlists!
    var plContainer = session.getPlaylistcontainer();
    plContainer.getPlaylists(function (a) {
        console.log(a);
    });
});

I would expect to see whatever 'a' contains in the callback.

Having followed the code path, it appears as though the error is coming from PlaylistContainer::_readyOrThrow. I'm guessing the sp_playlistcontainer isn't loaded by the time the callback triggers. Any idea why?

Thanks,

Make user of this lib only deal with loaded objects?

This is something I'd like to discuss with people actually using this lib.

I first tried to stick as closely as possible to the C API, just adding some javascript sugar and grouping namespaced C functions to objects.

But it seems to me that the Node Way would tell us to give users only ready objects.

Feel free to comment.

player.flush doesn't work

Is Player.flush suppose to clear out the player buffer so you can load in the next track and continue playing or is there a different way to play the next track in a list?

Memory leak when playing

Hi, I use your module since few days and it works pretty well.
I have just one issue that i'm not able to fix, so I supposed it's a problem on your module or libspotify (I'm not able to determine what is going wrong)

I use node 0.10.23 with the 0.7.0 version of libspotify and I try to make a streamable url from the return of the usenodejsaudio callback.

I use express and I send the buffer returned by this callback to my express responses. At this time, the memory usage of my node application increase at the same speed of receiving buffer from the 'useNodejsAudio'. But when the playing is done, the memory seems not to be free. So I suppose it is a leak ?

If I can provide more information or test for you, let me know.
Thanks for this awesome plugin

Should all object be available through the session?

Hi,

I'm wondering what peoples thoughts would be on interacting with all sub systems via single session object?

I think it makes the API a little cleaner.

Example chanegs to libspotify.js:

// **libspotify.js
var Session = require('./Session');
var b = require('bindings')('spotify.node');

function Spotify (config) {
    this.config = config || {};
}

Spotify.prototype.login = function (user, pass, cb) {
    var sess = new Session({
        applicationKey: this.config.applicationKey
    });

    // Use callback as main event handler
    sess.login(user, pass, cb);
}

exports = Spotify;

Example changes to session.js:

Session.prototype.login = function login(login, password, cb) {
    if('string' != typeof login) throw new TypeError('login should be a string');
    if('string' != typeof password) throw new TypeError('password should be a string');
    if('function' != typeof cb) cb = function () {};
    var self = this;
    this.once('login', function (err) {
        return cb(err, self);
    });
    b.session_login(this._sp_session, login, password);
 };

+Session.prototype.search = function (query, options, cb) {
    var s = new Search(this._sp_session, query);
    s.once('ready', cb);
    for (var i in options) {
        s[i] = options[i];
    }
    // Run the search
    s.execute();
}

In your script:

// Create new Spotify instance
var Spotify = new sp.Spotify({
    applicationKey: __dirname + '/../conf/spotify_appkey.key'
});

// Login and find something to play
Spotify.login(cred.login, cred.password, function (err, session) {
    console.log(session); // should log Session object
    // session is now an object to work with.
    // all processing/searching/playing would be done via session.
    session.search('sometrack', {trackCount:20}, function (err, search) {
        console.log(search); // Should log the Search object
    });
});

Public AppKey

It's possible to find out where you store your appkey and download it

npm install OSX Mountain Lion fails

Hi,

I don't know if I'm doing something wrong, but running npm install after cloning fails. The output I get is as follows:

node-libspotify git:(master)# npm install                                                                                                                                                        [3/314]

> [email protected] install /Users/me/Github/node-libspotify
> node-gyp configure build

  SOLINK_MODULE(target) Release/spotify.node
ld: library not found for -lspotify
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [Release/spotify.node] Error 1
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:256:23)
gyp ERR! stack     at ChildProcess.EventEmitter.emit (events.js:98:17)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (child_process.js:754:12)
gyp ERR! System Darwin 12.2.0
gyp ERR! command "node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "configure" "build"
gyp ERR! cwd /Users/me/Github/node-libspotify
gyp ERR! node -v v0.10.0
gyp ERR! node-gyp -v v0.8.5
gyp ERR! not ok
npm ERR! [email protected] install: `node-gyp configure build`
npm ERR! `sh "-c" "node-gyp configure build"` failed with 1
npm ERR!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is most likely a problem with the libspotify package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-gyp configure build
npm ERR! You can get their info via:
npm ERR!     npm owner ls libspotify
npm ERR! There is likely additional logging output above.

npm ERR! System Darwin 12.2.0
npm ERR! command "/usr/local/bin/node" "/usr/local/bin/npm" "install"
npm ERR! cwd /Users/me/Github/node-libspotify
npm ERR! node -v v0.10.0
npm ERR! npm -v 1.2.14
npm ERR! code ELIFECYCLE
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR!     /Users/me/Github/node-libspotify/npm-debug.log
npm ERR! not ok code 0

I'm guessing the error is "ld: library not found for -lspotify". However, I don't quite know what means. And I thought I'd managed to get libspotify installed. Could someone please inform me how check if it is?

Thanks

CHECK(allow_empty_handle || that != __null) failed

This seems to happen from time to time when playing. I think that the buffer underflow always happens right before.

[../deps/mpg123/src/output/coreaudio.c:81] warning: Didn't have any audio data in callback (buffer underflow)


#
# Fatal error in ../deps/v8/src/api.h, line 297
# CHECK(allow_empty_handle || that != __null) failed
#

[1]    665 abort      node .

spotify.createFromLink no longer working?

hi there,

i got this little script to play audio from libspotify. even though it was flaky from the get go, two days ago it completely stopped working. according to the trace file, there's still stuff happening, but spotify.createFromLink(uri) never loads...

const album = spotify.createFromLink(u)
if (!album) return queueNext(resume)
if (album.isLoaded) return albumIsLoaded(album)
spotify.waitForLoaded([album], albumIsLoaded)

function albumIsLoaded (loadedAlbum) { ... never called ...}

what am i doing wrong?

> node -v
v6.6.0

Is this project dead?

I want to work with libspotify and I rather working with node, but If it's this is dead I will have another way.

Segmentation fault

Finally! I managed to catch this while I was running under gdb. This has been bugging me for a long while now and seems to happen very rarely.

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0x0000000000000020
0x00000001022509de in sp_error_message ()
(gdb) bt
#0  0x00000001022509de in sp_error_message ()
#1  0x00000001021678ac in do_notify_handle ()
#2  0x000000010224d1f8 in sp_session_process_events ()
#3  0x0000000102106fac in Session_Process_Events (args=<value temporarily unavailable, due to optimizations>) at ../src/session.cc:458
#4  0x000019532880aafb in ?? ()
#5  0x00001953289d59c2 in ?? ()
#6  0x00001953288d602f in ?? ()
#7  0x00001953289d557e in ?? ()
#8  0x0000195327e0a96e in ?? ()
#9  0x0000195327e245e1 in ?? ()
#10 0x0000195327e118b7 in ?? ()
#11 0x000000010018a28c in v8::internal::Invoke ()
#12 0x0000000100146364 in v8::Function::Call ()
#13 0x0000000100008802 in node::MakeCallback ()
#14 0x00000001000088f5 in node::MakeCallback ()
#15 0x0000000100023a88 in node::TimerWrap::OnTimeout ()
#16 0x000000010012f60c in uv__run_timers ()
#17 0x0000000100125f7e in uv_run ()
#18 0x000000010000c6e3 in node::Start ()
#19 0x00000001000039f4 in start ()
(gdb) 

utils.js cannot set property 'prototype' of undefined

When runing tests i get this error:

domain.js:66
    throw er;
          ^
TypeError: Cannot read property 'prototype' of undefined
    at Object.exports.inherits (util.js:538:43)
    at Object.<anonymous> (/Users/gilbert/Downloads/node-libspotify-master/lib/Player.js:31:6)
    at Module._compile (module.js:449:26)
    at Object.Module._extensions..js (module.js:467:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:362:17)
    at require (module.js:378:17)
    at Object.<anonymous> (/Users/gilbert/Downloads/node-libspotify-master/lib/libspotify.js:3:18)
    at Module._compile (module.js:449:26)
    at Object.Module._extensions..js (module.js:467:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:362:17)
    at require (module.js:378:17)
    at Object.<anonymous> (/Users/gilbert/Downloads/node-libspotify-master/test/test-000-config.js:2:10)
    at Module._compile (module.js:449:26)
    at Object.Module._extensions..js (module.js:467:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:362:17)
    at require (module.js:378:17)
    at /Users/gilbert/Downloads/node-libspotify-master/node_modules/nodeunit/lib/nodeunit.js:75:37
    at _concat (/Users/gilbert/Downloads/node-libspotify-master/node_modules/nodeunit/deps/async.js:508:13)
    at async.forEachSeries.iterate (/Users/gilbert/Downloads/node-libspotify-master/node_modules/nodeunit/deps/async.js:118:13)
    at async.forEachSeries.iterate (/Users/gilbert/Downloads/node-libspotify-master/node_modules/nodeunit/deps/async.js:129:25)
    at _concat (/Users/gilbert/Downloads/node-libspotify-master/node_modules/nodeunit/deps/async.js:510:17)
    at exports.runModule (/Users/gilbert/Downloads/node-libspotify-master/node_modules/nodeunit/lib/core.js:164:9)
    at _concat (/Users/gilbert/Downloads/node-libspotify-master/node_modules/nodeunit/deps/async.js:513:13)
    at async.forEachSeries (/Users/gilbert/Downloads/node-libspotify-master/node_modules/nodeunit/deps/async.js:114:20)
npm ERR! Test failed.  See above for more details.
npm ERR! not ok code 0

I get a very similar error when running node play.js in the examples folder

Assertion error

This happened on a crappy connection...

Assertion failed: (val->IsObject()), function Data, file /Users/linus/.node-gyp/0.10.18/src/node_buffer.h, line 76.

Segmentation fault

I'm trying to run the example form the readme but without luck. I get a segmentation fault error:

[1]    47020 segmentation fault  node script.js

Going stept by step with a console log, it appears to be breaking here:

this._sp_session = b.session_create(session_config);

problems with compiling during npm install

I'm trying to setup a nodejs server with libspotify on a raspberrypi. I have libspotify v12.1.103beta installed to work with the hard float version of Raspbian (latest). I ran 'make install' in libspotify then tried to run 'npm install' on my project to compile node-libspotify and I get this error:

[email protected] install /home/pi/app/node_modules/libspotify
node-gyp configure build

make: Entering directory /home/pi/app/node_modules/libspotify/build' CXX(target) Release/obj.target/libspotify/src/album.o CXX(target) Release/obj.target/libspotify/src/artist.o CXX(target) Release/obj.target/libspotify/src/audio.o CXX(target) Release/obj.target/libspotify/src/binding.o CXX(target) Release/obj.target/libspotify/src/link.o ../src/playlistcallbacks.cc:105:39: warning: ‘nsp_playlistcontainer_callbacks’ defined but not used [-Wunused-variable] CXX(target) Release/obj.target/libspotify/src/player.o CXX(target) Release/obj.target/libspotify/src/search.o CXX(target) Release/obj.target/libspotify/src/session.o ../src/session.cc:290:1: error: invalid conversion from ‘void (*)(sp_session*, sp_error)’ to ‘void (*)(sp_session*)’ [-fpermissive] ../src/session.cc:290:1: error: invalid conversion from ‘void (*)(sp_session*, bool)’ to ‘void (*)(sp_session*, sp_error)’ [-fpermissive] ../src/session.cc:290:1: warning: missing initializer for member ‘sp_session_callbacks::private_session_mode_changed’ [-Wmissing-field-initializers] ../src/playlistcallbacks.cc:234:30: warning: ‘nsp_playlist_callbacks’ defined but not used [-Wunused-variable] make: *** [Release/obj.target/libspotify/src/session.o] Error 1 make: Leaving directory/home/pi/app/node_modules/libspotify/build'
gyp ERR! build error
gyp ERR! stack Error: make failed with exit code: 2
gyp ERR! stack at ChildProcess.onExit (/opt/node/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:267:23)
gyp ERR! stack at ChildProcess.EventEmitter.emit (events.js:98:17)
gyp ERR! stack at Process.ChildProcess._handle.onexit (child_process.js:789:12)
gyp ERR! System Linux 3.6.11+
gyp ERR! command "node" "/opt/node/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "configure" "build"
gyp ERR! cwd /home/pi/app/node_modules/libspotify
gyp ERR! node -v v0.10.11
gyp ERR! node-gyp -v v0.10.0
gyp ERR! not ok
npm ERR! weird error 1
npm ERR! not ok code 0

There isn't any documentation about version 12.1.103 libspotify so I'm having trouble figuring out whats wrong. Thought you might be able to figure it out.

[0.2.1] Wrong-type lookups

Exceptions should have taken a look at; currently, node dies [from C++ land] when a function of specific type (Album, Artist, Playlist et al.) is used to query a url of different type. (e.g. the album url of Random Access Memories by Daft Punk is used as parameter to query the Artist [Album->Artist]).

We could encounter this issue by obtaining the type of the given url and query its information, when possible. (Album->Artist should be possible, Artist->Album should throw an exception, etc.).

audio quality gets worse when playing song after song after song...

Hey folks.
Great Library you're working on!

When i play one song after another (...and so on) the quality gets worse.
It could be a desync between the L and R channel or something else.

it doesnt matter if i use the node-speaker or aplay player. so it looks like its the audio stream from spotify.

the code:
sidenote: i added Player.isPlaying attribute. this is just the spotify.js file. it wont run.

module.exports = function()
{

    var libspotify = require('libspotify');
    var config = require('../config.json');
    var Speaker = require('speaker');
    var audioOptions = {channels: 2, bitDepth: 16, sampleRate: 44100};
    var self = this;
    this.currentList = null;
    this.maxTrackCount = config.maxTrackCount || 12;

    this.search = function(data, callback)
    {
        console.log('spotify search');
        if(!self.session)
        {
            self.createSession();
        }
        var search = new libspotify.Search(data);
        search.trackCount = self.maxTrackCount;
        search.execute();
        search.once('ready', function() {
            if(!search.tracks.length) {
                console.error('there is no track to play :[');
                callback({error: 'there is no track to play :['});
            }
            else
            {
                self.currentList = search.tracks;
                callback(search.tracks);
                //console.log(search.tracks);
            }
        });
    };

    this.startPlayer = function(data, callback)
    {
        if( self.player && self.player.isPlaying )
        {
            self.player.stop();
        }
        if(self.session)
        {
            var track = self.currentList[data];
            self.player = self.session.getPlayer();
            self.player.load(track);
            self.player.play();
            self.player.pipe(new Speaker( audioOptions ));

            console.error('playing track. end in %s', track.humanDuration);

            self.player.once('track-end', function() {
                console.error('track ended');
                if(typeof callback === "function")
                {
                    callback();
                }
                self.player.stop();
                session.close();
            });
        }
        else
        {
            return false;
        }
    };

    this.stopPlayer = function()
    {
        console.log('stop Player');
        if(self.player)
        {
            self.player.stop();
        }

    };

    this.createSession = function()
    {
        console.log('spotify create Session');
        self.session = new libspotify.Session({
            applicationKey: __dirname + '/../spotify_appkey.key'
        });
        self.session.login(config.credentials.login, config.credentials.password);
        return self;
    };

    return {
        search: search,
        stopPlayer : stopPlayer,
        startPlayer : startPlayer
    };
};

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.