def _retrieve_recordings(self, recurse, itemCount=''):
     #
     url = 'https://{ipaddress}'.format(ipaddress=get_cfg_details_ip())
     uri = '/TiVoConnect?Command=QueryContainer&Container=%2FNowPlaying&Recurse={recurse}{itemCount}'.format(
         recurse=recurse, itemCount=itemCount)
     try:
         #
         r = self.tivoSession.get('{url}{uri}'.format(url=url, uri=uri))
         r_pass = True if r.status_code == requests.codes.ok else False
         #
         result = logPass if r_pass else logFail
         #
         log_outbound(result, get_cfg_details_ip(), self._port, 'GET', uri,
                      '-', '-', r.status_code)
         #
         if r.status_code == requests.codes.ok:
             try:
                 return r.content.decode()
             except:
                 return r.content
         else:
             return False
     except Exception as e:
         #
         log_outbound(logException,
                      get_cfg_details_ip(),
                      self._port,
                      'GET',
                      uri,
                      '-',
                      '-',
                      '-',
                      exception=e)
         return False
 def getChan(self):
     #
     response = self._send_telnet(get_cfg_details_ip(),
                                  self._port,
                                  response=True)
     #
     if not bool(response):
         return False
     #
     nums = [int(s) for s in response.split() if s.isdigit()]
     #
     if len(nums) > 0:
         chan_no = nums[0]
         if bool(chan_no):
             #
             chan_details = get_channel_details_from_key(chan_no)
             #
             json_channel = {}
             json_channel['channel'] = {}
             json_channel['channel']['id'] = chan_details['id']
             json_channel['channel']['name'] = chan_details['name']
             json_channel['channel']['number'] = str(chan_no)
             json_channel['channel']['quality'] = chan_details['quality']
             json_channel['channel']['plus1'] = chan_details['plus1']
             #
             return json_channel
     return False
 def _send_telnet(self, ipaddress, port, data='', response=False):
     try:
         tn = telnetlib.Telnet(ipaddress, port)
         time.sleep(0.1)
         output = tn.read_eager() if response else None
         if data:
             tn.write((str(data) + "\n").encode('ascii'))
             time.sleep(0.1)
             op = tn.read_eager()
             if op == '':
                 output = True
             elif response:
                 output = op if op else True
             else:
                 output = bool(op)
         tn.close()
         return output
     except Exception as e:
         #
         log_outbound(logException,
                      get_cfg_details_ip(),
                      self._port,
                      'TELNET',
                      '',
                      '-',
                      '-',
                      '-',
                      description=data,
                      exception=e)
         return False
 def sendCmd(self, command):
     try:
         r_pass = self._send_telnet(get_cfg_details_ip(),
                                    self._port,
                                    data=commands[command])
         #
         result = logPass if r_pass else logFail
         log_internal(result, logDescDeviceSendCommand)
         return r_pass
     except Exception as e:
         log_internal(logException, logDescDeviceSendCommand, exception=e)
         return False
 def __init__(self):
     #
     self._ipaddress = get_cfg_details_ip()
     self._port = 8080
     self._pairingkey = get_cfg_details_pairingkey()
     #
     self.is_paired = False
     self.apps_timestamp = False
     #
     self.create_session()
     #
     Process(target=self._start_instance).start()
 def sendPin(self):
     #
     pin = get_cfg_details_pin()
     #
     try:
         rsp = []
         for num in pin:
             code = commands[num]
             rsp.append(
                 self._send_telnet(get_cfg_details_ip(),
                                   self._port,
                                   data=code))
         #
         result = logPass if not (False in rsp) else logFail
         log_internal(result, logDescDeviceSendPin)
         return not (False in rsp)
     except Exception as e:
         log_internal(logException, logDescDeviceSendPin, exception=e)
         return False
 def sendChannel(self, chan_id, plus1=False):
     try:
         chan_key = get_channel_key_from_id(chan_id, plus1)
         if chan_key:
             response = self._send_telnet(
                 ipaddress=get_cfg_details_ip(),
                 port=self._port,
                 data=("SETCH {chan_key}\r").format(chan_key=chan_key),
                 response=True)
             if not isinstance(response, bool):
                 if response.startswith('CH_FAILED'):
                     log_internal(logFail, logDescDeviceSendChannel)
                     return False
                 else:
                     log_internal(logPass, logDescDeviceSendChannel)
                     return True
         log_internal(logFail, logDescDeviceSendChannel)
         return False
     except Exception as e:
         log_internal(logException, logDescDeviceSendChannel, exception=e)
         return False