diff --git a/ContentDirectory.py b/ContentDirectory.py index 1f61acc..b0ccdc0 100644 --- a/ContentDirectory.py +++ b/ContentDirectory.py @@ -39,17 +39,25 @@ class ContentDirectoryControl(UPnPPublisher, dict): def addContainer(self, parent, title, klass = Container, **kwargs): ret = self.addItem(parent, klass, title, **kwargs) - self.children[ret] = [] + self.children[ret] = self[ret] return ret def addItem(self, parent, klass, *args, **kwargs): assert isinstance(self[parent], Container) nid = self.getnextID() - i = klass(nid, parent, *args, **kwargs) + i = klass(self, nid, parent, *args, **kwargs) self.children[parent].append(i) self[i.id] = i return i.id + def delItem(self, id): + if isinstance(self[id], Container): + for i in self.children[id]: + self.delItem(i) + assert len(self.children[id]) == 0 + del self.children[id] + del self[id] + def getchildren(self, item): assert isinstance(self[item], Container) return self.children[item][:] diff --git a/DIDLLite.py b/DIDLLite.py index 10cd383..1b3b3a8 100644 --- a/DIDLLite.py +++ b/DIDLLite.py @@ -36,9 +36,10 @@ class Object: res = None writeStatus = None - def __init__(self, id, parentID, title, restricted = False, + def __init__(self, cd, id, parentID, title, restricted = False, creator = None): + self.cd = cd self.id = id self.parentID = parentID self.title = title @@ -203,19 +204,20 @@ class PlaylistItem(Item): class TextItem(Item): klass = Item.klass + '.textItem' -class Container(Object): +class Container(Object, list): """An object that can contain other objects.""" klass = Object.klass + '.container' elementName = 'container' - childCount = 0 + childCount = property(lambda x: len(x)) createClass = None searchClass = None searchable = None - def __init__(self, id, parentID, title, restricted = 0, creator = None): - Object.__init__(self, id, parentID, title, restricted, creator) + def __init__(self, cd, id, parentID, title, restricted = 0, creator = None): + Object.__init__(self, cd, id, parentID, title, restricted, creator) + list.__init__(self) def toElement(self):