예제 #1
0
    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
예제 #2
0
    def fetchxml(self, cmd):
        ''' convert xml to python object '''
        try:
            indexer = NewznabIndexers.select(limit=1).getOne()
            host = striphttp(indexer.host).rstrip('/')
            ssl = 's' if indexer.use_ssl == 'on' else ''
            apikey = indexer.apikey

        except SQLObjectNotFound:
            self.logger.warning("No configured Indexers. Please add one")
            return

        url = 'http' + ssl + '://' + host + '/api?o=xml&apikey=' + apikey + '&t=' + cmd

        self.logger.debug("Fetching category information from: %s" % url)
        try:
            # some newznab providers are insanely slow
            r = requests.get(url, timeout=20, headers=self.headers)
            if r.status_code == requests.codes.ok:
                xml = xmltodict.parse(r.content)
                if xml.get('error'):
                    self.logger.error('%s %s' % (url, xml['error']['@description']))
                else:
                    return xml

        except Exception as e:
            self.logger.error("Unable to fetch information from: %s %s" % (url, e))
            return
예제 #3
0
    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
예제 #4
0
    def _fetch(self, u, post=False, params={}, data=None):
        host = striphttp(htpc.settings.get('qbittorrent_host', ''))
        port = htpc.settings.get('qbittorrent_port', '')
        ssl = 's' if htpc.settings.get('qbittorrent_ssl') else ''
        url = 'http%s://%s:%s/' % (ssl, host, port)
        username = htpc.settings.get('qbittorrent_username', '')
        password = htpc.settings.get('qbittorrent_password', '')

        url += u

        if self.testapi is None:
            self.ping()

        if self.newapi:
            if self.authenticated is False:
                self.login()

        if post:
            if self.newapi:
                r = self.session.post(url, data=data, verify=False, timeout=8)
            else:
                r = self.session.post(url, data=data, verify=False, timeout=8, auth=HTTPDigestAuth(username, password))
        else:
            if self.newapi:
                r = self.session.get(url, verify=False, timeout=8)
            else:
                r = self.session.get(url, verify=False, timeout=8, auth=HTTPDigestAuth(username, password))

        return r
예제 #5
0
    def fetch(self, cmd):
        try:
            indexer = NewznabIndexers.select(limit=1).getOne()
            host = striphttp(indexer.host).rstrip('/')
            ssl = 's' if indexer.use_ssl == 'on' else ''
            apikey = indexer.apikey

        except SQLObjectNotFound:
            self.logger.warning("No configured Indexers. Please add one")
            return

        url = 'http' + ssl + '://' + host + '/api?o=json&apikey=' + apikey + '&t=' + cmd

        self.logger.debug("Fetching information from: %s" % url)
        try:
            # some newznab providers are insanely slow
            r = requests.get(url, timeout=20, headers=self.headers)
            return r.json()
        except ValueError as e:
            self.logger.error('%s' % e)
            try:
                self.logger.debug('Trying to convert xml to json')
                r = requests.get(url, timeout=20)
                return xmltodict.parse(r.content)
            except:
                self.logger.error('Failed to contert xml to js')
        except Exception as e:
            self.logger.error("Unable to fetch information from: %s %s" % (url, e))
            return
예제 #6
0
 def webinterface(self):
     host = striphttp(htpc.settings.get('qbittorrent_host', ''))
     port = htpc.settings.get('qbittorrent_port', '')
     ssl = 's' if htpc.settings.get('qbittorrent_ssl', 0) else ''
     url = 'http%s://%s:%s/' % (ssl, host, port)
     if htpc.settings.get('qbittorrent_reverse_proxy_link'):
         url = htpc.settings.get('qbittorrent_reverse_proxy_link')
     return url
예제 #7
0
 def webinterface(self):
     host = striphttp(htpc.settings.get('qbittorrent_host', ''))
     port = htpc.settings.get('qbittorrent_port', '')
     ssl = 's' if htpc.settings.get('qbittorrent_ssl', 0) else ''
     url = 'http%s://%s:%s/' % (ssl, host, port)
     if htpc.settings.get('qbittorrent_reverse_proxy_link'):
         url = htpc.settings.get('qbittorrent_reverse_proxy_link')
     return url
예제 #8
0
    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
예제 #9
0
    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
예제 #10
0
    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
예제 #11
0
    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
예제 #12
0
    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
예제 #13
0
    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
예제 #14
0
    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
예제 #15
0
    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
예제 #16
0
    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
예제 #17
0
    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
예제 #18
0
    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
예제 #19
0
    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
예제 #20
0
    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
예제 #21
0
    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
예제 #22
0
    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
예제 #23
0
    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
예제 #24
0
    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
예제 #25
0
    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
예제 #26
0
    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
예제 #27
0
    def _build_url(ssl=None, host=None, port=None, base_path=None):
        ssl = ssl or htpc.settings.get('headphones_ssl')
        host = host or htpc.settings.get('headphones_host')
        port = port or htpc.settings.get('headphones_port')
        base_path = base_path or htpc.settings.get('headphones_basepath')

        path = base_path or '/'
        if path.startswith('/') is False:
            path = '/' + path
        if path.endswith('/') is False:
            path += '/'

        url = '{protocol}://{host}:{port}{path}'.format(
            protocol='https' if ssl else 'http',
            host=striphttp(host),
            port=port,
            path=path,
        )

        return url
