Merge branch 'master' into beta-admin
[pyTivo.git] / pyTivo.py
blob857fa9a5629da0a07d66d9f55ffc4edaedf823e6
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 for f in os.listdir(path):
22 f = os.path.join(path, f)
23 if os.path.isdir(f):
24 build_recursive_list(f)
25 else:
26 pre_cache_filter(f)
28 build_recursive_list(settings.get('path'))
30 b = beacon.Beacon()
31 b.add_service('TiVoMediaServer:' + str(port) + '/http')
32 b.start()
33 if 'listen' in config.getBeaconAddresses():
34 b.listen()
36 print 'pyTivo is ready.'
37 try:
38 httpd.serve_forever()
39 except KeyboardInterrupt:
40 b.stop()