Ejemplo n.º 1
0
    def run(self, force=False):
        """
        Runs the failed searcher, queuing selected episodes for search that have failed to snatch
        :param force: Force search
        """
        if self.amActive or (not sickrage.app.config.use_failed_snatcher
                             or sickrage.app.developer) and not force:
            return

        self.amActive = True

        # set thread name
        threading.currentThread().setName(self.name)

        # trim failed download history
        FailedHistory.trimHistory()

        sickrage.app.log.info("Searching for failed snatches")

        show = None
        failed_snatches = False

        snatched_episodes = (
            x for x in sickrage.app.main_db.all('history')
            if x['action'] in Quality.SNATCHED + Quality.SNATCHED_BEST +
            Quality.SNATCHED_PROPER and 24 >= int(
                (datetime.datetime.now() - datetime.datetime.strptime(
                    x['date'], History.date_format)).total_seconds() /
                3600) >= sickrage.app.config.failed_snatch_age)

        downloaded_releases = ((x['showid'], x['season'], x['episode'])
                               for x in sickrage.app.main_db.all('history')
                               if x['action'] in Quality.DOWNLOADED)

        episodes = [
            x for x in snatched_episodes
            if (x['showid'], x['season'],
                x['episode']) not in downloaded_releases
        ]

        for episode in episodes:
            failed_snatches = True
            if not show or int(episode["showid"]) != show.indexerid:
                show = findCertainShow(int(episode["showid"]))

            # for when there is orphaned series in the database but not loaded into our showlist
            if not show or show.paused:
                continue

            ep_obj = show.getEpisode(int(episode['season']),
                                     int(episode['episode']))
            if isinstance(ep_obj, TVEpisode):
                # put it on the queue
                sickrage.app.search_queue.put(
                    FailedQueueItem(show, [ep_obj], True))

        if not failed_snatches:
            sickrage.app.log.info("No failed snatches found")

        self.amActive = False
Ejemplo n.º 2
0
    def run(self, force=False):
        if self.amActive:
            return

        self.amActive = True

        # set thread name
        threading.currentThread().setName(self.name)

        piList = []
        stale_should_update = []

        update_datetime = datetime.datetime.now()
        update_date = update_datetime.date()

        if sickrage.srCore.srConfig.USE_FAILED_DOWNLOADS:
            FailedHistory.trimHistory()

        if sickrage.srCore.srConfig.SHOWUPDATE_STALE:
            # select 10 'Ended' tv_shows updated more than 90 days ago to include in this update
            stale_update_date = (update_date - datetime.timedelta(days=90)).toordinal()

            # last_update_date <= 90 days, sorted ASC because dates are ordinal
            sql_result = main_db.MainDB().select(
                    "SELECT indexer_id FROM tv_shows WHERE status = 'Ended' AND last_update_indexer <= ? ORDER BY last_update_indexer ASC LIMIT 10;",
                    [stale_update_date])

            # list of stale shows
            [stale_should_update.append(int(cur_result['indexer_id'])) for cur_result in sql_result]

        # start update process
        sickrage.srCore.srLogger.info("Performing daily updates for all shows")
        for curShow in sickrage.srCore.SHOWLIST:
            try:
                # get next episode airdate
                curShow.nextEpisode()

                # if should_update returns True (not 'Ended') or show is selected stale 'Ended' then update, otherwise just refresh
                if curShow.should_update(update_date=update_date) or curShow.indexerid in stale_should_update:
                    try:
                        piList.append(
                                sickrage.srCore.SHOWQUEUE.updateShow(curShow, True))
                    except CantUpdateShowException as e:
                        sickrage.srCore.srLogger.debug("Unable to update show: {}".format(e.message))
                else:
                    piList.append(
                            sickrage.srCore.SHOWQUEUE.refreshShow(curShow, True))

            except (CantUpdateShowException, CantRefreshShowException) as e:
                sickrage.srCore.srLogger.error("Daily show update failed: {}".format(e.message))

        ProgressIndicators.setIndicator('dailyShowUpdates', QueueProgressIndicator("Daily Show Updates", piList))

        sickrage.srCore.srLogger.info("Completed daily updates for all shows")

        self.amActive = False
Ejemplo n.º 3
0
    def run(self, force=False):
        if self.amActive:
            return

        self.amActive = True

        update_datetime = datetime.datetime.now()
        update_date = update_datetime.date()

        if sickrage.USE_FAILED_DOWNLOADS:
            FailedHistory.trimHistory()

        sickrage.LOGGER.info("Doing full update on all shows")

        # select 10 'Ended' tv_shows updated more than 90 days ago to include in this update
        stale_should_update = []
        stale_update_date = (update_date - datetime.timedelta(days=90)).toordinal()

        # last_update_date <= 90 days, sorted ASC because dates are ordinal
        sql_result = main_db.MainDB().select(
                "SELECT indexer_id FROM tv_shows WHERE status = 'Ended' AND last_update_indexer <= ? ORDER BY last_update_indexer ASC LIMIT 10;",
                [stale_update_date])

        for cur_result in sql_result:
            stale_should_update.append(int(cur_result[b'indexer_id']))

        # start update process
        piList = []
        for curShow in sickrage.showList:

            try:
                # get next episode airdate
                curShow.nextEpisode()

                # if should_update returns True (not 'Ended') or show is selected stale 'Ended' then update, otherwise just refresh
                if curShow.should_update(update_date=update_date) or curShow.indexerid in stale_should_update:
                    try:
                        piList.append(
                                sickrage.SHOWQUEUE.updateShow(curShow, True))  # @UndefinedVariable
                    except CantUpdateShowException as e:
                        sickrage.LOGGER.debug("Unable to update show: {0}".format(str(e)))
                else:
                    sickrage.LOGGER.debug(
                            "Not updating episodes for show " + curShow.name + " because it's marked as ended and last/next episode is not within the grace period.")
                    piList.append(
                            sickrage.SHOWQUEUE.refreshShow(curShow, True))  # @UndefinedVariable

            except (CantUpdateShowException, CantRefreshShowException) as e:
                sickrage.LOGGER.error("Automatic update failed: {}".format(e))

        ProgressIndicators.setIndicator('dailyUpdate', QueueProgressIndicator("Daily Update", piList))

        sickrage.LOGGER.info("Completed full update on all shows")

        self.amActive = False
Ejemplo n.º 4
0
    def run(self, force=False):
        """
        Runs the failed searcher, queuing selected episodes for search that have failed to snatch
        :param force: Force search
        """
        if self.amActive or (not sickrage.app.config.use_failed_snatcher or sickrage.app.developer) and not force:
            return

        self.amActive = True

        # set thread name
        threading.currentThread().setName(self.name)

        # trim failed download history
        FailedHistory.trimHistory()

        sickrage.app.log.info("Searching for failed snatches")

        show = None
        failed_snatches = False

        snatched_episodes = (x for x in sickrage.app.main_db.all('history')
                             if x['action'] in Quality.SNATCHED + Quality.SNATCHED_BEST + Quality.SNATCHED_PROPER
                             and 24 >= int((datetime.datetime.now() - datetime.datetime.strptime(x['date'],
                                                                                                 History.date_format)).total_seconds() / 3600) >= sickrage.app.config.failed_snatch_age)

        downloaded_releases = ((x['showid'], x['season'], x['episode']) for x in
                               sickrage.app.main_db.all('history')
                               if x['action'] in Quality.DOWNLOADED)

        episodes = [x for x in snatched_episodes if (x['showid'], x['season'], x['episode']) not in downloaded_releases]

        for episode in episodes:
            failed_snatches = True
            if not show or int(episode["showid"]) != show.indexerid:
                show = findCertainShow(int(episode["showid"]))

            # for when there is orphaned series in the database but not loaded into our showlist
            if not show or show.paused:
                continue

            ep_obj = show.get_episode(int(episode['season']), int(episode['episode']))
            if isinstance(ep_obj, TVEpisode):
                curStatus, curQuality = Quality.splitCompositeStatus(ep_obj.status)
                if curStatus not in {SNATCHED, SNATCHED_BEST, SNATCHED_PROPER}:
                    continue

                # put it on the queue
                sickrage.app.search_queue.put(FailedQueueItem(show, [ep_obj], True))

        if not failed_snatches:
            sickrage.app.log.info("No failed snatches found")

        self.amActive = False
