Exemplo n.º 1
0
    def test_sceneExceptionsResetNameCache(self):
        # clear the exceptions
        myDB = db.DBConnection("cache.db")
        myDB.action("DELETE FROM scene_exceptions")

        # put something in the cache
        name_cache.addNameToCache('Cached Name', 0)

        # updating should clear the cache so our previously "Cached Name" won't be in there
        scene_exceptions.retrieve_exceptions()
        self.assertEqual(name_cache.retrieveNameFromCache('Cached Name'), None)

        # put something in the cache
        name_cache.addNameToCache('Cached Name', 0)

        # updating should not clear the cache this time since our exceptions didn't change
        scene_exceptions.retrieve_exceptions()
        self.assertEqual(name_cache.retrieveNameFromCache('Cached Name'), 0)
Exemplo n.º 2
0
    def test_sceneExceptionsResetNameCache(self):
        # clear the exceptions
        my_db = db.DBConnection('cache.db')
        my_db.action('DELETE FROM scene_exceptions')

        # put something in the cache
        name_cache.addNameToCache('Cached Name', 0)

        # updating should not clear the cache this time since our exceptions didn't change
        scene_exceptions.retrieve_exceptions()
        self.assertEqual(name_cache.retrieveNameFromCache('Cached Name'), 0)
Exemplo n.º 3
0
    def test_sceneExceptionsResetNameCache(self):
        # clear the exceptions
        my_db = db.DBConnection()
        my_db.action('DELETE FROM scene_exceptions')

        # put something in the cache
        name_cache.addNameToCache('Cached Name', 0)

        # updating should not clear the cache this time since our exceptions didn't change
        scene_exceptions.retrieve_exceptions()
        self.assertEqual(name_cache.retrieveNameFromCache('Cached Name'), 0)
Exemplo n.º 4
0
    def test_scene_ex_reset_name_cache(self):
        """
        Test scene exceptions reset name cache
        """
        # clear the exceptions
        my_db = db.DBConnection("cache.db")
        my_db.action("DELETE FROM scene_exceptions")

        # put something in the cache
        name_cache.addNameToCache('Cached Name', 0)

        # updating should not clear the cache this time since our exceptions didn't change
        scene_exceptions.retrieve_exceptions()
        self.assertEqual(name_cache.retrieveNameFromCache('Cached Name'), 0)
Exemplo n.º 5
0
    def test_scene_ex_reset_name_cache(self):
        """
        Test scene exceptions reset name cache
        """
        # clear the exceptions
        test_cache_db_con = db.DBConnection('cache.db')
        test_cache_db_con.action("DELETE FROM scene_exceptions")

        # put something in the cache
        name_cache.addNameToCache('Cached Name', 0)

        # updating should not clear the cache this time since our exceptions didn't change
        scene_exceptions.retrieve_exceptions()
        self.assertEqual(name_cache.retrieveNameFromCache('Cached Name'), 0)
