node-sonos-http-api icon indicating copy to clipboard operation
node-sonos-http-api copied to clipboard

Spotify resulting in different errors

Open denbue opened this issue 5 years ago • 9 comments

Hi, first off, I was able to recreate the issue with fresh installs on linux, mac, docker and non-docker. System parameters like /clearqueue or /zones etc are all working fine.

I am trying to use the spotify feature to add songs to the queue and to play. Spotify credentials are set correctly in settings.json.

It used to work until a couple months ago and I can't get it to work anymore.

It's the same issue for track, album and playlist. Here is an example with an album for {now/queue/next}:

http://192.168.0.91:5005/Hallway/spotify/now/spotify:album:0JKjuvDUPrnlblAZyB1Aje
=
Error: Got status 500 when invoking /MediaRenderer/AVTransport/Control
    at Object.invoke (/node-sonos-http-api-master/node_modules/sonos-discovery/lib/helpers/soap.js:99:10)
    at Player.addURIToQueue (/node-sonos-http-api-master/node_modules/sonos-discovery/lib/models/Player.js:616:15)
    at promise.then (/node-sonos-http-api-master/lib/actions/spotify.js:37:33)

http://192.168.0.91:5005/Hallway/spotify/queue/spotify:playlist:37i9dQZF1DWSNmwgf7Nv11
=
Error: Got status 500 when invoking /MediaRenderer/AVTransport/Control
    at Object.invoke (/node-sonos-http-api-master/node_modules/sonos-discovery/lib/helpers/soap.js:99:10)
    at Player.addURIToQueue (/node-sonos-http-api-master/node_modules/sonos-discovery/lib/models/Player.js:616:15)
    at Object.spotify (/node-sonos-http-api-master/lib/actions/spotify.js:28:31)
    at handleAction (/node-sonos-http-api-master/lib/sonos-http-api.js:117:35)
    at HttpAPI.requestHandler (/node-sonos-http-api-master/lib/sonos-http-api.js:94:21)
    at /node-sonos-http-api-master/server.js:50:13
    at Server.finish (/node-sonos-http-api-master/node_modules/node-static/lib/node-static.js:111:13)
    at finish (/node-sonos-http-api-master/node_modules/node-static/lib/node-static.js:170:14)
    at /node-sonos-http-api-master/node_modules/node-static/lib/node-static.js:144:17
    at FSReqWrap.oncomplete (fs.js:123:15)

http://192.168.0.91:5005/Hallway/spotify/next/spotify:playlist:37i9dQZF1DWSNmwgf7Nv11
=
Error: Got status 500 when invoking /MediaRenderer/AVTransport/Control
    at Object.invoke (/node-sonos-http-api-master/node_modules/sonos-discovery/lib/helpers/soap.js:99:10)
    at Player.addURIToQueue (/node-sonos-http-api-master/node_modules/sonos-discovery/lib/models/Player.js:616:15)
    at Object.spotify (/node-sonos-http-api-master/lib/actions/spotify.js:44:31)
    at handleAction (/node-sonos-http-api-master/lib/sonos-http-api.js:117:35)
    at HttpAPI.requestHandler (/node-sonos-http-api-master/lib/sonos-http-api.js:94:21)
    at /node-sonos-http-api-master/server.js:50:13
    at Server.finish (/node-sonos-http-api-master/node_modules/node-static/lib/node-static.js:111:13)
    at finish (/node-sonos-http-api-master/node_modules/node-static/lib/node-static.js:170:14)
    at /node-sonos-http-api-master/node_modules/node-static/lib/node-static.js:144:17
    at FSReqWrap.oncomplete (fs.js:123:15)

my settings.json:

{
  "ip": "192.168.0.91",
  "port": "5005",
  "spotify": {
    "clientId": "b0f90b49ae1d4ca98e72ea0004e3_XXX",
    "clientSecret": "d2c7528701c542cf937f9c0390e_XXX"
	},
 }

my preset:

{
  "players": [
    {
      "roomName": "Hallway",
      "volume": 10
    },
    {
      "roomName": "Living Room",
      "volume": 10
    }
  ],
  "playMode": {
    "shuffle": true,
    "repeat": "all",
    "crossfade": false
  },
  "pauseOthers": false,

}

denbue avatar Oct 11 '19 16:10 denbue

Hello,

I have the same issue and the only way that I found to play a song from Spotify was:

http://localhost:5005/"Zone"/SetAVTransportURI/x-sonos-spotify:spotify:track:1WSGTYKLEpKfNQYYW5Oymt?sid=9&sn=12, but it is not the correct way to do that action, because I cant see all the information of the song.

Could you find the solution?

AlejandroSossa avatar Oct 19 '19 14:10 AlejandroSossa

