@property
def item_id(self): # pylint: disable=C0103
"""Returns the id."""
out = 'SQ:' + super(MLSonosPlaylist, self).item_id
return out
This fixes the bug I have raises in issue #196 where to browse the Sonos queues you need to add SQ: before the item_id (playlist number).
With SoCo fixed you can now do:
"""
Demo of listing Sonos Playlists
"""
from soco import SoCo
import urllib
soc = SoCo('192.168.1.64')
playlist_info = soc.get_music_library_information('sonos_playlists')
print('Found {} Sonos playlists'.format(playlist_info['number_returned']))
playlists = playlist_info['item_list']
for playlist in playlists:
#for each playlist
print ' '
print '>>>>', playlist.title
track_list = soc.browse(playlist)['item_list']
for item in track_list:
#for each track in a playlist
title = item.title
album = item.album
artist = item.title
uri = item.uri
art = item.album_art_uri
try:
print 'Title: {} Album: {} Artist: {} Source: {}'.format(
title, album, artist, uri)
except UnicodeEncodeError:
print 'UnicodeError - special characters used!'
The only reason to have the try / except on Unicode error is some tracks have foreign characters in them and these won't print properly.
I need to learn how to handles these better.....
This will give you the path and file name of each track in all you Sonos playlists
However - it is read only! So useful information, but won't really help you update it!
It will at least tell you which ones to change.
Re documentation form Sonos - there isn't any! Sonos don't release it. So it is all by discovery using wire shark / UPNP tools for developers and learning from others.
Hope this all helps,
let me know you progress or any further question
Cheers David