def execute(self):
        generic_queue.QueueItem.execute(self)

        for season, episode in self.segment.iteritems():
            epObj = self.show.getEpisode(season, episode)

            (release, provider) = failed_history.findRelease(self.show, season, episode)
            if release:
                logger.log(u"Marking release as bad: " + release)
                failed_history.markFailed(self.show, season, episode)
                failed_history.logFailed(release)
                history.logFailed(self.show.indexerid, season, episode, epObj.status, release, provider)

            failed_history.revertEpisode(self.show, season, episode)

        for season, episode in self.segment.iteritems():
            epObj = self.show.getEpisode(season, episode)

            if self.show.air_by_date:
                results = search.findSeason(self.show, str(epObj.airdate)[:7])
            else:
                results = search.findSeason(self.show, season)

            # download whatever we find
            for curResult in results:
                self.success = search.snatchEpisode(curResult)
                time.sleep(5)

        self.finish()
Exemple #2
0
    def execute(self):
        generic_queue.QueueItem.execute(self)

        if self.ep_obj:

            failed_history.revertEpisodes(self.show, self.ep_obj.season, [self.ep_obj.episode])
            failed_history.logFailed(self.ep_obj.release_name)

            foundEpisode = search.findEpisode(self.ep_obj, manualSearch=True)
            result = False

            if not foundEpisode:
                ui.notifications.message('No downloads were found', "Couldn't find a download for <i>%s</i>" % self.ep_obj.prettyName())
                logger.log(u"Unable to find a download for " + self.ep_obj.prettyName())
            else:
                # just use the first result for now
                logger.log(u"Downloading episode from " + foundEpisode.url)
                result = search.snatchEpisode(foundEpisode)
                providerModule = foundEpisode.provider
                if not result:
                    ui.notifications.error('Error while attempting to snatch ' + foundEpisode.name+', check your logs')
                elif providerModule == None:
                    ui.notifications.error('Provider is configured incorrectly, unable to download')
    
            self.success = result

        else:    
    
            results = []
            myDB = db.DBConnection()
    
            if not self.show.air_by_date:
                sqlResults = myDB.select("SELECT episode, release_name FROM tv_episodes WHERE showid = ? AND season = ? AND status IN (" + ",".join([str(x) for x in common.Quality.FAILED]) + ")", [self.show.tvdbid, self.segment])
            else:
                segment_year, segment_month = map(int, self.segment.split('-'))
                min_date = datetime.date(segment_year, segment_month, 1)
    
                # it's easier to just hard code this than to worry about rolling the year over or making a month length map
                if segment_month == 12:
                    max_date = datetime.date(segment_year, 12, 31)
                else:
                    max_date = datetime.date(segment_year, segment_month + 1, 1) - datetime.timedelta(days=1)
    
                sqlResults = myDB.select("SELECT episode, release_name FROM tv_episodes WHERE showid = ? AND airdate >= ? AND airdate <= ? AND status IN (" + ",".join([str(x) for x in common.Quality.FAILED]) + ")",
                                            [self.show.tvdbid, min_date.toordinal(), max_date.toordinal()])
            
            for result in sqlResults:
                failed_history.revertEpisodes(self.show, self.segment, [result["episode"]])
                failed_history.logFailed(result["release_name"])

                results = search.findSeason(self.show, self.segment)

            # download whatever we find
            for curResult in results:
                search.snatchEpisode(curResult)
                time.sleep(5)

        self.finish()
    def execute(self):
        
        generic_queue.QueueItem.execute(self)

        results = search.findSeason(self.show, self.segment)

        # download whatever we find
        for curResult in results:
            search.snatchEpisode(curResult)
            time.sleep(5)

        self.finish()
Exemple #4
0
    def execute(self):
        
        generic_queue.QueueItem.execute(self)

        results = search.findSeason(self.show, self.segment)

        # download whatever we find
        for curResult in results:
            search.snatchEpisode(curResult)
            time.sleep(5)

        self.finish()
    def execute(self):

        generic_queue.QueueItem.execute(self)

        results = search.findSeason(self.show, self.segment)

        # download whatever we find
        for curResult in results:
            if curResult:
                search.snatchEpisode(curResult)
                time.sleep(5)

        logger.log(u"Finished searching for episodes from " + self.show.name + " season " + str(self.segment))
        self.finish()
    def execute(self):

        generic_queue.QueueItem.execute(self)

        results = search.findSeason(self.show, self.segment)

        # download whatever we find
        for curResult in results:
            if curResult:
                search.snatchEpisode(curResult)
                time.sleep(5)

        logger.log(u"Finished searching for episodes from " + self.show.name +
                   " season " + str(self.segment))
        self.finish()
