Skip to content

Instantly share code, notes, and snippets.

@l4p4
Forked from funzoneq/gist:efd3d641d5a92a73afd0
Created March 15, 2016 18:12
Show Gist options
  • Save l4p4/d10e108a539a526237e7 to your computer and use it in GitHub Desktop.
Save l4p4/d10e108a539a526237e7 to your computer and use it in GitHub Desktop.
22tracks for Sonos
#!/usr/bin/env python
from soco import SoCo
import requests
from pprint import pprint
pl = requests.get("http://22tracks.com/api/tracks/20")
playlist = pl.json()
file = playlist[0]['filename']
t = requests.get("http://app01.22tracks.com/token.php?desktop=true&u=/128/%s" % file)
token = t.json()
url = "http://audio.22tracks.com/128/%s?st=%s&e=%s" % (file, token['st'], token['e'])
if __name__ == '__main__':
sonos = SoCo('192.168.123.23') # Pass in the IP of your Sonos speaker
# You could use the discover function instead, if you don't know the IP
# Pass in a URI to a media file to have it streamed through the Sonos
# speaker
sonos.play_uri(url)
track = sonos.get_current_track_info()
print track['title']
sonos.pause()
# Play a stopped or paused track
sonos.play()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment