This module implements the 'Spotify Web' WebSocket protocol that is used onSpotify's Web UI.
Node.js implementation of the Spotify Web protocol
I would bet that the Spotify desktop client is among the top 25 most intricate uses of JavaScript in the world. The Spotify desktop client UI is completely built with JavaScript, resting on top of the same C core that the iOS and Android clients. Getting an access token for a React app from the Spotify API using Node.js and Axios - spotify-axios-basic-auth.js.
This module is heavily inspired by the original open-source Python implementation:Hexxeh/spotify-websocket-api.
InstallationExample
Here's an example of logging in to the Spotify server and creating a session. Thenrequesting the metadata for a given track URI, and playing the track audio filethrough the speakers:
See the
example directory for some more example code.
API
TODO: document!
License
(The MIT License)
Copyright (c) 2013-2014 Nathan Rajlich <[email protected]>
Permission is hereby granted, free of charge, to any person obtaininga copy of this software and associated documentation files (the'Software'), to deal in the Software without restriction, includingwithout limitation the rights to use, copy, modify, merge, publish,distribute, sublicense, and/or sell copies of the Software, and topermit persons to whom the Software is furnished to do so, subject tothe following conditions:
The above copyright notice and this permission notice shall beincluded in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OFMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANYCLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THESOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
This application requires node 4.0.0 or higher!
This should now work with node 6, let me know if that is not the case.
A simple http based API for controlling your Sonos system.
There is a simple sandbox at /docs (incomplete atm)
USAGE
Start by fixing your dependencies. Invoke the following command:
npm install --production
This will download the necessary dependencies if possible.
start the server by running
npm start
Now you can control your system by invoking the following commands:
Example:
http://localhost:5005/living room/volume/15 (will set volume for room Living Room to 15%)
http://localhost:5005/living room/volume/+1 (will increase volume by 1%)
http://localhost:5005/living room/next (will skip to the next track on living room, unless it’s not a coordinator)
http://localhost:5005/living room/pause (will pause the living room)
http://localhost:5005/living room/favorite/mysuperplaylist (will replace queue with the favorite called “mysuperplaylist”)
http://localhost:5005/living room/repeat/on (will turn on repeat mode for group)
The actions supported as of today:
State
Example of a state json:
Queue
Obtain the current queue list from a specified player. The request will accept:
Example queue response:
Preset
A preset is a predefined grouping of players with predefined volumes, that will start playing whatever is in the coordinators queue.
Example preset (state and uri are optional): Do first responders get free spotify premium.
The first player listed in the example, “room1”, will become the coordinator. Playmode defines the three options “shuffle”, “repeat”, “crossfade” similar to the state. Favorite will have precedence over a uri. pauseOthers will pause all zones before applying the preset, effectively muting your system.
presets.json
You can create a file with pre made presets, called presets.json. It will be loaded upon start, any changes requires a restart of the server.
Example content:
In the example, there is one preset called
all , which you can apply by invoking:
http://localhost:5005/preset/all
settings.json
If you want to change default settings, you can create a settings.json file and put in the root folder.
Available options are:
Nodejs Spotify
Example:
Override as it suits you.
Favorites
It has support for starting favorites. Simply invoke:
http://localhost:5005/living room/favorite/[favorite name]
and it will replace the queue with that favorite. Bear in mind that favorites may share name, which might give unpredictable behavior at the moment.
Playlist
Playing a Sonos playlist is supported. Invoke the following:
http://localhost:5005/living room/playlist/[playlist name]
and it will replace the queue with the playlist and starts playing.
Say (TTS support)
Experimental support for TTS. This REQUIRES a registered API key from voiceRSS! See http://www.voicerss.org/ for info.
You need to add this to a file called settings.json (create if it doesn’t exist), like this:
Replace the code above (it is just made up) with the api-key you’ve got after registering.
Action is:
Example:
language code needs to be before volume if specified.
Sayall will group all players, set 40% volume (by default) and then try and restore everything as the way it where. Please try it out, it will probably contain glitches but please report detailed descriptions on what the problem is (starting state, error that occurs, and the final state of your system).
The supported language codes are:
Spotify, Apple Music, and SiriusXM (Experimental)
The following endpoints are available:
You can find Apple Music song and album IDs via the iTunes SearchAPI.
Node.js Download Spotify App
You can specify an artist name, song title, or combination of the two, iTunes search will be searched automatically, and the results will be played. With the radio action you can specify the same and an Apple Music Radio station for the artist or track will be played.
It only handles a single spotify account currently. It will probably use the first account added on your system.
You can specify a SiriusXM channel number or station name and the station will be played.
Experiment with these and leave feedback!
Webhook
NOTE! This is experimental and might change in the future! Please leave your feedback as github issues if you feel like it doesn’t suit your need, since I don’t know what kind of restrictions you will be facing.
If you add a setting in settings.json like this:
Every state change, topology change and volume change will be posted (method POST) to that URL, as JSON. The following data structure will be sent:
or
or
“data” property will be equal to the same data as you would get from /RoomName/state or /zones. There is an example endpoint in the root if this project called test_endpoint.js which you may fire up to get an understanding of what is posted, just invoke it with “node test_endpoint.js” in a terminal, and then start the http-api in another terminal.
Pre-composed raspberry pi image
There is a pre-composed image based on AlpineLinux available for simplicitly. This is a cross-version build that runs on raspberry pi B/B+, 2 and version 3. For more information on AlpineLinux, visit their homepage and read the wiki.
The system will run from a RAM-drive, except for the files related to Sonos HTTP API. Because of this, it should be fairly resistent against powercuts or sudden resets. The tear on the SD-card should only be minimal
The sshd daemon will generate new host keys upon first boot, and persist these for future boots. By default the root user has no password, if you want to set a password, just SSH to that machine and set a new root password.
It also has samba installed by default, and sharing the /flash folder with read/write permissions for easier access. Is spotify free on mobile phone. Just visit sonos from a windows machine or smb://sonos from macOS (replace sonos with the IP if it doesn't work)
To write the image to an SD-card, use the command on Linux and OS X, or Win32DiskWriter for Windows.
Comments are closed.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |