@@ -47,15 +47,15 @@ import os.path
import random
import socket
import string
import urlparse
from twisted.application import internet, service
from twisted.python import usage
def generateuuid():
if False:
return 'uuid:asdflkjewoifjslkdfj'
return ''.join([ 'uuid:'] + map(lambda x: random.choice(string.letters), xrange(20)))
class Options(usage.Options):
checkpath = True
optParameters = [
[ 'title', 't', 'My Media Server', 'Title of the server.', ],
[ 'path', 'p', 'media', 'Root path of the media to be served.', ],
@@ -63,7 +63,7 @@ class Options(usage.Options):
def postOptions(self):
p = self['path']
if not os.path.isdir(p):
if self.checkpath and not os.path.isdir(p):
raise usage.UsageError, 'path %s does not exist' % `p`
def parseArgs(self, *args):
@@ -83,6 +83,10 @@ class Options(usage.Options):
'port must be between 1024 and 65535')
self['port'] = port
class PyMedS(service.MultiService):
def startService(self):
service.MultiService.startService(self)
def makeService(config):
listenAddr = config['addr']
listenPort = config['port']
@@ -98,7 +102,10 @@ def makeService(config):
internet.MulticastServer(SSDP_PORT, s,
listenMultiple=True).setServiceParent(serv)
uuid = generateuuid()
uuid = config.get('uuid', None)
if uuid is None:
uuid = generateuuid()
urlbase = 'http://%s:%d/' % (listenAddr, listenPort)
# Create SOAP server and content server
@@ -123,11 +130,11 @@ def makeService(config):
root = WebServer()
debug.insertnamespace('root', root)
content = resource.Resource()
# This sets up the root to be the media dir so we don't have to enumerate
# the directory
# This sets up the root to be the media dir so we don't have to
# enumerate the directory.
cds = ContentDirectoryServer(config['title'], klass=FSDirectory,
path=config['path'], urlbase=os.path. join(urlbase, 'content'),
webbase=content)
path=config['path'], urlbase=urlparse.url join(urlbase, 'content'),
webbase=content)
debug.insertnamespace('cds', cds)
root.putChild('ContentDirectory', cds)
cds = cds.control
@@ -137,7 +144,8 @@ def makeService(config):
# Purely to ensure some sane mime-types. On MacOSX I need these.
# XXX - There isn't any easier way to get to the mime-type dict that I know of.
# XXX - There isn't any easier way to get to the mime-type dict
# that I know of.
medianode = static.File('pymediaserv')
medianode.contentTypes.update( {
# From: http://support.microsoft.com/kb/288102
@@ -171,7 +179,6 @@ def makeService(config):
internet.TCPServer(listenPort, site).setServiceParent(serv)
# we need to do this after the children are there, since we send notifies
import urlparse
rdxml = urlparse.urljoin(urlbase, 'root-device.xml')
s.register('%s::upnp:rootdevice' % uuid,
'upnp:rootdevice', rdxml)