Updated to support webvideo
[pyTivo.git] / pyTivo.py
blob6a161c7da49ff15302aad6e5561cecfb1db5a06b
1 #!/usr/bin/env python
3 import beacon, httpserver, os, sys
4 import config
5 from plugin import GetPlugin
7 port = config.getPort()
9 httpd = httpserver.TivoHTTPServer(('', int(port)), httpserver.TivoHTTPHandler)
11 for section, settings in config.getShares():
12 httpd.add_container(section, settings)
13 # Precaching of files: does a recursive list of base path
14 if settings.get('precache', 'False').lower() == 'true':
15 plugin = GetPlugin(settings.get('type'))
16 if hasattr(plugin, 'pre_cache'):
17 print 'Pre-caching the', section, 'share.'
18 pre_cache_filter = getattr(plugin, 'pre_cache')
20 def build_recursive_list(path):
21 try:
22 for f in os.listdir(path):
23 f = os.path.join(path, f)
24 if os.path.isdir(f):
25 build_recursive_list(f)
26 else:
27 pre_cache_filter(f)
28 except:
29 pass
31 build_recursive_list(settings.get('path'))
33 b = beacon.Beacon()
34 b.add_service('TiVoMediaServer:' + str(port) + '/http')
35 b.start()
36 if 'listen' in config.getBeaconAddresses():
37 b.listen()
39 print 'pyTivo is ready.'
40 try:
41 httpd.serve_forever()
42 except KeyboardInterrupt:
43 b.stop()