Updated music plugin to suport the full paths
[pyTivo/krkeegan.git] / beacon.py
blob9536fc6b6030c7357cfd5e617566e7ba845eac45
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 beacon.append('machine=%s' % gethostname())
29 beacon.append('platform=pc')
30 beacon.append('services=' + self.format_services())
32 return '\n'.join(beacon)
34 def send_beacon(self):
35 beacon_ips = config.getBeaconAddreses()
36 for beacon_ip in beacon_ips.split():
37 try:
38 self.UDPSock.sendto(self.format_beacon(), (beacon_ip, 2190))
39 except error, e:
40 print e
41 pass
43 def start(self):
44 self.send_beacon()
45 self.timer = Timer(60, self.start)
46 self.timer.start()
48 def stop(self):
49 self.timer.cancel()
51 if __name__ == '__main__':
52 b = Beacon()
55 b.add_service('TiVoMediaServer:9032/http')
56 b.send_beacon_timer()