#!/usr/bin/python # Licensed under the MIT license # http://opensource.org/licenses/mit-license.php # (c) 2005, Tim Potter import sys from twisted.python import log from twisted.internet import reactor listenAddr = sys.argv[1] log.startLogging(sys.stdout) # Create SSDP server from SSDP import SSDPServer, SSDP_PORT, SSDP_ADDR s = SSDPServer() port = reactor.listenMulticast(SSDP_PORT, s, SSDP_ADDR) port.joinGroup(SSDP_ADDR, listenAddr) uuid = 'uuid:XVKKBUKYRDLGJQDTPOT' s.register('%s::upnp:rootdevice' % uuid, 'upnp:rootdevice', 'http://%s:8080/root-device.xml' % listenAddr) s.register(uuid, uuid, 'http://%s:8080/root-device.xml' % listenAddr) s.register('%s::urn:schemas-upnp-org:device:MediaServer:1' % uuid, 'urn:schemas-upnp-org:device:MediaServer:1', 'http://%s:8080/root-device.xml' % listenAddr) s.register('%s::urn:schemas-upnp-org:service:ConnectionManager:1' % uuid, 'urn:schemas-upnp-org:device:ConnectionManager:1', 'http://%s:8080/root-device.xml' % listenAddr) s.register('%s::urn:schemas-upnp-org:service:ContentDirectory:1' % uuid, 'urn:schemas-upnp-org:device:ContentDirectory:1', 'http://%s:8080/root-device.xml' % listenAddr) # Create SOAP server from twisted.web import server, resource, static from ContentDirectory import ContentDirectoryServer from ConnectionManager import ConnectionManagerServer class WebServer(resource.Resource): def __init__(self): resource.Resource.__init__(self) class RootDevice(static.File): def __init__(self): static.File.__init__(self, 'root-device.xml', defaultType = 'text/xml') root = WebServer() root.putChild('ContentDirectory', ContentDirectoryServer()) root.putChild('ConnectionManager', ConnectionManagerServer()) root.putChild('root-device.xml', RootDevice()) # Area of server to serve media files from from MediaServer import MediaServer root.putChild('media', static.File('media')) site = server.Site(root) reactor.listenTCP(8080, site) # Main loop reactor.run()