diff --git a/pymediaserv b/pymediaserv index 4407164..4fcbb51 100755 --- a/pymediaserv +++ b/pymediaserv @@ -5,7 +5,7 @@ # Copyright 2005, Tim Potter # Copyright 2006 John-Mark Gurney -from DIDLLite import TextItem, AudioItem, VideoItem, Resource +from DIDLLite import TextItem, AudioItem, VideoItem, Resource, StorageFolder import os import os.path import random @@ -86,31 +86,37 @@ medianode.contentTypes.update( { root.putChild('media', medianode) # Set up media files -allmedia = cds.addContainer('0', 'All Media') -for i in os.listdir('media'): - fpath = os.path.join('media', i) - try: - if not os.path.isfile(fpath): - continue - fn, ext = os.path.splitext(i) - if ext == '.ts': - continue - mt = medianode.contentTypes[ext] - ty = mt.split('/')[0] - if ty == 'video': - klass = VideoItem - elif ty == 'audio': - klass = AudioItem - elif ty == 'text': - klass = TextItem - else: - raise KeyError, 'no item for mt: %s' % mt - - item = cds.addItem(allmedia, klass, fn) - cds[item].res = Resource('%smedia/%s' % (urlbase, i), 'http-get:*:%s:*' % mt) - cds[item].res.size = os.path.getsize(fpath) - except KeyError: - pass +def addFSPath(parent, title, dpath): + folder = cds.addContainer(parent, title, klass = StorageFolder) + log.msg('title: %s, dpath: %s' % (title, dpath)) + for i in os.listdir(dpath): + fpath = os.path.join(dpath, i) + try: + fn, ext = os.path.splitext(i) + if os.path.isdir(fpath): + addFSPath(folder, fn, fpath) + if not os.path.isfile(fpath): + continue + if ext == '.ts': + continue + mt = medianode.contentTypes[ext] + ty = mt.split('/')[0] + if ty == 'video': + klass = VideoItem + elif ty == 'audio': + klass = AudioItem + elif ty == 'text': + klass = TextItem + else: + raise KeyError, 'no item for mt: %s' % mt + + item = cds.addItem(folder, klass, fn) + cds[item].res = Resource('%smedia/%s' % (urlbase, i), 'http-get:*:%s:*' % mt) + cds[item].res.size = os.path.getsize(fpath) + except KeyError: + pass + +addFSPath('0', 'All Media', 'media') site = server.Site(root) reactor.listenTCP(listenPort, site)