Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- """An mDNS daemon designed to appear, to the iPad app, to be a TiVo Premiere."""
- import sys
- import Zeroconf
- import socket
- import time
- tivo_nicenames={'1234':'Tivo Bedroom', 'ABCD':'Tivo Lounge'}
- def find_tivos_zc():
- """ Find TiVos on the LAN using Zeroconf. This is simpler and
- cleaner than the fake HTTP method, but slightly slower, and
- requires the Zeroconf module. (It's still much faster than
- waiting for beacons.)
- """
- global tivo_swversions
- class ZCListener:
- def __init__(self, names):
- self.names = names
- def removeService(self, server, type, name):
- self.names.remove(name)
- def addService(self, server, type, name):
- self.names.append(name)
- service_name = '_tivo-device._tcp.local.'
- tivos = []
- tivo_names = []
- # Get the names of TiVos offering network remote control
- try:
- serv = Zeroconf.Zeroconf()
- browser = Zeroconf.ServiceBrowser(serv, service_name, ZCListener(tivo_names))
- except:
- return tivos
- # Give them half a second to respond
- time.sleep(0.5)
- # Now get the addresses -- this is the slow part
- for t in tivo_names:
- s = serv.getServiceInfo(service_name, t)
- if s:
- new_tivo = {}
- name = t.replace('.' + service_name, '')
- address = socket.inet_ntoa(s.getAddress())
- new_tivo['service_name'] = name;
- new_tivo['ip_address'] = address;
- new_tivo['tsn'] = s.getProperties()['TSN'];
- tivos.append(new_tivo);
- serv.close()
- return tivos
- def registerTivo( server, local_ip, TSN, tivo_name ):
- # You need the right value here. Either use tcpdump to find the value that
- # your TiVo device advertises, or navigate to:
- # Account & System Info
- # System Information
- # TiVo Service Number
- # It should be 15 hex digits (0-9 and a-f) with no dashes. All in uppercase
- # to be safe.
- #IP address of your PC/laptop
- server.registerService(
- Zeroconf.ServiceInfo(
- '_tivo-device._tcp.local.',
- tivo_name+'._tivo-device._tcp.local.',
- address = local_ip,
- port = 80,
- weight = 0, priority=0,
- properties = {
- 'path': '/',
- 'services': '_tivo-mindrpc._tcp,_tivo-remote._tcp',
- 'platformname': 'TiVo Premiere',
- 'swversion': '14.8.U2-01-3.746',
- 'platform': 'tcd/Series4',
- 'TSN': TSN,
- }
- )
- )
- server.registerService(
- Zeroconf.ServiceInfo(
- '_http._tcp.local.',
- tivo_name+'._http._tcp.local.',
- address = local_ip,
- port = 80,
- weight = 0, priority=0,
- properties = {
- 'path': '/index.html',
- 'swversion': '14.8.U2-01-3.746',
- 'platform': 'tcd/Series4',
- 'TSN': TSN,
- }
- )
- )
- server.registerService(
- Zeroconf.ServiceInfo(
- '_tivo-mindrpc._tcp.local.',
- tivo_name+'._tivo-mindrpc._tcp.local.',
- address = local_ip,
- port = 1413,
- weight = 0, priority=0,
- properties = {
- 'protocol': 'tivo-mindrpc',
- 'path': '/',
- 'swversion': '14.8.U2-01-3.746',
- 'platform': 'tcd/Series4',
- 'TSN': TSN,
- }
- )
- )
- server.registerService(
- Zeroconf.ServiceInfo(
- '_tivo-videos._tcp.local.',
- tivo_name+'._tivo-videos._tcp.local.',
- address = local_ip,
- port = 443,
- weight = 0, priority=0,
- properties = {
- 'protocol': 'https',
- 'path': '/TiVoConnect?Command=QueryContainer&Container=%2FNowPlaying',
- 'swversion': '14.8.U2-01-3.746',
- 'platform': 'tcd/Series4',
- 'TSN': TSN,
- }
- )
- )
- server.registerService(
- Zeroconf.ServiceInfo(
- '_tivo-remote._tcp.local.',
- tivo_name+'._tivo-remote._tcp.local.',
- address = local_ip,
- port = 1393,
- weight = 0, priority=0,
- properties = {
- 'platformname': 'TiVo Premiere',
- 'swversion': '14.8.U2-01-3.746',
- 'platform': 'tcd/Series4',
- 'TSN': TSN,
- }
- )
- )
- tivos = find_tivos_zc();
- server = Zeroconf.Zeroconf()
- for tivo in tivos:
- tivo_name = ""
- if tivo_nicenames.has_key(tivo['service_name']):
- tivo_name = tivo_nicenames[tivo['service_name']];
- else:
- tivo_name = "VM "+tivo['service_name'];
- print("Registering tivo "+tivo['service_name']+" as "+tivo_name+"...")
- registerTivo(server, socket.inet_aton(tivo['ip_address']), tivo['tsn'], tivo_name);
- print 'Running mDNS daemon ...'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement