def search_backlog(self, which_shows=None, force_type=NORMAL_BACKLOG): if self.amActive: logger.log(u'Backlog is still running, not starting it again', logger.DEBUG) return if which_shows: show_list = which_shows standard_backlog = False else: show_list = sickbeard.showList standard_backlog = True self._get_lastBacklog() curDate = datetime.date.today().toordinal() fromDate = datetime.date.fromordinal(1) limited_backlog = False if (not which_shows and force_type == LIMITED_BACKLOG) or (not which_shows and force_type != FULL_BACKLOG and not curDate - self._lastBacklog >= self.cycleTime): logger.log(u'Running limited backlog for episodes missed during the last %s day(s)' % str(sickbeard.BACKLOG_DAYS)) fromDate = datetime.date.today() - datetime.timedelta(days=sickbeard.BACKLOG_DAYS) limited_backlog = True forced = False if not which_shows and force_type != NORMAL_BACKLOG: forced = True self.amActive = True self.amPaused = False # go through non air-by-date shows and see if they need any episodes for curShow in show_list: if curShow.paused: continue segments = wanted_episodes(curShow, fromDate, make_dict=True) for season, segment in segments.items(): self.currentSearchInfo = {'title': curShow.name + ' Season ' + str(season)} backlog_queue_item = search_queue.BacklogQueueItem(curShow, segment, standard_backlog=standard_backlog, limited_backlog=limited_backlog, forced=forced) sickbeard.searchQueueScheduler.action.add_item(backlog_queue_item) # @UndefinedVariable else: logger.log(u'Nothing needs to be downloaded for %s, skipping' % str(curShow.name), logger.DEBUG) # don't consider this an actual backlog search if we only did recent eps # or if we only did certain shows if fromDate == datetime.date.fromordinal(1) and not which_shows: self._set_lastBacklog(curDate) self._get_lastBacklog() self.amActive = False self._resetPI()
def run(self): generic_queue.QueueItem.run(self) try: self._change_missing_episodes() self.update_providers() show_list = sickbeard.showList from_date = datetime.date.fromordinal(1) for curShow in show_list: if curShow.paused: continue self.episodes.extend(wanted_episodes(curShow, from_date)) if not self.episodes: logger.log(u'No search of cache for episodes required') self.success = True else: num_shows = len(set([ep.show.name for ep in self.episodes])) logger.log(u'Found %d needed episode%s spanning %d show%s' % (len(self.episodes), helpers.maybe_plural(len(self.episodes)), num_shows, helpers.maybe_plural(num_shows))) try: logger.log(u'Beginning recent search for episodes') found_results = search.search_for_needed_episodes(self.episodes) if not len(found_results): logger.log(u'No needed episodes found') else: for result in found_results: # just use the first result for now logger.log(u'Downloading %s from %s' % (result.name, result.provider.name)) self.success = search.snatch_episode(result) # give the CPU a break time.sleep(common.cpu_presets[sickbeard.CPU_PRESET]) except Exception: logger.log(traceback.format_exc(), logger.DEBUG) if None is self.success: self.success = False finally: self.finish()
def run(self): generic_queue.QueueItem.run(self) try: self._change_missing_episodes() show_list = sickbeard.showList from_date = datetime.date.fromordinal(1) needed = common.neededQualities() for curShow in show_list: if curShow.paused: continue wanted_eps = wanted_episodes(curShow, from_date, unaired=sickbeard.SEARCH_UNAIRED) if wanted_eps: if not needed.all_needed: if not needed.all_types_needed: needed.check_needed_types(curShow) if not needed.all_qualities_needed: for w in wanted_eps: if needed.all_qualities_needed: break if not w.show.is_anime and not w.show.is_sports: needed.check_needed_qualities( w.wantedQuality) self.episodes.extend(wanted_eps) if sickbeard.DOWNLOAD_PROPERS: properFinder.get_needed_qualites(needed) self.update_providers(needed=needed) self._check_for_propers(needed) if not self.episodes: logger.log(u'No search of cache for episodes required') self.success = True else: num_shows = len(set([ep.show.name for ep in self.episodes])) logger.log(u'Found %d needed episode%s spanning %d show%s' % (len(self.episodes), helpers.maybe_plural(len(self.episodes)), num_shows, helpers.maybe_plural(num_shows))) try: logger.log(u'Beginning recent search for episodes') found_results = search.search_for_needed_episodes( self.episodes) if not len(found_results): logger.log(u'No needed episodes found') else: for result in found_results: # just use the first result for now logger.log(u'Downloading %s from %s' % (result.name, result.provider.name)) self.success = search.snatch_episode(result) helpers.cpu_sleep() except (StandardError, Exception): logger.log(traceback.format_exc(), logger.ERROR) if None is self.success: self.success = False finally: self.finish()
def run(self): generic_queue.QueueItem.run(self) try: self._change_missing_episodes() show_list = sickbeard.showList from_date = datetime.date.fromordinal(1) need_anime = need_sports = need_sd = need_hd = need_uhd = False max_sd = Quality.SDDVD hd_qualities = [Quality.HDTV, Quality.FULLHDTV, Quality.HDWEBDL, Quality.FULLHDWEBDL, Quality.HDBLURAY, Quality.FULLHDBLURAY] max_hd = Quality.FULLHDBLURAY for curShow in show_list: if curShow.paused: continue wanted_eps = wanted_episodes(curShow, from_date, unaired=sickbeard.SEARCH_UNAIRED) if wanted_eps: if not need_anime and curShow.is_anime: need_anime = True if not need_sports and curShow.is_sports: need_sports = True if not need_sd or not need_hd or not need_uhd: for w in wanted_eps: if need_sd and need_hd and need_uhd: break if not w.show.is_anime and not w.show.is_sports: if Quality.UNKNOWN in w.wantedQuality: need_sd = need_hd = need_uhd = True else: if not need_sd and max_sd >= min(w.wantedQuality): need_sd = True if not need_hd and any(i in hd_qualities for i in w.wantedQuality): need_hd = True if not need_uhd and max_hd < max(w.wantedQuality): need_uhd = True self.episodes.extend(wanted_eps) self.update_providers(need_anime=need_anime, need_sports=need_sports, need_sd=need_sd, need_hd=need_hd, need_uhd=need_uhd) if not self.episodes: logger.log(u'No search of cache for episodes required') self.success = True else: num_shows = len(set([ep.show.name for ep in self.episodes])) logger.log(u'Found %d needed episode%s spanning %d show%s' % (len(self.episodes), helpers.maybe_plural(len(self.episodes)), num_shows, helpers.maybe_plural(num_shows))) try: logger.log(u'Beginning recent search for episodes') found_results = search.search_for_needed_episodes(self.episodes) if not len(found_results): logger.log(u'No needed episodes found') else: for result in found_results: # just use the first result for now logger.log(u'Downloading %s from %s' % (result.name, result.provider.name)) self.success = search.snatch_episode(result) helpers.cpu_sleep() except Exception: logger.log(traceback.format_exc(), logger.DEBUG) if None is self.success: self.success = False finally: self.finish()
def run(self): generic_queue.QueueItem.run(self) try: self._change_missing_episodes() show_list = sickbeard.showList from_date = datetime.date.fromordinal(1) needed = common.neededQualities() for curShow in show_list: if curShow.paused: continue wanted_eps = wanted_episodes(curShow, from_date, unaired=sickbeard.SEARCH_UNAIRED) if wanted_eps: if not needed.all_needed: if not needed.all_types_needed: needed.check_needed_types(curShow) if not needed.all_qualities_needed: for w in wanted_eps: if needed.all_qualities_needed: break if not w.show.is_anime and not w.show.is_sports: needed.check_needed_qualities(w.wantedQuality) self.episodes.extend(wanted_eps) if sickbeard.DOWNLOAD_PROPERS: properFinder.get_needed_qualites(needed) self.update_providers(needed=needed) self._check_for_propers(needed) if not self.episodes: logger.log(u'No search of cache for episodes required') self.success = True else: num_shows = len(set([ep.show.name for ep in self.episodes])) logger.log(u'Found %d needed episode%s spanning %d show%s' % (len(self.episodes), helpers.maybe_plural(len(self.episodes)), num_shows, helpers.maybe_plural(num_shows))) try: logger.log(u'Beginning recent search for episodes') found_results = search.search_for_needed_episodes(self.episodes) if not len(found_results): logger.log(u'No needed episodes found') else: for result in found_results: # just use the first result for now logger.log(u'Downloading %s from %s' % (result.name, result.provider.name)) self.success = search.snatch_episode(result) if self.success: for ep in result.episodes: self.snatched_eps.add((ep.show.indexer, ep.show.indexerid, ep.season, ep.episode)) helpers.cpu_sleep() except (StandardError, Exception): logger.log(traceback.format_exc(), logger.ERROR) if None is self.success: self.success = False finally: self.finish()
def search_backlog(self, which_shows=None, force_type=NORMAL_BACKLOG): if self.amActive: logger.log(u'Backlog is still running, not starting it again', logger.DEBUG) return if which_shows: show_list = which_shows standard_backlog = False else: show_list = sickbeard.showList standard_backlog = True self._get_lastBacklog() curDate = datetime.date.today().toordinal() fromDate = datetime.date.fromordinal(1) limited_backlog = False if (not which_shows and force_type == LIMITED_BACKLOG) or ( not which_shows and force_type != FULL_BACKLOG and not curDate - self._lastBacklog >= self.cycleTime): logger.log( u'Running limited backlog for episodes missed during the last %s day(s)' % str(sickbeard.BACKLOG_DAYS)) fromDate = datetime.date.today() - datetime.timedelta( days=sickbeard.BACKLOG_DAYS) limited_backlog = True forced = False if not which_shows and force_type != NORMAL_BACKLOG: forced = True self.amActive = True self.amPaused = False # go through non air-by-date shows and see if they need any episodes for curShow in show_list: if curShow.paused: continue segments = wanted_episodes(curShow, fromDate, make_dict=True) for season, segment in segments.items(): self.currentSearchInfo = { 'title': curShow.name + ' Season ' + str(season) } backlog_queue_item = search_queue.BacklogQueueItem( curShow, segment, standard_backlog=standard_backlog, limited_backlog=limited_backlog, forced=forced) sickbeard.searchQueueScheduler.action.add_item( backlog_queue_item) # @UndefinedVariable else: logger.log( u'Nothing needs to be downloaded for %s, skipping' % str(curShow.name), logger.DEBUG) # don't consider this an actual backlog search if we only did recent eps # or if we only did certain shows if fromDate == datetime.date.fromordinal(1) and not which_shows: self._set_lastBacklog(curDate) self._get_lastBacklog() self.amActive = False self._resetPI()
def search_backlog(self, which_shows=None, force_type=NORMAL_BACKLOG, force=False): if self.amActive and not which_shows: logger.log(u'Backlog is still running, not starting it again', logger.DEBUG) return if which_shows: show_list = which_shows standard_backlog = False else: show_list = sickbeard.showList standard_backlog = True now = datetime.datetime.now() any_torrent_enabled = continued_backlog = False if not force and standard_backlog and ( datetime.datetime.now() - datetime.datetime.fromtimestamp( self._get_last_runtime())) < datetime.timedelta(hours=23): any_torrent_enabled = any([ x for x in sickbeard.providers.sortedProviderList() if x.is_active() and x.enable_backlog and x.providerType == GenericProvider.TORRENT ]) if not any_torrent_enabled: logger.log( 'Last scheduled Backlog run was within the last day, skipping this run.', logger.DEBUG) return self._get_last_backlog() self.amActive = True self.amPaused = False cur_date = datetime.date.today().toordinal() from_date = datetime.date.fromordinal(1) limited_from_date = datetime.date.today() - datetime.timedelta( days=sickbeard.BACKLOG_DAYS) limited_backlog = False if standard_backlog and (any_torrent_enabled or sickbeard.BACKLOG_NOFULL): logger.log( u'Running limited backlog for episodes missed during the last %s day(s)' % str(sickbeard.BACKLOG_DAYS)) from_date = limited_from_date limited_backlog = True runparts = [] if standard_backlog and not any_torrent_enabled and sickbeard.BACKLOG_NOFULL: logger.log( u'Skipping automated full backlog search because it is disabled in search settings' ) my_db = db.DBConnection('cache.db') if standard_backlog and not any_torrent_enabled and not sickbeard.BACKLOG_NOFULL: sql_result = my_db.select( 'SELECT * FROM backlogparts WHERE part in (SELECT MIN(part) FROM backlogparts)' ) if sql_result: sl = [] part_nr = int(sql_result[0]['part']) for s in sql_result: show_obj = find_show_by_id( sickbeard.showList, {int(s['indexer']): int(s['indexerid'])}) if show_obj: sl.append(show_obj) runparts.append( [int(s['indexerid']), int(s['indexer'])]) show_list = sl continued_backlog = True my_db.action('DELETE FROM backlogparts WHERE part = ?', [part_nr]) forced = standard_backlog and force_type != NORMAL_BACKLOG wanted_list = [] for curShow in show_list: if not curShow.paused: w = wanted_episodes( curShow, from_date, make_dict=True, unaired=(sickbeard.SEARCH_UNAIRED and not sickbeard.UNAIRED_RECENT_SEARCH_ONLY)) if w: wanted_list.append(w) parts = [] if standard_backlog and not any_torrent_enabled and not continued_backlog and not sickbeard.BACKLOG_NOFULL: fullbacklogparts = sum([len(w) for w in wanted_list if w ]) // sickbeard.BACKLOG_FREQUENCY h_part = [] counter = 0 for w in wanted_list: f = False for season, segment in w.iteritems(): counter += 1 if not f: h_part.append([ segment[0].show.indexerid, segment[0].show.indexer ]) f = True if counter > fullbacklogparts: counter = 0 parts.append(h_part) h_part = [] if h_part: parts.append(h_part) def in_showlist(show, showlist): return 0 < len([ item for item in showlist if item[1] == show.indexer and item[0] == show.indexerid ]) if not runparts and parts: runparts = parts[0] wanted_list = [ w for w in wanted_list if w and in_showlist(w.itervalues().next()[0].show, runparts) ] limited_wanted_list = [] if standard_backlog and not any_torrent_enabled and runparts: for curShow in sickbeard.showList: if not curShow.paused and not in_showlist(curShow, runparts): w = wanted_episodes( curShow, limited_from_date, make_dict=True, unaired=(sickbeard.SEARCH_UNAIRED and not sickbeard.UNAIRED_RECENT_SEARCH_ONLY)) if w: limited_wanted_list.append(w) self.add_backlog_item(wanted_list, standard_backlog, limited_backlog, forced, any_torrent_enabled) if standard_backlog and not any_torrent_enabled and limited_wanted_list: self.add_backlog_item(limited_wanted_list, standard_backlog, True, forced, any_torrent_enabled) if standard_backlog and not sickbeard.BACKLOG_NOFULL and not any_torrent_enabled and not continued_backlog: cl = ([], [['DELETE FROM backlogparts']])[len(parts) > 1] for i, l in enumerate(parts): if 0 == i: continue for m in l: cl.append([ 'INSERT INTO backlogparts (part, indexerid, indexer) VALUES (?,?,?)', [i + 1, m[0], m[1]] ]) if 0 < len(cl): my_db.mass_action(cl) # don't consider this an actual backlog search if we only did recent eps # or if we only did certain shows if from_date == datetime.date.fromordinal(1) and standard_backlog: self._set_last_backlog(cur_date) self._get_last_backlog() if standard_backlog and not any_torrent_enabled: self._set_last_runtime(now) self.amActive = False self._reset_progress_indicator()