From af5d2e454c49f1c99450ea9c042870c4476a5b52 Mon Sep 17 00:00:00 2001 From: William McBrine Date: Sun, 1 Jun 2014 13:16:04 -0400 Subject: [PATCH] Fall back to adding responders with TSNs *only* if no TiVos are found either via Zeroconf or hardwired in pyTivo.conf. --- beacon.py | 4 ++++ config.py | 11 +++++------ httpserver.py | 9 ++++----- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/beacon.py b/beacon.py index ae604fa..719ba00 100644 --- a/beacon.py +++ b/beacon.py @@ -77,6 +77,10 @@ class ZCBroadcast: # Give them a second to respond time.sleep(1) + # Any results? + if names: + config.tivos_found = True + # Now get the addresses -- this is the slow part for name in names: info = self.rz.getServiceInfo(VIDS, name + '.' + VIDS) diff --git a/config.py b/config.py index 001df39..fbd029f 100644 --- a/config.py +++ b/config.py @@ -17,9 +17,11 @@ def init(argv): global tivos global guid global config_files + global tivos_found tivos = {} guid = uuid.uuid4() + tivos_found = False p = os.path.dirname(__file__) config_files = ['/etc/pyTivo.conf', os.path.join(p, 'pyTivo.conf')] @@ -41,6 +43,7 @@ def reset(): global bin_paths global config global configs_found + global tivos_found bin_paths = {} @@ -55,12 +58,8 @@ def reset(): if section.startswith('_tivo_'): tsn = section[6:] if tsn.upper() not in ['SD', 'HD']: - if config.has_option(section, 'name'): - tivo_names[tsn] = config.get(section, 'name') - else: - tivo_names[tsn] = tsn - if config.has_option(section, 'address'): - tivos[tsn] = config.get(section, 'address') + tivos_found = True + tivos[tsn] = Bdict(config.items(section)) for section in ['Server', '_tivo_SD', '_tivo_HD']: if not config.has_section(section): diff --git a/httpserver.py b/httpserver.py index e1bdf1d..37b489c 100644 --- a/httpserver.py +++ b/httpserver.py @@ -106,12 +106,11 @@ class TivoHTTPHandler(BaseHTTPServer.BaseHTTPRequestHandler): self.headers.getheader('tsn', '')) if not self.authorize(tsn): return - #if tsn: - # ip = self.address_string() - # config.tivos[tsn] = ip - # if not tsn in config.tivo_names or config.tivo_names[tsn] == tsn: - # config.tivo_names[tsn] = self.server.beacon.get_name(ip) + if tsn and not config.tivos_found and not tsn in config.tivos: + ip = self.address_string() + name = self.server.beacon.get_name(ip) + config.tivos[tsn] = {'address': ip, 'name': name} if '?' in self.path: path, opts = self.path.split('?', 1) -- 2.11.4.GIT