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.
 
 

78 lines
2.1 KiB

  1. #!/usr/bin/python
  2. # Licensed under the MIT license
  3. # http://opensource.org/licenses/mit-license.php
  4. # (c) 2005, Tim Potter <tpot@samba.org>
  5. import sys
  6. from twisted.python import log
  7. from twisted.internet import reactor
  8. listenAddr = sys.argv[1]
  9. log.startLogging(sys.stdout)
  10. # Create SSDP server
  11. from SSDP import SSDPServer, SSDP_PORT, SSDP_ADDR
  12. s = SSDPServer()
  13. port = reactor.listenMulticast(SSDP_PORT, s, SSDP_ADDR)
  14. port.joinGroup(SSDP_ADDR, listenAddr)
  15. uuid = 'uuid:XVKKBUKYRDLGJQDTPOT'
  16. s.register('%s::upnp:rootdevice' % uuid,
  17. 'upnp:rootdevice',
  18. 'http://%s:8080/root-device.xml' % listenAddr)
  19. s.register(uuid,
  20. uuid,
  21. 'http://%s:8080/root-device.xml' % listenAddr)
  22. s.register('%s::urn:schemas-upnp-org:device:MediaServer:1' % uuid,
  23. 'urn:schemas-upnp-org:device:MediaServer:1',
  24. 'http://%s:8080/root-device.xml' % listenAddr)
  25. s.register('%s::urn:schemas-upnp-org:service:ConnectionManager:1' % uuid,
  26. 'urn:schemas-upnp-org:device:ConnectionManager:1',
  27. 'http://%s:8080/root-device.xml' % listenAddr)
  28. s.register('%s::urn:schemas-upnp-org:service:ContentDirectory:1' % uuid,
  29. 'urn:schemas-upnp-org:device:ContentDirectory:1',
  30. 'http://%s:8080/root-device.xml' % listenAddr)
  31. # Create SOAP server
  32. from twisted.web import server, resource, static
  33. from ContentDirectory import ContentDirectoryServer
  34. from ConnectionManager import ConnectionManagerServer
  35. class WebServer(resource.Resource):
  36. def __init__(self):
  37. resource.Resource.__init__(self)
  38. class RootDevice(static.File):
  39. def __init__(self):
  40. static.File.__init__(self, 'root-device.xml', defaultType = 'text/xml')
  41. root = WebServer()
  42. root.putChild('ContentDirectory', ContentDirectoryServer())
  43. root.putChild('ConnectionManager', ConnectionManagerServer())
  44. root.putChild('root-device.xml', RootDevice())
  45. # Area of server to serve media files from
  46. from MediaServer import MediaServer
  47. root.putChild('media', static.File('media'))
  48. site = server.Site(root)
  49. reactor.listenTCP(8080, site)
  50. # Main loop
  51. reactor.run()