Exemplo n.º 6
0
    def _addCacheEntry(self, name, url, season=None, episodes=None, tvdb_id=0, tvrage_id=0, quality=None, extraNames=[]):

        myDB = self._getDB()

        parse_result = None

        # if we don't have complete info then parse the filename to get it
        for curName in [name] + extraNames:
            try:
                myParser = NameParser()
                parse_result = myParser.parse(curName)
            except InvalidNameException:
                logger.log(u"Unable to parse the filename "+curName+" into a valid episode", logger.DEBUG)
                continue

        if not parse_result:
            logger.log(u"Giving up because I'm unable to parse this name: "+name, logger.DEBUG)
            return False

        if not parse_result.series_name:
            logger.log(u"No series name retrieved from "+name+", unable to cache it", logger.DEBUG)
            return False

        tvdb_lang = None

        # if we need tvdb_id or tvrage_id then search the DB for them
        if not tvdb_id or not tvrage_id:

            # if we have only the tvdb_id, use the database
            if tvdb_id:
                showObj = helpers.findCertainShow(sickbeard.showList, tvdb_id)
                if showObj:
                    tvrage_id = showObj.tvrid
                    tvdb_lang = showObj.lang
                else:
                    logger.log(u"We were given a TVDB id "+str(tvdb_id)+" but it doesn't match a show we have in our list, so leaving tvrage_id empty", logger.DEBUG)
                    tvrage_id = 0

            # if we have only a tvrage_id then use the database
            elif tvrage_id:
                showObj = helpers.findCertainTVRageShow(sickbeard.showList, tvrage_id)
                if showObj:
                    tvdb_id = showObj.tvdbid
                    tvdb_lang = showObj.lang
                else:
                    logger.log(u"We were given a TVRage id "+str(tvrage_id)+" but it doesn't match a show we have in our list, so leaving tvdb_id empty", logger.DEBUG)
                    tvdb_id = 0

            # if they're both empty then fill out as much info as possible by searching the show name
            else:

                # check the name cache and see if we already know what show this is
                logger.log(u"Checking the cache to see if we already know the tvdb id of "+parse_result.series_name, logger.DEBUG)
                tvdb_id = name_cache.retrieveNameFromCache(parse_result.series_name)
                
                # remember if the cache lookup worked or not so we know whether we should bother updating it later
                if tvdb_id == None:
                    logger.log(u"No cache results returned, continuing on with the search", logger.DEBUG)
                    from_cache = False
                else:
                    logger.log(u"Cache lookup found "+repr(tvdb_id)+", using that", logger.DEBUG)
                    from_cache = True
                
                # if the cache failed, try looking up the show name in the database
                if tvdb_id == None:
                    logger.log(u"Trying to look the show up in the show database", logger.DEBUG)
                    showResult = helpers.searchDBForShow(parse_result.series_name)
                    if showResult:
                        logger.log(parse_result.series_name+" was found to be show "+showResult[1]+" ("+str(showResult[0])+") in our DB.", logger.DEBUG)
                        tvdb_id = showResult[0]

                # if the DB lookup fails then do a comprehensive regex search
                if tvdb_id == None:
                    logger.log(u"Couldn't figure out a show name straight from the DB, trying a regex search instead", logger.DEBUG)
                    for curShow in sickbeard.showList:
                        if show_name_helpers.isGoodResult(name, curShow, False):
                            logger.log(u"Successfully matched "+name+" to "+curShow.name+" with regex", logger.DEBUG)
                            tvdb_id = curShow.tvdbid
                            tvdb_lang = curShow.lang
                            break

                # if tvdb_id was anything but None (0 or a number) then 
                if not from_cache:
                    name_cache.addNameToCache(parse_result.series_name, tvdb_id)

                # if we came out with tvdb_id = None it means we couldn't figure it out at all, just use 0 for that
                if tvdb_id == None:
                    tvdb_id = 0

                # if we found the show then retrieve the show object
                if tvdb_id:
                    showObj = helpers.findCertainShow(sickbeard.showList, tvdb_id)
                    if showObj:
                        tvrage_id = showObj.tvrid
                        tvdb_lang = showObj.lang

        # if we weren't provided with season/episode information then get it from the name that we parsed
        if not season:
            season = parse_result.season_number if parse_result.season_number != None else 1
        if not episodes:
            episodes = parse_result.episode_numbers

        # if we have an air-by-date show then get the real season/episode numbers
        if parse_result.air_by_date and tvdb_id:
            try:
                # There's gotta be a better way of doing this but we don't wanna
                # change the language value elsewhere
                ltvdb_api_parms = sickbeard.TVDB_API_PARMS.copy()

                if not (tvdb_lang == "" or tvdb_lang == "en" or tvdb_lang == None):
                    ltvdb_api_parms['language'] = tvdb_lang

                t = tvdb_api.Tvdb(**ltvdb_api_parms)
                epObj = t[tvdb_id].airedOn(parse_result.air_date)[0]
                season = int(epObj["seasonnumber"])
                episodes = [int(epObj["episodenumber"])]
            except tvdb_exceptions.tvdb_episodenotfound:
                logger.log(u"Unable to find episode with date "+str(parse_result.air_date)+" for show "+parse_result.series_name+", skipping", logger.WARNING)
                return False
            except tvdb_exceptions.tvdb_error, e:
                logger.log(u"Unable to contact TVDB: "+ex(e), logger.WARNING)
                return False
