Example #1
0
def check_auth(body, indexer):
    if '<error code="100"' in body:
        raise IndexerAuthException("The API key seems to be incorrect.",
                                   indexer)
    if '<error code="101"' in body:
        raise IndexerAuthException("The account seems to be suspended.",
                                   indexer)
    if '<error code="102"' in body:
        raise IndexerAuthException("You're not allowed to use the API.",
                                   indexer)
    if '<error code="910"' in body:
        raise IndexerAccessException(
            "The API seems to be disabled for the moment.", indexer)
    if "Site Maintenance" in body:
        raise IndexerAccessException("Site is down for maintenance.", indexer)
    if '<error code=' in body:
        try:
            tree = ET.fromstring(body)
            code = tree.attrib["code"]
            description = tree.attrib["description"]
            if "Request limit reached" in body:
                raise IndexerApiLimitReachedException("API limit reached",
                                                      indexer)
            logger.error(
                "Indexer %s returned unknown error code %s with description: %s"
                % (indexer, code, description))
            exception = IndexerAccessException(
                "Unknown error while trying to access the indexer: %s" %
                description, indexer)
        except Exception:
            logger.error("Indexer %s returned an error page: %s" %
                         (indexer, body))
            exception = IndexerAccessException(
                "Unknown error while trying to access the indexer.", indexer)
        raise exception
Example #2
0
def _testId(host,
            apikey,
            t,
            idkey,
            idvalue,
            expectedResult,
            username=None,
            password=None):
    logger.info("Testing for ID capability \"%s\"" % idkey)

    try:
        url = _build_base_url(host, apikey, t, None, 50)
        url.query.add({idkey: idvalue})
        headers = {'User-Agent': config.settings.searching.userAgent}
        logger.debug("Requesting %s" % url)
        r = webaccess.get(url,
                          timeout=config.settings.searching.timeout,
                          headers=headers,
                          auth=HTTPBasicAuth(username, password)
                          if username is not None else None)
        r.raise_for_status()
        logger.debug("Indexer returned: " + r.text[:500])
        check_auth(r.text, None)
        titles = []
        tree = ET.fromstring(r.content)
    except Exception as e:
        if isinstance(e, IndexerAccessException):
            raise
        else:
            logger.error("Error getting or parsing XML: %s" % e)
            raise IndexerAccessException("Error getting or parsing XML", None)
    for item in tree.find("channel").findall("item"):
        titles.append(item.find("title").text)

    #Hacky way of preventing nzb.su of shutting us down. If more than 5 requests are done in 6 seconds the indexer will block further requests for some time
    if "nzb.su" in host.lower():
        sleep(1)

    if len(titles) == 0:
        logger.debug("Search with t=%s and %s=%s returned no results" %
                     (t, idkey, idvalue))
        return False, t
    countWrong = 0
    for title in titles:
        title = title.lower()
        if expectedResult.lower() not in title:
            logger.debug(
                "Search with t=%s and %s=%s returned \"%s\" which does not contain the expected string \"%s\""
                % (t, idkey, idvalue, title, expectedResult))
            countWrong += 1
    percentWrong = (100 * countWrong) / len(titles)
    if percentWrong > 10:
        logger.info(
            "%d%% wrong results, this indexer probably doesn't support %s" %
            (percentWrong, idkey))
        return False, t
    logger.info("%d%% wrong results, this indexer probably supports %s" %
                (percentWrong, idkey))

    return True, t
Example #3
0
def _testId(host,
            apikey,
            t,
            idkey,
            idvalue,
            expectedResult,
            username=None,
            password=None):
    logger.info("Testing for ID capability \"%s\"" % idkey)

    try:
        url = _build_base_url(host, apikey, t, None, 25)
        url.query.add({idkey: idvalue})
        headers = {'User-Agent': config.settings.searching.userAgent}
        logger.debug("Requesting %s" % url)
        r = webaccess.get(url,
                          timeout=config.settings.searching.timeout,
                          headers=headers,
                          auth=HTTPBasicAuth(username, password)
                          if username is not None else None)
        r.raise_for_status()
        titles = []
        tree = ET.fromstring(r.content)
    except Exception as e:
        logger.error("Error getting or parsing XML: %s" % e)
        raise IndexerAccessException("Error getting or parsing XML", None)
    for item in tree.find("channel").findall("item"):
        titles.append(item.find("title").text)

    if len(titles) == 0:
        logger.debug("Search with t=%s and %s=%s returned no results" %
                     (t, idkey, idvalue))
        return False, t
    countWrong = 0
    for title in titles:
        title = title.lower()
        if expectedResult.lower() not in title:
            logger.debug(
                "Search with t=%s and %s=%s returned \"%s\" which does not contain the expected string \"%s\""
                % (t, idkey, idvalue, title, expectedResult))
            countWrong += 1
    percentWrong = (100 * countWrong) / len(titles)
    if percentWrong > 30:
        logger.info(
            "%d%% wrong results, this indexer probably doesn't support %s" %
            (percentWrong, idkey))
        return False, t
    logger.info("%d%% wrong results, this indexer probably supports %s" %
                (percentWrong, idkey))

    return True, t
Example #4
0
 def check_auth(self, body):
     if "The search service is temporarily unavailable" in body:
         raise IndexerAccessException(
             "The search service is temporarily unavailable.", self)
Example #5
0
 def check_auth(self, body):
     if "503 Service Temporarily Unavailable" in body or "The search service is temporarily unavailable" in body:
         raise IndexerAccessException(
             "The search service is temporarily unavailable.",
             self)  # The server should return code 503 instead of 200...
Example #6
0
 def check_auth(self, xml):
     if "your user/api information is incorrect.. check and try again" in xml:
         raise IndexerAuthException("Wrong API key or username", None)
     if "applying some updates please try again later." in xml:
         raise IndexerAccessException("Indexer down for maintenance", None)