Esempio n. 1
0
 def test_should_delete_episode(self):
     test_cases = [
         ((SNATCHED, Quality.HDTV), False),
         ((SNATCHED_PROPER, Quality.HDTV), False),
         ((SNATCHED_BEST, Quality.HDTV), False),
         ((DOWNLOADED, Quality.HDTV), False),
         ((ARCHIVED, Quality.HDTV), False),
         ((ARCHIVED, Quality.NONE), False),
         ((SKIPPED, Quality.NONE), True),
         ((IGNORED, Quality.NONE), False),
         ((UNAIRED, Quality.NONE), True),
         ((UNKNOWN, Quality.NONE), True),
         ((WANTED, Quality.NONE), True),
     ]
     for c, b in test_cases:
         self.assertEqual(helpers.should_delete_episode(Quality.compositeStatus(*c)), b)
Esempio n. 2
0
 def test_should_delete_episode(self):
     test_cases = [
         ((SNATCHED, Quality.HDTV), False),
         ((SNATCHED_PROPER, Quality.HDTV), False),
         ((SNATCHED_BEST, Quality.HDTV), False),
         ((DOWNLOADED, Quality.HDTV), False),
         ((ARCHIVED, Quality.HDTV), False),
         ((ARCHIVED, Quality.NONE), False),
         ((SKIPPED, Quality.NONE), True),
         ((IGNORED, Quality.NONE), False),
         ((UNAIRED, Quality.NONE), True),
         ((UNKNOWN, Quality.NONE), True),
         ((WANTED, Quality.NONE), True),
     ]
     for c, b in test_cases:
         self.assertEqual(
             helpers.should_delete_episode(Quality.compositeStatus(*c)), b)
Esempio n. 3
0
    def run(self):

        ShowQueueItem.run(self)

        if not sickbeard.indexerApi(self.show.indexer).config['active']:
            logger.log(
                'Indexer %s is marked inactive, aborting update for show %s and continue with refresh.'
                % (sickbeard.indexerApi(
                    self.show.indexer).config['name'], self.show.name))
            sickbeard.showQueueScheduler.action.refreshShow(
                self.show,
                self.force,
                self.scheduled_update,
                after_update=True)
            return

        logger.log('Beginning update of %s' % self.show.name)

        logger.log(
            'Retrieving show info from %s' %
            sickbeard.indexerApi(self.show.indexer).name, logger.DEBUG)
        try:
            result = self.show.loadFromIndexer(cache=not self.force)
            if None is not result:
                return
        except sickbeard.indexer_error as e:
            logger.log(
                'Unable to contact %s, aborting: %s' %
                (sickbeard.indexerApi(self.show.indexer).name, ex(e)),
                logger.WARNING)
            return
        except sickbeard.indexer_attributenotfound as e:
            logger.log(
                'Data retrieved from %s was incomplete, aborting: %s' %
                (sickbeard.indexerApi(self.show.indexer).name, ex(e)),
                logger.ERROR)
            return

        if self.force_web:
            self.show.load_imdb_info()

        try:
            self.show.saveToDB()
        except Exception as e:
            logger.log('Error saving the show to the database: %s' % ex(e),
                       logger.ERROR)
            logger.log(traceback.format_exc(), logger.ERROR)

        # get episode list from DB
        logger.log('Loading all episodes from the database', logger.DEBUG)
        DBEpList = self.show.loadEpisodesFromDB(update=True)

        # get episode list from TVDB
        logger.log(
            'Loading all episodes from %s' %
            sickbeard.indexerApi(self.show.indexer).name, logger.DEBUG)
        try:
            IndexerEpList = self.show.loadEpisodesFromIndexer(
                cache=not self.force, update=True)
        except sickbeard.indexer_exception as e:
            logger.log(
                'Unable to get info from %s, the show info will not be refreshed: %s'
                % (sickbeard.indexerApi(self.show.indexer).name, ex(e)),
                logger.ERROR)
            IndexerEpList = None

        if None is IndexerEpList:
            logger.log(
                'No data returned from %s, unable to update episodes for show: %s'
                %
                (sickbeard.indexerApi(self.show.indexer).name, self.show.name),
                logger.ERROR)
        elif not IndexerEpList or 0 == len(IndexerEpList):
            logger.log(
                'No episodes returned from %s for show: %s' %
                (sickbeard.indexerApi(self.show.indexer).name, self.show.name),
                logger.WARNING)
        else:
            # for each ep we found on TVDB delete it from the DB list
            for curSeason in IndexerEpList:
                for curEpisode in IndexerEpList[curSeason]:
                    logger.log(
                        'Removing %sx%s from the DB list' %
                        (curSeason, curEpisode), logger.DEBUG)
                    if curSeason in DBEpList and curEpisode in DBEpList[
                            curSeason]:
                        del DBEpList[curSeason][curEpisode]

            # for the remaining episodes in the DB list just delete them from the DB
            for curSeason in DBEpList:
                for curEpisode in DBEpList[curSeason]:
                    curEp = self.show.getEpisode(curSeason, curEpisode)
                    status = sickbeard.common.Quality.splitCompositeStatus(
                        curEp.status)[0]
                    if should_delete_episode(status):
                        logger.log(
                            'Permanently deleting episode %sx%s from the database'
                            % (curSeason, curEpisode), logger.MESSAGE)
                        try:
                            curEp.deleteEpisode()
                        except exceptions.EpisodeDeletedException:
                            pass
                    else:
                        logger.log(
                            'Not deleting episode %sx%s from the database because status is: %s'
                            % (curSeason, curEpisode, statusStrings[status]),
                            logger.MESSAGE)

        if self.priority != generic_queue.QueuePriorities.NORMAL:
            self.kwargs['priority'] = self.priority
        sickbeard.showQueueScheduler.action.refreshShow(
            self.show,
            self.force,
            self.scheduled_update,
            after_update=True,
            force_image_cache=self.force_web,
            **self.kwargs)
