def fetch(self, cmd, img=False, timeout=10): try: host = htpc.settings.get('sickbeard_host', '') port = str(htpc.settings.get('sickbeard_port', '')) apikey = htpc.settings.get('sickbeard_apikey', '') ssl = 's' if htpc.settings.get('sickbeard_ssl', 0) else '' sickbeard_basepath = fix_basepath( htpc.settings.get('sickbeard_basepath', '/')) url = 'http' + ssl + '://' + host + ':' + str( port) + sickbeard_basepath + 'api/' + apikey + '/?cmd=' + cmd self.logger.debug('Fetching information from: %s' % url) if img is True: # Cache image return get_image(url) r = requests.get(url, timeout=timeout, verify=False) if r: r = r.json() return r except: self.logger.error('Unable to fetch information') return
def ping(self, sickbeard_host, sickbeard_port, sickbeard_apikey, sickbeard_basepath, sickbeard_ssl=False, **kwargs): self.logger.info('Testing connectivity') ssl = 's' if sickbeard_ssl else '' if not sickbeard_basepath: sickbeard_basepath = fix_basepath(sickbeard_basepath) url = 'http%s://%s:%s%sapi/%s/?cmd=sb.ping' % ( ssl, striphttp(sickbeard_host), sickbeard_port, sickbeard_basepath, sickbeard_apikey) try: self.logger.debug('Trying to contact sickbeard via %s' % url) response = requests.get(url, timeout=10, verify=False) r = response.json() if r.get('result') == 'success': self.logger.debug('Sicbeard connectivity test success') return r except: self.logger.error('Unable to contact sickbeard via %s' % url) return
def version(self, nzbget_host, nzbget_basepath, nzbget_port, nzbget_username, nzbget_password, nzbget_ssl=False, **kwargs): self.logger.debug("Fetching version information from nzbget") ssl = 's' if nzbget_ssl else '' nzbget_basepath = fix_basepath(nzbget_basepath) url = 'http%s://%s:%s%sjsonrpc/version' % ( ssl, striphttp(nzbget_host), nzbget_port, nzbget_basepath) try: if nzbget_username and nzbget_password: r = requests.get(url, timeout=10, auth=(nzbget_username, nzbget_password)) else: r = requests.get(url, timeout=10) return r.json() except: self.logger.error("Unable to contact nzbget via %s" % url) return
def fetch(self, method, arguments=''): ''' Do request to Transmission api ''' self.logger.debug('Request transmission method: ' + method) host = striphttp(htpc.settings.get('transmission_host', '')) port = str(htpc.settings.get('transmission_port', '')) basepath = htpc.settings.get('transmission_rpcbasepath') username = htpc.settings.get('transmission_username') password = htpc.settings.get('transmission_password') auth = None # Default basepath is transmission if not basepath: basepath = '/transmission/' basepath = fix_basepath(basepath) url = 'http://%s:%s%srpc/' % (host, str(port), basepath) # format post data data = {'method': method} if arguments: data['arguments'] = arguments data = dumps(data) # Set Header header = { 'X-Transmission-Session-Id': self.sessionId, 'Content-Type': 'json; charset=UTF-8' } if username and password: auth = (username, password) try: r = self.reqz.post(url, data=data, timeout=10, auth=auth, headers=header) if r.ok: return r.json() else: if r.status_code == 409 and r.headers[ 'x-transmission-session-id']: self.renewsession(url, data, header, auth, r) except Exception as e: self.logger.error('Unable to fetch information from: %s %s %s' % (url, data, e)) return
def webinterface(self): ''' Generate page from template ''' ssl = 's' if htpc.settings.get('couchpotato_ssl', 0) else '' host = striphttp(htpc.settings.get('couchpotato_host', '')) port = str(htpc.settings.get('couchpotato_port', '')) basepath = fix_basepath(htpc.settings.get('couchpotato_basepath', '/')) url = 'http%s://%s:%s%s' % (ssl, host, port, basepath) if htpc.settings.get('couchpotato_reverse_proxy_link'): url = htpc.settings.get('couchpotato_reverse_proxy_link') return url
def webinterface(self): ''' Generate page from template ''' ssl = 's' if htpc.settings.get('sickbeard_ssl', 0) else '' host = striphttp(htpc.settings.get('sickbeard_host', '')) port = str(htpc.settings.get('sickbeard_port', '')) basepath = fix_basepath(htpc.settings.get('sickbeard_basepath', '/')) url = 'http%s://%s:%s%s' % (ssl, host, port, basepath) if htpc.settings.get('sickbeard_reverse_proxy_link'): url = htpc.settings.get('sickbeard_reverse_proxy_link') return url
def webinterface(self): host = striphttp(htpc.settings.get('deluge_host', '')) port = str(htpc.settings.get('deluge_port', '')) deluge_basepath = fix_basepath(htpc.settings.get( 'deluge_basepath', '')) ssl = 's' if htpc.settings.get('deluge_ssl') else '' url = 'http%s://%s:%s%s' % (ssl, host, port, deluge_basepath) if htpc.settings.get('deluge_reverse_proxy_link'): url = htpc.settings.get('deluge_reverse_proxy_link') return url
def webinterface(self): host = striphttp(htpc.settings.get('sickrage_host', '')) port = str(htpc.settings.get('sickrage_port', '')) apikey = htpc.settings.get('sickrage_apikey', '') ssl = 's' if htpc.settings.get('sickrage_ssl', 0) else '' sickrage_basepath = fix_basepath(htpc.settings.get('sickrage_basepath', '/')) url = 'http%s://%s:%s%s' % (ssl, host, port, sickrage_basepath) if htpc.settings.get('sickrage_reverse_proxy_link'): url = htpc.settings.get('sickrage_reverse_proxy_link') return url
def _build_url(ssl=None, host=None, port=None, base_path=None): ssl = ssl or htpc.settings.get('mylar_ssl') host = host or htpc.settings.get('mylar_host') port = port or htpc.settings.get('mylar_port') path = fix_basepath(htpc.settings.get('mylar_basepath', '/')) url = '{protocol}://{host}:{port}{path}'.format( protocol='https' if ssl else 'http', host=host, port=port, path=path, ) return url
def fetch(self, path): try: host = striphttp(htpc.settings.get('sabnzbd_host', '')) port = str(htpc.settings.get('sabnzbd_port', '')) apikey = htpc.settings.get('sabnzbd_apikey', '') sabnzbd_basepath = fix_basepath(htpc.settings.get('sabnzbd_basepath', '/sabnzbd/')) ssl = 's' if htpc.settings.get('sabnzbd_ssl', 0) else '' url = 'http%s://%s:%s%sapi?output=json&apikey=%s%s' % (ssl, host, port, sabnzbd_basepath, apikey, path) self.logger.debug('Fetching information from: %s' % url) return loads(urlopen(url, timeout=10).read(), strict=False) except Exception as e: self.logger.error('Cannot contact sabnzbd %s' % e) return
def ping(self, couchpotato_host, couchpotato_port, couchpotato_apikey, couchpotato_basepath, couchpotato_ssl=False, **kwargs): self.logger.debug('Testing connectivity to couchpotato') couchpotato_basepath = fix_basepath(couchpotato_basepath) couchpotato_host = striphttp(couchpotato_host) ssl = 's' if couchpotato_ssl else '' url = 'http%s://%s:%s%sapi/%s' % (ssl, couchpotato_host, couchpotato_port, couchpotato_apikey) try: f = requests.get(url + '/app.available/', timeout=10) return f.json() except: self.logger.error('Unable to connect to couchpotato') self.logger.debug('connection-URL: %s' % url) return
def Version(self, sonarr_host, sonarr_port, sonarr_basepath, sonarr_apikey, sonarr_ssl=False, **kwargs): try: ssl = 's' if sonarr_ssl else '' if not sonarr_basepath: sonarr_basepath = fix_basepath(sonarr_basepath) headers = {'X-Api-Key': str(sonarr_apikey)} url = 'http%s://%s:%s%sapi/system/status' % (ssl, striphttp(sonarr_host), sonarr_port, sonarr_basepath) result = requests.get(url, headers=headers, verify=False) return result.json() except: return
def webinterface(self): host = striphttp(htpc.settings.get('sonarr_host', '')) port = str(htpc.settings.get('sonarr_port', '')) sonarr_basepath = htpc.settings.get('sonarr_basepath', '/') ssl = 's' if htpc.settings.get('sonarr_ssl', True) else '' # Makes sure that the basepath is /whatever/ sonarr_basepath = fix_basepath(sonarr_basepath) url = 'http%s://%s:%s%s' % (ssl, host, port, sonarr_basepath) if htpc.settings.get('sonarr_reverse_proxy_link'): url = htpc.settings.get('sonarr_reverse_proxy_link') return url
def nzbget_url(self): host = striphttp(htpc.settings.get('nzbget_host', '')) port = str(htpc.settings.get('nzbget_port', '')) username = htpc.settings.get('nzbget_username', '') password = htpc.settings.get('nzbget_password', '') nzbget_basepath = fix_basepath(htpc.settings.get('nzbget_basepath', '/')) ssl = 's' if htpc.settings.get('nzbget_ssl', True) else '' if username and password: authstring = '%s:%s@' % (username, password) else: authstring = '' url = 'http%s://%s%s:%s%sjsonrpc' % (ssl, authstring, host, port, nzbget_basepath) return url
def version(self, sabnzbd_host, sabnzbd_basepath, sabnzbd_port, sabnzbd_apikey, sabnzbd_ssl=False, **kwargs): self.logger.debug('Fetching version information from sabnzbd') ssl = 's' if sabnzbd_ssl else '' if not sabnzbd_basepath: sabnzbd_basepath = '/sabnzbd/' sabnzbd_basepath = fix_basepath(sabnzbd_basepath) url = 'http%s://%s:%s%sapi?output=json&apikey=%s' % (ssl, striphttp(sabnzbd_host), sabnzbd_port, sabnzbd_basepath, sabnzbd_apikey) try: return loads(urlopen(url + '&mode=version', timeout=10).read()) except: self.logger.error('Unable to contact sabnzbd via ' + url) return
def ping(self, **kwargs): ''' Test connection to Transmission ''' host = kwargs['transmission_host'] port = kwargs['transmission_port'] username = kwargs['transmission_username'] password = kwargs['transmission_password'] basepath = kwargs['transmission_rpcbasepath'] auth = None if not basepath: basepath = fix_basepath('/transmission/') url = 'http://%s:%s%srpc/' % (striphttp(host), port, basepath) # format post data data = {'method': 'session-get'} data = dumps(data) # Set Header header = { 'X-Transmission-Session-Id': self.sessionId, 'Content-Type': 'json; charset=UTF-8' } # Add authentication if username and password: auth = (username, password) try: r = self.reqz.post(url, data=data, timeout=10, headers=header, auth=auth) if r.ok: return r.json() else: if r.status_code == 409 and r.headers[ 'x-transmission-session-id']: self.logger.debug( 'Retry Transmission api with new session id.') res = self.renewsession(url, data, header, auth, r) return res except Exception as e: self.logger.error('Unable to fetch information from: %s %s' % (url, e)) return
def fetch(self, method, arguments=''): ''' Do request to Transmission api ''' self.logger.debug('Request transmission method: ' + method) host = striphttp(htpc.settings.get('transmission_host', '')) port = str(htpc.settings.get('transmission_port', '')) basepath = htpc.settings.get('transmission_rpcbasepath') username = htpc.settings.get('transmission_username') password = htpc.settings.get('transmission_password') auth = None # Default basepath is transmission if not basepath: basepath = '/transmission/' basepath = fix_basepath(basepath) url = 'http://%s:%s%srpc/' % (host, str(port), basepath) # format post data data = {'method': method} if arguments: data['arguments'] = arguments data = dumps(data) # Set Header header = { 'X-Transmission-Session-Id': self.sessionId, 'Content-Type': 'json; charset=UTF-8' } if username and password: auth = (username, password) try: r = self.reqz.post(url, data=data, timeout=10, auth=auth, headers=header) if r.ok: return r.json() else: if r.status_code == 409 and r.headers['x-transmission-session-id']: self.renewsession(url, data, header, auth, r) except Exception as e: self.logger.error('Unable to fetch information from: %s %s %s' % (url, data, e)) return
def webinterface(self): host = striphttp(htpc.settings.get('sabnzbd_host', '')) port = str(htpc.settings.get('sabnzbd_port', '')) basepath = htpc.settings.get('sabnzbd_basepath') ssl = 's' if htpc.settings.get('sabnzbd_ssl', 0) else '' if not basepath: basepath = '/sabnzbd/' sabnzbd_basepath = fix_basepath(basepath) url = 'http%s://%s:%s%s' % (ssl, host, port, sabnzbd_basepath) if htpc.settings.get('sabnzbd_reverse_proxy_link'): url = htpc.settings.get('sabnzbd_reverse_proxy_link') return url
def nzbget_url(self): host = striphttp(htpc.settings.get('nzbget_host', '')) port = str(htpc.settings.get('nzbget_port', '')) username = htpc.settings.get('nzbget_username', '') password = htpc.settings.get('nzbget_password', '') nzbget_basepath = fix_basepath( htpc.settings.get('nzbget_basepath', '/')) ssl = 's' if htpc.settings.get('nzbget_ssl', True) else '' if username and password: authstring = '%s:%s@' % (username, password) else: authstring = '' url = 'http%s://%s%s:%s%sjsonrpc' % (ssl, authstring, host, port, nzbget_basepath) return url
def ping(self, sickrage_host, sickrage_port, sickrage_apikey, sickrage_basepath, sickrage_ssl=False, **kwargs): ssl = 's' if sickrage_ssl else '' self.logger.debug('Testing connectivity') try: sickrage_basepath = fix_basepath(sickrage_basepath) url = 'http%s://%s:%s%sapi/%s/?cmd=sb.ping' % (ssl, striphttp(sickrage_host), sickrage_port, sickrage_basepath, sickrage_apikey) self.logger.debug('Trying to contact sickrage via %s' % url) response = requests.get(url, timeout=10, verify=False) ret = response.json() if ret.get('result') == 'success': self.logger.debug('Sickrage connectivity test success') return ret except: self.logger.error('Unable to contact sickrage via %s' % url) return
def version(self, nzbget_host, nzbget_basepath, nzbget_port, nzbget_username, nzbget_password, nzbget_ssl=False, **kwargs): self.logger.debug("Fetching version information from nzbget") ssl = 's' if nzbget_ssl else '' nzbget_basepath = fix_basepath(nzbget_basepath) url = 'http%s://%s:%s%sjsonrpc/version' % (ssl, striphttp(nzbget_host), nzbget_port, nzbget_basepath) try: if nzbget_username and nzbget_password: r = requests.get(url, timeout=10, auth=(nzbget_username, nzbget_password)) else: r = requests.get(url, timeout=10) return r.json() except: self.logger.error("Unable to contact nzbget via %s" % url) return
def fetch(self, path): try: host = striphttp(htpc.settings.get('couchpotato_host', '')) port = str(htpc.settings.get('couchpotato_port', '')) apikey = htpc.settings.get('couchpotato_apikey', '') basepath = fix_basepath(htpc.settings.get('couchpotato_basepath', '/')) ssl = 's' if htpc.settings.get('couchpotato_ssl', 0) else '' url = 'http%s://%s:%s%sapi/%s/%s' % (ssl, host, port, basepath, apikey, path) self.logger.debug('Fetching information from: %s' % url) f = requests.get(url, timeout=60, verify=False) return f.json() except Exception as e: self.logger.debug('Exception: %s' % e) self.logger.error('Unable to fetch information') return
def webinterface(self): host = striphttp(htpc.settings.get('nzbget_host', '')) port = str(htpc.settings.get('nzbget_port', '')) username = htpc.settings.get('nzbget_username', '') password = htpc.settings.get('nzbget_password', '') nzbget_basepath = fix_basepath(htpc.settings.get('nzbget_basepath', '/')) ssl = 's' if htpc.settings.get('nzbget_ssl', True) else '' if username and password: authstring = '%s:%s@' % (username, password) else: authstring = '' url = 'http%s://%s%s:%s%s' % (ssl, authstring, host, port, nzbget_basepath) if htpc.settings.get('nzbget_reverse_proxy_link'): url = htpc.settings.get('nzbget_reverse_proxy_link') return url
def fetch(self, method, arguments=None): """ Do request to Deluge api """ if arguments is None: arguments = [] host = striphttp(htpc.settings.get('deluge_host', '')) port = htpc.settings.get('deluge_port', '') deluge_basepath = fix_basepath( htpc.settings.get('deluge_basepath', '/')) ssl = 's' if htpc.settings.get('deluge_ssl') else '' url = 'http%s://%s:%s%sjson' % (ssl, host, port, deluge_basepath) self.logger.debug("Request deluge method: %s arguments %s" % (method, arguments)) try: # format post data data = {'id': 1, 'method': method, 'params': arguments} response = self.session.post(url, data=dumps(data), verify=False) result = response.json() if result and result['error']: self.logger.debug('Authenticating') self.session.post( url, data=dumps({ "method": "auth.login", "params": [htpc.settings.get('deluge_password', '')], "id": 1 }), verify=False) response = self.session.post(url, data=dumps(data), verify=False) return result except Exception as e: self.logger.error('Failed to fetch method %s arguments %s %s' % (method, arguments, e))
def webinterface(self): host = striphttp(htpc.settings.get('nzbget_host', '')) port = str(htpc.settings.get('nzbget_port', '')) username = htpc.settings.get('nzbget_username', '') password = htpc.settings.get('nzbget_password', '') nzbget_basepath = fix_basepath( htpc.settings.get('nzbget_basepath', '/')) ssl = 's' if htpc.settings.get('nzbget_ssl', True) else '' if username and password: authstring = '%s:%s@' % (username, password) else: authstring = '' url = 'http%s://%s%s:%s%s' % (ssl, authstring, host, port, nzbget_basepath) if htpc.settings.get('nzbget_reverse_proxy_link'): url = htpc.settings.get('nzbget_reverse_proxy_link') return url
def getapikey(self, couchpotato_username, couchpotato_password, couchpotato_host, couchpotato_port, couchpotato_apikey, couchpotato_basepath, couchpotato_ssl=False, **kwargs): self.logger.debug('Testing connectivity to couchpotato') if couchpotato_password and couchpotato_username != '': couchpotato_password = hashlib.md5(couchpotato_password).hexdigest() couchpotato_username = hashlib.md5(couchpotato_username).hexdigest() getkey = 'getkey/?p=%s&u=%s' % (couchpotato_password, couchpotato_username) couchpotato_basepath = fix_basepath(couchpotato_basepath) ssl = 's' if couchpotato_ssl else '' url = 'http%s://%s:%s%s%s' % (ssl, striphttp(couchpotato_host), couchpotato_port, couchpotato_basepath, getkey) try: f = requests.get(url, timeout=10, verify=False) return f.json() except Exception as e: self.logger.error('Unable to connect to couchpotato %s' % e) self.logger.debug('connection-URL: %s' % url) return
def ping(self, **kwargs): ''' Test connection to Transmission ''' host = kwargs['transmission_host'] port = kwargs['transmission_port'] username = kwargs['transmission_username'] password = kwargs['transmission_password'] basepath = kwargs['transmission_rpcbasepath'] auth = None if not basepath: basepath = fix_basepath('/transmission/') url = 'http://%s:%s%srpc/' % (striphttp(host), port, basepath) # format post data data = {'method': 'session-get'} data = dumps(data) # Set Header header = { 'X-Transmission-Session-Id': self.sessionId, 'Content-Type': 'json; charset=UTF-8' } # Add authentication if username and password: auth = (username, password) try: r = self.reqz.post(url, data=data, timeout=10, headers=header, auth=auth) if r.ok: return r.json() else: if r.status_code == 409 and r.headers['x-transmission-session-id']: self.logger.debug('Retry Transmission api with new session id.') res = self.renewsession(url, data, header, auth, r) return res except Exception as e: self.logger.error('Unable to fetch information from: %s %s' % (url, e)) return
def fetch(self, cmd, img=False, timeout=20): try: host = striphttp(htpc.settings.get('sickrage_host', '')) port = str(htpc.settings.get('sickrage_port', '')) apikey = htpc.settings.get('sickrage_apikey', '') ssl = 's' if htpc.settings.get('sickrage_ssl', 0) else '' sickrage_basepath = fix_basepath(htpc.settings.get('sickrage_basepath', '/')) url = 'http%s://%s:%s%sapi/%s/?cmd=%s' % (ssl, host, port, sickrage_basepath, apikey, cmd) self.logger.debug('Fetching information from: %s' % url) if img is True: # Cache the images return get_image(url) res = requests.get(url, timeout=timeout, verify=False) return res.json() except Exception as e: self.logger.error('Unable to fetch information') self.logger.error(url) self.logger.error(e) return
def fetch(self, path, banner=None, type=None, data=None): try: host = striphttp(htpc.settings.get('sonarr_host', '')) port = str(htpc.settings.get('sonarr_port', '')) sonarr_basepath = htpc.settings.get('sonarr_basepath', '/') ssl = 's' if htpc.settings.get('sonarr_ssl', True) else '' # Makes sure that the basepath is /whatever/ sonarr_basepath = fix_basepath(sonarr_basepath) headers = {'X-Api-Key': htpc.settings.get('sonarr_apikey', '')} url = 'http%s://%s:%s%sapi/%s' % (ssl, host, port, sonarr_basepath, path) if banner: # the path includes the basepath automaticly (if fetched from api command 'Series') # Cache the image in HTPC Manager aswell. return get_image(url, headers=headers) if type == 'post': r = requests.post(url, data=dumps(data), headers=headers, verify=False) return r.content elif type == 'put': r = requests.put(url, data=dumps(data), headers=headers, verify=False) return r.content elif type == 'delete': r = requests.delete(url, data=dumps(data), headers=headers, verify=False) return r.content else: r = requests.get(url, headers=headers, verify=False) return loads(r.text) except Exception as e: self.logger.error('Failed to fetch url=%s path=%s error %s' % (url, path, e))
def fetch(self, cmd, img=False, timeout=10): try: host = htpc.settings.get('sickbeard_host', '') port = str(htpc.settings.get('sickbeard_port', '')) apikey = htpc.settings.get('sickbeard_apikey', '') ssl = 's' if htpc.settings.get('sickbeard_ssl', 0) else '' sickbeard_basepath = fix_basepath(htpc.settings.get('sickbeard_basepath', '/')) url = 'http' + ssl + '://' + host + ':' + str(port) + sickbeard_basepath + 'api/' + apikey + '/?cmd=' + cmd self.logger.debug('Fetching information from: %s' % url) if img is True: # Cache image return get_image(url) r = requests.get(url, timeout=timeout, verify=False) if r: r = r.json() return r except: self.logger.error('Unable to fetch information') return