Can I still send streaming commands to my sonos?

100 views
Skip to first unread message

qch.j...@gmail.com

unread,
May 15, 2021, 11:13:07 AM5/15/21
to SoCo - Sonos Controller
A bunch of years ago I wrote a python script to send a command to my Sonos speaker to play a napster radio station.  It looked something like this:

import soco
zp = soco.SoCo('192.168.0.72')
media_uri = 'x-sonosapi-radio:station%3a%3aps.8647821?sid=202&flags=76&sn=1'
media_metadata = '<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="000c005cstation%3a%3aps.8627841" parentID="00084066radio%3amystations" restricted="true"><dc:title>&apos;80s Rock</dc:title><upnp:class>object.item.audioItem.audioBroadcast</upnp:class><desc id="cdudn" nameSpace="urn:schemas-rinconnetworks-com:metadata-1-0/">SA_RINCON5...@aol.com</desc></item></DIDL-Lite>'
zp.volume = 65
zp.play_uri(media_uri, media_metadata, start=True)

I got this stream by sniffing it with wireshark while starting a stream from the Sonos controller on my pc.

Is it still possible to sniff these streams to create scripts?  I heard that they encrypted these commands and we are no longer able to do this.

I wanted to create scripts for a few other radio stations but when I tried to sniff I saw a bunch of TLS packets and was unable to find anything like I used in my script above.  It's been quite a few years so I may be missing something, but I figured I'd ask to see if it was still possible.

Thanks,

Roveer

Psychlist

unread,
May 15, 2021, 11:35:29 AM5/15/21
to SoCo - Sonos Controller
I'm not an expert on this aspect of SoCo, however one can still inspect most of the UPnP command streams (they are not encrypted). Whether using 'play_uri()' will work with the Napster radio streams is less certain, due to changes made by Sonos in how authentication with music services works. There's work being done in SoCo to accommodate this.

In the case of Spotify, I can save a 'Radio' station as a Sonos favourite and play it using SoCo. Perhaps the same will work for Napster, and be easily scriptable.

Btw, if you want a convenient way of creating scripting Sonos, you may want to take a look at SoCo-CLI.

qch.j...@gmail.com

unread,
May 16, 2021, 9:54:47 AM5/16/21
to SoCo - Sonos Controller
Thanks for the info.  Just tried soco-cli and it worked like a charm.  This is a game changer for me.  
Reply all
Reply to author
Forward
0 new messages