예제 #28
0
    def _build_url(ssl=None, host=None, port=None, base_path=None):
        ssl = ssl or htpc.settings.get('headphones_ssl')
        host = host or htpc.settings.get('headphones_host')
        port = port or htpc.settings.get('headphones_port')
        base_path = base_path or htpc.settings.get('headphones_basepath')

        path = base_path or '/'
        if path.startswith('/') is False:
            path = '/' + path
        if path.endswith('/') is False:
            path += '/'

        url = '{protocol}://{host}:{port}{path}'.format(
            protocol='https' if ssl else 'http',
            host=striphttp(host),
            port=port,
            path=path,
        )

        return url
예제 #29
0
    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))
예제 #30
0
    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
예제 #31
0
    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
예제 #32
0
    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
예제 #33
0
    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
예제 #34
0
    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))
예제 #35
0
    def _fetch(self, u, post=False, params={}, data=None):
        host = striphttp(htpc.settings.get('qbittorrent_host', ''))
        port = htpc.settings.get('qbittorrent_port', '')
        ssl = 's' if htpc.settings.get('qbittorrent_ssl') else ''
        url = 'http%s://%s:%s/' % (ssl, host, port)
        username = htpc.settings.get('qbittorrent_username', '')
        password = htpc.settings.get('qbittorrent_password', '')

        url += u

        if self.testapi is None:
            self.ping()

        if self.newapi:
            if self.authenticated is False:
                self.login()

        if post:
            if self.newapi:
                r = self.session.post(url, data=data, verify=False, timeout=8)
            else:
                r = self.session.post(url,
                                      data=data,
                                      verify=False,
                                      timeout=8,
                                      auth=HTTPDigestAuth(username, password))
        else:
            if self.newapi:
                r = self.session.get(url, verify=False, timeout=8)
            else:
                r = self.session.get(url,
                                     verify=False,
                                     timeout=8,
                                     auth=HTTPDigestAuth(username, password))

        return r
예제 #36
0
 def webhost(self, path=''):
     host = striphttp(htpc.settings.get('squeezebox_host', ''))
     port = htpc.settings.get('squeezebox_port', '')
     return 'http://%s:%s/%s' % (host, port, path)
예제 #37
0
 def qbturl(self):
     host = striphttp(htpc.settings.get('qbittorrent_host', ''))
     port = htpc.settings.get('qbittorrent_port', '')
     ssl = 's' if htpc.settings.get('qbittorrent_ssl', 0) else ''
     url = 'http%s://%s:%s/' % (ssl, host, port)
     return url
예제 #38
0
 def qbturl(self):
     host = striphttp(htpc.settings.get('qbittorrent_host', ''))
     port = htpc.settings.get('qbittorrent_port', '')
     ssl = 's' if htpc.settings.get('qbittorrent_ssl', 0) else ''
     url = 'http%s://%s:%s/' % (ssl, host, port)
     return url
예제 #39
0
 def webhost(self, path=''):
     host = striphttp(htpc.settings.get('squeezebox_host', ''))
     port = htpc.settings.get('squeezebox_port', '')
     return 'http://%s:%s/%s' % (host, port, path)
예제 #40
0
    def setindexer(self, **kw):
        """
        newznab_enable='',
        newznab_name='',
        newznab_show_in_menu='',
        newznab_indexer_id='',
        newznab_indexer_name='',
        newznab_indexer_host='',
        newznab_indexer_apikey='',
        newznab_indexer_ssl='',
        """
        # kw is empty if kw is predef to ''
        for k, v in kw.items():
            if k not in ('newznab_enable', 'newznab_name', 'newznab_show_in_menu',
                         'newznab_indexer_id', 'newznab_indexer_name',
                         'newznab_indexer_host', 'newznab_indexer_apikey', 'newznab_indexer_ssl'):
                            del kw[k]

            # protection against the hack
            # only allow correct kw be save to db
            if k in ['newznab_enable', 'newznab_name', 'newznab_show_in_menu']:
                htpc.settings.set(k, v)

        # Clean hostname
        host = striphttp(kw.get('newznab_indexer_host')).rstrip('/')

        # make the search url
        ssl = 's' if kw.get('newznab_indexer_ssl') == 'on' else ''

        apiurl = 'http%s://%s/api?o=xml&apikey=%s&t=' % (ssl, host, kw.get('newznab_indexer_apikey'))

        if kw.get('newznab_indexer_id') == "0":
            self.logger.debug("Creating newznab indexer in database")
            try:
                indexer = NewznabIndexers(name=kw.get('newznab_indexer_name'),
                                          host=host,
                                          apikey=kw.get('newznab_indexer_apikey'),
                                          use_ssl=kw.get('newznab_indexer_ssl'),
                                          apiurl=apiurl)

                if kw.get('newznab_indexer_apikey') not in htpc.BLACKLISTWORDS:
                    htpc.BLACKLISTWORDS.append(kw.get('newznab_indexer_apikey'))

                self.changeindexer(indexer.id)
                return 1
            except Exception as e:
                self.logger.debug("Exception: %s" % e)
                self.logger.error("Unable to create newznab indexer in database")
                return 0
        else:
            # Dont allow empty indexer be saved to db
            if host == '':
                self.logger.error('You must provide a url to the indexers %s' % kw.get('newznab_indexer_name', ''))
                return 0
            self.logger.debug("Updating newznab indexer %s in database" % kw.get('newznab_indexer_name'))
            try:
                indexer = NewznabIndexers.selectBy(id=kw.get('newznab_indexer_id')).getOne()
                indexer.name = kw.get('newznab_indexer_name')
                indexer.host = host
                indexer.apikey = kw.get('newznab_indexer_apikey')
                indexer.use_ssl = kw.get('newznab_indexer_ssl', 'on')
                indexer.apiurl = apiurl

                return 1
            except SQLObjectNotFound, e:
                self.logger.error("Unable to update %s in database %s" % (kw.get('newznab_indexer_name'), e))
                return 0