Esempio n. 4
0
    def run(self):

        ShowQueueItem.run(self)

        if not sickbeard.indexerApi(self.show.indexer).config['active']:
            logger.log('Indexer %s is marked inactive, aborting update for show %s and continue with refresh.' % (sickbeard.indexerApi(self.show.indexer).config['name'], self.show.name))
            sickbeard.showQueueScheduler.action.refreshShow(self.show, self.force, self.scheduled_update, after_update=True)
            return

        logger.log('Beginning update of %s' % self.show.name)

        logger.log('Retrieving show info from %s' % sickbeard.indexerApi(self.show.indexer).name, logger.DEBUG)
        try:
            result = self.show.loadFromIndexer(cache=not self.force)
            if None is not result:
                return
        except sickbeard.indexer_error as e:
            logger.log('Unable to contact %s, aborting: %s' % (sickbeard.indexerApi(self.show.indexer).name, ex(e)),
                       logger.WARNING)
            return
        except sickbeard.indexer_attributenotfound as e:
            logger.log('Data retrieved from %s was incomplete, aborting: %s' %
                       (sickbeard.indexerApi(self.show.indexer).name, ex(e)), logger.ERROR)
            return

        if self.force_web:
            self.show.load_imdb_info()

        try:
            self.show.saveToDB()
        except Exception as e:
            logger.log('Error saving the show to the database: %s' % ex(e), logger.ERROR)
            logger.log(traceback.format_exc(), logger.ERROR)

        # get episode list from DB
        logger.log('Loading all episodes from the database', logger.DEBUG)
        DBEpList = self.show.loadEpisodesFromDB(update=True)

        # get episode list from TVDB
        logger.log('Loading all episodes from %s' % sickbeard.indexerApi(self.show.indexer).name, logger.DEBUG)
        try:
            IndexerEpList = self.show.loadEpisodesFromIndexer(cache=not self.force, update=True)
        except sickbeard.indexer_exception as e:
            logger.log('Unable to get info from %s, the show info will not be refreshed: %s' %
                       (sickbeard.indexerApi(self.show.indexer).name, ex(e)), logger.ERROR)
            IndexerEpList = None

        if None is IndexerEpList:
            logger.log('No data returned from %s, unable to update episodes for show: %s' %
                       (sickbeard.indexerApi(self.show.indexer).name, self.show.name), logger.ERROR)
        elif not IndexerEpList or 0 == len(IndexerEpList):
            logger.log('No episodes returned from %s for show: %s' %
                       (sickbeard.indexerApi(self.show.indexer).name, self.show.name), logger.WARNING)
        else:
            # for each ep we found on TVDB delete it from the DB list
            for curSeason in IndexerEpList:
                for curEpisode in IndexerEpList[curSeason]:
                    logger.log('Removing %sx%s from the DB list' % (curSeason, curEpisode), logger.DEBUG)
                    if curSeason in DBEpList and curEpisode in DBEpList[curSeason]:
                        del DBEpList[curSeason][curEpisode]

            # for the remaining episodes in the DB list just delete them from the DB
            for curSeason in DBEpList:
                for curEpisode in DBEpList[curSeason]:
                    curEp = self.show.getEpisode(curSeason, curEpisode)
                    status = sickbeard.common.Quality.splitCompositeStatus(curEp.status)[0]
                    if should_delete_episode(status):
                        logger.log('Permanently deleting episode %sx%s from the database' %
                                   (curSeason, curEpisode), logger.MESSAGE)
                        try:
                            curEp.deleteEpisode()
                        except exceptions.EpisodeDeletedException:
                            pass
                    else:
                        logger.log('Not deleting episode %sx%s from the database because status is: %s' %
                                   (curSeason, curEpisode, statusStrings[status]), logger.MESSAGE)

        if self.priority != generic_queue.QueuePriorities.NORMAL:
            self.kwargs['priority'] = self.priority
        sickbeard.showQueueScheduler.action.refreshShow(self.show, self.force, self.scheduled_update, after_update=True,
                                                        force_image_cache=self.force_web, **self.kwargs)