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

        self.amActive = True

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

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

        try:
            dbData = sickrage.app.cache_db.db.get('lastUpdate',
                                                  'theTVDB',
                                                  with_doc=True)['doc']
            last_update = int(dbData['time'])
        except RecordNotFound:
            last_update = update_timestamp
            dbData = sickrage.app.cache_db.db.insert({
                '_t': 'lastUpdate',
                'provider': 'theTVDB',
                'time': 0
            })

        # get indexer updated show ids
        indexer_api = IndexerApi().indexer(**IndexerApi().api_params.copy())
        updated_shows = set(s["id"]
                            for s in indexer_api.updated(last_update) or {})

        # start update process
        pi_list = []
        for show in sickrage.app.showlist:
            if show.paused:
                sickrage.app.log.info(
                    'Show update skipped, show: {} is paused.'.format(
                        show.name))
            try:
                show.nextEpisode()
                stale = (
                    datetime.datetime.now() -
                    datetime.datetime.fromordinal(show.last_update)).days > 7
                if show.indexerid in updated_shows or stale:
                    pi_list.append(
                        sickrage.app.show_queue.updateShow(show, False))
                else:
                    pi_list.append(
                        sickrage.app.show_queue.refreshShow(show, False))
            except (CantUpdateShowException, CantRefreshShowException) as e:
                sickrage.app.log.debug("Automatic update failed: {}".format(
                    e.message))

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

        dbData['time'] = update_timestamp
        sickrage.app.cache_db.db.update(dbData)

        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)

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

        dbData = sickrage.app.cache_db.get('lastUpdate', 'theTVDB')
        if dbData:
            last_update = int(dbData['time'])
        else:
            last_update = update_timestamp
            dbData = sickrage.app.cache_db.insert({
                '_t': 'lastUpdate',
                'provider': 'theTVDB',
                'time': 0
            })

        # get indexer updated show ids
        indexer_api = IndexerApi().indexer(**IndexerApi().api_params.copy())
        updated_shows = set(s["id"] for s in indexer_api.updated(last_update) or {})

        # start update process
        pi_list = []
        for show in sickrage.app.showlist:
            if show.paused:
                sickrage.app.log.info('Show update skipped, show: {} is paused.'.format(show.name))
                continue

            if show.status == 'Ended':
                if not sickrage.app.config.showupdate_stale:
                    sickrage.app.log.info('Show update skipped, show: {} status is ended.'.format(show.name))
                    continue
                elif not (datetime.datetime.now() - datetime.datetime.fromordinal(show.last_update)).days >= 90:
                    sickrage.app.log.info(
                        'Show update skipped, show: {} status is ended and recently updated.'.format(show.name))
                    continue

            try:
                if show.indexerid in updated_shows:
                    pi_list.append(sickrage.app.show_queue.updateShow(show, indexer_update_only=True, force=False))
                elif (datetime.datetime.now() - datetime.datetime.fromordinal(show.last_update)).days >= 7:
                    pi_list.append(sickrage.app.show_queue.updateShow(show, force=False))
                #else:
                #    pi_list.append(sickrage.app.show_queue.refreshShow(show, False))
            except (CantUpdateShowException, CantRefreshShowException) as e:
                sickrage.app.log.debug("Automatic update failed: {}".format(e))

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

        dbData['time'] = update_timestamp
        sickrage.app.cache_db.update(dbData)

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

        self.amActive = True

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

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

        try:
            dbData = sickrage.srCore.cacheDB.db.get('lastUpdate',
                                                    'theTVDB',
                                                    with_doc=True)['doc']
            last_update = long(dbData['time'])
        except RecordNotFound:
            last_update = long(time.mktime(datetime.datetime.min.timetuple()))
            dbData = sickrage.srCore.cacheDB.db.insert({
                '_t':
                'lastUpdate',
                'provider':
                'theTVDB',
                'time':
                long(last_update)
            })

        # get indexer updated show ids
        updated_shows = set(d["id"] for d in srIndexerApi().indexer(
            **srIndexerApi().api_params.copy()).updated(long(last_update))
                            or {})

        # start update process
        pi_list = []
        for curShow in sickrage.srCore.SHOWLIST:
            try:
                curShow.nextEpisode()

                if curShow.indexerid in updated_shows:
                    pi_list.append(
                        sickrage.srCore.SHOWQUEUE.updateShow(curShow, True))
                else:
                    pi_list.append(
                        sickrage.srCore.SHOWQUEUE.refreshShow(curShow, False))
            except (CantUpdateShowException, CantRefreshShowException) as e:
                sickrage.srCore.srLogger.debug(
                    "Automatic update failed: {}".format(e.message))

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

        dbData['time'] = long(update_timestamp)
        sickrage.srCore.cacheDB.db.update(dbData)

        self.amActive = False
