Allow passthrough of MPEG-1 video, but force remuxing, since TiVos don't
[pyTivo/wmcbrine.git] / pyTivo.py
blob3ceff0ceb7452a905159044ffaf3c0804612edfd
1 #!/usr/bin/env python
3 import logging
4 import os
5 import sys
7 import beacon
8 import httpserver
9 import config
10 from plugin import GetPlugin
12 def exceptionLogger(type, value, tb):
13 sys.excepthook = sys.__excepthook__
14 logging.getLogger('pyTivo').exception('Exception in pyTivo')
16 config.init_logging()
17 sys.excepthook = exceptionLogger
19 port = config.getPort()
21 httpd = httpserver.TivoHTTPServer(('', int(port)), httpserver.TivoHTTPHandler)
23 logger = logging.getLogger('pyTivo')
25 for section, settings in config.getShares():
26 httpd.add_container(section, settings)
27 # Precaching of files: does a recursive list of base path
28 if settings.get('precache', 'False').lower() == 'true':
29 plugin = GetPlugin(settings.get('type'))
30 if hasattr(plugin, 'pre_cache'):
31 logger.info('Pre-caching the ' + section + ' share.')
32 pre_cache_filter = getattr(plugin, 'pre_cache')
34 def build_recursive_list(path):
35 try:
36 for f in os.listdir(path):
37 f = os.path.join(path, f)
38 if os.path.isdir(f):
39 build_recursive_list(f)
40 else:
41 pre_cache_filter(f)
42 except:
43 pass
45 build_recursive_list(settings.get('path'))
47 b = beacon.Beacon()
48 b.add_service('TiVoMediaServer:%s/http' % port)
49 b.start()
50 if 'listen' in config.getBeaconAddresses():
51 b.listen()
53 logger.info('pyTivo is ready.')
55 try:
56 httpd.set_beacon(b)
57 httpd.serve_forever()
58 except KeyboardInterrupt:
59 b.stop()