예제 #1
0
def check_caps(host, apikey, username=None, password=None, userAgent=None, timeout=None, skipIdsAndTypes=False):
    toCheck = [
        {"t": "tvsearch",
         "id": "tvdbid",
         "key": "121361",
         "expected": "Thrones"
         },
        {"t": "movie",
         "id": "imdbid",
         "key": "0848228",
         "expected": "Avengers"
         },
        {"t": "tvsearch",
         "id": "rid",
         "key": "24493",
         "expected": "Thrones"
         },
        {"t": "tvsearch",
         "id": "tvmazeid",
         "key": "82",
         "expected": "Thrones"
         },
        {"t": "tvsearch",
         "id": "traktid",
         "key": "1390",
         "expected": "Thrones"
         },
        {"t": "tvsearch",
         "id": "tmdbid",
         "key": "1399",
         "expected": "Thrones"
         }

    ]
    supportedIds = []
    supportedTypes = []
    # Try to find out from caps first
    try:
        url = _build_base_url(host, apikey, "caps", None)
        headers = {
            'User-Agent': userAgent if userAgent is not None else config.settings.searching.userAgent
        }
        logger.debug("Requesting %s" % url)
        r = webaccess.get(url, timeout=timeout if timeout is not None else config.settings.searching.timeout, headers=headers, auth=HTTPBasicAuth(username, password) if username is not None else None)
        r.raise_for_status()

        tree = ET.fromstring(r.content)

        categories = []
        subCategories = {}
        for xmlMainCategory in tree.find("categories").findall("category"):
            categories.append(xmlMainCategory.attrib["name"].lower())
            for subcat in xmlMainCategory.findall("subcat"):
                subCategories[subcat.attrib["id"]] = subcat.attrib["name"]
        animeCategory = getCategoryNumberOrNone(subCategories, ["5070", "7040"], ["anime", "tv/anime", "tv->anime"])
        comicCategory = getCategoryNumberOrNone(subCategories, ["7030"], ["comic", "comics", "books/comics"])
        magazineCategory = getCategoryNumberOrNone(subCategories, ["7010"], ["magazine", "mags", "magazines"])
        audiobookCategory = getCategoryNumberOrNone(subCategories, ["3030"], ["audiobook", "audio", "audio/audiobook"])
        ebookCategory = getCategoryNumberOrNone(subCategories, ["7020", "4050"], ["ebook"])
        supportedCategories = []
        if "movies" in categories:
            supportedCategories.extend(["movies", "movieshd", "moviessd"])
        if "tv" in categories:
            supportedCategories.extend(["tv", "tvhd", "tvsd"])
        if "audio" in categories:
            supportedCategories.extend(["audio", "flac", "mp3"])
        if "xxx" in categories or "adult" in categories:
            supportedCategories.append("xxx")
        if "console" in categories or "gaming" in categories:
            supportedCategories.append("console")
        if "apps" in categories or "pc" in categories:
            supportedCategories.append("pc")
        if animeCategory:
            supportedCategories.append("anime")
        if comicCategory:
            supportedCategories.append("comic")
        if audiobookCategory:
            supportedCategories.append("audiobook")
        if ebookCategory:
            supportedCategories.append("ebook")
        

        searching = tree.find("searching")
        if searching is not None and not skipIdsAndTypes:
            book_search = searching.find("book-search")
            if book_search is not None and book_search.attrib["available"] == "yes":
                supportedTypes.append("movie")
                logger.debug("Found supported book search")

            can_handle = [y["id"] for y in toCheck]
            supportedIds = [x for x in supportedIds if x in can_handle]  # Only use those we can handle

        if not skipIdsAndTypes:
            logger.info("Checking capabilities of indexer by brute force to make sure supported search types are correctly recognized")
            supportedIds, supportedTypes = checkCapsBruteForce(supportedTypes, toCheck, host, apikey, username=username, password=password)

        #Check indexer type (nzedb, newznab, nntmux)
        url = _build_base_url(host, apikey, "tvsearch", None)
        headers = {
            'User-Agent': userAgent if userAgent is not None else config.settings.searching.userAgent
        }
        logger.debug("Requesting %s" % url)
        r = webaccess.get(url, timeout=timeout if timeout is not None else config.settings.searching.timeout, headers=headers, auth=HTTPBasicAuth(username, password) if username is not None else None)
        r.raise_for_status()
        generator = ET.fromstring(r.content).find("channel/generator")
        if generator is not None:
            backend = generator.text
            logger.info("Found generator tag indicating that indexer %s is a %s based indexer" % (host, backend))
        else:
            logger.info("Assuming indexer %s is a newznab based indexer" % host)
            backend = "newznab"


        return {
            "animeCategory": animeCategory, 
            "comicCategory": comicCategory, 
            "magazineCategory": magazineCategory, 
            "audiobookCategory": audiobookCategory, 
            "ebookCategory": ebookCategory, 
            "supportedIds": sorted(list(set(supportedIds))), 
            "supportedTypes": sorted(list(set(supportedTypes))),
            "supportedCategories": supportedCategories,
            "supportsAllCategories": len(supportedCategories) == getNumberOfSelectableCategories() - 1, #Without "all
            "backend": backend
        }

    except HTTPError as e:
        logger.error("Error while trying to determine caps: %s" % e)
        raise IndexerResultParsingException("Unable to check caps: %s" % str(e), None)
    except Exception as e:
        logger.error("Error getting or parsing caps XML. Error message: %s" % e)
        return None
