2
from twisted.internet import reactor
4
from coherence.base import Coherence
5
from coherence.upnp.devices.control_point import ControlPoint
6
from coherence.upnp.core import DIDLLite
9
def process_media_server_browse(result, client):
10
print "browsing root of", client.device.get_friendly_name()
11
print "result contains %d out of %d total matches" % \
12
(int(result['NumberReturned']), int(result['TotalMatches']))
14
elt = DIDLLite.DIDLElement.fromString(result['Result'])
15
for item in elt.getItems():
17
if item.upnp_class.startswith("object.container"):
18
print " container %s (%s) with %d items" % \
19
(item.title,item.id, item.childCount)
21
if item.upnp_class.startswith("object.item"):
22
print " item %s (%s)" % (item.title, item.id)
24
# called for each media server found
25
def media_server_found(client, udn):
26
print "media_server_found", client
27
print "media_server_found", client.device.get_friendly_name()
29
d = client.content_directory.browse(0,
30
browse_flag='BrowseDirectChildren', process_result=False,
31
backward_compatibility=False)
32
d.addCallback(process_media_server_browse, client)
34
# sadly they sometimes get removed as well :(
35
def media_server_removed(udn):
36
print "media_server_removed", udn
39
control_point = ControlPoint(Coherence({'logmode':'warning'}),
40
auto_client=['MediaServer'])
41
control_point.connect(media_server_found,
42
'Coherence.UPnP.ControlPoint.MediaServer.detected')
43
control_point.connect(media_server_removed,
44
'Coherence.UPnP.ControlPoint.MediaServer.removed')
46
# now we should also try to discover the ones that are already there:
47
for device in control_point.coherence.devices:
50
if __name__ == "__main__":
51
reactor.callWhenRunning(start)