Ejemplo n.º 5
0
    def run(self, force=False):
        if self.amActive:
            return

        self.amActive = True

        # set thread name
        threading.currentThread().setName(self.name)

        update_timestamp = time.mktime(datetime.datetime.now().timetuple())

        sqlResult = cache_db.CacheDB().select('SELECT `time` FROM lastUpdate WHERE provider = ?', ['theTVDB'])
        if sqlResult:
            last_update = sqlResult[0]['time']
        else:
            last_update = time.mktime(datetime.datetime.min.timetuple())
            cache_db.CacheDB().action('INSERT INTO lastUpdate (provider, `time`) VALUES (?, ?)',
                                      ['theTVDB', long(last_update)])

        if sickrage.srCore.srConfig.USE_FAILED_DOWNLOADS:
            FailedHistory.trimHistory()

        # get indexer updated show ids
        updated_shows = srIndexerApi(1).indexer(**srIndexerApi(1).api_params.copy()).updated(long(last_update))

        # start update process
        piList = []
        for curShow in sickrage.srCore.SHOWLIST:
            try:
                curShow.nextEpisode()
                if curShow.indexerid in set(d["id"] for d in updated_shows or {}):
                    piList.append(sickrage.srCore.SHOWQUEUE.updateShow(curShow, True))
                else:
                    piList.append(sickrage.srCore.SHOWQUEUE.refreshShow(curShow, False))
            except (CantUpdateShowException, CantRefreshShowException) as e:
                continue

        ProgressIndicators.setIndicator('dailyShowUpdates', QueueProgressIndicator("Daily Show Updates", piList))

        cache_db.CacheDB().action('UPDATE lastUpdate SET `time` = ? WHERE provider=?',
                                  [long(update_timestamp), 'theTVDB'])

        self.amActive = False
Ejemplo n.º 6
0
    def run(self, force=False):
        """
        Runs the daily searcher, queuing selected episodes for search
        :param force: Force search
        """
        if self.amActive or sickrage.DEVELOPER and not force:
            return

        self.amActive = True

        # set thread name
        threading.currentThread().setName(self.name)

        # trim failed download history
        if sickrage.srCore.srConfig.USE_FAILED_DOWNLOADS:
            FailedHistory.trimHistory()

        # queue episode for daily search
        sickrage.srCore.SEARCHQUEUE.put(DailySearchQueueItem())

        self.amActive = False