Hi, Glad to hear I’m not the only one with the issue. I haven’t looked at it but is there a way to enable a debug mode?

denbue avatar Oct 21 '19 07:10 denbue

Hi, I found a way to capture the traffic and this is the difference between the SONOS App and the API:

Correct way:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> <s:Body> <u:AddURIToQueue xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"> <InstanceID>0</InstanceID> <EnqueuedURI>x-sonos-spotify:spotify%3atrack%3a0fea68AdmYNygeTGI4RC18?sid=9&flags=8224&sn=15</EnqueuedURI> <EnqueuedURIMetaData><DIDL-Lite xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/" xmlns:r="urn:schemas-rinconnetworks-com:metadata-1-0/" xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/"><item id="10032020spotify%3atrack%3a0fea68AdmYNygeTGI4RC18" parentID="00020000track:la cancion" restricted="true"><dc:title>LA CANCI..N</dc:title><upnp:class>object.item.audioItem.musicTrack</upnp:class><upnp:album>OASIS</upnp:album><dc:creator>J Balvin</dc:creator><upnp:albumArtURI>https://i.scdn.co/image/ab67616d0000b2734891d9b25d8919448388f3bb</upnp:albumArtURI><r:albumArtist>J Balvin</r:albumArtist><desc id="cdudn" nameSpace="urn:schemas-rinconnetworks-com:metadata-1-0/">SA_RINCON2311_X_#Svc2311-0-Token</desc></item></DIDL-Lite></EnqueuedURIMetaData> <DesiredFirstTrackNumberEnqueued>1</DesiredFirstTrackNumberEnqueued> <EnqueueAsNext>1</EnqueueAsNext> </u:AddURIToQueue> </s:Body> </s:Envelope>

Incorrect:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> <s:Body> <u:AddURIToQueue xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"> <InstanceID>0</InstanceID> <EnqueuedURI>x-sonos-spotify:spotify%3Atrack%3A0fea68AdmYNygeTGI4RC18?sid=12&flags=32&sn=1</EnqueuedURI> <EnqueuedURIMetaData><DIDL-Lite xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/" xmlns:r="urn:schemas-rinconnetworks-com:metadata-1-0/" xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/"> <item id="00030020spotify%3Atrack%3A0fea68AdmYNygeTGI4RC18" restricted="true"><upnp:class>object.item.audioItem.musicTrack</upnp:class><desc id="cdudn" nameSpace="urn:schemas-rinconnetworks-com:metadata-1-0/">SA_RINCON3079_X_#Svc3079-0-Token</desc></item></DIDL-Lite></EnqueuedURIMetaData> <DesiredFirstTrackNumberEnqueued>2</DesiredFirstTrackNumberEnqueued> <EnqueueAsNext>1</EnqueueAsNext> </u:AddURIToQueue> </s:Body> </s:Envelope>

The difference is: EnqueuedURIMetaData

I dont know how to implement that solution.

AlejandroSossa avatar Oct 21 '19 14:10 AlejandroSossa

The issue was the token number. I manually entered the value and it worked, but it should work automatically.

If you open "Spotify.js" and find: SA_RINCON${serviceType}X#Svc${serviceType}-0-Token

You should change it for numbers: SA_RINCON2311_X_#Svc2311-0-Token

AlejandroSossa avatar Oct 21 '19 18:10 AlejandroSossa

Yeah you are right, when you change 3079 to 2311 in the above code snippet, it works again. I'm trying to find out where the 3079 originally comes from?

denbue avatar Oct 22 '19 10:10 denbue

Previously, Spotlfy used different service identifiers in different regions, where 2311 (sn=9) was used in EU, and 3079 was used in US (I think).

It uses a Sonos system call to get available music services and fetches the one that is listed there and called "Spotify".

Please invoke /services against the API and also tell me which country you live in, maybe we can find what is going on.

jishi avatar Oct 22 '19 10:10 jishi

Yeah, I saw this in #306

My /services is Spotify: { id: 12, capabilities: 1116691, type: 3079 }

The Spotify account is EU, and the Sonos was set up as an US account but I just switched it to EU and restarted the sonos speaker and reinstalled the app. It still says 3079.

denbue avatar Oct 22 '19 11:10 denbue

Re-invoking the /services changed my Spotify type to EU (2311) now. Not sure if my mixed countries were the issue, but it seems solved now.

denbue avatar Oct 22 '19 11:10 denbue

Just as a follow up: I'm using docker-compose to update my containers every night. This seems to reset the region of this package every time back to 3079 and I have to invoke /services after each removal/pull. Not sure if this is an issue of this package or the docker-container?

denbue avatar Dec 04 '19 10:12 denbue