Exemple #1
0
    def put(self, 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 = full_sanitizeSceneName(name)
        if name not in self.cache:
            self.cache[name] = int(indexer_id)

            try:
                dbData = [
                    x['doc'] for x in CacheDB().db.get_many(
                        'scene_names', name, with_doc=True)
                    if x['doc']['indexer_id'] == indexer_id
                ]

                if not len(dbData):
                    # insert name into cache
                    CacheDB().db.insert({
                        '_t': 'scene_names',
                        'indexer_id': indexer_id,
                        'name': name
                    })
            except RecordNotFound:
                # insert name into cache
                CacheDB().db.insert({
                    '_t': 'scene_names',
                    'indexer_id': indexer_id,
                    'name': name
                })
    def put(self, 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 = full_sanitizeSceneName(name)
        if name not in self.cache:
            self.cache[name] = int(indexer_id)

            try:
                dbData = [x['doc'] for x in sickrage.srCore.cacheDB.db.get_many('scene_names', name, with_doc=True) if
                          x['doc']['indexer_id'] == indexer_id]

                if not len(dbData):
                    # insert name into cache
                    sickrage.srCore.cacheDB.db.insert({
                        '_t': 'scene_names',
                        'indexer_id': indexer_id,
                        'name': name
                    })
            except RecordNotFound:
                # insert name into cache
                sickrage.srCore.cacheDB.db.insert({
                    '_t': 'scene_names',
                    'indexer_id': indexer_id,
                    'name': name
                })
Exemple #3
0
    def buildNameCache(self, show=None):
        """Build internal name cache

        :param show: Specify show to build name cache for, if None, just do all shows
        """

        if self.shouldUpdate():
            if not show:
                retrieve_exceptions()
                for show in sickrage.showList:
                    sickrage.LOGGER.info("Building internal name cache for all shows")
                    self.buildNameCache(show)
            else:
                self.lastUpdate = datetime.datetime.fromtimestamp(
                        int(time.mktime(datetime.datetime.today().timetuple()))
                )

                sickrage.LOGGER.debug("Building internal name cache for [{}]".format(show.name))
                self.clearCache(show.indexerid)
                for curSeason in [-1] + get_scene_seasons(show.indexerid):
                    for name in list(set(get_scene_exceptions(
                            show.indexerid, season=curSeason) + [show.name])):

                        name = full_sanitizeSceneName(name)
                        if name not in self.cache:
                            self.cache[name] = int(show.indexerid)

                sickrage.LOGGER.debug("Internal name cache for [{}] set to: [{}]".format(
                        show.name, [key for key, value in self.cache.items() if value == show.indexerid][0]))
Exemple #4
0
    def get_show(self, name, tryIndexers=False):
        if not sickrage.showList:
            return

        showObj = None
        fromCache = False

        if not name:
            return showObj

        try:
            # check cache for show
            cache = sickrage.NAMECACHE.retrieveNameFromCache(name)
            if cache:
                fromCache = True
                showObj = findCertainShow(sickrage.showList, int(cache))

            # try indexers
            if not showObj and tryIndexers:
                showObj = findCertainShow(sickrage.showList,
                                          searchIndexerForShowID(full_sanitizeSceneName(name), ui=ShowListUI)[2])

            # try scene exceptions
            if not showObj:
                ShowID = get_scene_exception_by_name(name)[0]
                if ShowID:
                    showObj = findCertainShow(sickrage.showList, int(ShowID))

            # add show to cache
            if showObj and not fromCache:
                sickrage.NAMECACHE.addNameToCache(name, showObj.indexerid)
        except Exception as e:
            sickrage.LOGGER.debug("Error when attempting to find show: %s in SiCKRAGE. Error: %r " % (name, repr(e)))

        return showObj
Exemple #5
0
    def get_show(self, name):
        show = None
        show_id = 0
        fromCache = False

        if not all([name, sickrage.app.showlist]): return show, show_id

        try:
            # check cache for show
            cache = sickrage.app.name_cache.get(name)
            if cache:
                fromCache = True
                show_id = cache

            # try indexers
            if not show_id and self.tryIndexers:
                try:
                    show_id1 = int(IndexerApi().searchForShowID(
                        full_sanitizeSceneName(name))[2])
                    show_id2 = int(srTraktAPI()['search'].query(
                        full_sanitizeSceneName(name), 'show')[0].ids['tvdb'])
                    show_id = (show_id, show_id1)[show_id1 == show_id2]
                except Exception:
                    pass

            # try scene exceptions
            if not show_id:
                try:
                    show_id = get_scene_exception_by_name(name)[0]
                except Exception:
                    pass

            # create show object
            show = findCertainShow(sickrage.app.showlist,
                                   int(show_id)) if show_id else None

            # add show to cache
            if show and not fromCache:
                sickrage.app.name_cache.put(name, show.indexerid)
        except Exception as e:
            sickrage.app.log.debug(
                "Error when attempting to find show: %s in SiCKRAGE. Error: %r "
                % (name, repr(e)))

        return show, show_id or 0
Exemple #6
0
    def get(self, 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 = full_sanitizeSceneName(name)
        if name in self.cache:
            return int(self.cache[name])
    def get(self, 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 = full_sanitizeSceneName(name)
        if name in self.cache:
            return int(self.cache[name])
Exemple #8
0
    def get_show(self, name):
        show = None
        show_id = 0
        fromCache = False

        if not all([name, sickrage.app.showlist]): return show, show_id

        try:
            # check cache for show
            cache = sickrage.app.name_cache.get(name)
            if cache:
                fromCache = True
                show_id = cache

            # try indexers
            if not show_id and self.tryIndexers:
                try:
                    show_id1 = int(IndexerApi().searchForShowID(full_sanitizeSceneName(name))[2])
                    show_id2 = int(srTraktAPI()['search'].query(full_sanitizeSceneName(name), 'show')[0].ids['tvdb'])
                    show_id = (show_id, show_id1)[show_id1 == show_id2]
                except Exception:
                    pass

            # try scene exceptions
            if not show_id:
                try:
                    show_id = get_scene_exception_by_name(name)[0]
                except Exception:
                    pass

            # create show object
            show = findCertainShow(sickrage.app.showlist, int(show_id)) if show_id else None

            # add show to cache
            if show and not fromCache:
                sickrage.app.name_cache.put(name, show.indexerid)
        except Exception as e:
            sickrage.app.log.debug(
                "Error when attempting to find show: %s in SiCKRAGE. Error: %r " % (name, repr(e)))

        return show, show_id or 0
def check_against_names(nameInQuestion, show, season=-1):
    showNames = []
    if season in [-1, 1]:
        showNames = [show.name]

    showNames.extend(get_scene_exceptions(show.indexerid, season=season))

    for showName in showNames:
        nameFromList = full_sanitizeSceneName(showName)
        if nameFromList == nameInQuestion:
            return True

    return False
Exemple #10
0
def check_against_names(nameInQuestion, show, season=-1):
    showNames = []
    if season in [-1, 1]:
        showNames = [show.name]

    showNames.extend(get_scene_exceptions(show.indexerid, season=season))

    for showName in showNames:
        nameFromList = full_sanitizeSceneName(showName)
        if nameFromList == nameInQuestion:
            return True

    return False
Exemple #11
0
    def addNameToCache(self, 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 = full_sanitizeSceneName(name)
        if name not in self.cache:
            self.cache[name] = int(indexer_id)
            cache_db.CacheDB().action("INSERT OR REPLACE INTO scene_names (indexer_id, name) VALUES (?, ?)",
                                      [indexer_id, name])
Exemple #12
0
    def put(self, 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 = full_sanitizeSceneName(name)

        self.cache[name] = int(indexer_id)

        dbData = [x for x in sickrage.app.cache_db.get_many('scene_names', name) if x['indexer_id'] == indexer_id]
        if not len(dbData):
            # insert name into cache
            sickrage.app.cache_db.insert({
                '_t': 'scene_names',
                'indexer_id': indexer_id,
                'name': name
            })
Exemple #13
0
    def get_show(self, name, tryIndexers=False):
        if not sickrage.srCore.SHOWLIST:
            return

        showObj = None
        fromCache = False

        if not name:
            return showObj

        try:
            # check cache for show
            cache = sickrage.srCore.NAMECACHE.get(name)
            if cache:
                fromCache = True
                showObj = findCertainShow(sickrage.srCore.SHOWLIST, int(cache))

            # try indexers
            if not showObj and tryIndexers:
                showObj = findCertainShow(
                    sickrage.srCore.SHOWLIST,
                    srIndexerApi().searchForShowID(
                        full_sanitizeSceneName(name))[2])

            # try scene exceptions
            if not showObj:
                ShowID = get_scene_exception_by_name(name)[0]
                if ShowID:
                    showObj = findCertainShow(sickrage.srCore.SHOWLIST,
                                              int(ShowID))

            # add show to cache
            if showObj and not fromCache:
                sickrage.srCore.NAMECACHE.put(name, showObj.indexerid)
        except Exception as e:
            sickrage.srCore.srLogger.debug(
                "Error when attempting to find show: %s in SiCKRAGE. Error: %r "
                % (name, repr(e)))

        return showObj
Exemple #14
0
    def buildNameCache(self, show=None):
        """Build internal name cache

        :param show: Specify show to build name cache for, if None, just do all shows
        """

        if self.shouldUpdate():
            if not show:
                retrieve_exceptions()
                for show in sickrage.showList:
                    sickrage.LOGGER.info(
                        "Building internal name cache for all shows")
                    self.buildNameCache(show)
            else:
                self.lastUpdate = datetime.datetime.fromtimestamp(
                    int(time.mktime(datetime.datetime.today().timetuple())))

                sickrage.LOGGER.debug(
                    "Building internal name cache for [{}]".format(show.name))
                self.clearCache(show.indexerid)
                for curSeason in [-1] + get_scene_seasons(show.indexerid):
                    for name in list(
                            set(
                                get_scene_exceptions(show.indexerid,
                                                     season=curSeason) +
                                [show.name])):

                        name = full_sanitizeSceneName(name)
                        if name not in self.cache:
                            self.cache[name] = int(show.indexerid)

                sickrage.LOGGER.debug(
                    "Internal name cache for [{}] set to: [{}]".format(
                        show.name, [
                            key for key, value in self.cache.items()
                            if value == show.indexerid
                        ][0]))
Exemple #15
0
    def get_show(self, name, tryIndexers=False):
        if not sickrage.srCore.SHOWLIST:
            return

        showObj = None
        fromCache = False

        if not name:
            return showObj

        try:
            # check cache for show
            cache = sickrage.srCore.NAMECACHE.get(name)
            if cache:
                fromCache = True
                showObj = findCertainShow(sickrage.srCore.SHOWLIST, int(cache))

            # try indexers
            if not showObj and tryIndexers:
                showObj = findCertainShow(sickrage.srCore.SHOWLIST,
                                          srIndexerApi().searchForShowID(full_sanitizeSceneName(name))[2])

            # try scene exceptions
            if not showObj:
                ShowID = get_scene_exception_by_name(name)[0]
                if ShowID:
                    showObj = findCertainShow(sickrage.srCore.SHOWLIST, int(ShowID))

            # add show to cache
            if showObj and not fromCache:
                sickrage.srCore.NAMECACHE.put(name, showObj.indexerid)
        except Exception as e:
            sickrage.srCore.srLogger.debug(
                "Error when attempting to find show: %s in SiCKRAGE. Error: %r " % (name, repr(e)))

        return showObj
Exemple #16
0
 def indexer_lookup(term):
     show_id1 = int(IndexerApi().searchForShowID(
         full_sanitizeSceneName(term))[2])
     show_id2 = int(srTraktAPI()['search'].query(
         full_sanitizeSceneName(term), 'show')[0].ids['tvdb'])
     return (None, show_id1)[show_id1 == show_id2]