pyTivo
[pyTivo/krkeegan.git] / beacon.py
blob5052dbee03555e7a0f710d53c53f17cb35f4388b
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 beacon.append('tivoconnect=1')
21 beacon.append('swversion=1')
22 beacon.append('method=broadcast')
23 beacon.append('identity={AD78BB50-6E59-45E3-B955-1CA740E434C9}')
24 beacon.append('machine=Armooo-Py')
25 beacon.append('platform=pc')
26 beacon.append('services=' + self.format_services())
28 return '\n'.join(beacon)
30 def send_beacon(self):
31 self.UDPSock.sendto(self.format_beacon(), ('255.255.255.255', 2190))
33 def send_beacon_timer(self):
34 self.send_beacon()
35 t = Timer(60, self.send_beacon_timer)
36 t.start()
38 if __name__ == '__main__':
39 b = Beacon()
42 b.add_service('TiVoMediaServer:9032/http')
43 b.send_beacon_timer()