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