Omit the colon when there's no episode title.
[pyTivo/TheBayer.git] / pyTivoService.py
blobc216a6dea26177572e2b5695873935f518909c3f
1 import beacon, httpserver
2 import win32serviceutil
3 import win32service
4 import win32event
5 import select, sys
6 import config
8 class PyTivoService(win32serviceutil.ServiceFramework):
9 _svc_name_ = 'pyTivo'
10 _svc_display_name_ = 'pyTivo'
12 def __init__(self, args):
13 win32serviceutil.ServiceFramework.__init__(self, args)
14 self.stop_event = win32event.CreateEvent(None, 0, 0, None)
16 def SvcDoRun(self):
18 import sys, os
20 p = os.path.dirname(__file__)
22 f = open(os.path.join(p, 'log.txt'), 'w')
23 sys.stdout = f
24 sys.stderr = f
27 port = config.getPort()
29 httpd = httpserver.TivoHTTPServer(('', int(port)),
30 httpserver.TivoHTTPHandler)
32 for section, settings in config.getShares():
33 httpd.add_container(section, settings)
35 b = beacon.Beacon()
36 b.add_service('TiVoMediaServer:' + str(port) + '/http')
37 b.start()
38 if 'listen' in config.getBeaconAddresses():
39 b.listen()
41 httpd.set_beacon(b)
43 while 1:
44 sys.stdout.flush()
45 (rx, tx, er) = select.select((httpd,), (), (), 5)
46 for sck in rx:
47 sck.handle_request()
48 rc = win32event.WaitForSingleObject(self.stop_event, 5)
49 if rc == win32event.WAIT_OBJECT_0:
50 b.stop()
51 break
53 def SvcStop(self):
54 win32event.SetEvent(self.stop_event)
56 if __name__ == '__main__':
57 win32serviceutil.HandleCommandLine(PyTivoService)