Some more fields from DVR-MS/etc. More sample data needed.
[pyTivo/TheBayer.git] / pyTivo.py
blob6c1acf3d3ea61ed7a526444b4277a694a77f9c47
1 #!/usr/bin/env python
3 import logging
4 import os
5 import sys
7 import beacon
8 import config
9 import httpserver
10 from plugin import GetPlugin
12 def exceptionLogger(*args):
13 sys.excepthook = sys.__excepthook__
14 logging.getLogger('pyTivo').error('Exception in pyTivo', exc_info=args)
16 config.init(sys.argv[1:])
17 config.init_logging()
18 sys.excepthook = exceptionLogger
20 port = config.getPort()
22 httpd = httpserver.TivoHTTPServer(('', int(port)), httpserver.TivoHTTPHandler)
24 logger = logging.getLogger('pyTivo')
26 for section, settings in config.getShares():
27 httpd.add_container(section, settings)
28 # Precaching of files: does a recursive list of base path
29 if settings.get('precache', 'False').lower() == 'true':
30 plugin = GetPlugin(settings.get('type'))
31 if hasattr(plugin, 'pre_cache'):
32 logger.info('Pre-caching the ' + section + ' share.')
33 pre_cache_filter = getattr(plugin, 'pre_cache')
35 def build_recursive_list(path):
36 try:
37 for f in os.listdir(path):
38 f = os.path.join(path, f)
39 if os.path.isdir(f):
40 build_recursive_list(f)
41 else:
42 pre_cache_filter(f)
43 except:
44 pass
46 build_recursive_list(settings.get('path'))
48 b = beacon.Beacon()
49 b.add_service('TiVoMediaServer:%s/http' % port)
50 b.start()
51 if 'listen' in config.getBeaconAddresses():
52 b.listen()
54 logger.info('pyTivo is ready.')
56 try:
57 httpd.set_beacon(b)
58 httpd.serve_forever()
59 except KeyboardInterrupt:
60 b.stop()