Ejemplo n.º 4
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.º 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())

        try:
            dbData = CacheDB().db.get('lastUpdate', 'theTVDB',
                                      with_doc=True)['doc']
            last_update = dbData['time']
        except RecordNotFound:
            last_update = time.mktime(datetime.datetime.min.timetuple())
            dbData = CacheDB().db.insert({
                '_t': 'lastUpdate',
                'provider': 'theTVDB',
                'time': long(last_update)
            })

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

        # start update process
        piList = []
        for curShow in sickrage.srCore.SHOWLIST:
            try:
                curShow.nextEpisode()

                if not os.path.isdir(curShow.location):
                    continue

                if curShow.indexerid in set(d["id"]
                                            for d in updated_shows or {}):
                    piList.append(
                        sickrage.srCore.SHOWQUEUE.updateShow(curShow, True))
                elif datetime.date.fromordinal(
                        curShow.last_refresh) > datetime.timedelta(days=1):
                    piList.append(
                        sickrage.srCore.SHOWQUEUE.refreshShow(curShow, False))
            except (CantUpdateShowException, CantRefreshShowException):
                continue

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

        dbData['time'] = long(update_timestamp)
        CacheDB().db.update(dbData)

        self.amActive = False
Ejemplo n.º 6
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.º 7
0
    def run(self, force=False):
        if self.amActive:
            return

        self.amActive = True

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

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

        try:
            dbData = sickrage.app.cache_db.db.get('lastUpdate', 'theTVDB', with_doc=True)['doc']
            last_update = int(dbData['time'])
        except RecordNotFound:
            last_update = update_timestamp
            dbData = sickrage.app.cache_db.db.insert({
                '_t': 'lastUpdate',
                'provider': 'theTVDB',
                'time': 0
            })

        # get indexer updated show ids
        indexer_api = IndexerApi().indexer(**IndexerApi().api_params.copy())
        updated_shows = set(s["id"] for s in indexer_api.updated(last_update) or {})

        # start update process
        pi_list = []
        for show in sickrage.app.showlist:
            if show.paused:
                sickrage.app.log.info('Show update skipped, show: {} is paused.'.format(show.name))
            try:
                show.nextEpisode()
                stale = (datetime.datetime.now() - datetime.datetime.fromordinal(show.last_update)).days > 7
                if show.indexerid in updated_shows or stale:
                    pi_list.append(sickrage.app.show_queue.updateShow(show, False))
                else:
                    pi_list.append(sickrage.app.show_queue.refreshShow(show, False))
            except (CantUpdateShowException, CantRefreshShowException) as e:
                sickrage.app.log.debug("Automatic update failed: {}".format(e.message))

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

        dbData['time'] = update_timestamp
        sickrage.app.cache_db.db.update(dbData)

        self.amActive = False
Ejemplo n.º 8
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.º 9
0
    def task(self, force=False):
        if self.running and not force:
            return

        try:
            self.running = True

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

            session = sickrage.app.cache_db.session()

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

            try:
                dbData = session.query(
                    CacheDB.LastUpdate).filter_by(provider='theTVDB').one()
                last_update = int(dbData.time)
            except orm.exc.NoResultFound:
                last_update = update_timestamp
                dbData = CacheDB.LastUpdate(**{
                    'provider': 'theTVDB',
                    'time': 0
                })
                session.add(dbData)
            finally:
                session.commit()

            # get indexer updated show ids
            indexer_api = IndexerApi().indexer(
                **IndexerApi().api_params.copy())
            updated_shows = set(
                s["id"] for s in indexer_api.updated(last_update) or {})

            # start update process
            pi_list = []
            for show_obj in get_show_list():
                if show_obj.paused:
                    sickrage.app.log.info(
                        'Show update skipped, show: {} is paused.'.format(
                            show_obj.name))
                    continue

                if show_obj.status == 'Ended':
                    if not sickrage.app.config.showupdate_stale:
                        sickrage.app.log.info(
                            'Show update skipped, show: {} status is ended.'.
                            format(show_obj.name))
                        continue
                    elif not (datetime.datetime.now() -
                              datetime.datetime.fromordinal(
                                  show_obj.last_update)).days >= 90:
                        sickrage.app.log.info(
                            'Show update skipped, show: {} status is ended and recently updated.'
                            .format(show_obj.name))
                        continue

                try:
                    if show_obj.indexer_id in updated_shows:
                        pi_list.append(
                            sickrage.app.show_queue.update_show(
                                show_obj.indexer_id,
                                indexer_update_only=True,
                                force=False))
                    elif (datetime.datetime.now() -
                          datetime.datetime.fromordinal(
                              show_obj.last_update)).days >= 7:
                        pi_list.append(
                            sickrage.app.show_queue.update_show(
                                show_obj.indexer_id, force=False))
                except (CantUpdateShowException,
                        CantRefreshShowException) as e:
                    sickrage.app.log.debug(
                        "Automatic update failed: {}".format(e))

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

            dbData.time = update_timestamp
            session.commit()
        finally:
            self.running = False
Ejemplo n.º 10
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