~ubuntu-branches/ubuntu/precise/coherence/precise

« back to all changes in this revision

Viewing changes to misc/media_server_observer.py

  • Committer: Bazaar Package Importer
  • Author(s): Charlie Smotherman
  • Date: 2010-01-02 10:57:15 UTC
  • mfrom: (1.1.7 upstream) (3.2.8 sid)
  • Revision ID: james.westby@ubuntu.com-20100102105715-sghzl2nw4lr5b1ob
Tags: 0.6.6.2-1
*  New  upstream release, summary of changes:
    - adding all necessary files to MANIFEST.in, to compensate for the
      gone 'auto-include-all-files-under-version-control' setuptools
      feature.
    - rearranging genre and genres attribute in DIDLLite - thx Caleb  
    - fix face_path typo, fixes #275.   

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
from twisted.internet import reactor
 
3
 
 
4
from coherence.base import Coherence
 
5
from coherence.upnp.devices.control_point import ControlPoint
 
6
from coherence.upnp.core import DIDLLite
 
7
 
 
8
# browse callback
 
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']))
 
13
 
 
14
    elt = DIDLLite.DIDLElement.fromString(result['Result'])
 
15
    for item in elt.getItems():
 
16
 
 
17
        if item.upnp_class.startswith("object.container"):
 
18
            print "  container %s (%s) with %d items" % \
 
19
                    (item.title,item.id, item.childCount)
 
20
 
 
21
        if item.upnp_class.startswith("object.item"):
 
22
            print "  item %s (%s)" % (item.title, item.id)
 
23
 
 
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()
 
28
 
 
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)
 
33
 
 
34
# sadly they sometimes get removed as well :(
 
35
def media_server_removed(udn):
 
36
    print "media_server_removed", udn
 
37
 
 
38
def start():
 
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')
 
45
 
 
46
    # now we should also try to discover the ones that are already there:
 
47
    for device in control_point.coherence.devices:
 
48
        print device
 
49
 
 
50
if __name__ == "__main__":
 
51
    reactor.callWhenRunning(start)
 
52
    reactor.run()
 
53