Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
Adds SoCo.get_sonos_playlists and MLSonosPlaylist #114
based on comments in #113
to test it
I'm not sure yet why the unit-test is failing.
A starting point for use in socos https://github.com/petteraas/socos/tree/get_sonos_playlists
My thinking is that we can have a 'list_sonos_playlists' and something like 'add_sonos_playlist %d' which adds the specified to current queue based on index from 'list_sonos_playlists'. A bit like how 'list' and 'set' works today, but this is as you can see far from finished yet.
@KennethNielsen no worries, do it when you find the time!
After seeing your SoCo/socos#26 I will probably not continue on https://github.com/petteraas/socos/tree/get_sonos_playlists , but instead incorporate it in that new MusicLibrary class.
So I found some time to look at this. I assume really, that we should be able to add these Sonos playlists to the queue with the normal
Currently this fails like so:
>>> soco_instance.add_to_queue(sonos_playlist) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "soco/core.py", line 1082, in add_to_queue raise AttributeError(message) AttributeError: queueable_item has no attribute didl_metadata
which is really an error on my part in the
>>> sonos_playlist.didl_metadata Traceback (most recent call last): File "<stdin>", line 1, in <module> File "soco/data_structures.py", line 254, in didl_metadata 'DIDL Metadata cannot be created when item_id returns None ' soco.exceptions.CannotCreateDIDLMetadata: DIDL Metadata cannot be created when item_id returns None (most likely because uri is not set)
we can see that it does indeed have a didl_metadata property, but it fails to generate the metadata, which is why
In any case it also gives as a clue as to why it fails. It fails because
From MusicLibraryItem we can see that:
@property def item_id(self): # pylint: disable=C0103 """Return the id. The id is extracted as the part of the URI after the first # character. For the few music library types where that is not correct, this method should be overwritten. """ out = self.content['uri'] try: out = out[out.index('#') + 1:] except ValueError: out = None return out
and I can see that you have indeed overwritten it, with what appears to be a copy of the way it is overwritten in some of the other music library items:
@property def item_id(self): #pylint: disable=C0103 """ Returns the id. """ out = self.content['uri'] if 'x-file-cids' in out: out = out.replace('x-file-cifs', 'S') else: out = None return out
and that returns None because there is no
<ns0:container xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:ns0="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/" xmlns:ns2="urn:schemas-upnp-org:metadata-1-0/upnp/" id="SQ:0" parentID="SQ:" restricted="true"> <dc:title>Test</dc:title> <ns0:res protocolInfo="file:*:audio/mpegurl:*">file:///jffs/settings/savedqueues.rsq#0</ns0:res> <ns2:class>object.container.playlistContainer</ns2:class> </ns0:container>
it appears that for this type of item, there is actually an ID property with the value
Lets try and get this working first and then we can look at the tests.
Ok, so this isn't very nice now that I put it all up there for you to try, but I couldn't help myself from trying. It appears that if you overwrite with:
@property def item_id(self): #pylint: disable=C0103 """ Returns the id. """ queue_number = super(MLSonosPlaylist, self).item_id return 'SQ:' + queue_number
I should say, that I can see now, that there, dispite my best efforts, might be some holes in the documentation. I would appreciate your input afterwards on where I might improve it.