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