jishi / node-sonos-http-api

An HTTP API bridge for Sonos easing automation. Hostable on any node.js capable device, like a raspberry pi or similar.
http://jishi.github.io/node-sonos-http-api/
MIT License
1.84k stars 461 forks source link

Spotify Playlist URL #632

Open iceweb-ch opened 6 years ago

iceweb-ch commented 6 years ago

Hi there,

thanks for this API really cool.

Can someone help me with spotify playlist URL?

I want to play the following playlist https://open.spotify.com/user/spotify/playlist/37i9dQZF1DWZ0OzPeadl0h

I tried http://localhost:5005/wohnzimmer/spotify/now/spotify:user:spotify:playlist:37i9dQZF1DWZ0OzPeadl0h

which gives me {"status":"error","error":"Got status 500 when invoking /MediaRenderer/AVTransport/Control","stack":"Error\n at Object.invoke (/home/pi/sonos/node_modules/sonos-discovery/lib/helpers/soap.js:94:10)\n at Player.nextTrack (/home/pi/sonos/node_modules/sonos-discovery/lib/models/Player.js:399:15)\n at player.coordinator.addURIToQueue.then (/home/pi/sonos/lib/actions/spotify.js:28:38)\n at process._tickCallback (internal/process/next_tick.js:68:7)"}

With next http://localhost:5005/wohnzimmer/spotify/next/spotify:user:spotify:playlist:37i9dQZF1DWZ0OzPeadl0h

This gives me {"firsttracknumberenqueued":"1","numtracksadded":"75","newqueuelength":"491"} but does not play anything. If I put a followup command with /wohnzimmer/play I get an error. {"status":"error","error":"Got status 500 when invoking /MediaRenderer/AVTransport/Control","stack":"Error\n at Object.invoke (/home/pi/sonos/node_modules/sonos-discovery/lib/helpers/soap.js:94:10)\n at Player.play (/home/pi/sonos/node_modules/sonos-discovery/lib/models/Player.js:379:15)\n at Object.play (/home/pi/sonos/lib/actions/playpause.js:11:28)\n at handleAction (/home/pi/sonos/lib/sonos-http-api.js:110:35)\n at HttpAPI.requestHandler (/home/pi/sonos/lib/sonos-http-api.js:87:5)\n at /home/pi/sonos/server.js:80:13\n at Server.finish (/home/pi/sonos/node_modules/node-static/lib/node-static.js:111:13)\n at finish (/home/pi/sonos/node_modules/node-static/lib/node-static.js:170:14)\n at /home/pi/sonos/node_modules/node-static/lib/node-static.js:144:17\n at FSReqWrap.oncomplete (fs.js:158:21)"}

I tried many variations just dont get this working :(

iceweb-ch commented 6 years ago

anyone? :)

jishi commented 6 years ago

So it seems like it manages to actually add the tracks to queue. What does it look like in the Sonos Controller after you've added the playlist? And can you start playback of these tracks from the official controller?

FYI, now will append the tracks onto current queue and then move the queue position, however that shouldn't matter if the queue is already empty.

The 500 error is from the player, and that indicates that it actually doesn't know what to do when you invoke play.

iceweb-ch commented 6 years ago

Hey Jishi, thanks for the response. Is there a way to clear the current queue?

jishi commented 6 years ago

Yes, just invoke /player_name/clearqueue

acatoire commented 5 years ago

Hi, I have the same issue trying to start a playlist with

http://192.xxx.xxx.xxx:5005/spotify/now/spotify:playlist:5p0Mw9D1i1EjkJyIafFsvH

Album works great

http://192.xxx.xxx.xxx:5005/spotify/now/spotify:album:5lFcL4pj96ZRsoIiHpFl79

I have this error: "Error: Got status 500 when invoking /MediaRenderer/AVTransport/Control\n at Object.invoke (/app/node_modules/sonos-discovery/lib/helpers/soap.js:99:10)\n at Player.addURIToQueue (/app/node_modules/sonos-discovery/lib/models/Player.js:616:15)\n at promise.then (/app/lib/actions/spotify.js:37:33)"

I try to execute a /clearqueue before the /spotify/now/spotify:xxx with the same error.

Does anybody succeeded to use playlist on spotify?

weidaj commented 5 years ago

Yes, I am seeing the same thing with playlists. Album, song, station all work with Spotify, but playlist does not. And I agree, super cool API, thank you for this.

DavidDeSloovere commented 5 years ago

@acatoire To start a playlist, you need this format http://192.168.0.201:5005/kitchen/spotify/now/spotify:user:spotify:playlist:37i9dQZF1DWUI9wBgUr4BH

The spotify:user: part is requird as prefix to spotify:playlist:37i9dQZF1DWUI9wBgUr4BH

@iceweb-ch Your playlist/url works for me, not in yourliving room but in my kitchen 😸 http://192.168.0.201:5005/kitchen/spotify/now/spotify:user:spotify:playlist:37i9dQZF1DWZ0OzPeadl0h

Maybe something was corrupt locally?

weidaj commented 5 years ago

It works! Thanks @DavidDeSloovere! Did I miss this in the doc somewhere? I did not see this format on the webpage: .../spotify:user:spotify:playlist:...

Regarding the status 500 error, it seems like it might be related to me playing to Sonos from the Spotify App on my phone, then later trying to use the API, but I can't reproduce it 100%. I'll try to get the steps to reproduce. When it was happening I noticed the player on my phone says "Last played from Spotify /Resume /End Session". I did something to clear the issue, but I don't know what did it.

DavidDeSloovere commented 5 years ago

Created this PR yesterday to update the docs. https://github.com/jishi/node-sonos-http-api/pull/712

acatoire commented 5 years ago

Great, it works, thanks

KogResten commented 3 years ago

I was banging my head against this issue as well in a case where my kitchen speaker would work fine, but the living room speaker would throw an error.

I resolved the issue by going to the Sonos App on my phone and ending the session which was started from Spotify on my living room speaker.

Is there any way to end a session via the API?

ucdscott commented 3 weeks ago

Is there any way to end a session via the API?

@KogResten I asked the same question: Repeat of Grouped Zones Returns Error #854

The inability to End Session is a 5+ year-old gaping hole in this project.

@DavidDeSloovere You seem smart. Any idea on how to craft a URI to End Session?