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

Spotify account selection if multiple exists #350

Open
TakkuzOld opened this issue Oct 27, 2018 · 12 comments
Open

Spotify account selection if multiple exists #350

TakkuzOld opened this issue Oct 27, 2018 · 12 comments

Comments

@TakkuzOld
Copy link

I've multiple Spotify account registered and when calling .play(URISong) it responds with uPNPError 711. After launching a song using official app everything starts working as expected.

I didn't find any way to select Spotify account.

@bencevans
Copy link
Owner

@Takkuz are you familiar with Wireshark. It would be handy if you could load up the Sonos app, queue two songs from different accounts while recording the network traffic. Then we can try to identify how the Sonos app is differentiating when loading from each account.

Although I'd of thought if the accounts are in the same region then both should be able to play the music anyway. Just brain dumping but some more information would be required to continue.

@svrooij
Copy link
Collaborator

svrooij commented Dec 4, 2018

@Takkuz We have no way of verifying this.

Closing this issue for now, please re-open if you got some wireshark output for us to analyze.

@herennium
Copy link

If it helps I recorded the

SOAPACTION: "urn:schemas-upnp-org:service:AVTransport:1#AddURIToQueue"

from three different Spotify accounts in Sonos and got these envelopes:

<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%3a4AmIsuwgVauWiF9FfS1Adu?sid=9&amp;flags=8224&amp;sn=7</EnqueuedURI><EnqueuedURIMetaData>&lt;DIDL-Lite xmlns:dc=&quot;http://purl.org/dc/elements/1.1/&quot; xmlns:upnp=&quot;urn:schemas-upnp-org:metadata-1-0/upnp/&quot; xmlns:r=&quot;urn:schemas-rinconnetworks-com:metadata-1-0/&quot; xmlns=&quot;urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/&quot;&gt;&lt;item id=&quot;10032020spotify%3atrack%3a4AmIsuwgVauWiF9FfS1Adu&quot; parentID=&quot;00020000track:Johnny Walker&quot; restricted=&quot;true&quot;&gt;&lt;dc:title&gt;Johnny Walker - Remastered&lt;/dc:title&gt;&lt;upnp:class&gt;object.item.audioItem.musicTrack&lt;/upnp:class&gt;&lt;upnp:album&gt;Keine Zeit&lt;/upnp:album&gt;&lt;dc:creator&gt;Westernhagen&lt;/dc:creator&gt;&lt;upnp:albumArtURI&gt;https://i.scdn.co/image/ab67616d0000b2731f3e034841811c4da0223c9a&lt;/upnp:albumArtURI&gt;&lt;r:albumArtist&gt;Westernhagen&lt;/r:albumArtist&gt;&lt;desc id=&quot;cdudn&quot; nameSpace=&quot;urn:schemas-rinconnetworks-com:metadata-1-0/&quot;&gt;SA_RINCON2311_X_#Svc2311-23e9faa4-Token&lt;/desc&gt;&lt;/item&gt;&lt;/DIDL-Lite&gt;</EnqueuedURIMetaData><DesiredFirstTrackNumberEnqueued>4</DesiredFirstTrackNumberEnqueued><EnqueueAsNext>1</EnqueueAsNext></u:AddURIToQueue></s:Body></s:Envelope>
<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%3a4AmIsuwgVauWiF9FfS1Adu?sid=9&amp;flags=8224&amp;sn=5</EnqueuedURI><EnqueuedURIMetaData>&lt;DIDL-Lite xmlns:dc=&quot;http://purl.org/dc/elements/1.1/&quot; xmlns:upnp=&quot;urn:schemas-upnp-org:metadata-1-0/upnp/&quot; xmlns:r=&quot;urn:schemas-rinconnetworks-com:metadata-1-0/&quot; xmlns=&quot;urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/&quot;&gt;&lt;item id=&quot;10032020spotify%3atrack%3a4AmIsuwgVauWiF9FfS1Adu&quot; parentID=&quot;00020000track:Johnny Walker&quot; restricted=&quot;true&quot;&gt;&lt;dc:title&gt;Johnny Walker - Remastered&lt;/dc:title&gt;&lt;upnp:class&gt;object.item.audioItem.musicTrack&lt;/upnp:class&gt;&lt;upnp:album&gt;Keine Zeit&lt;/upnp:album&gt;&lt;dc:creator&gt;Westernhagen&lt;/dc:creator&gt;&lt;upnp:albumArtURI&gt;https://i.scdn.co/image/ab67616d0000b2731f3e034841811c4da0223c9a&lt;/upnp:albumArtURI&gt;&lt;r:albumArtist&gt;Westernhagen&lt;/r:albumArtist&gt;&lt;desc id=&quot;cdudn&quot; nameSpace=&quot;urn:schemas-rinconnetworks-com:metadata-1-0/&quot;&gt;SA_RINCON2311_X_#Svc2311-5a12c29c-Token&lt;/desc&gt;&lt;/item&gt;&lt;/DIDL-Lite&gt;</EnqueuedURIMetaData><DesiredFirstTrackNumberEnqueued>3</DesiredFirstTrackNumberEnqueued><EnqueueAsNext>1</EnqueueAsNext></u:AddURIToQueue></s:Body></s:Envelope>
<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%3a4AmIsuwgVauWiF9FfS1Adu?sid=9&amp;flags=8224&amp;sn=8</EnqueuedURI><EnqueuedURIMetaData>&lt;DIDL-Lite xmlns:dc=&quot;http://purl.org/dc/elements/1.1/&quot; xmlns:upnp=&quot;urn:schemas-upnp-org:metadata-1-0/upnp/&quot; xmlns:r=&quot;urn:schemas-rinconnetworks-com:metadata-1-0/&quot; xmlns=&quot;urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/&quot;&gt;&lt;item id=&quot;10032020spotify%3atrack%3a4AmIsuwgVauWiF9FfS1Adu&quot; parentID=&quot;00020000track:Johnny Walker&quot; restricted=&quot;true&quot;&gt;&lt;dc:title&gt;Johnny Walker - Remastered&lt;/dc:title&gt;&lt;upnp:class&gt;object.item.audioItem.musicTrack&lt;/upnp:class&gt;&lt;upnp:album&gt;Keine Zeit&lt;/upnp:album&gt;&lt;dc:creator&gt;Westernhagen&lt;/dc:creator&gt;&lt;upnp:albumArtURI&gt;https://i.scdn.co/image/ab67616d0000b2731f3e034841811c4da0223c9a&lt;/upnp:albumArtURI&gt;&lt;r:albumArtist&gt;Westernhagen&lt;/r:albumArtist&gt;&lt;desc id=&quot;cdudn&quot; nameSpace=&quot;urn:schemas-rinconnetworks-com:metadata-1-0/&quot;&gt;SA_RINCON2311_X_#Svc2311-65273c18-Token&lt;/desc&gt;&lt;/item&gt;&lt;/DIDL-Lite&gt;</EnqueuedURIMetaData><DesiredFirstTrackNumberEnqueued>2</DesiredFirstTrackNumberEnqueued><EnqueueAsNext>1</EnqueueAsNext></u:AddURIToQueue></s:Body></s:Envelope>