예제 #2
0
def check_caps(host,
               apikey,
               userAgent=None,
               timeout=None,
               skipIdsAndTypes=False):
    toCheck = [{
        "t": "tvsearch",
        "id": "tvdbid",
        "key": "121361",
        "expected": "Thrones"
    }, {
        "t": "movie",
        "id": "imdbid",
        "key": "0848228",
        "expected": "Avengers"
    }, {
        "t": "tvsearch",
        "id": "rid",
        "key": "24493",
        "expected": "Thrones"
    }, {
        "t": "tvsearch",
        "id": "tvmazeid",
        "key": "82",
        "expected": "Thrones"
    }, {
        "t": "tvsearch",
        "id": "traktid",
        "key": "1390",
        "expected": "Thrones"
    }, {
        "t": "tvsearch",
        "id": "tmdbid",
        "key": "1399",
        "expected": "Thrones"
    }]
    supportedIds = []
    supportedTypes = []
    # Try to find out from caps first
    try:
        url = _build_base_url(host, apikey, "caps", None)
        headers = {
            'User-Agent':
            userAgent
            if userAgent is not None else config.settings.searching.userAgent
        }
        logger.debug("Requesting %s" % url)
        r = requests.get(url,
                         verify=False,
                         timeout=timeout if timeout is not None else
                         config.settings.searching.timeout,
                         headers=headers)
        r.raise_for_status()

        tree = ET.fromstring(r.content)

        categories = []
        subCategories = {}
        for xmlMainCategory in tree.find("categories").findall("category"):
            categories.append(xmlMainCategory.attrib["name"].lower())
            for subcat in xmlMainCategory.findall("subcat"):
                subCategories[subcat.attrib["id"]] = subcat.attrib["name"]
        animeCategory = getCategoryNumberOrNone(
            subCategories, ["5070", "7040"],
            ["anime", "tv/anime", "tv->anime"])
        comicCategory = getCategoryNumberOrNone(
            subCategories, ["7030"], ["comic", "comics", "books/comics"])
        magazineCategory = getCategoryNumberOrNone(
            subCategories, ["7010"], ["magazine", "mags", "magazines"])
        audiobookCategory = getCategoryNumberOrNone(
            subCategories, ["3030"], ["audiobook", "audio", "audio/audiobook"])
        ebookCategory = getCategoryNumberOrNone(subCategories,
                                                ["7020", "4050"], ["ebook"])
        supportedCategories = []
        if "movies" in categories:
            supportedCategories.extend(["movies", "movieshd", "moviessd"])
        if "tv" in categories:
            supportedCategories.extend(["tv", "tvhd", "tvsd"])
        if "audio" in categories:
            supportedCategories.extend(["audio", "flac", "mp3"])
        if "xxx" in categories or "adult" in categories:
            supportedCategories.append("xxx")
        if "console" in categories or "gaming" in categories:
            supportedCategories.append("console")
        if "apps" in categories or "pc" in categories:
            supportedCategories.append("pc")
        if animeCategory:
            supportedCategories.append("anime")
        if comicCategory:
            supportedCategories.append("comic")
        if audiobookCategory:
            supportedCategories.append("audiobook")
        if ebookCategory:
            supportedCategories.append("ebook")

        searching = tree.find("searching")
        doBruteForce = False
        if searching is not None and not skipIdsAndTypes:
            tvsearch = searching.find("tv-search")
            if tvsearch is not None and tvsearch.attrib["available"] == "yes":
                supportedTypes.append("tvsearch")
                logger.debug("Found supported TV search")
                if "supportedParams" in tvsearch.attrib:
                    params = tvsearch.attrib["supportedParams"]
                    params = params.split(",")
                    for x in ["q", "season", "ep"]:
                        if x in params:
                            params.remove(x)
                    supportedIds.extend(params)
                    logger.debug("Found supported TV IDs: %s" % params)
                else:
                    doBruteForce = True
            movie_search = searching.find("movie-search")
            if movie_search is not None and movie_search.attrib[
                    "available"] == "yes":
                supportedTypes.append("movie")
                logger.debug("Found supported movie search")
                if "supportedParams" in movie_search.attrib:
                    params = movie_search.attrib["supportedParams"]
                    params = params.split(",")
                    for x in ["q", "genre"]:
                        if x in params:
                            params.remove(x)
                    supportedIds.extend(params)
                    logger.debug("Found supported movie IDs: %s" % params)
                else:
                    doBruteForce = True
            book_search = searching.find("book-search")
            if book_search is not None and book_search.attrib[
                    "available"] == "yes":
                supportedTypes.append("movie")
                logger.debug("Found supported book search")

            can_handle = [y["id"] for y in toCheck]
            supportedIds = [x for x in supportedIds
                            if x in can_handle]  # Only use those we can handle

        if doBruteForce and not skipIdsAndTypes:
            logger.info(
                "Unable to read supported params from caps. Will continue with brute force"
            )
            supportedIds, supportedTypes = checkCapsBruteForce(
                supportedTypes, toCheck, host, apikey)
        return {
            "animeCategory":
            animeCategory,
            "comicCategory":
            comicCategory,
            "magazineCategory":
            magazineCategory,
            "audiobookCategory":
            audiobookCategory,
            "ebookCategory":
            ebookCategory,
            "supportedIds":
            sorted(list(set(supportedIds))),
            "supportedTypes":
            sorted(list(set(supportedTypes))),
            "supportedCategories":
            supportedCategories,
            "supportsAllCategories":
            len(supportedCategories) == getNumberOfSelectableCategories() -
            1  #Without "all
        }

    except HTTPError as e:
        logger.error("Error while trying to determine caps: %s" % e)
        raise IndexerResultParsingException(
            "Unable to check caps: %s" % str(e), None)
    except Exception as e:
        logger.error("Error getting or parsing caps XML. Error message: %s" %
                     e)
        return None