Ejemplo n.º 7
0
    def run(self, force=False):
        """
        Runs the daily searcher, queuing selected episodes for search
        :param force: Force search
        """
        if self.amActive:
            return

        self.amActive = True

        # set thread name
        threading.currentThread().setName(self.name)

        # trim failed download history
        if sickrage.srCore.srConfig.USE_FAILED_DOWNLOADS:
            FailedHistory.trimHistory()

        sickrage.srCore.srLogger.info(
            "Searching for new released episodes ...")

        curDate = (datetime.date.today() +
                   datetime.timedelta(days=2)).toordinal()
        if tz_updater.load_network_dict():
            curDate = (datetime.date.today() +
                       datetime.timedelta(days=1)).toordinal()

        curTime = datetime.datetime.now(tz_updater.sr_timezone)

        show = None
        for dbData in [
                x['doc'] for x in MainDB().db.all('tv_episodes', with_doc=True)
                if x['doc']['status'] in [UNAIRED, WANTED] and
                x['doc']['season'] > 0 and curDate >= x['doc']['airdate'] > 1
        ]:
            try:
                if not show or int(dbData['showid']) != show.indexerid:
                    show = findCertainShow(sickrage.srCore.SHOWLIST,
                                           int(dbData['showid']))

                # for when there is orphaned series in the database but not loaded into our showlist
                if not show or show.paused:
                    continue

            except MultipleShowObjectsException:
                sickrage.srCore.srLogger.info(
                    "ERROR: expected to find a single show matching " +
                    str(dbData['showid']))
                continue

            if show.airs and show.network:
                # This is how you assure it is always converted to local time
                air_time = tz_updater.parse_date_time(
                    dbData['airdate'], show.airs, show.network,
                    dateOnly=True).astimezone(tz_updater.sr_timezone)

                # filter out any episodes that haven't started airing yet,
                # but set them to the default status while they are airing
                # so they are snatched faster
                if air_time > curTime:
                    continue

            ep = show.getEpisode(int(dbData['season']), int(dbData['episode']))
            with ep.lock:
                if ep.season == 0:
                    sickrage.srCore.srLogger.info(
                        "New episode " + ep.prettyName() +
                        " airs today, setting status to SKIPPED because is a special season"
                    )
                    ep.status = SKIPPED
                else:
                    sickrage.srCore.srLogger.info(
                        "New episode %s airs today, setting to default episode status for this show: %s"
                        % (ep.prettyName(),
                           statusStrings[ep.show.default_ep_status]))
                    ep.status = ep.show.default_ep_status

                ep.saveToDB()
        else:
            sickrage.srCore.srLogger.info("No new released episodes found ...")

        # queue episode for daily search
        sickrage.srCore.SEARCHQUEUE.put(DailySearchQueueItem())

        self.amActive = False
Ejemplo n.º 8
0
    def run(self, force=False):
        """
        Runs the daily searcher, queuing selected episodes for search
        :param force: Force search
        """
        if self.amActive:
            return

        self.amActive = True

        # trim failed download history
        if sickrage.USE_FAILED_DOWNLOADS:
            FailedHistory.trimHistory()

        sickrage.LOGGER.info("Searching for new released episodes ...")

        if tz_updater.network_dict:
            curDate = (datetime.date.today() +
                       datetime.timedelta(days=1)).toordinal()
        else:
            curDate = (datetime.date.today() +
                       datetime.timedelta(days=2)).toordinal()

        curTime = datetime.datetime.now(tz_updater.sr_timezone)

        sqlResults = main_db.MainDB().select(
            "SELECT * FROM tv_episodes WHERE status = ? AND season > 0 AND (airdate <= ? AND airdate > 1)",
            [UNAIRED, curDate])

        sql_l = []
        show = None

        for sqlEp in sqlResults:
            try:
                if not show or int(sqlEp[b"showid"]) != show.indexerid:
                    show = findCertainShow(sickrage.showList,
                                           int(sqlEp[b"showid"]))

                # for when there is orphaned series in the database but not loaded into our showlist
                if not show or show.paused:
                    continue

            except MultipleShowObjectsException:
                sickrage.LOGGER.info(
                    "ERROR: expected to find a single show matching " +
                    str(sqlEp[b'showid']))
                continue

            if show.airs and show.network:
                # This is how you assure it is always converted to local time
                air_time = tz_updater.parse_date_time(
                    sqlEp[b'airdate'], show.airs,
                    show.network).astimezone(tz_updater.sr_timezone)

                # filter out any episodes that haven't started airing yet,
                # but set them to the default status while they are airing
                # so they are snatched faster
                if air_time > curTime:
                    continue

            ep = show.getEpisode(int(sqlEp[b"season"]), int(sqlEp[b"episode"]))
            with ep.lock:
                if ep.season == 0:
                    sickrage.LOGGER.info(
                        "New episode " + ep.prettyName() +
                        " airs today, setting status to SKIPPED because is a special season"
                    )
                    ep.status = SKIPPED
                else:
                    sickrage.LOGGER.info(
                        "New episode %s airs today, setting to default episode status for this show: %s"
                        % (ep.prettyName(),
                           statusStrings[ep.show.default_ep_status]))
                    ep.status = ep.show.default_ep_status

                sql_l.append(ep.get_sql())

        if len(sql_l) > 0:
            main_db.MainDB().mass_action(sql_l)
        else:
            sickrage.LOGGER.info("No new released episodes found ...")

        # queue episode for daily search
        dailysearch_queue_item = DailySearchQueueItem()
        sickrage.SEARCHQUEUE.add_item(dailysearch_queue_item)

        self.amActive = False