I recognized differences at three positions:

  1. In EnqueuedURI the value sn=
  2. The numbers in SA_RINCON2311_X_#Svc2311-23e9faa4-Token
  3. The field DesiredFirstTrackNumberEnqueued - this is my fault, just added to queue...

Can it be the sn or the token which differs from one account to another?

@pascalopitz
Copy link
Contributor

pascalopitz commented Aug 9, 2020 via email

@svrooij svrooij reopened this Aug 9, 2020
@herennium
Copy link

Snipped the network traffic again to check if the tokens vary two days later - they don't.
So they should be reusable.
I see the problem of getting those tokens and find out which Spotify account belongs to which token without Wireshark.

Also I don't know how to check in Sonos controller (Windows) or sonos.getQueue (node-sonos) what Spotify account is used on which room for playing audio.
I added the same Spotify track to queue with different Sonos Accounts (different Tokens recorded) but afterwards I cannot see any differences e.g. what Account they enqueued or with which account they are played.

Maybe I don't understand the system. Maybe it doesn't matter which account they queued and the information isn't stored.

@pascalopitz
Copy link
Contributor

I would assume that for queuing single tracks on the Sonos itself it doesn't actually matter all that much. However, the devices will use an API call and auth mechanism to retrieve the file and meta information from the 3rd party service, which might do some statistics like play count etc.

Where on the Sonos side it would make a noticeable difference is for personalised radio streams or playlists that would carry the same ID, think something like "radio:favourites:mine", and the service decides the upcoming tracks by user.

@svrooij
Copy link
Collaborator

svrooij commented Aug 11, 2020

I personally don't see why you would link several accounts to your system.

A year ago they stopped others accessing which services are connected, this also stops other (like this library) from accessing Spotify service to search for songs for instance.

Recently I've been messing with this and I maybe found a way to mimic the old behavior. Still a work-in-progress, but currently logging in works, as is saving the account details and querying Spotify through the Sonos music api. This (and documentation) will be released if I find the time to finish it (or if I have 25 sponsors GitHub)

What I found out is that most data we send to the Sonos speaker as metadata doesn't matter. If your start a Spotify song from artist a, but send artist b in the metadata, the Sonos speaker will do a new request for the metadata to the Sonos music service. Same also counts for radio streams from all services.

Spotify will also stop other devices (phones/laptops) playing music on the same account if you start playing on your Sonos speaker. That would be the only reason I can think of to connect two accounts.

@herennium
Copy link

Why I have different spotify accounts linked to Sonos:

I build my little children a box (raspi, ir receiver, 7 segment display) where they can start spotify tracks/albums via entering numbers in a small ir remote.

At the backend the raspi starts the tracks via node-sonos on the corresponding sonos device in their rooms.
When just having registered one account, the playback stops either the second child starts a track, or we adults start a track via Alexa.

I now managed to seperate the rooms by monitoring the different account tokens with wireshark and editing the helpers.js in node-sonos. E.g.:
sed -i -e 's/-0-Token/-5a12c29a-Token/g' helpers.js

Now node-sonos starts all spotify calls to sonos with the designated spotify account and even the Alexa enabled devices in living room don't interfere with the children's rooms.

@svrooij
Copy link
Collaborator

svrooij commented Aug 22, 2020

We don’t use Alexa, but we never had problems when playing two different playlists in two different rooms.

Can I summarize that you actually want an easy way to set the spotify token?
Since there isn’t a way to discover the token, can we close the issue?

@herennium
Copy link

For me an "easy way" is not necessary.
The workaround with wireshark and editing the helper.js works for me but might be a bit tricky for others.

Nevertheless when using just one Spotify Account the playback often stopped when another machine (Amazon Echo, Alexa on Sonos, Spotify on Windows, Spotify on smartphone) starts another playback. Therefore I needed more than one account.

@pascalopitz
Copy link
Contributor

So what would be an "easy" way? A getter and setter for the spotify token on a sonos instance?

@svrooij
Copy link
Collaborator

svrooij commented Nov 2, 2020

I recently came across this stackoverflow post it shows the sn parameter in the cloud api apperantly.

The easiest fix is probably a static get/set on the helper because that is wat generates the metadata for track uris

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

No branches or pull requests

5 participants