2 from threading
import Timer
3 from Config
import config
7 UDPSock
= socket(AF_INET
, SOCK_DGRAM
)
8 UDPSock
.setsockopt(SOL_SOCKET
, SO_BROADCAST
, 1)
11 def add_service(self
, service
):
12 self
.services
.append(service
)
15 def format_services(self
):
16 return ';'.join(self
.services
)
18 def format_beacon(self
):
21 from Config
import config
23 if config
.has_option('Server', 'GUID'):
24 guid
= config
.get('Server', 'GUID')
28 beacon
.append('tivoconnect=1')
29 beacon
.append('swversion=1')
30 beacon
.append('method=broadcast')
31 beacon
.append('identity=%s' % guid
)
34 beacon
.append('machine=%s' % socket
.gethostname())
35 beacon
.append('platform=pc')
36 beacon
.append('services=' + self
.format_services())
38 return '\n'.join(beacon
)
40 def send_beacon(self
):
41 if config
.has_option('Server', 'beacon'):
42 beacon_ips
= config
.get('Server', 'beacon')
44 beacon_ips
= '255.255.255.255'
45 for beacon_ip
in beacon_ips
.split():
46 self
.UDPSock
.sendto(self
.format_beacon(), (beacon_ip
, 2190))
50 self
.timer
= Timer(60, self
.start
)
56 if __name__
== '__main__':
60 b
.add_service('TiVoMediaServer:9032/http')