Ejemplo n.º 9
0
    def run(self, force=False):
        if self.amActive:
            return

        self.amActive = True

        # set thread name
        threading.currentThread().setName(self.name)

        piList = []
        stale_should_update = []

        update_datetime = datetime.datetime.now()
        update_date = update_datetime.date()

        if sickrage.srCore.srConfig.USE_FAILED_DOWNLOADS:
            FailedHistory.trimHistory()

        if sickrage.srCore.srConfig.SHOWUPDATE_STALE:
            # select 10 'Ended' tv_shows updated more than 90 days ago to include in this update
            stale_update_date = (update_date -
                                 datetime.timedelta(days=90)).toordinal()

            # last_update_date <= 90 days, sorted ASC because dates are ordinal
            sql_result = main_db.MainDB().select(
                "SELECT indexer_id FROM tv_shows WHERE status = 'Ended' AND last_update_indexer <= ? ORDER BY last_update_indexer ASC LIMIT 10;",
                [stale_update_date])

            # list of stale shows
            [
                stale_should_update.append(int(cur_result['indexer_id']))
                for cur_result in sql_result
            ]

        # start update process
        sickrage.srCore.srLogger.info("Performing daily updates for all shows")
        for curShow in sickrage.srCore.SHOWLIST:
            try:
                # get next episode airdate
                curShow.nextEpisode()

                # if should_update returns True (not 'Ended') or show is selected stale 'Ended' then update, otherwise just refresh
                if curShow.should_update(
                        update_date=update_date
                ) or curShow.indexerid in stale_should_update:
                    try:
                        piList.append(
                            sickrage.srCore.SHOWQUEUE.updateShow(
                                curShow, True))
                    except CantUpdateShowException as e:
                        sickrage.srCore.srLogger.debug(
                            "Unable to update show: {}".format(e.message))
                else:
                    piList.append(
                        sickrage.srCore.SHOWQUEUE.refreshShow(curShow, True))

            except (CantUpdateShowException, CantRefreshShowException) as e:
                sickrage.srCore.srLogger.error(
                    "Daily show update failed: {}".format(e.message))

        ProgressIndicators.setIndicator(
            'dailyShowUpdates',
            QueueProgressIndicator("Daily Show Updates", piList))

        sickrage.srCore.srLogger.info("Completed daily updates for all shows")

        self.amActive = False