Exemplo n.º 7
0
    def _addCacheEntry(self,
                       name,
                       url,
                       season=None,
                       episodes=None,
                       tvdb_id=0,
                       tvrage_id=0,
                       quality=None,
                       extraNames=[]):

        myDB = self._getDB()

        parse_result = None

        # if we don't have complete info then parse the filename to get it
        for curName in [name] + extraNames:
            try:
                myParser = NameParser()
                parse_result = myParser.parse(curName)
            except InvalidNameException:
                logger.log(
                    u"Unable to parse the filename " + curName +
                    " into a valid episode", logger.DEBUG)
                continue

        if not parse_result:
            logger.log(
                u"Giving up because I'm unable to parse this name: " + name,
                logger.DEBUG)
            return False

        if not parse_result.series_name:
            logger.log(
                u"No series name retrieved from " + name +
                ", unable to cache it", logger.DEBUG)
            return False

        tvdb_lang = None

        # if we need tvdb_id or tvrage_id then search the DB for them
        if not tvdb_id or not tvrage_id:

            # if we have only the tvdb_id, use the database
            if tvdb_id:
                showObj = helpers.findCertainShow(sickbeard.showList, tvdb_id)
                if showObj:
                    tvrage_id = showObj.tvrid
                    tvdb_lang = showObj.lang
                else:
                    logger.log(
                        u"We were given a TVDB id " + str(tvdb_id) +
                        " but it doesn't match a show we have in our list, so leaving tvrage_id empty",
                        logger.DEBUG)
                    tvrage_id = 0

            # if we have only a tvrage_id then use the database
            elif tvrage_id:
                showObj = helpers.findCertainTVRageShow(
                    sickbeard.showList, tvrage_id)
                if showObj:
                    tvdb_id = showObj.tvdbid
                    tvdb_lang = showObj.lang
                else:
                    logger.log(
                        u"We were given a TVRage id " + str(tvrage_id) +
                        " but it doesn't match a show we have in our list, so leaving tvdb_id empty",
                        logger.DEBUG)
                    tvdb_id = 0

            # if they're both empty then fill out as much info as possible by searching the show name
            else:

                # check the name cache and see if we already know what show this is
                logger.log(
                    u"Checking the cache to see if we already know the tvdb id of "
                    + parse_result.series_name, logger.DEBUG)
                tvdb_id = name_cache.retrieveNameFromCache(
                    parse_result.series_name)

                # remember if the cache lookup worked or not so we know whether we should bother updating it later
                if tvdb_id == None:
                    logger.log(
                        u"No cache results returned, continuing on with the search",
                        logger.DEBUG)
                    from_cache = False
                else:
                    logger.log(
                        u"Cache lookup found " + repr(tvdb_id) +
                        ", using that", logger.DEBUG)
                    from_cache = True

                # if the cache failed, try looking up the show name in the database
                if tvdb_id == None:
                    logger.log(
                        u"Trying to look the show up in the show database",
                        logger.DEBUG)
                    showResult = helpers.searchDBForShow(
                        parse_result.series_name)
                    if showResult:
                        logger.log(
                            parse_result.series_name +
                            " was found to be show " + showResult[1] + " (" +
                            str(showResult[0]) + ") in our DB.", logger.DEBUG)
                        tvdb_id = showResult[0]

                # if the DB lookup fails then do a comprehensive regex search
                if tvdb_id == None:
                    logger.log(
                        u"Couldn't figure out a show name straight from the DB, trying a regex search instead",
                        logger.DEBUG)
                    for curShow in sickbeard.showList:
                        if show_name_helpers.isGoodResult(
                                name, curShow, False):
                            logger.log(
                                u"Successfully matched " + name + " to " +
                                curShow.name + " with regex", logger.DEBUG)
                            tvdb_id = curShow.tvdbid
                            tvdb_lang = curShow.lang
                            break

                # if tvdb_id was anything but None (0 or a number) then
                if not from_cache:
                    name_cache.addNameToCache(parse_result.series_name,
                                              tvdb_id)

                # if we came out with tvdb_id = None it means we couldn't figure it out at all, just use 0 for that
                if tvdb_id == None:
                    tvdb_id = 0

                # if we found the show then retrieve the show object
                if tvdb_id:
                    showObj = helpers.findCertainShow(sickbeard.showList,
                                                      tvdb_id)
                    if showObj:
                        tvrage_id = showObj.tvrid
                        tvdb_lang = showObj.lang

        # if we weren't provided with season/episode information then get it from the name that we parsed
        if not season:
            season = parse_result.season_number if parse_result.season_number != None else 1
        if not episodes:
            episodes = parse_result.episode_numbers

        # if we have an air-by-date show then get the real season/episode numbers
        if parse_result.air_by_date and tvdb_id:
            try:
                # There's gotta be a better way of doing this but we don't wanna
                # change the language value elsewhere
                ltvdb_api_parms = sickbeard.TVDB_API_PARMS.copy()

                if not (tvdb_lang == "" or tvdb_lang == "en"
                        or tvdb_lang == None):
                    ltvdb_api_parms['language'] = tvdb_lang

                t = tvdb_api.Tvdb(**ltvdb_api_parms)
                epObj = t[tvdb_id].airedOn(parse_result.air_date)[0]
                season = int(epObj["seasonnumber"])
                episodes = [int(epObj["episodenumber"])]
            except tvdb_exceptions.tvdb_episodenotfound:
                logger.log(
                    u"Unable to find episode with date " +
                    str(parse_result.air_date) + " for show " +
                    parse_result.series_name + ", skipping", logger.WARNING)
                return False
            except tvdb_exceptions.tvdb_error, e:
                logger.log(u"Unable to contact TVDB: " + ex(e), logger.WARNING)
                return False
