Now sending good datetimes, title fixed on display
[pyTivo.git] / beacon.py
blobfe0b05bc0e3b99c9c60df62af420726e071cb4d2
1 from socket import *
2 from threading import Timer
3 import config
5 class Beacon:
7 UDPSock = socket(AF_INET, SOCK_DGRAM)
8 UDPSock.setsockopt(SOL_SOCKET, SO_BROADCAST, 1)
9 services = []
11 def add_service(self, service):
12 self.services.append(service)
13 self.send_beacon()
15 def format_services(self):
16 return ';'.join(self.services)
18 def format_beacon(self):
19 beacon = []
21 guid = config.getGUID()
23 beacon.append('tivoconnect=1')
24 beacon.append('swversion=1')
25 beacon.append('method=broadcast')
26 beacon.append('identity=%s' % guid)
28 import socket
29 beacon.append('machine=%s' % socket.gethostname())
30 beacon.append('platform=pc')
31 beacon.append('services=' + self.format_services())
33 return '\n'.join(beacon)
35 def send_beacon(self):
36 beacon_ips = config.getBeaconAddreses()
37 for beacon_ip in beacon_ips.split():
38 self.UDPSock.sendto(self.format_beacon(), (beacon_ip, 2190))
40 def start(self):
41 self.send_beacon()
42 self.timer = Timer(60, self.start)
43 self.timer.start()
45 def stop(self):
46 self.timer.cancel()
48 if __name__ == '__main__':
49 b = Beacon()
52 b.add_service('TiVoMediaServer:9032/http')
53 b.send_beacon_timer()