Ejemplo n.º 10
0
    def run(self, force=False):
        """
        Runs the daily searcher, queuing selected episodes for search
        :param force: Force search
        """
        if self.amActive or sickrage.srCore.srConfig.DEVELOPER and not force:
            return

        self.amActive = True

        # set thread name
        threading.currentThread().setName(self.name)

        # trim failed download history
        if sickrage.srCore.srConfig.USE_FAILED_DOWNLOADS:
            FailedHistory.trimHistory()

        sickrage.srCore.srLogger.info("{}: Searching for new released episodes".format(self.name))

        curDate = datetime.date.today()
        curDate += datetime.timedelta(days=2)
        if tz_updater.load_network_dict():
            curDate += datetime.timedelta(days=1)

        curTime = datetime.datetime.now(tz_updater.sr_timezone)

        show = None

        episodes = [x['doc'] for x in sickrage.srCore.mainDB.db.all('tv_episodes', with_doc=True)
                    if x['doc']['status'] == UNAIRED
                    and x['doc']['season'] > 0
                    and curDate.toordinal() >= x['doc']['airdate'] > 1]

        for episode in episodes:
            if not show or int(episode["showid"]) != show.indexerid:
                show = findCertainShow(sickrage.srCore.SHOWLIST, int(episode["showid"]))

            # for when there is orphaned series in the database but not loaded into our showlist
            if not show or show.paused:
                continue

            if show.airs and show.network:
                # This is how you assure it is always converted to local time
                air_time = tz_updater.parse_date_time(
                    episode['airdate'], show.airs, show.network, dateOnly=True
                ).astimezone(tz_updater.sr_timezone)

                # filter out any episodes that haven't started airing yet,
                # but set them to the default status while they are airing
                # so they are snatched faster
                if air_time > curTime: continue

            ep = show.getEpisode(int(episode['season']), int(episode['episode']))
            with ep.lock:
                if ep.season == 0:
                    sickrage.srCore.srLogger.info(
                        "New episode {} airs today, setting status to SKIPPED because is a special season".format(
                            ep.prettyName()))
                    ep.status = SKIPPED
                else:
                    sickrage.srCore.srLogger.info(
                        "New episode {} airs today, setting to default episode status for this show: {}".format(
                            ep.prettyName(), statusStrings[ep.show.default_ep_status]))
                    ep.status = ep.show.default_ep_status

                ep.saveToDB()
        else:
            sickrage.srCore.srLogger.info("{}: No new released episodes found".format(self.name))

        # queue episode for daily search
        sickrage.srCore.SEARCHQUEUE.put(DailySearchQueueItem())

        self.amActive = False
Ejemplo n.º 11
0
    def run(self, force=False):
        """
        Runs the daily searcher, queuing selected episodes for search
        :param force: Force search
        """
        if self.amActive or sickrage.app.developer and not force:
            return

        self.amActive = True

        # set thread name
        threading.currentThread().setName(self.name)

        # trim failed download history
        if sickrage.app.config.use_failed_downloads:
            FailedHistory.trimHistory()

        sickrage.app.log.info("Searching for new released episodes")

        curDate = datetime.date.today()
        curDate += datetime.timedelta(days=2)
        if tz_updater.load_network_dict():
            curDate += datetime.timedelta(days=1)

        curTime = datetime.datetime.now(sickrage.app.tz)

        show = None

        episodes = [
            x['doc']
            for x in sickrage.app.main_db.db.all('tv_episodes', with_doc=True)
            if x['doc']['status'] == common.UNAIRED and x['doc']['season'] > 0
            and curDate.toordinal() >= x['doc']['airdate'] > 1
        ]

        new_episodes = False
        for episode in episodes:
            if not show or int(episode["showid"]) != show.indexerid:
                show = findCertainShow(sickrage.app.showlist,
                                       int(episode["showid"]))

            # for when there is orphaned series in the database but not loaded into our showlist
            if not show or show.paused:
                continue

            if show.airs and show.network:
                # This is how you assure it is always converted to local time
                air_time = tz_updater.parse_date_time(
                    episode['airdate'], show.airs, show.network,
                    dateOnly=True).astimezone(sickrage.app.tz)

                # filter out any episodes that haven't started airing yet,
                # but set them to the default status while they are airing
                # so they are snatched faster
                if air_time > curTime: continue

            ep_obj = show.getEpisode(int(episode['season']),
                                     int(episode['episode']))
            with ep_obj.lock:
                ep_obj.status = show.default_ep_status if ep_obj.season else common.SKIPPED
                sickrage.app.log.info(
                    'Setting status ({status}) for show airing today: {name} {special}'
                    .format(
                        name=ep_obj.pretty_name(),
                        status=common.statusStrings[ep_obj.status],
                        special='(specials are not supported)'
                        if not ep_obj.season else '',
                    ))

                ep_obj.saveToDB()
                new_episodes = True

        if not new_episodes:
            sickrage.app.log.info("No new released episodes found")

        # queue episode for daily search
        sickrage.app.search_queue.put(DailySearchQueueItem())

        self.amActive = False