Exemplo n.º 8
0
    def _addCacheEntry(self,
                       name,
                       url,
                       season=None,
                       episodes=None,
                       indexer_id=0,
                       quality=None,
                       extraNames=[]):

        myDB = self._getDB()

        parse_result = None

        # if we don't have complete info then parse the filename to get it
        for curName in [name] + extraNames:
            try:
                myParser = NameParser()
                parse_result = myParser.parse(curName, True)
            except InvalidNameException:
                logger.log(
                    u"Unable to parse the filename " + curName +
                    " into a valid episode", logger.DEBUG)
                continue

        if not parse_result:
            logger.log(
                u"Giving up because I'm unable to parse this name: " + name,
                logger.DEBUG)
            return None

        if not parse_result.series_name:
            logger.log(
                u"No series name retrieved from " + name +
                ", unable to cache it", logger.DEBUG)
            return None

        indexer_lang = None

        if indexer_id:
            # if we have only the indexer_id, use the database
            showObj = helpers.findCertainShow(sickbeard.showList, indexer_id)
            if showObj:
                self.indexer = int(showObj.indexer)
                indexer_lang = showObj.lang
            else:
                logger.log(
                    u"We were given a Indexer ID " + str(indexer_id) +
                    " but it doesn't match a show we have in our list, so leaving indexer_id empty",
                    logger.DEBUG)
                indexer_id = 0

        # if no indexerID then fill out as much info as possible by searching the show name
        if not indexer_id:
            # check the name cache and see if we already know what show this is
            logger.log(
                u"Checking the cache to see if we already know the Indexer ID of "
                + parse_result.series_name, logger.DEBUG)
            indexer_id = name_cache.retrieveNameFromCache(
                parse_result.series_name)

            # remember if the cache lookup worked or not so we know whether we should bother updating it later
            if indexer_id == None:
                logger.log(
                    u"No cache results returned, continuing on with the search",
                    logger.DEBUG)
                from_cache = False
            else:
                logger.log(
                    u"Cache lookup found " + repr(indexer_id) + ", using that",
                    logger.DEBUG)
                from_cache = True

            # if the cache failed, try looking up the show name in the database
            if indexer_id == None:
                logger.log(u"Trying to look the show up in the show database",
                           logger.DEBUG)
                showResult = helpers.searchDBForShow(parse_result.series_name)
                if showResult:
                    logger.log(
                        u"" + parse_result.series_name +
                        " was found to be show " + showResult[2] + " (" +
                        str(showResult[1]) + ") in our DB.", logger.DEBUG)
                    indexer_id = showResult[1]

            # if the DB lookup fails then do a comprehensive regex search
            if indexer_id == None:
                logger.log(
                    u"Couldn't figure out a show name straight from the DB, trying a regex search instead",
                    logger.DEBUG)
                for curShow in sickbeard.showList:
                    if show_name_helpers.isGoodResult(name, curShow, False):
                        logger.log(
                            u"Successfully matched " + name + " to " +
                            curShow.name + " with regex", logger.DEBUG)
                        indexer_id = curShow.indexerid
                        indexer_lang = curShow.lang
                        break

            # if indexer_id was anything but None (0 or a number) then
            if not from_cache:
                name_cache.addNameToCache(parse_result.series_name, indexer_id)

            # if we came out with indexer_id = None it means we couldn't figure it out at all, just use 0 for that
            if indexer_id == None:
                indexer_id = 0

            # if we found the show then retrieve the show object
            if indexer_id:
                try:
                    showObj = helpers.findCertainShow(sickbeard.showList,
                                                      indexer_id)
                except (MultipleShowObjectsException):
                    showObj = None
                if showObj:
                    self.indexer = int(showObj.indexer)
                    indexer_lang = showObj.lang

        # if we weren't provided with season/episode information then get it from the name that we parsed
        if not season:
            season = parse_result.season_number if parse_result.season_number != None else 1
        if not episodes:
            episodes = parse_result.episode_numbers

        # if we have an air-by-date show then get the real season/episode numbers
        if (parse_result.air_by_date or parse_result.sports) and indexer_id:
            try:
                lINDEXER_API_PARMS = sickbeard.indexerApi(
                    self.indexer).api_params.copy()
                if not (indexer_lang == "" or indexer_lang == "en"
                        or indexer_lang == None):
                    lINDEXER_API_PARMS['language'] = indexer_lang

                t = sickbeard.indexerApi(
                    self.indexer).indexer(**lINDEXER_API_PARMS)

                epObj = None
                if parse_result.air_by_date:
                    epObj = t[indexer_id].airedOn(parse_result.air_date)[0]
                elif parse_result.sports:
                    epObj = t[indexer_id].airedOn(parse_result.sports_date)[0]

                if epObj is None:
                    return None

                season = int(epObj["seasonnumber"])
                episodes = [int(epObj["episodenumber"])]
            except sickbeard.indexer_episodenotfound:
                logger.log(
                    u"Unable to find episode with date " +
                    str(parse_result.air_date) + " for show " +
                    parse_result.series_name + ", skipping", logger.WARNING)
                return None
            except sickbeard.indexer_error, e:
                logger.log(
                    u"Unable to contact " +
                    sickbeard.indexerApi(self.indexer).name + ": " + ex(e),
                    logger.WARNING)
                return None