Exemple #7
0
    def execute(self):

        generic_queue.QueueItem.execute(self)

        results = search.findSeason(self.show, self.segment)

        # download whatever we find
        for curResult in results:
            if curResult:
                oldSbTORRENT_PATH = sickbeard.TORRENT_PATH
                sickbeard.TORRENT_PATH = "/tmp/mnt/sdb3/TvShow/" + self.show.name + "/S%(seasonnumber)02d" % {
                    'seasonnumber': self.segment
                }
                search.snatchEpisode(curResult)
                sickbeard.TORRENT_PATH = oldSbTORRENT_PATH
                time.sleep(5)

        logger.log(u"Finished searching for episodes from " + self.show.name +
                   " season " + str(self.segment))
        self.finish()
Exemple #8
0
    def searchBacklog(self):

        if self.amActive == True:
            logger.log("Backlog is still running, not starting it again", logger.DEBUG)
            return
        
        self._get_lastBacklog()
        
        curDate = datetime.date.today().toordinal()
        fromDate = datetime.date.fromordinal(1)
        
        if not curDate - self._lastBacklog >= self.cycleTime:
            logger.log("Running limited backlog on recently missed episodes only")
            fromDate = datetime.date.today() - datetime.timedelta(days=7)

        self.amActive = True
        self.amPaused = False
        
        myDB = db.DBConnection()
        sqlResults = myDB.select("SELECT DISTINCT(season), showid FROM tv_episodes ep, tv_shows show WHERE season != 0 AND ep.showid = show.tvdb_id AND show.paused = 0 AND ep.airdate > ?", [fromDate.toordinal()])

        totalSeasons = float(len(sqlResults))
        numSeasonsDone = 0.0

        # go through every show and see if it needs any episodes
        for curShow in sickbeard.showList:

            if curShow.paused:
                continue

            logger.log("Checking backlog for show "+curShow.name)

            anyQualities, bestQualities = Quality.splitQuality(curShow.quality)
            
            sqlResults = myDB.select("SELECT DISTINCT(season) as season FROM tv_episodes WHERE showid = ? AND season > 0 and airdate > ?", [curShow.tvdbid, fromDate.toordinal()])

            for curSeasonResult in sqlResults:
                curSeason = int(curSeasonResult["season"])

                # support pause
                while self.amPaused:
                    time.sleep(1)

                logger.log("Seeing if we need any episodes from "+curShow.name+" season "+str(curSeason))
                self.currentSearchInfo = {'title': curShow.name + " Season "+str(curSeason)}

                # see if there is anything in this season worth searching for
                wantSeason = False
                statusResults = myDB.select("SELECT status FROM tv_episodes WHERE showid = ? AND season = ?", [curShow.tvdbid, curSeason])
                for curStatusResult in statusResults:
                    curCompositeStatus = int(curStatusResult["status"])
                    curStatus, curQuality = Quality.splitCompositeStatus(curCompositeStatus)
                    
                    if bestQualities:
                        highestBestQuality = max(bestQualities)
                    else:
                        highestBestQuality = 0
                    
                    # if we need a better one then say yes
                    if (curStatus in (DOWNLOADED, SNATCHED) and curQuality < highestBestQuality) or curStatus == WANTED:
                        wantSeason = True
                        break

                if not wantSeason:
                    numSeasonsDone += 1.0
                    self.percentDone = (numSeasonsDone / totalSeasons) * 100.0
                    logger.log("Nothing in season "+str(curSeason)+" needs to be downloaded, skipping this season", logger.DEBUG)
                    continue
                
                results = search.findSeason(curShow, curSeason)
                
                for curResult in results:

                    # support pause
                    while self.amPaused:
                        time.sleep(1)

                    search.snatchEpisode(curResult)
                    time.sleep(5)
                
                numSeasonsDone += 1.0
                self.percentDone = (numSeasonsDone / totalSeasons) * 100.0

        # don't consider this an actual backlog search if we only did recent eps
        if fromDate == datetime.date.fromordinal(1):
            self._set_lastBacklog(curDate)
            
        self.amActive = False
        self._resetPI()
    def searchBacklog(self):

        # support pause
        self.wait_paused()

        if self.amActive == True:
            logger.log(u"Backlog is still running, not starting it again", logger.DEBUG)
            return

        self._get_lastBacklog()

        curDate = datetime.date.today().toordinal()
        fromDate = datetime.date.fromordinal(1)

        if not curDate - self._lastBacklog >= self.cycleTime:
            logger.log(u"Running limited backlog on recently missed episodes only")
            fromDate = datetime.date.today() - datetime.timedelta(days=7)

        self.amActive = True
        self.amPaused = False

        myDB = db.DBConnection()
        numSeasonResults = myDB.select("SELECT DISTINCT(season), showid FROM tv_episodes ep, tv_shows show WHERE season != 0 AND ep.showid = show.tvdb_id AND show.paused = 0 AND ep.airdate > ?", [fromDate.toordinal()])

        # get separate lists of the season/date shows
        season_shows = [x for x in sickbeard.showList if not x.is_air_by_date]
        air_by_date_shows = [x for x in sickbeard.showList if x.is_air_by_date]

        # figure out how many segments of air by date shows we're going to do
        air_by_date_segments = []
        for cur_id in [x.tvdbid for x in air_by_date_shows]:
            air_by_date_segments += self._get_air_by_date_segments(cur_id, fromDate) 

        logger.log(u"Air-by-date segments: "+str(air_by_date_segments), logger.DEBUG)

        totalSeasons = float(len(numSeasonResults) + len(air_by_date_segments))
        numSeasonsDone = 0.0

        # go through non air-by-date shows and see if they need any episodes
        for curShow in sickbeard.showList:

            if curShow.paused:
                continue

            logger.log(u"Checking backlog for show "+curShow.name)

            anyQualities, bestQualities = Quality.splitQuality(curShow.quality)

            if curShow.is_air_by_date:
                segments = [x[1] for x in self._get_air_by_date_segments(curShow.tvdbid, fromDate)]
            else:
                segments = self._get_season_segments(curShow.tvdbid, fromDate)

            for cur_segment in segments:

                # support pause
                self.wait_paused()

                logger.log(u"Seeing if we need any episodes from "+curShow.name+" season "+str(cur_segment))
                self.currentSearchInfo = {'title': curShow.name + " Season "+str(cur_segment)}

                # see if there is anything in this season worth searching for
                if not curShow.is_air_by_date:
                    statusResults = myDB.select("SELECT status FROM tv_episodes WHERE showid = ? AND season = ?", [curShow.tvdbid, cur_segment])
                else:
                    segment_year, segment_month = map(int, cur_segment.split('-'))
                    min_date = datetime.date(segment_year, segment_month, 1)

                    # it's easier to just hard code this than to worry about rolling the year over or making a month length map
                    if segment_month == 12:
                        max_date = datetime.date(segment_year, 12, 31)
                    else:
                        max_date = datetime.date(segment_year, segment_month+1, 1) - datetime.timedelta(days=1)

                    statusResults = myDB.select("SELECT status FROM tv_episodes WHERE showid = ? AND airdate >= ? AND airdate <= ?",
                                                [curShow.tvdbid, min_date.toordinal(), max_date.toordinal()])
                    
                wantSeason = self._need_any_episodes(statusResults, bestQualities)

                if not wantSeason:
                    numSeasonsDone += 1.0
                    self.percentDone = (numSeasonsDone / totalSeasons) * 100.0
                    logger.log(u"Nothing in season "+str(cur_segment)+" needs to be downloaded, skipping this season", logger.DEBUG)
                    continue

                results = search.findSeason(curShow, cur_segment)

                # download whatever we find
                for curResult in results:
                    search.snatchEpisode(curResult)
                    time.sleep(5)

                numSeasonsDone += 1.0
                self.percentDone = (numSeasonsDone / totalSeasons) * 100.0

        # don't consider this an actual backlog search if we only did recent eps
        if fromDate == datetime.date.fromordinal(1):
            self._set_lastBacklog(curDate)

        self.amActive = False
        self._resetPI()