diff --git a/ContentDirectory.py b/ContentDirectory.py index d94633e..1f61acc 100644 --- a/ContentDirectory.py +++ b/ContentDirectory.py @@ -33,37 +33,44 @@ class ContentDirectoryControl(UPnPPublisher, dict): """This class implements the CDS actions over SOAP.""" def getnextID(self): - ret = str(self.nextID) - self.nextID += 1 - return ret + ret = str(self.nextID) + self.nextID += 1 + return ret def addContainer(self, parent, title, klass = Container, **kwargs): - ret = self.addItem(parent, klass, title, **kwargs) - self.children[ret] = [] - return ret + ret = self.addItem(parent, klass, title, **kwargs) + self.children[ret] = [] + return ret def addItem(self, parent, klass, *args, **kwargs): - assert isinstance(self[parent], Container) - nid = self.getnextID() - i = klass(nid, parent, *args, **kwargs) - self.children[parent].append(i) - self[i.id] = i - return i.id + assert isinstance(self[parent], Container) + nid = self.getnextID() + i = klass(nid, parent, *args, **kwargs) + self.children[parent].append(i) + self[i.id] = i + return i.id def getchildren(self, item): - assert isinstance(self[item], Container) - return self.children[item][:] + assert isinstance(self[item], Container) + return self.children[item][:] def __init__(self, title, *args): - super(ContentDirectoryControl, self).__init__(*args) - fakeparent = '-1' - self.nextID = 0 - self.children = { fakeparent: []} - self[fakeparent] = Container(None, '-1', 'fake') - root = self.addContainer(fakeparent, title) - assert root == '0' - del self[fakeparent] - del self.children[fakeparent] + super(ContentDirectoryControl, self).__init__(*args) + fakeparent = '-1' + self.nextID = 0 + self.children = { fakeparent: []} + self.needupdate = False + self.updateId = 0 + self[fakeparent] = Container(None, '-1', 'fake') + root = self.addContainer(fakeparent, title) + assert root == '0' + del self[fakeparent] + del self.children[fakeparent] + + def doupdate(self): + if self.needupdate: + self.needupdate += 1 + self.needupdate = False # Required actions @@ -71,20 +78,21 @@ class ContentDirectoryControl(UPnPPublisher, dict): """Required: Return the searching capabilities supported by the device.""" log.msg('GetSearchCapabilities()') - return { 'SearchCapabilitiesResponse': { 'SearchCaps': '' }} + return { 'SearchCapabilitiesResponse': { 'SearchCaps': '' }} def soap_GetSortCapabilities(self, *args, **kwargs): """Required: Return the CSV list of meta-data tags that can be used in sortCriteria.""" log.msg('GetSortCapabilities()') - return { 'SortCapabilitiesResponse': { 'SortCaps': '' }} + return { 'SortCapabilitiesResponse': { 'SortCaps': '' }} def soap_GetSystemUpdateID(self, *args, **kwargs): """Required: Return the current value of state variable SystemUpdateID.""" log.msg('GetSystemUpdateID()') - return { 'SystemUpdateIdResponse': { 'Id': 5 }} + self.needupdate = True + return { 'SystemUpdateIdResponse': { 'Id': self.updateId }} BrowseFlags = ('BrowseMetaData', 'BrowseDirectChildren') @@ -94,8 +102,8 @@ class ContentDirectoryControl(UPnPPublisher, dict): (ObjectID, BrowseFlag, Filter, StartingIndex, RequestedCount, SortCriteria) = args - StartingIndex = int(StartingIndex) - RequestedCount = int(RequestedCount) + StartingIndex = int(StartingIndex) + RequestedCount = int(RequestedCount) log.msg('Browse(ObjectID=%s, BrowseFlags=%s, Filter=%s, ' 'StartingIndex=%s RequestedCount=%s SortCriteria=%s)' % @@ -103,14 +111,14 @@ class ContentDirectoryControl(UPnPPublisher, dict): `RequestedCount`, `SortCriteria`)) didl = DIDLElement() - result = {} + result = {} try: - if BrowseFlag == 'BrowseDirectChildren': - ch = self.getchildren(ObjectID)[StartingIndex: StartingIndex + RequestedCount] - filter(lambda x, s = self, d = didl: d.addItem(s[x.id]) and None, ch) - else: - didl.addItem(self[ObjectID]) + if BrowseFlag == 'BrowseDirectChildren': + ch = self.getchildren(ObjectID)[StartingIndex: StartingIndex + RequestedCount] + filter(lambda x, s = self, d = didl: d.addItem(s[x.id]) and None, ch) + else: + didl.addItem(self[ObjectID]) result = {'BrowseResponse': {'Result': didl.toString() , 'NumberReturned': didl.numItems(), @@ -217,5 +225,5 @@ class ContentDirectoryServer(resource.Resource): def __init__(self, title): resource.Resource.__init__(self) self.putChild('scpd.xml', static.File('content-directory-scpd.xml')) - self.control = ContentDirectoryControl(title) + self.control = ContentDirectoryControl(title) self.putChild('control', self.control)