Example #1
0
def build_name_cache(show=None):
    """Build internal name cache

    :param show: Specify show to build name cache for, if None, just do all shows
    """
    with name_cache_lock:
        scene_exceptions.retrieve_exceptions()

    if not show:
        # logger.info("Building internal name cache for all shows")
        for show in settings.showList:
            build_name_cache(show)
    else:
        logger.debug("Building internal name cache for " + show.name)
        clear_cache(show.indexerid)
        for season in scene_exceptions.get_all_scene_exceptions(show.indexerid).values():
            for exception in season:
                name_cache[helpers.full_sanitizeSceneName(exception["show_name"])] = int(show.indexerid)

        name_cache[helpers.full_sanitizeSceneName(show.show_name)] = int(show.indexerid)
        if show.custom_name:
            name_cache[helpers.full_sanitizeSceneName(show.custom_name)] = int(show.indexerid)

        logger.debug(
            "Internal name cache for " + show.name + " set to: [ " + ", ".join([key for key, value in name_cache.items() if value == show.indexerid]) + " ]"
        )
Example #2
0
def buildNameCache(show=None):
    """Build internal name cache

    :param show: Specify show to build name cache for, if None, just do all shows
    """
    with nameCacheLock:
        scene_exceptions.retrieve_exceptions()

    if not show:
        # logger.info("Building internal name cache for all shows")
        for show in settings.showList:
            buildNameCache(show)
    else:
        # logger.debug("Building internal name cache for " + show.name)
        clearCache(show.indexerid)
        for curSeason in [-1] + scene_exceptions.get_scene_seasons(
                show.indexerid):
            for name in set(
                    scene_exceptions.get_scene_exceptions(
                        show.indexerid, season=curSeason) + [show.name]):
                name = helpers.full_sanitizeSceneName(name)
                if name in nameCache:
                    continue

                nameCache[name] = int(show.indexerid)
Example #3
0
def get_id_from_name(name):
    """
    Looks up the given name in the scene_names table in cache.db.

    :param name: The show name to look up.
    :return: the TVDB id that resulted from the cache lookup or None if the show wasn't found in the cache
    """
    name = helpers.full_sanitizeSceneName(name)
    if name in name_cache:
        return int(name_cache[name])
Example #4
0
def add_name(name, indexer_id=0):
    """
    Adds the show & tvdb id to the scene_names table in cache.db.

    :param name: The show name to cache
    :param indexer_id: the TVDB id that this show should be cached with (can be None/0 for unknown)
    """

    # standardize the name we're using to account for small differences in providers
    name = helpers.full_sanitizeSceneName(name)
    if name not in name_cache:
        name_cache[name] = int(indexer_id)
        cache_db_con = db.DBConnection("cache.db")
        cache_db_con.action("INSERT OR REPLACE INTO scene_names (indexer_id, name) VALUES (?, ?)", [indexer_id, name])
Example #5
0
def get_id_from_name(name):
    """
    Looks up the given name in the scene_names table in cache.db.

    :param name: The show name to look up.
    :return: the TVDB id that resulted from the cache lookup or None if the show wasn't found in the cache
    """
    name = helpers.full_sanitizeSceneName(name)
    if name not in name_cache:
        cache_db_con = db.DBConnection("cache.db")
        results = cache_db_con.select_one("SELECT indexer_id FROM scene_names WHERE name = ?", [name])
        if results:
            indexer_id = results["indexer_id"]
            show = Show.find(settings.showList, indexer_id)
            if show:
                build_name_cache(show)
    else:
        return int(name_cache[name])