private Movie RefreshMovieInfo(int movieId) { // Get the movie before updating, that way any changes made to the movie after the refresh started, // but before this movie was refreshed won't be lost. var movie = _movieService.GetMovie(movieId); _logger.ProgressInfo("Updating info for {0}", movie.Title); Movie movieInfo; List <Credit> credits; try { var tuple = _movieInfo.GetMovieInfo(movie.TmdbId); movieInfo = tuple.Item1; credits = tuple.Item2; } catch (MovieNotFoundException) { if (movie.Status != MovieStatusType.Deleted) { movie.Status = MovieStatusType.Deleted; _movieService.UpdateMovie(movie); _logger.Debug("Movie marked as deleted on TMDb for {0}", movie.Title); _eventAggregator.PublishEvent(new MovieUpdatedEvent(movie)); } throw; } if (movie.TmdbId != movieInfo.TmdbId) { _logger.Warn("Movie '{0}' (TMDb: {1}) was replaced with '{2}' (TMDb: {3}), because the original was a duplicate.", movie.Title, movie.TmdbId, movieInfo.Title, movieInfo.TmdbId); movie.TmdbId = movieInfo.TmdbId; } movie.Title = movieInfo.Title; movie.TitleSlug = movieInfo.TitleSlug; movie.ImdbId = movieInfo.ImdbId; movie.Overview = movieInfo.Overview; movie.Status = movieInfo.Status; movie.CleanTitle = movieInfo.CleanTitle; movie.SortTitle = movieInfo.SortTitle; movie.LastInfoSync = DateTime.UtcNow; movie.Runtime = movieInfo.Runtime; movie.Images = movieInfo.Images; movie.Ratings = movieInfo.Ratings; movie.Collection = movieInfo.Collection; movie.Genres = movieInfo.Genres; movie.Certification = movieInfo.Certification; movie.InCinemas = movieInfo.InCinemas; movie.Website = movieInfo.Website; movie.Year = movieInfo.Year; movie.SecondaryYear = movieInfo.SecondaryYear; movie.PhysicalRelease = movieInfo.PhysicalRelease; movie.DigitalRelease = movieInfo.DigitalRelease; movie.YouTubeTrailerId = movieInfo.YouTubeTrailerId; movie.Studio = movieInfo.Studio; movie.OriginalTitle = movieInfo.OriginalTitle; movie.OriginalLanguage = movieInfo.OriginalLanguage; movie.HasPreDBEntry = movieInfo.HasPreDBEntry; movie.Recommendations = movieInfo.Recommendations; try { movie.Path = new DirectoryInfo(movie.Path).FullName; movie.Path = movie.Path.GetActualCasing(); } catch (Exception e) { _logger.Warn(e, "Couldn't update movie path for " + movie.Path); } movie.AlternativeTitles = _titleService.UpdateTitles(movieInfo.AlternativeTitles, movie); _movieTranslationService.UpdateTranslations(movieInfo.Translations, movie); _movieService.UpdateMovie(new List <Movie> { movie }, true); _creditService.UpdateCredits(credits, movie); _logger.Debug("Finished movie refresh for {0}", movie.Title); _eventAggregator.PublishEvent(new MovieUpdatedEvent(movie)); return(movie); }