Exemplo n.º 9
0
            return (None, None, None, None)

        ep = self._build_anidb_episode(sickbeard.ADBA_CONNECTION, filePath)
        try:
            self._log(u"Trying to lookup " + str(filePath) + " on anidb", logger.MESSAGE)
            ep.load_data()
        except Exception, e:
            self._log(u"exception msg: " + str(e))
            raise InvalidNameException
        else:
            self.anidbEpisode = ep

        #TODO: clean code. it looks like it's from hell
        for name in ep.allNames:

            indexer_id = name_cache.retrieveNameFromCache(name)
            if not indexer_id:
                show = helpers.get_show_by_name(name)
                if show:
                    indexer_id = show.indexerid
                else:
                    indexer_id = 0

                if indexer_id:
                    name_cache.addNameToCache(name, indexer_id)
            if indexer_id:
                try:
                    show = helpers.findCertainShow(sickbeard.showList, indexer_id)
                    (season, episodes) = helpers.get_all_episodes_from_absolute_number(show, None, [ep.epno])
                except exceptions.EpisodeNotFoundByAbsoluteNumberException:
                    self._log(str(indexer_id) + ": Indexer object absolute number " + str(
Exemplo n.º 10
0
    def _analyze_name(self, name, file=True):
        """
        Takes a name and tries to figure out a show, season, and episode from it.

        name: A string which we want to analyze to determine show info from (unicode)

        Returns a (indexer_id, season, [episodes]) tuple. The first two may be None and episodes may be []
        if none were found.
        """

        logger.log(u"Analyzing name " + repr(name))

        to_return = (None, None, [])

        if not name:
            return to_return

        # parse the name to break it into show name, season, and episode
        np = NameParser(file)
        parse_result = np.parse(name)

        self._log("Parsed " + name + " into " + str(parse_result).decode('utf-8'), logger.DEBUG)

        if parse_result.air_by_date:
            season = -1
            episodes = [parse_result.air_date]
        elif parse_result.sports:
            season = -1
            episodes = [parse_result.sports_date]
        else:
            season = parse_result.season_number
            episodes = parse_result.episode_numbers

        to_return = (None, season, episodes)

        # do a scene reverse-lookup to get a list of all possible names
        name_list = show_name_helpers.sceneToNormalShowNames(parse_result.series_name)

        if not name_list:
            return (None, season, episodes)

        def _finalize(parse_result):
            self.release_group = parse_result.release_group

            # remember whether it's a proper
            if parse_result.extra_info:
                self.is_proper = re.search('(^|[\. _-])(proper|repack)([\. _-]|$)', parse_result.extra_info,
                                           re.I) != None

            # if the result is complete then remember that for later
            if parse_result.series_name and parse_result.season_number != None and parse_result.episode_numbers and parse_result.release_group:
                test_name = os.path.basename(name)
                if test_name == self.nzb_name:
                    self.good_results[self.NZB_NAME] = True
                elif test_name == self.folder_name:
                    self.good_results[self.FOLDER_NAME] = True
                elif test_name == self.file_name:
                    self.good_results[self.FILE_NAME] = True
                else:
                    logger.log(u"Nothing was good, found " + repr(test_name) + " and wanted either " + repr(
                        self.nzb_name) + ", " + repr(self.folder_name) + ", or " + repr(self.file_name))
            else:
                logger.log(u"Parse result not sufficient(all following have to be set). Will not save release name",
                           logger.DEBUG)
                logger.log("Parse result(series_name): " + str(parse_result.series_name), logger.DEBUG)
                logger.log("Parse result(season_number): " + str(parse_result.season_number), logger.DEBUG)
                logger.log("Parse result(episode_numbers): " + str(parse_result.episode_numbers), logger.DEBUG)
                logger.log("Parse result(release_group): " + str(parse_result.release_group), logger.DEBUG)

        # for each possible interpretation of that scene name
        for cur_name in name_list:
            self._log(u"Checking cache for " + cur_name, logger.DEBUG)
            cache_id = name_cache.retrieveNameFromCache(parse_result.series_name)
            if cache_id:
                self._log(u"Cache lookup got a Indexer ID " + str(cache_id) + ", using that", logger.DEBUG)
                _finalize(parse_result)
                return (cache_id, season, episodes)

        # for each possible interpretation of that scene name
        for cur_name in name_list:
            self._log(u"Checking scene exceptions for a match on " + cur_name, logger.DEBUG)
            scene_id = scene_exceptions.get_scene_exception_by_name(cur_name)
            if scene_id:
                self._log(u"Scene exception lookup got a Indexer ID " + str(scene_id) + ", using that", logger.DEBUG)
                _finalize(parse_result)
                return (scene_id, season, episodes)

        # see if we can find the name directly in the DB, if so use it
        for cur_name in name_list:
            self._log(u"Looking up " + cur_name + u" in the DB", logger.DEBUG)
            db_result = helpers.searchDBForShow(cur_name)
            if db_result:
                self._log(u"Lookup successful, using " + sickbeard.indexerApi(db_result[0]).name + " id " + str(
                    db_result[1]),
                          logger.DEBUG)
                _finalize(parse_result)
                return (int(db_result[1]), season, episodes)

        # see if we can find the name on the Indexer
        for cur_name in name_list:
            foundInfo = helpers.searchIndexerForShowID(cur_name, ui=classes.ShowListUI)
            if foundInfo:
                indexer_id = foundInfo[1]
                self._log(
                    u"Lookup successful, using " + sickbeard.indexerApi(self.indexer).name + " id " + str(indexer_id),
                    logger.DEBUG)
                _finalize(parse_result)
                return (indexer_id, season, episodes)

        _finalize(parse_result)
        return to_return
Exemplo n.º 11
0
    def _addCacheEntry(self, name, url):

        cacheDB = self._getDB()
        parse_result = None
        from_cache = False
        indexer_id = None

        # if we don't have complete info then parse the filename to get it
        while(True):
            try:
                myParser = NameParser()
                parse_result = myParser.parse(name)
            except InvalidNameException:
                logger.log(u"Unable to parse the filename " + name + " into a valid episode", logger.DEBUG)
                return None

            if not parse_result:
                logger.log(u"Giving up because I'm unable to parse this name: " + name, logger.DEBUG)
                return None

            if not parse_result.series_name:
                logger.log(u"No series name retrieved from " + name + ", unable to cache it", logger.DEBUG)
                return None

            logger.log(
                u"Checking the cahe for show:" + str(parse_result.series_name),
                logger.DEBUG)

            # remember if the cache lookup worked or not so we know whether we should bother updating it later
            cache_id = name_cache.retrieveNameFromCache(parse_result.series_name)
            if cache_id:
                logger.log(u"Cache lookup found Indexer ID:" + repr(indexer_id) + ", using that for " + parse_result.series_name, logger.DEBUG)
                from_cache = True
                indexer_id = cache_id
                break

            # if the cache failed, try looking up the show name in the database
            logger.log(
                u"Checking the database for show:" + str(parse_result.series_name),
                logger.DEBUG)

            showResult = helpers.searchDBForShow(parse_result.series_name)
            if showResult:
                logger.log(
                    u"Database lookup found Indexer ID:" + str(showResult[1]) + ", using that for " + parse_result.series_name, logger.DEBUG)
                indexer_id = showResult[1]
            break

        # if we didn't find a Indexer ID return None
        if not indexer_id:
            return None

        # if the show isn't in out database then return None
        try:showObj = helpers.findCertainShow(sickbeard.showList, indexer_id)
        except:return None

        if not showObj:
            return None

        # if we weren't provided with season/episode information then get it from the name that we parsed
        season = None
        episodes = None
        myDB = db.DBConnection()
        if parse_result.air_by_date:
            sql_results = myDB.select("SELECT season, episode FROM tv_episodes WHERE showid = ? AND airdate = ?",
                                      [showObj.indexerid, parse_result.air_date.toordinal()])
            if sql_results > 0:
                season = int(sql_results[0]["season"])
                episodes = [int(sql_results[0]["episode"])]
        elif parse_result.sports:
            sql_results = myDB.select("SELECT season, episode FROM tv_episodes WHERE showid = ? AND airdate = ?",
                                      [showObj.indexerid, parse_result.sports_date.toordinal()])
            if sql_results > 0:
                season = int(sql_results[0]["season"])
                episodes = [int(sql_results[0]["episode"])]
        else:
            season = parse_result.season_number
            episodes = parse_result.episode_numbers

        if not (season and episodes):
            return None

        # convert scene numbered releases before storing to cache
        convertedEps = {}
        for curEp in episodes:
            epObj = showObj.getEpisode(season, curEp, sceneConvert=True)
            if not epObj:
                return None
            if not epObj.season in convertedEps:
                convertedEps[epObj.season] = []
            convertedEps[epObj.season].append(epObj.episode)

        # get the current timestamp
        curTimestamp = int(time.mktime(datetime.datetime.today().timetuple()))

        # get quality of release
        quality = Quality.sceneQuality(name)

        if not isinstance(name, unicode):
            name = unicode(name, 'utf-8')

        for season, episodes in convertedEps.items():
            episodeText = "|" + "|".join(map(str, episodes)) + "|"
            cacheDB.action(
                "INSERT INTO [" + self.providerID + "] (name, season, episodes, indexerid, url, time, quality) VALUES (?,?,?,?,?,?,?)",
                [name, season, episodeText, indexer_id, url, curTimestamp, quality])
            return (None, None, None)
        
        ep = self._build_anidb_episode(sickbeard.ADBA_CONNECTION,filePath)
        try:
            self._log(u"Trying to lookup "+str(filePath)+" on anidb", logger.MESSAGE)        
            ep.load_data()
        except Exception,e :
            self._log(u"exception msg: "+str(e))
            raise InvalidNameException
        else:
            self.anidbEpisode = ep
        
        #TODO: clean code. it looks like it's from hell
        for name in ep.allNames:
            
            tvdb_id = name_cache.retrieveNameFromCache(name)
            if not tvdb_id:
                show = helpers.get_show_by_name(name, sickbeard.showList, True)
                if show:
                    tvdb_id = show.tvdbid
                else:
                    tvdb_id = 0

                if tvdb_id:
                    name_cache.addNameToCache(name, tvdb_id)
            if tvdb_id:
                try:
                    show = helpers.findCertainShow(sickbeard.showList, tvdb_id)
                    (season, episodes) = helpers.get_all_episodes_from_absolute_number(show, None, [ep.epno])
                except exceptions.EpisodeNotFoundByAbsoluteNumerException:
                    self._log(str(tvdb_id) + ": TVDB object absolute number " + str(ep.epno) + " is incomplete, skipping this episode")
        ep = self._build_anidb_episode(sickbeard.ADBA_CONNECTION, filePath)
        try:
            self._log(u"Trying to lookup " + str(filePath) + " on anidb",
                      logger.MESSAGE)
            ep.load_data()
        except Exception, e:
            self._log(u"exception msg: " + str(e))
            raise InvalidNameException
        else:
            self.anidbEpisode = ep

        #TODO: clean code. it looks like it's from hell
        for name in ep.allNames:

            tvdb_id = name_cache.retrieveNameFromCache(name)
            if not tvdb_id:
                show = helpers.get_show_by_name(name, sickbeard.showList, True)
                if show:
                    tvdb_id = show.tvdbid
                else:
                    tvdb_id = 0

                if tvdb_id:
                    name_cache.addNameToCache(name, tvdb_id)
            if tvdb_id:
                try:
                    show = helpers.findCertainShow(sickbeard.showList, tvdb_id)
                    (season,
                     episodes) = helpers.get_all_episodes_from_absolute_number(
                         show, None, [ep.epno])
Exemplo n.º 14
0
    def _addCacheEntry(self, name, url, season=None, episodes=None, indexer_id=0, quality=None, extraNames=[]):

        myDB = self._getDB()

        parse_result = None

        # if we don't have complete info then parse the filename to get it
        for curName in [name] + extraNames:
            try:
                myParser = NameParser()
                parse_result = myParser.parse(curName)
            except InvalidNameException:
                logger.log(u"Unable to parse the filename " + curName + " into a valid episode", logger.DEBUG)
                continue

        if not parse_result:
            logger.log(u"Giving up because I'm unable to parse this name: " + name, logger.DEBUG)
            return None

        if not parse_result.series_name:
            logger.log(u"No series name retrieved from " + name + ", unable to cache it", logger.DEBUG)
            return None

        indexer_lang = None

        if indexer_id:
            # if we have only the indexer_id, use the database
            showObj = helpers.findCertainShow(sickbeard.showList, indexer_id)
            if showObj:
                self.indexer = int(showObj.indexer)
                indexer_lang = showObj.lang
            else:
                logger.log(u"We were given a Indexer ID " + str(indexer_id) + " but it doesn't match a show we have in our list, so leaving indexer_id empty",logger.DEBUG)
                indexer_id = 0

        # if no indexerID then fill out as much info as possible by searching the show name
        if not indexer_id:
            from_cache = False

            # check the name cache and see if we already know what show this is
            logger.log(
                u"Checking the cache for Indexer ID of " + parse_result.series_name,
                logger.DEBUG)

            # remember if the cache lookup worked or not so we know whether we should bother updating it later
            indexer_id = name_cache.retrieveNameFromCache(parse_result.series_name)
            if indexer_id:
                logger.log(u"Cache lookup found " + repr(indexer_id) + ", using that", logger.DEBUG)
                from_cache = True

            # if the cache failed, try looking up the show name in the database
            if not indexer_id:
                logger.log(
                    u"Checking the database for Indexer ID of " + str(parse_result.series_name),
                    logger.DEBUG)

                showResult = helpers.searchDBForShow(parse_result.series_name)
                if showResult:
                    logger.log(
                        u"" + parse_result.series_name + " was found to be show " + showResult[2] + " (" + str(
                            showResult[1]) + ") in our DB.", logger.DEBUG)
                    indexer_id = showResult[1]

            # if the database failed, try looking up the show name from scene exceptions list
            if not indexer_id:
                logger.log(
                    u"Checking the scene exceptions list for Indexer ID of " + parse_result.series_name,
                    logger.DEBUG)
                sceneResult = sickbeard.scene_exceptions.get_scene_exception_by_name(parse_result.series_name)
                if sceneResult:
                    logger.log(
                        u"" + str(parse_result.series_name) + " was found in scene exceptions list with Indexer ID: " + str(sceneResult), logger.DEBUG)
                    indexer_id = sceneResult

            # if the DB lookup fails then do a comprehensive regex search
            if not indexer_id:
                logger.log(
                    u"Checking the shows list for Indexer ID of " + str(parse_result.series_name),
                    logger.DEBUG)
                for curShow in sickbeard.showList:
                    if show_name_helpers.isGoodResult(name, curShow, False):
                        logger.log(u"Successfully matched " + name + " to " + curShow.name + " from shows list",
                                   logger.DEBUG)
                        indexer_id = curShow.indexerid
                        indexer_lang = curShow.lang
                        break

            # if the database failed, try looking up the show name from scene exceptions list
            if not indexer_id:
                logger.log(
                    u"Checking Indexers for Indexer ID of " + parse_result.series_name,
                    logger.DEBUG)

                # check indexers
                try:indexerResult = helpers.searchIndexerForShowID(parse_result.series_name)
                except:indexerResult = None

                if indexerResult:
                    logger.log(
                        u"" + str(parse_result.series_name) + " was found on " + str(sickbeard.indexerApi(indexerResult[0]).name) + " with Indexer ID: " + str(indexerResult[1]), logger.DEBUG)
                    indexer_id = indexerResult[1]

            # if indexer_id was anything but None (0 or a number) then
            if not from_cache:
                name_cache.addNameToCache(parse_result.series_name, indexer_id)

            # if we came out with indexer_id = None it means we couldn't figure it out at all, just use 0 for that
            if indexer_id == None:
                indexer_id = 0

            # if we found the show then retrieve the show object
            if indexer_id:
                try:
                    showObj = helpers.findCertainShow(sickbeard.showList, indexer_id)
                except (MultipleShowObjectsException):
                    showObj = None
                if showObj:
                    self.indexer = int(showObj.indexer)
                    indexer_lang = showObj.lang

        # if we weren't provided with season/episode information then get it from the name that we parsed
        if not season:
            season = parse_result.season_number if parse_result.season_number != None else 1
        if not episodes:
            episodes = parse_result.episode_numbers

        # if we have an air-by-date show then get the real season/episode numbers
        if (parse_result.air_by_date or parse_result.sports) and indexer_id:
            try:
                lINDEXER_API_PARMS = sickbeard.indexerApi(self.indexer).api_params.copy()
                if not (indexer_lang == "" or indexer_lang == "en" or indexer_lang == None):
                    lINDEXER_API_PARMS['language'] = indexer_lang

                t = sickbeard.indexerApi(self.indexer).indexer(**lINDEXER_API_PARMS)

                epObj = None
                if parse_result.air_by_date:
                    epObj = t[indexer_id].airedOn(parse_result.air_date)[0]
                elif parse_result.sports:
                    epObj = t[indexer_id].airedOn(parse_result.sports_date)[0]

                if epObj is None:
                    return None

                season = int(epObj["seasonnumber"])
                episodes = [int(epObj["episodenumber"])]
            except sickbeard.indexer_episodenotfound:
                logger.log(u"Unable to find episode with date " + str(
                    parse_result.air_date) + " for show " + parse_result.series_name + ", skipping", logger.WARNING)
                return None
            except sickbeard.indexer_error, e:
                logger.log(u"Unable to contact " + sickbeard.indexerApi(self.indexer).name + ": " + ex(e),
                           logger.WARNING)
                return None
Exemplo n.º 15
0
    def _addCacheEntry(self, name, url):

        cacheDB = self._getDB()
        parse_result = None
        from_cache = False
        indexer_id = None

        # if we don't have complete info then parse the filename to get it
        while (True):
            try:
                myParser = NameParser()
                parse_result = myParser.parse(name)
            except InvalidNameException:
                logger.log(
                    u"Unable to parse the filename " + name +
                    " into a valid episode", logger.DEBUG)
                return None

            if not parse_result:
                logger.log(
                    u"Giving up because I'm unable to parse this name: " +
                    name, logger.DEBUG)
                return None

            if not parse_result.series_name:
                logger.log(
                    u"No series name retrieved from " + name +
                    ", unable to cache it", logger.DEBUG)
                return None

            logger.log(
                u"Checking the cahe for show:" + str(parse_result.series_name),
                logger.DEBUG)

            # remember if the cache lookup worked or not so we know whether we should bother updating it later
            cache_id = name_cache.retrieveNameFromCache(
                parse_result.series_name)
            if cache_id:
                logger.log(
                    u"Cache lookup found Indexer ID:" + repr(indexer_id) +
                    ", using that for " + parse_result.series_name,
                    logger.DEBUG)
                from_cache = True
                indexer_id = cache_id
                break

            # if the cache failed, try looking up the show name in the database
            logger.log(
                u"Checking the database for show:" +
                str(parse_result.series_name), logger.DEBUG)

            showResult = helpers.searchDBForShow(parse_result.series_name)
            if showResult:
                logger.log(
                    u"Database lookup found Indexer ID:" + str(showResult[1]) +
                    ", using that for " + parse_result.series_name,
                    logger.DEBUG)
                indexer_id = showResult[1]
            break

        # if we didn't find a Indexer ID return None
        if not indexer_id:
            return None

        # if the show isn't in out database then return None
        try:
            showObj = helpers.findCertainShow(sickbeard.showList, indexer_id)
        except:
            return None

        if not showObj:
            return None

        # if we weren't provided with season/episode information then get it from the name that we parsed
        season = None
        episodes = None
        myDB = db.DBConnection()
        if parse_result.air_by_date:
            sql_results = myDB.select(
                "SELECT season, episode FROM tv_episodes WHERE showid = ? AND airdate = ?",
                [showObj.indexerid,
                 parse_result.air_date.toordinal()])
            if sql_results > 0:
                season = int(sql_results[0]["season"])
                episodes = [int(sql_results[0]["episode"])]
        elif parse_result.sports:
            sql_results = myDB.select(
                "SELECT season, episode FROM tv_episodes WHERE showid = ? AND airdate = ?",
                [showObj.indexerid,
                 parse_result.sports_date.toordinal()])
            if sql_results > 0:
                season = int(sql_results[0]["season"])
                episodes = [int(sql_results[0]["episode"])]
        else:
            season = parse_result.season_number
            episodes = parse_result.episode_numbers

        if not (season and episodes):
            return None

        # convert scene numbered releases before storing to cache
        convertedEps = {}
        for curEp in episodes:
            epObj = showObj.getEpisode(season, curEp, sceneConvert=True)
            if not epObj:
                return None
            if not epObj.season in convertedEps:
                convertedEps[epObj.season] = []
            convertedEps[epObj.season].append(epObj.episode)

        # get the current timestamp
        curTimestamp = int(time.mktime(datetime.datetime.today().timetuple()))

        # get quality of release
        quality = Quality.sceneQuality(name)

        if not isinstance(name, unicode):
            name = unicode(name, 'utf-8')

        for season, episodes in convertedEps.items():
            episodeText = "|" + "|".join(map(str, episodes)) + "|"
            cacheDB.action(
                "INSERT INTO [" + self.providerID +
                "] (name, season, episodes, indexerid, url, time, quality) VALUES (?,?,?,?,?,?,?)",
                [
                    name, season, episodeText, indexer_id, url, curTimestamp,
                    quality
                ])
Exemplo n.º 16
0
            return (None, None, None, None)

        ep = self._build_anidb_episode(sickbeard.ADBA_CONNECTION, filePath)
        try:
            self._log(u"Trying to lookup " + str(filePath) + " on anidb", logger.MESSAGE)
            ep.load_data()
        except Exception, e:
            self._log(u"exception msg: " + str(e))
            raise InvalidNameException
        else:
            self.anidbEpisode = ep

        #TODO: clean code. it looks like it's from hell
        for name in ep.allNames:

            indexer_id = name_cache.retrieveNameFromCache(name)
            if not indexer_id:
                show = helpers.get_show_by_name(name)
                if show:
                    indexer_id = show.indexerid
                else:
                    indexer_id = 0

                if indexer_id:
                    name_cache.addNameToCache(name, indexer_id)
            if indexer_id:
                try:
                    show = helpers.findCertainShow(sickbeard.showList, indexer_id)
                    (season, episodes) = helpers.get_all_episodes_from_absolute_number(show, None, [ep.epno])
                except exceptions.EpisodeNotFoundByAbsoluteNumberException:
                    self._log(str(indexer_id) + ": Indexer object absolute number " + str(