Skip to content

Commit

Permalink
Merge pull request #200 from svrooij/master
Browse files Browse the repository at this point in the history
Some work on all Spotify releated issues
  • Loading branch information
svrooij authored Jan 3, 2018
2 parents 814398b + 9a53a3a commit 89662eb
Show file tree
Hide file tree
Showing 5 changed files with 193 additions and 134 deletions.
48 changes: 35 additions & 13 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ Get Current Muted

### Sonos.prototype.play = function(uri, callback) ###

Resumes Queue or Plays Provided URI
Resumes Queue or adds provided url to queue and starts playing
#### Parameters ####

* uri *String* Optional - URI to Audio Stream, also supports Spotify resource ids (see notes)
Expand All @@ -148,11 +148,32 @@ Resumes Queue or Plays Provided URI
*Void* undefined

#### Notes ####
```text
spotify:track:<id>
spotify:album:<id>
spotify:artistTopTracks:<id>
spotify:user:<userid>:playlist:<id>
```
spotify:track:<id>
spotify:album:<id>
spotify:artistTopTracks:<id>
spotify:user:<userid>:playlist:<id>
* * *

### Sonos.prototype.playWithoutQueue = function(uri, callback) ###

Plays an uri without using the queue
#### Parameters ####

* uri *String* Optional - URI to Audio Stream, also supports Spotify resource ids (see notes)
* callback *Function* (err, playing)

#### Returns ####

*Void* undefined

#### Notes ####
```text
spotify:track:<id>
spotify:album:<id>
spotify:artistTopTracks:<id>
spotify:user:<userid>:playlist:<id>
```
* * *

Expand Down Expand Up @@ -241,7 +262,7 @@ Play previous in queue
Queue a Song Next
#### Parameters ####

* uri *String* URI to Audio Stream
* uri *String* URI to Audio Stream, also supports Spotify resources ids (see play)
* callback *Function* (err, queued)

#### Returns ####
Expand All @@ -252,7 +273,7 @@ Queue a Song Next

### Sonos.prototype.playTuneinRadio = function(stationId, stationTitle, callback) ###

Add tunein radio station to the queue
Directly plays a TuneIn station (queue isn't used)
#### Parameters ####

* stationId *String* tunein radio station id
Expand All @@ -267,7 +288,7 @@ Add tunein radio station to the queue

### Sonos.prototype.playSpotifyRadio = function(artistId, artistName, callback) ###

Add a song to the queue
Starts playing the artists radio (queue isn't used)
#### Parameters ####

* artistId *String* Spotify Id to for artist (e.g. ```spotify:artist:<id>```)
Expand Down Expand Up @@ -295,11 +316,12 @@ defaults to end of queue, 0 to explicitly set end of queue)
*[type]* undefined

#### Notes ####
```
spotify:track:<id>
spotify:album:<id>
spotify:artistTopTracks:<id>
spotify:user:<userid>:playlist:<id>

```text
spotify:track:<id>
spotify:album:<id>
spotify:artistTopTracks:<id>
spotify:user:<userid>:playlist:<id>
```
* * *

Expand Down
25 changes: 15 additions & 10 deletions examples/playSpotifyMusic.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var Sonos = require('../').Sonos
var Regions = require('../').SpotifyRegion
var sonos = new Sonos(process.env.SONOS_HOST || '192.168.2.11')

sonos.setSpotifyRegion(Regions.EU)
// This example demonstrates playing various spotify uri types.
// The Spotify uris can be obtained by using the Spotify
// REST apis:
Expand All @@ -9,18 +10,22 @@ var sonos = new Sonos(process.env.SONOS_HOST || '192.168.2.11')
// Or by using a scoped internet search and scraping the results:
// e.g. "A night at the opera site:spotify.com"
//
// And right from spotify, click the three dots => share => Copy spotify uri
//
// Spotify uri examples:
// Bohemian Rhapsody track - spotify:track:1AhDOtG9vPSOmsWgNW0BEY
// A night at the opera album - spotify:album:1TSZDcvlPtAnekTaItI3qO
// Top tracks by Queen - spotify:artistTopTracks:1dfeR4HaWDbWqFHLkxsg1d
// Top Tracks by Guus Meeuwis spotify:artistTopTracks:72qVrKXRp9GeFQOesj0Pmv
// Queen playlist (public user) - spotify:user:lorrainehelen:playlist:2ytnaITywUiPoS9JDYig5I
// Summer rewind by Spotify - spotify:user:spotify:playlist:37i9dQZF1DWSBi5svWQ9Nk
//
// This assumes you have the Spotify music service connected to
// your Sonos system.

var spotifyUri = 'spotify:track:1AhDOtG9vPSOmsWgNW0BEY'
var spotifyUri = 'spotify:artistTopTracks:72qVrKXRp9GeFQOesj0Pmv'

this.sonos.play(spotifyUri, (err, result) => {
sonos.play(spotifyUri, (err, result) => {
if (err) {
return console.log(err)
}
Expand All @@ -31,11 +36,11 @@ this.sonos.play(spotifyUri, (err, result) => {
// artistName is just a string to be used in the Sonos Queue
// as the name for the radio station playlist.

var artistId = '1dfeR4HaWDbWqFHLkxsg1d'
var artistName = 'Queen'
// var artistId = '1dfeR4HaWDbWqFHLkxsg1d'
// var artistName = 'Queen'

sonos.playSpotifyRadio(artistId, artistName, (err, result) => {
if (err) {
return console.log(err)
}
})
// sonos.playSpotifyRadio(artistId, artistName, (err, result) => {
// if (err) {
// return console.log(err)
// }
// })
2 changes: 1 addition & 1 deletion examples/playTuneinRadio.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var sonos = new Sonos(process.env.SONOS_HOST || '192.168.2.11')
var stationId = '34682'
var stationTitle = '88.5 | Jazz24 (Jazz)'

sonos.playSpotifyRadio(stationId, stationTitle, (err, result) => {
sonos.playTuneinRadio(stationId, stationTitle, (err, result) => {
if (err) {
return console.log(err)
}
Expand Down
Loading

0 comments on commit 89662eb

Please sign in to comment.