A Python UPnP Media Server
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
2.0 KiB

  1. #!/usr/bin/python
  2. #
  3. # Test harness for UPnP ContentDirectory:1 service.
  4. #
  5. # Licensed under the MIT license
  6. # http://opensource.org/licenses/mit-license.php
  7. # Copyright 2005, Tim Potter <tpot@samba.org>
  8. from twisted.web import client
  9. from twisted.internet import reactor
  10. from twisted.python import usage
  11. import sys, string, SOAPpy
  12. class UPnPSOAPProxy:
  13. """A proxy for making UPnP SOAP calls."""
  14. def __init__(self, url):
  15. self.url = url
  16. def _cbGotResult(self, result):
  17. return SOAPpy.parseSOAPRPC(result)
  18. def callRemote(self, method, *args, **kwargs):
  19. payload = SOAPpy.buildSOAP(args = args, kw = kwargs, method = method)
  20. payload = string.replace(payload, '\n', '\r\n')
  21. action = \
  22. '"urn:schemas-upnp-org:service:ContentDirectory:1#%s"' % method
  23. page = client.getPage(self.url, postdata = payload, method = 'POST',
  24. headers = {'Content-Type': 'text/xml',
  25. 'SOAPACTION': action})
  26. return page.addCallback(self._cbGotResult)
  27. class Options(usage.Options):
  28. pass
  29. def printResult(value):
  30. print value
  31. reactor.stop()
  32. def printError(error):
  33. print 'error', error
  34. reactor.stop()
  35. #proxy = UPnPSOAPProxy('http://192.168.126.128:5643/ContentDirectory/control')
  36. proxy = UPnPSOAPProxy('http://127.0.0.1:8080/ContentDirectory/control')
  37. #proxy = UPnPSOAPProxy('http://16.176.65.48:5643/ContentDirectory/control')
  38. #proxy.callRemote('GetSearchCapabilities').addCallbacks(printResult, printError)
  39. #proxy.callRemote('GetSortCapabilities').addCallbacks(printResult, printError)
  40. proxy.callRemote('Browse',
  41. ObjectID = '0\\Music\\Genres\\Others\\chimes.wav',
  42. # BrowseFlag = 'BrowseDirectChildren',
  43. BrowseFlag = 'BrowseMetadata',
  44. Filter = '*',
  45. StartingIndex = 0,
  46. RequestedCount = 700,
  47. SortCriteria = None).addCallbacks(printResult, printError)
  48. reactor.run()