Ejemplo n.º 12
0
    def run(self, force=False):
        """
        Runs the daily searcher, queuing selected episodes for search
        :param force: Force search
        """
        if self.amActive:
            return

        self.amActive = True

        # trim failed download history
        if sickrage.USE_FAILED_DOWNLOADS:
            FailedHistory.trimHistory()

        sickrage.LOGGER.info("Searching for new released episodes ...")

        if tz_updater.network_dict:
            curDate = (datetime.date.today() + datetime.timedelta(days=1)).toordinal()
        else:
            curDate = (datetime.date.today() + datetime.timedelta(days=2)).toordinal()

        curTime = datetime.datetime.now(tz_updater.sr_timezone)

        sqlResults = main_db.MainDB().select(
                "SELECT * FROM tv_episodes WHERE status = ? AND season > 0 AND (airdate <= ? AND airdate > 1)",
                [UNAIRED, curDate])

        sql_l = []
        show = None

        for sqlEp in sqlResults:
            try:
                if not show or int(sqlEp[b"showid"]) != show.indexerid:
                    show = findCertainShow(sickrage.showList, int(sqlEp[b"showid"]))

                # for when there is orphaned series in the database but not loaded into our showlist
                if not show or show.paused:
                    continue

            except MultipleShowObjectsException:
                sickrage.LOGGER.info("ERROR: expected to find a single show matching " + str(sqlEp[b'showid']))
                continue

            if show.airs and show.network:
                # This is how you assure it is always converted to local time
                air_time = tz_updater.parse_date_time(sqlEp[b'airdate'], show.airs, show.network).astimezone(
                        tz_updater.sr_timezone)

                # filter out any episodes that haven't started airing yet,
                # but set them to the default status while they are airing
                # so they are snatched faster
                if air_time > curTime:
                    continue

            ep = show.getEpisode(int(sqlEp[b"season"]), int(sqlEp[b"episode"]))
            with ep.lock:
                if ep.season == 0:
                    sickrage.LOGGER.info(
                            "New episode " + ep.prettyName() + " airs today, setting status to SKIPPED because is a special season")
                    ep.status = SKIPPED
                else:
                    sickrage.LOGGER.info("New episode %s airs today, setting to default episode status for this show: %s" % (
                        ep.prettyName(), statusStrings[ep.show.default_ep_status]))
                    ep.status = ep.show.default_ep_status

                sql_l.append(ep.get_sql())

        if len(sql_l) > 0:
            main_db.MainDB().mass_action(sql_l)
        else:
            sickrage.LOGGER.info("No new released episodes found ...")

        # queue episode for daily search
        dailysearch_queue_item = DailySearchQueueItem()
        sickrage.SEARCHQUEUE.add_item(dailysearch_queue_item)

        self.amActive = False
