Skip to content

Instantly share code, notes, and snippets.

@funzoneq
Created July 3, 2014 13:14
Show Gist options
  • Save funzoneq/efd3d641d5a92a73afd0 to your computer and use it in GitHub Desktop.
Save funzoneq/efd3d641d5a92a73afd0 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()
@funzoneq
Copy link
Author

funzoneq commented Jul 3, 2014

#!/usr/bin/env python
import soco
import requests
from pprint import pprint

pl = requests.get("http://22tracks.com/api/tracks/20")
playlist = pl.json()

file = playlist[1]['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__':
    speakers = list(soco.discover())
    pprint(speakers[0])

    if not speakers:
        print 'no speakers found, exiting.'
        exit(1)

    sonos = speakers[0] # Pass in the IP of your Sonos speaker
    # You could use the discover function instead, if you don't know the IP

    print url

    # 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