Finding the URI for a spotify track

469 views
Skip to first unread message

Paulo Matos

unread,
Jul 31, 2016, 9:42:39 AM7/31/16
to SoCo - Sonos Controller
Hello,

I have seen people online with cryptic uris for spotify tracks so we can pass them to play_uri but how do I find this uri?
Once I have the uri, is there a way to play for example just a bit of the track, like 10 seconds starting from 0:15?

Kind regards,

Paulo Matos

DPH

unread,
Aug 1, 2016, 4:48:35 AM8/1/16
to SoCo - Sonos Controller
Hi,
SoCo lets you access the current playing track - this example will get the URI (Change the IP address to the zone player that is a master playing the track)

import soco
zone = soco.SoCo('192.168.1.72')
print(zone.get_current_track_info()['uri'])

You can then use the uri to play a stream from spotify with a seek to 15 seconds in and play for 10 secs:

import soco
import time

zone = soco.SoCo('192.168.1.72')

zone.play_uri('x-sonos-spotify:spotify%3atrack%3a45yEy5WJywhJ3sDI28ajTm?sid=9&flags=8224&sn=7', start=False)
zone.seek('00:00:15')
zone.play()
time.sleep(10)
zone.stop()

I think that answers your question, but you will note that the Sonos controller shows the uri as the title etc. as meta data is missing.
I guess what you really want to do is to browse Spotify and pull out the tracks you want then add them to a queue to play - even if only 10 seconds of.
The interface to music services is still work in progress on SoCo see https://github.com/SoCo/SoCo/pull/412 great work by Kenneth Nielsen.

Hope this helps - feel free to ask more here or on the SoCo issues page on github.

Cheers David 

Paulo Matos

unread,
Aug 1, 2016, 6:13:37 AM8/1/16
to SoCo - Sonos Controller
Thanks for the help.

That's really useful.

Kind regards,

Paulo Matos
Reply all
Reply to author
Forward
0 new messages