예제 #3
0
def check_caps(host,
               apikey,
               username=None,
               password=None,
               userAgent=None,
               timeout=None,
               skipIdsAndTypes=False):
    toCheck = [{
        "t": "tvsearch",
        "id": "tvdbid",
        "key": "121361",
        "expected": "Thrones"
    }, {
        "t": "movie",
        "id": "imdbid",
        "key": "0848228",
        "expected": "Avengers"
    }, {
        "t": "tvsearch",
        "id": "rid",
        "key": "24493",
        "expected": "Thrones"
    }, {
        "t": "tvsearch",
        "id": "tvmazeid",
        "key": "82",
        "expected": "Thrones"
    }, {
        "t": "tvsearch",
        "id": "traktid",
        "key": "1390",
        "expected": "Thrones"
    }, {
        "t": "tvsearch",
        "id": "tmdbid",
        "key": "1399",
        "expected": "Thrones"
    }]
    supportedIds = []
    supportedTypes = []
    # Try to find out from caps first
    try:
        url = _build_base_url(host, apikey, "caps", None)
        headers = {
            'User-Agent':
            userAgent
            if userAgent is not None else config.settings.searching.userAgent
        }
        logger.debug("Requesting %s" % url)
        r = webaccess.get(url,
                          timeout=timeout if timeout is not None else
                          config.settings.searching.timeout,
                          headers=headers,
                          auth=HTTPBasicAuth(username, password)
                          if username is not None else None)
        r.raise_for_status()

        tree = ET.fromstring(r.content)

        categories = []
        subCategories = {}
        for xmlMainCategory in tree.find("categories").findall("category"):
            categories.append(xmlMainCategory.attrib["name"].lower())
            for subcat in xmlMainCategory.findall("subcat"):
                subCategories[subcat.attrib["id"]] = subcat.attrib["name"]
        animeCategory = getCategoryNumberOrNone(
            subCategories, ["5070", "7040"],
            ["anime", "tv/anime", "tv->anime"])
        comicCategory = getCategoryNumberOrNone(
            subCategories, ["7030"], ["comic", "comics", "books/comics"])
        magazineCategory = getCategoryNumberOrNone(
            subCategories, ["7010"], ["magazine", "mags", "magazines"])
        audiobookCategory = getCategoryNumberOrNone(
            subCategories, ["3030"], ["audiobook", "audio", "audio/audiobook"])
        ebookCategory = getCategoryNumberOrNone(subCategories,
                                                ["7020", "4050"], ["ebook"])
        supportedCategories = []
        if "movies" in categories:
            supportedCategories.extend(["movies", "movieshd", "moviessd"])
        if "tv" in categories:
            supportedCategories.extend(["tv", "tvhd", "tvsd"])
        if "audio" in categories or "music" in categories:
            supportedCategories.extend(["audio", "flac", "mp3"])
        if "xxx" in categories or "adult" in categories:
            supportedCategories.append("xxx")
        if "console" in categories or "gaming" in categories or "games" in categories:
            supportedCategories.append("console")
        if "apps" in categories or "pc" in categories:
            supportedCategories.append("pc")
        if animeCategory:
            supportedCategories.append("anime")
        if comicCategory:
            supportedCategories.append("comic")
        if audiobookCategory:
            supportedCategories.append("audiobook")
        if ebookCategory:
            supportedCategories.append("ebook")

        searching = tree.find("searching")
        if searching is not None and not skipIdsAndTypes:
            book_search = searching.find("book-search")
            if book_search is not None and book_search.attrib[
                    "available"] == "yes":
                supportedTypes.append("movie")
                logger.debug("Found supported book search")

            can_handle = [y["id"] for y in toCheck]
            supportedIds = [x for x in supportedIds
                            if x in can_handle]  # Only use those we can handle

        if not skipIdsAndTypes:
            logger.info(
                "Checking capabilities of indexer by brute force to make sure supported search types are correctly recognized"
            )
            supportedIds, supportedTypes = checkCapsBruteForce(
                supportedTypes,
                toCheck,
                host,
                apikey,
                username=username,
                password=password)

        #Check indexer type (nzedb, newznab, nntmux)
        url = _build_base_url(host, apikey, "tvsearch", None)
        headers = {
            'User-Agent':
            userAgent
            if userAgent is not None else config.settings.searching.userAgent
        }
        logger.debug("Requesting %s" % url)
        r = webaccess.get(url,
                          timeout=timeout if timeout is not None else
                          config.settings.searching.timeout,
                          headers=headers,
                          auth=HTTPBasicAuth(username, password)
                          if username is not None else None)
        r.raise_for_status()
        generator = ET.fromstring(r.content).find("channel/generator")
        if generator is not None:
            backend = generator.text
            logger.info(
                "Found generator tag indicating that indexer %s is a %s based indexer"
                % (host, backend))
        else:
            logger.info("Assuming indexer %s is a newznab based indexer" %
                        host)
            backend = "newznab"

        return {
            "animeCategory":
            animeCategory,
            "comicCategory":
            comicCategory,
            "magazineCategory":
            magazineCategory,
            "audiobookCategory":
            audiobookCategory,
            "ebookCategory":
            ebookCategory,
            "supportedIds":
            sorted(list(set(supportedIds))),
            "supportedTypes":
            sorted(list(set(supportedTypes))),
            "supportedCategories":
            supportedCategories,
            "supportsAllCategories":
            len(supportedCategories) == getNumberOfSelectableCategories() -
            1,  #Without "all
            "backend":
            backend
        }
    except Exception as e:
        logger.error("Error getting or parsing caps XML. Error message: %s" %
                     e)
        raise IndexerResultParsingException(
            "Unable to check caps: %s" % str(e), None)