def _add_season(self, season, blacklist=[0]): number = season.get('season_number', 0) folder = u'Season {}'.format(number) # Skip blacklisted seasons if try_int(number) in blacklist: # TODO: Optional whitelist also self._log._add('tv', self.tv.tmdb_id, 'skipped special season', season=number) return # Skip if we've added season before and it isn't the most recent season # We still add most recent season even if we added it before because it might currently be airing if self._log._add('tv', self.tv.tmdb_id, self.tv._cache.is_added_season(number), season=number): return # Add our episodes for x, episode in enumerate(self.tv.get_episodes(number), 1): self._add_episode(episode, number, folder) self._update(x, self.tv.e_total) # Store a season value of where we got up to if self.tv.e_total > 2 and season.get( 'air_date') and not is_future_timestamp( season.get('air_date'), "%Y-%m-%d", 10): self.tv._cache.my_history['latest_season'] = try_int(number)
def set_next_check(self, next_aired, last_aired, status): """ Set the next check date for this show based on next/last aired and status """ if next_aired and next_aired.get('air_date'): next_aired_dt = next_aired.get('air_date') if is_future_timestamp(next_aired_dt, "%Y-%m-%d", 10): if not is_future_timestamp( next_aired_dt, "%Y-%m-%d", 10, days=7): self.my_history['next_check'] = next_aired.get('air_date') self.my_history[ 'log_msg'] = 'Show had next aired date this week' # Check again on the next aired date elif not is_future_timestamp( next_aired_dt, "%Y-%m-%d", 10, days=30): self.my_history['next_check'] = get_todays_date(days=7) self.my_history[ 'log_msg'] = 'Show has next aired date this month' # Check again in a week just to be safe in case air date changes else: self.my_history['next_check'] = get_todays_date(days=30) self.my_history[ 'log_msg'] = 'Show has next aired date in more than a month' # Check again in a month just to be safe in case air date changes else: next_aired = None # Next aired was in the past for some reason so dont use that date if not next_aired and last_aired and last_aired.get('air_date'): last_aired_dt = last_aired.get('air_date') if is_future_timestamp(last_aired_dt, "%Y-%m-%d", 10, days=-30): self.my_history['next_check'] = get_todays_date(days=1) self.my_history[ 'log_msg'] = 'Show aired in last month but no next aired date' # Show might be currently airing but just hasnt updated next date yet so check again tomorrow elif is_future_timestamp(last_aired_dt, "%Y-%m-%d", 10, days=-90): self.my_history[ 'log_msg'] = 'Show aired in last quarter but not in last month' self.my_history['next_check'] = get_todays_date(days=7) # Show might be on a mid-season break so check again in a week for a return date elif status in ['Canceled', 'Ended']: self.my_history['log_msg'] = 'Show was canceled or ended' self.my_history['next_check'] = get_todays_date(days=30) # Show was canceled so check again in a month just to be safe else: self.my_history[ 'log_msg'] = 'Show last aired more than 3 months ago and no next aired date set' self.my_history['next_check'] = get_todays_date(days=7)
def is_unaired(self, format_label=u'[COLOR=ffcc0000][I]{}[/I][/COLOR]', check_hide_settings=True): try: if not is_future_timestamp(self.infolabels.get('premiered'), "%Y-%m-%d", 10): return if format_label: self.label = format_label.format(self.label) except Exception as exc: kodi_log(u'Error: {}'.format(exc), 1) if not check_hide_settings: return True return self.unaired_bool()
def get_pickle(cache_name, json_dump=False): cache_name = get_pickle_name(cache_name) if not cache_name: return try: with open(os.path.join(get_write_path('pickle'), cache_name), 'r' if json_dump else 'rb') as file: cache_obj = json.load(file) if json_dump else _pickle.load(file) except IOError: cache_obj = None if cache_obj and is_future_timestamp(cache_obj.get('expires', '')): return cache_obj.get('my_object')
def _add_episode(self, episode, season, folder): number = episode.get('episode_number') filename = validify_filename(u'S{:02d}E{:02d} - {}'.format( try_int(season), try_int(number), episode.get('name'))) self.tv._cache.my_history['episodes'].append(filename) # Skip episodes we added in the past if self._log._add('tv', self.tv.tmdb_id, self.tv._cache.is_added_episode(filename), season=season, episode=number): return # Skip future episodes if self.hide_unaired and is_future_timestamp(episode.get('air_date'), "%Y-%m-%d", 10): self.tv._cache.my_history['skipped'].append(filename) self._log._add('tv', self.tv.tmdb_id, 'unaired episode', season=season, episode=number, air_date=episode.get('air_date')) return # Check if item has already been added file = self.tv.get_episode_db_info(season, number, info='file') if file: self._log._add('tv', self.tv.tmdb_id, 'found in library', season=season, episode=number, path=file) return # Add our strm file file = create_file(STRM_EPISODE.format(self.tv.tmdb_id, season, number), filename, self.tv.name, folder, basedir=BASEDIR_TV) self._log._add('tv', self.tv.tmdb_id, 'added strm file', season=season, episode=number, path=file)
def get_next_check(self): """ If next check value is in future return log message """ next_check = self.cache_info.get('next_check') if next_check and is_future_timestamp(next_check, "%Y-%m-%d", 10): return u'{} next update {}'.format(self.cache_info.get('log_msg'), next_check)