public bool SyncMovies() { try { TestStatus = "[Trakt.SyncMovies]"; Guid[] types = { MediaAspect.ASPECT_ID, MovieAspect.ASPECT_ID }; var contentDirectory = ServiceRegistration.Get <IServerConnectionManager>().ContentDirectory; if (contentDirectory == null) { TestStatus = "[Trakt.MediaLibraryNotConnected]"; return(false); } var movies = contentDirectory.Search(new MediaItemQuery(types, null, null), true); TraktMovieSync syncData = new TraktMovieSync { UserName = Username, Password = Password, MovieList = new List <TraktMovieSync.Movie>() }; // First send all movies to Trakt that we have so they appear in library foreach (var movie in movies) { syncData.MovieList.Add(ToMovie(movie)); } TraktSyncModes traktSyncMode = TraktSyncModes.library; var response = TraktAPI.SyncMovieLibrary(syncData, traktSyncMode); ServiceRegistration.Get <ILogger>().Info("Trakt.tv: Movies '{0}': {1} inserted, {2} existing, {3} skipped movies.", traktSyncMode, response.Inserted, SafeCount(response.AlreadyExistMovies), SafeCount(response.SkippedMovies)); syncData.MovieList.Clear(); // Then send only the watched movies as "seen" foreach (var movie in movies.Where(IsWatched)) { syncData.MovieList.Add(ToMovie(movie)); } traktSyncMode = TraktSyncModes.seen; response = TraktAPI.SyncMovieLibrary(syncData, traktSyncMode); ServiceRegistration.Get <ILogger>().Info("Trakt.tv: Movies '{0}': {1} inserted, {2} existing, {3} skipped movies.", traktSyncMode, response.Inserted, SafeCount(response.AlreadyExistMovies), SafeCount(response.SkippedMovies)); return(true); } catch (Exception ex) { ServiceRegistration.Get <ILogger>().Error("Trakt.tv: Exception while synchronizing media library.", ex); } return(false); }