Ejemplo n.º 13
0
    def run(self, force=False):
        """
        Runs the daily searcher, queuing selected episodes for search
        :param force: Force search
        """
        if self.amActive or sickrage.app.developer and not force:
            return

        self.amActive = True

        # set thread name
        threading.currentThread().setName(self.name)

        # trim failed download history
        if sickrage.app.config.use_failed_downloads:
            FailedHistory.trimHistory()

        sickrage.app.log.info("Searching for new released episodes")

        curDate = datetime.date.today()
        curDate += datetime.timedelta(days=2)
        if tz_updater.load_network_dict():
            curDate += datetime.timedelta(days=1)

        curTime = datetime.datetime.now(sickrage.app.tz)

        show = None

        episodes = [x['doc'] for x in sickrage.app.main_db.db.all('tv_episodes', with_doc=True)
                    if x['doc']['status'] == common.UNAIRED
                    and x['doc']['season'] > 0
                    and curDate.toordinal() >= x['doc']['airdate'] > 1]

        new_episodes = False
        for episode in episodes:
            if not show or int(episode["showid"]) != show.indexerid:
                show = findCertainShow(sickrage.app.showlist, int(episode["showid"]))

            # for when there is orphaned series in the database but not loaded into our showlist
            if not show or show.paused:
                continue

            if show.airs and show.network:
                # This is how you assure it is always converted to local time
                air_time = tz_updater.parse_date_time(
                    episode['airdate'], show.airs, show.network, dateOnly=True
                ).astimezone(sickrage.app.tz)

                # filter out any episodes that haven't started airing yet,
                # but set them to the default status while they are airing
                # so they are snatched faster
                if air_time > curTime: continue

            ep_obj = show.getEpisode(int(episode['season']), int(episode['episode']))
            with ep_obj.lock:
                ep_obj.status = show.default_ep_status if ep_obj.season else common.SKIPPED
                sickrage.app.log.info('Setting status ({status}) for show airing today: {name} {special}'.format(
                    name=ep_obj.pretty_name(),
                    status=common.statusStrings[ep_obj.status],
                    special='(specials are not supported)' if not ep_obj.season else '',
                ))

                ep_obj.saveToDB()
                new_episodes = True

        if not new_episodes:
            sickrage.app.log.info("No new released episodes found")

        # queue episode for daily search
        sickrage.app.search_queue.put(DailySearchQueueItem())

        self.amActive = False
Ejemplo n.º 14
0
    def run(self, force=False):
        """
        Runs the daily searcher, queuing selected episodes for search
        :param force: Force search
        """
        if self.amActive:
            return

        self.amActive = True

        # set thread name
        threading.currentThread().setName(self.name)

        # trim failed download history
        if sickrage.srCore.srConfig.USE_FAILED_DOWNLOADS:
            FailedHistory.trimHistory()

        sickrage.srCore.srLogger.info("Searching for new released episodes ...")

        curDate = (datetime.date.today() + datetime.timedelta(days=2)).toordinal()
        if tz_updater.load_network_dict():
            curDate = (datetime.date.today() + datetime.timedelta(days=1)).toordinal()

        curTime = datetime.datetime.now(tz_updater.sr_timezone)

        show = None
        for dbData in [x['doc'] for x in sickrage.srCore.mainDB.db.all('tv_episodes', with_doc=True)
                       if x['doc']['status'] in [UNAIRED, WANTED]
                       and x['doc']['season'] > 0
                       and curDate >= x['doc']['airdate'] > 1]:
            try:
                if not show or int(dbData['showid']) != show.indexerid:
                    show = findCertainShow(sickrage.srCore.SHOWLIST, int(dbData['showid']))

                # for when there is orphaned series in the database but not loaded into our showlist
                if not show or show.paused:
                    continue

            except MultipleShowObjectsException:
                sickrage.srCore.srLogger.info("ERROR: expected to find a single show matching " + str(dbData['showid']))
                continue

            if show.airs and show.network:
                # This is how you assure it is always converted to local time
                air_time = tz_updater.parse_date_time(dbData['airdate'], show.airs, show.network,
                                                      dateOnly=True).astimezone(tz_updater.sr_timezone)

                # filter out any episodes that haven't started airing yet,
                # but set them to the default status while they are airing
                # so they are snatched faster
                if air_time > curTime:
                    continue

            ep = show.getEpisode(int(dbData['season']), int(dbData['episode']))
            with ep.lock:
                if ep.season == 0:
                    sickrage.srCore.srLogger.info(
                        "New episode " + ep.prettyName() + " airs today, setting status to SKIPPED because is a special season")
                    ep.status = SKIPPED
                else:
                    sickrage.srCore.srLogger.info(
                        "New episode %s airs today, setting to default episode status for this show: %s" % (
                            ep.prettyName(), statusStrings[ep.show.default_ep_status]))
                    ep.status = ep.show.default_ep_status

                ep.saveToDB()
        else:
            sickrage.srCore.srLogger.info("No new released episodes found ...")

        # queue episode for daily search
        sickrage.srCore.SEARCHQUEUE.put(DailySearchQueueItem())

        self.amActive = False