- pyTivo
[pyTivo/krkeegan.git] / beacon.py
blobf7afbadf267f18abceb1c0670d72b0b6f4934264
1 from socket import *
2 from threading import Timer
4 class Beacon:
6 UDPSock = socket(AF_INET, SOCK_DGRAM)
7 UDPSock.setsockopt(SOL_SOCKET, SO_BROADCAST, 1)
8 services = []
10 def add_service(self, service):
11 self.services.append(service)
12 self.send_beacon()
14 def format_services(self):
15 return ';'.join(self.services)
17 def format_beacon(self):
18 beacon = []
20 from Config import config
22 if config.has_option('Server', 'GUID'):
23 guid = config.get('Server', 'GUID')
24 else:
25 guid = '123456'
27 beacon.append('tivoconnect=1')
28 beacon.append('swversion=1')
29 beacon.append('method=broadcast')
30 beacon.append('identity=%s' % guid)
32 import socket
33 beacon.append('machine=%s' % socket.gethostname())
34 beacon.append('platform=pc')
35 beacon.append('services=' + self.format_services())
37 return '\n'.join(beacon)
39 def send_beacon(self):
40 self.UDPSock.sendto(self.format_beacon(), ('255.255.255.255', 2190))
42 def start(self):
43 self.send_beacon()
44 self.timer = Timer(60, self.start)
45 self.timer.start()
47 def stop(self):
48 self.timer.cancel()
50 if __name__ == '__main__':
51 b = Beacon()
54 b.add_service('TiVoMediaServer:9032/http')
55 b.send_beacon_timer()