/// <summary> /// syncs the watched state locally from trakt.tv /// </summary> public static void SyncTraktWatchedState() { if (string.IsNullOrEmpty(TraktAPI.Username) || string.IsNullOrEmpty(TraktAPI.Password)) { return; } // Get all local unwatched episodes SQLCondition conditions = new SQLCondition(new DBOnlineEpisode(), DBOnlineEpisode.cWatched, false, SQLConditionType.Equal); List <DBEpisode> episodes = DBEpisode.Get(conditions, false); var watchedItems = TraktAPI.GetUserWatched(TraktAPI.Username); MPTVSeriesLog.Write("Trakt: Syncronizing Watched/Seen from trakt.tv"); // go through all unwatched episodes and check if watched online foreach (DBEpisode episode in episodes) { // if the episode exists on server response // then we mark as watched locally if (HasEpisode(watchedItems, episode)) { MPTVSeriesLog.Write("Trakt: Marking '{0}' as watched", episode.ToString()); episode[DBOnlineEpisode.cWatched] = true; episode[DBOnlineEpisode.cTraktSeen] = true; episode.Commit(); } } MPTVSeriesLog.Write("Finished Syncronizing Watched/Seen state from trakt.tv"); }