public static IEnumerable<TraktShowRated> GetRatedShowsFromTrakt(bool ignoreLastSyncTime = false)
{
// get from cache regardless of last sync time
if (ignoreLastSyncTime)
return RatedShows;
TraktLogger.Info("Getting current user rated shows from trakt.tv");
// get the last time we did anything to our library online
var lastSyncActivities = LastSyncActivities;
// something bad happened e.g. site not available
if (lastSyncActivities == null || lastSyncActivities.Shows == null)
return null;
// check the last time we have against the online time
// if the times are the same try to load from cache
if (lastSyncActivities.Shows.Rating == TraktSettings.LastSyncActivities.Shows.Rating)
{
var cachedItems = RatedShows;
if (cachedItems != null)
return cachedItems;
}
TraktLogger.Info("TV show ratings cache is out of date, requesting updated data. Local Date = '{0}', Online Date = '{1}'", TraktSettings.LastSyncActivities.Shows.Rating ?? "<empty>", lastSyncActivities.Shows.Rating ?? "<empty>");
// we get from online, local cache is not up to date
var onlineItems = TraktAPI.TraktAPI.GetRatedShows();
if (onlineItems != null)
{
_RatedShows = onlineItems;
// save to local file cache
SaveFileCache(ShowsRatedFile, _RatedShows.ToJSON());
// save new activity time for next time
TraktSettings.LastSyncActivities.Shows.Rating = lastSyncActivities.Shows.Rating;
}
return onlineItems;
}