public static IEnumerable<TraktEpisodeWatchList> GetWatchlistedEpisodesFromTrakt(bool ignoreLastSyncTime = false)
{
lock (syncLists)
{
// get from cache regardless of last sync time
if (ignoreLastSyncTime)
return WatchListEpisodes;
TraktLogger.Info("Getting current user watchlisted episodes from trakt.tv", TraktSettings.Username);
// 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.Episodes == 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.Episodes.Watchlist == TraktSettings.LastSyncActivities.Episodes.Watchlist)
{
var cachedItems = WatchListEpisodes;
if (cachedItems != null)
return cachedItems;
}
TraktLogger.Info("TV episode watchlist cache is out of date, requesting updated data. Local Date = '{0}', Online Date = '{1}'", TraktSettings.LastSyncActivities.Episodes.Watchlist ?? "<empty>", lastSyncActivities.Episodes.Watchlist ?? "<empty>");
// we get from online, local cache is not up to date
var onlineItems = TraktAPI.TraktAPI.GetWatchListEpisodes();
if (onlineItems == null)
return null;
_WatchListEpisodes = onlineItems;
// save to local file cache
SaveFileCache(EpisodesWatchlistedFile, _WatchListEpisodes.ToJSON());
// save new activity time for next time
TraktSettings.LastSyncActivities.Episodes.Watchlist = lastSyncActivities.Episodes.Watchlist;
return onlineItems;
}
}