Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] local API for play/pause/skip, etc... #457

Closed
m-a-x-i-m-z opened this issue Apr 9, 2020 · 14 comments
Closed

[Feature Request] local API for play/pause/skip, etc... #457

m-a-x-i-m-z opened this issue Apr 9, 2020 · 14 comments

Comments

@m-a-x-i-m-z
Copy link

m-a-x-i-m-z commented Apr 9, 2020

I'm using librespot embedded in moodeaudio suite as a headless player based on raspberry-pi zero. In general it's great, but what I'm missing is a possibility to stop/start playback and also skip to the next song in the list (to be activated by the remote control, which is wired and is waiting to be supported by the software).

librespot-java has a local socket-based API, which can be conveniently used from a command line or potentially from a local IR daemon in my case. However, I'm not convinced that running a java thing on the pi-zero hardware is a good idea...

So IDEALLY I would love to know, whether there is a similar API in librespot or whether it can be easily hacked in.

ALTERNATIVELY: I am aware of the official WEB API, however, I'm missing a way of acquiring credentials and IDs of the current spotify user. The player is installed in the living room and is used by five people/accounts, so hard-wiring the login/credentials into the IR event scripts is not an option. But even though it feels strange, that for stopping/pausing the playback locally I have to send a request to a remote server, I would do so if I was aware of getting the bits and pieces needed for forming a spotify's WEB-API request.

Any input is greatly appreciated!

--Max

@bluepuma77
Copy link

spotifyd is a "related project" in Rust using librespot, there is a similar feature request.

I have the same challenge, would like to use Spotify Connect and still control music.

Lets see if one of the projects implements this feature 😃

@ashthespy
Copy link
Member

ashthespy commented Apr 13, 2020

I implemented a simple socket over at Vollibrespot that should could someday work its way into librespotd, the fabled daemon version of the librespot library ;-)

@m-a-x-i-m-z
Copy link
Author

Good pointers, thanks! I'll keep searching... too bad I don't speak Rust... And even if I did it would include setting up a complete cross-compile tool chain for RPI...

@ashthespy
Copy link
Member

ashthespy commented Apr 15, 2020

Good pointers, thanks! I'll keep searching... too bad I don't speak Rust... And even if I did it would include setting up a complete cross-compile tool chain for RPI...

FWIW, you could grab a pre-compiled release from https://github.com/ashthespy/Vollibrespot/releases/

The armv6l version should run on all raspbian images..

@m-a-x-i-m-z
Copy link
Author

m-a-x-i-m-z commented Apr 16, 2020

FWIW, you could grab a pre-compiled release from https://github.com/ashthespy/Vollibrespot/releases/tag/v0.1.9

The armv6l version should run on all raspibian images..

OK, it does start, indeed. Great, many thanks! However, now I see two further problems :

  1. the librespot version shipped with moode-player uses option --onevent /var/local/www/commandw/spotevent.sh which does'n seem to be supported by vollibrespot
  2. I've seen some bits and pieces regarding the control socket communication, but not enough to get a picture how it is supposed to work.

I imagine that the simple feedback mechanism of librespot was superseded by the socket mechanism of vollibrespot, so point 1 may be solvable somehow in the end. But for that I need more info about point 2. Any hints?

Thanks in advance!

@ashthespy
Copy link
Member

ashthespy commented Apr 17, 2020

@m-a-x-i-m-z vollibrespot was born as a way to pipe metadata to a Volumio plugin, so it caters more to that need, the --onevent was moot as events are instead exposed over a socket and can be used from there. nc -ulp 5030 should give you typical events exposed currently..

It's not meant to be a drop-in replacement for librespot. I was under the impression you wanted to roll your own interface, it should be quiet simple though - ashthespy/Volumio-SpotifyConnect should give you a simple nodejs based implementation.

But this is all a stopgap, and a long term solution would be to have different metadata providers (websocket/REST/socket) etc similar to how we currently have our backends baked into librespotd

@txoof
Copy link

txoof commented May 2, 2020

@ashthespy
Thanks for the tip on vollibrespot.

I'm trying to pull the "now playing" JSON data from spotify so I can use it for this project:
https://github.com/txoof/slimpi_epd

I've successfully managed to start up vollibrespot; I'd like to connect to it and start pulling the JSON, but I'm not sure where to begin.

Thanks!

@ashthespy
Copy link
Member

@txoof nice project, I have been meaning to do something similar with some nfc cards as well. If you hop onto gitter, I can help you without spamming everyone here ;-)

@HBeserra
Copy link

if librespot receives a scope and generates the token, the rest can be done by another application

@ashthespy
Copy link
Member

@HBeserra it does that already - check out keymaster::get_token

@HBeserra
Copy link

@ashthespy As I understand it, the get_token () function will generate a token based on a section, scope and client_id, but I would like to receive the most recent token from the connected user.

@ashthespy
Copy link
Member

ashthespy commented Jul 24, 2020

get_token() lets you generate a token (access_token in Spotify's parlance, that with the appropriate scopes can be passed out to an external application that can then control playback, retrieve metadata, or basically what ever Spotify's API's allow you to do..

Not sure what you mean by "the most recent token from the connected user" here..
Ah - get_token returns a token for the user attached to the current authenticated Session

@HBeserra
Copy link

My goal is to define a scope and export the valid acess_token to another application and update it from time to time.

I didn't find any reference to the function in code besides the keymaster, our a documentation about. Is there any documentation or other repository?

@ashthespy
Copy link
Member

@HBeserra Just added #512 as a simple example.

The core library only provides you a way to fetch an API token, and doesn't keep track of the expiry of the token and refresh it. But that is trivial to manage in your end application.. :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants