Spotify
AddSpotifyToQueue -https://github.com/DjMomo/sonos/blob/9833a311832d59d0946b30d20f7f85918dedf023/sonos.class.php#L473
I try to play a Spotify playlist with
sonos.play('x-rincon-cpcontainer:1006006cspotify%3auser%3aspotify%3aplaylist%3a7BixMZxL4bhgULJQ5wPbUz', function( ...
and it doesn't work (HTTP response 500). Would this enhancement be the missing piece or are I'm doing something wrong?
Not 100% sure without looking into it further put it's quite likely
I did a little experimentation on how to play a Spotify playlist, although it may be the wrong place here because the link in your initial post shows how to add a Spotify track to the queue.
First I used Wireshark to sniff the communication between the Sonos app and the speakers. The body it sends looks like this:
<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-rincon-cpcontainer:1006006cspotify%3auser%3abaretom%3aplaylist%3a50oyVNwpgWEaBSL5YDybtC</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="1006006cspotify%3auser%3casretom%3aplaylist%3a50oyVNwpgWEaBSL5YDybtC" parentID="10080664playlists%3afolder%3a6954091786839755846" restricted="true"><dc:title>Enter The Dub</dc:title><upnp:class>object.container.playlistContainer</upnp:class><desc id="cdudn" nameSpace="urn:schemas-rinconnetworks-com:metadata-1-0/">SA_RINCON2311_X_#Svc2311-0-Token</desc></item></DIDL-Lite>
</EnqueuedURIMetaData>
<DesiredFirstTrackNumberEnqueued>0</DesiredFirstTrackNumberEnqueued>
<EnqueueAsNext>0</EnqueueAsNext>
</u:AddURIToQueue>
</s:Body>
</s:Envelope>
Required to successfully queue a Spotify playlist are the URI and the metadata. Unfortunately there seems to be no possibility to get the information without a tool like Wireshark, but maybe (hopefully) I'm wrong. But for me this is no problem, I sniff the information of all playlists I want to use and store them in variables.
I used your Sonos.prototype.queue function and modified it a little bit. It already has everything needed except a parameter to hand over the metadata.
var Sonos = require('sonos').Sonos;
// Extend with the ability to add Spotify and other playlists to queue
Sonos.prototype.queuePlaylist = function (uri, metadata, positionInQueue, callback) {
if (typeof positionInQueue === 'function') {
callback = positionInQueue;
positionInQueue = 0;
}
var action = '"urn:schemas-upnp-org:service:AVTransport:1#AddURIToQueue"';
var body = '<u:AddURIToQueue xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"><InstanceID>0</InstanceID><EnqueuedURI>' + uri + '</EnqueuedURI><EnqueuedURIMetaData>' + metadata + '</EnqueuedURIMetaData><DesiredFirstTrackNumberEnqueued>0</DesiredFirstTrackNumberEnqueued><EnqueueAsNext>0</EnqueueAsNext></u:AddURIToQueue>';
this.request(this.options.endpoints.transport, action, body, 'u:AddURIToQueueResponse', function(err, data) {
return callback(err, data);
});
}
// Stored playlist information
var sonosPlaylist = {
'Enter The Dub': {
'uri': 'x-rincon-cpcontainer:1006006cspotify%3auser%3casretom%3aplaylist%3a50oyVNwpgWEaBSL5YDybtC',
'meta': '<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="1006006cspotify%3auser%3casretom%3aplaylist%3a50oyVNwpgWEaBSL5YDybtC" parentID="10080664playlists%3afolder%3a6954091786839755846" restricted="true"><dc:title>Enter The Dub</dc:title><upnp:class>object.container.playlistContainer</upnp:class><desc id="cdudn" nameSpace="urn:schemas-rinconnetworks-com:metadata-1-0/">SA_RINCON2311_X_#Svc2311-0-Token</desc></item></DIDL-Lite>'
}
};
// Queue the playlist
var sonos = new Sonos('192.168.2.204');
sonos.queuePlaylist(sonosPlaylist['Enter The Dub'].uri, sonosPlaylist['Enter The Dub'].meta, function(err, data){});
// Play the Spotify playlist :-)
sonos.play(function(err, data){});
I think this should work with every music service on our Sonos.
Thanks for the research! If you fancy writing an abstraction to make this easier in future a pull request would be gratefully received.
On Saturday, March 21, 2015, Matthias Brünning [email protected] wrote:
I did a little experimentation on how to play a Spotify playlist, although it may be the wrong place here because the link in your initial post shows how to add a Spotify track to the queue.
First I used Wireshark to sniff the communication between the Sonos app and the speakers. The body it sends looks like this:
<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">
0 x-rincon-cpcontainer:1006006cspotify%3auser%3abaretom%3aplaylist%3a50oyVNwpgWEaBSL5YDybtC <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="1006006cspotify%3auser%3casretom%3aplaylist%3a50oyVNwpgWEaBSL5YDybtC" parentID="10080664playlists%3afolder%3a6954091786839755846" restricted="true"><dc:title>Enter The Dub</dc:title><upnp:class>object.container.playlistContainer</upnp:class><desc id="cdudn" nameSpace="urn:schemas-rinconnetworks-com:metadata-1-0/">SA_RINCON2311_X_#Svc2311-0-Token</desc></item></DIDL-Lite> 0 0 /u:AddURIToQueue /s:Body /s:EnvelopeRequired to successfully queue a Spotify playlist are the URI and the metadata. Unfortunately there seems to be no possibility to get the information without a tool like Wireshark, but maybe (hopefully) I'm wrong. But for me this is no problem, I sniff the information of all playlists I want to use and store them in variables.
I used your Sonos.prototype.queue function and modified it a little bit. It already has everything needed except a parameter to hand over the metadata.
var Sonos = require('sonos').Sonos; // Extend with the ability to add Spotify and other playlists to queue Sonos.prototype.queuePlaylist = function (uri, metadata, positionInQueue, callback) { if (typeof positionInQueue === 'function') { callback = positionInQueue; positionInQueue = 0; } var action = '"urn:schemas-upnp-org:service:AVTransport:1#AddURIToQueue"'; var body = '<u:AddURIToQueue xmlns:u="urn:schemas-upnp-org:service:AVTransport:1">
0 ' + uri + ' ' + metadata + ' 0 0 /u:AddURIToQueue';this.request(this.options.endpoints.transport, action, body, 'u:AddURIToQueueResponse', function(err, data) { return callback(err, data); }); } // Stored playlist information var sonosPlaylist = { 'Enter The Dub': { 'uri': 'x-rincon-cpcontainer:1006006cspotify%3auser%3casretom%3aplaylist%3a50oyVNwpgWEaBSL5YDybtC', 'meta': '<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="1006006cspotify%3auser%3casretom%3aplaylist%3a50oyVNwpgWEaBSL5YDybtC" parentID="10080664playlists%3afolder%3a6954091786839755846" restricted="true"><dc:title>Enter The Dub</dc:title><upnp:class>object.container.playlistContainer</upnp:class><desc id="cdudn" nameSpace="urn:schemas-rinconnetworks-com:metadata-1-0/">SA_RINCON2311_X_#Svc2311-0-To ken</desc></item></DIDL-Lite>' } }; // Queue the playlist var sonos = new Sonos('192.168.2.204');
sonos.queuePlaylist(sonosPlaylist['Enter The Dub'].uri, sonosPlaylist['Enter The Dub'].meta, function(err, data){}); // Play the Spotify playlist :-)
sonos.play(function(err, data){});
I think this should work with every music service on your Sonos.
— Reply to this email directly or view it on GitHub https://github.com/bencevans/node-sonos/issues/23#issuecomment-84464386.
It would be an honor for me to collaborate on your project. However, I am a Node.js novice. I need to figure out how to include this to your code in a useful manner. In the meantime I have some other components I could contribute.
Anyone wanting to contribute is more than welcome too whatever your level! We are all novices at some point :)
On Wednesday, March 25, 2015, Matthias Brünning [email protected] wrote:
It would be an honor for me to collaborate on your project. However, I am a Node.js novice. I need to figure out how to include this to your code in a useful manner. In the meantime I have some other components I could contribute.
— Reply to this email directly or view it on GitHub https://github.com/bencevans/node-sonos/issues/23#issuecomment-86181138.
Added by #89