private List <Book> ProcessReports(List <ImportListItemInfo> reports) { var processed = new List <Book>(); var artistsToAdd = new List <Author>(); var albumsToAdd = new List <Book>(); _logger.ProgressInfo("Processing {0} list items", reports.Count); var reportNumber = 1; var listExclusions = _importListExclusionService.All(); foreach (var report in reports) { _logger.ProgressTrace("Processing list item {0}/{1}", reportNumber, reports.Count); reportNumber++; var importList = _importListFactory.Get(report.ImportListId); if (report.Book.IsNotNullOrWhiteSpace() || report.EditionGoodreadsId.IsNotNullOrWhiteSpace()) { if (report.EditionGoodreadsId.IsNullOrWhiteSpace() || report.AuthorGoodreadsId.IsNullOrWhiteSpace()) { MapAlbumReport(report); } ProcessAlbumReport(importList, report, listExclusions, albumsToAdd); } else if (report.Author.IsNotNullOrWhiteSpace() || report.AuthorGoodreadsId.IsNotNullOrWhiteSpace()) { if (report.AuthorGoodreadsId.IsNullOrWhiteSpace()) { MapArtistReport(report); } ProcessArtistReport(importList, report, listExclusions, artistsToAdd); } } var addedArtists = _addAuthorService.AddAuthors(artistsToAdd, false); var addedAlbums = _addBookService.AddBooks(albumsToAdd, false); var message = string.Format($"Import List Sync Completed. Items found: {reports.Count}, Authors added: {artistsToAdd.Count}, Books added: {albumsToAdd.Count}"); _logger.ProgressInfo(message); var toRefresh = addedArtists.Select(x => x.Id).Concat(addedAlbums.Select(x => x.Author.Value.Id)).Distinct().ToList(); if (toRefresh.Any()) { _commandQueueManager.Push(new BulkRefreshAuthorCommand(toRefresh, true)); } return(processed); }
private void ProcessReports(ImportListFetchResult listFetchResult) { listFetchResult.Movies = listFetchResult.Movies.DistinctBy(x => { if (x.TmdbId != 0) { return(x.TmdbId.ToString()); } if (x.ImdbId.IsNotNullOrWhiteSpace()) { return(x.ImdbId); } return(x.Title); }).ToList(); var listedMovies = listFetchResult.Movies.ToList(); var importExclusions = _exclusionService.GetAllExclusions(); var dbMovies = _movieService.AllMovieTmdbIds(); var moviesToAdd = new List <Movie>(); var groupedMovies = listedMovies.GroupBy(x => x.ListId); foreach (var list in groupedMovies) { var importList = _importListFactory.Get(list.Key); foreach (var movie in list) { if (movie.TmdbId != 0) { ProcessMovieReport(importList, movie, importExclusions, dbMovies, moviesToAdd); } } } if (moviesToAdd.Any()) { _logger.Info($"Adding {moviesToAdd.Count} movies from your auto enabled lists to library"); } _addMovieService.AddMovies(moviesToAdd, true); }
private void ProcessReports(List <ImportListItemInfo> reports) { var seriesToAdd = new List <Series>(); _logger.ProgressInfo("Processing {0} list items", reports.Count); var reportNumber = 1; var listExclusions = _importListExclusionService.All(); foreach (var report in reports) { _logger.ProgressTrace("Processing list item {0}/{1}", reportNumber, reports.Count); reportNumber++; var importList = _importListFactory.Get(report.ImportListId); // Map TVDb if we only have a series name if (report.TvdbId <= 0 && report.Title.IsNotNullOrWhiteSpace()) { var mappedSeries = _seriesSearchService.SearchForNewSeries(report.Title) .FirstOrDefault(); if (mappedSeries != null) { report.TvdbId = mappedSeries.TvdbId; report.Title = mappedSeries?.Title; } } // Check to see if series in DB var existingSeries = _seriesService.FindByTvdbId(report.TvdbId); // Break if Series Exists in DB if (existingSeries != null) { _logger.Debug("{0} [{1}] Rejected, Series Exists in DB", report.TvdbId, report.Title); continue; } // Check to see if series excluded var excludedSeries = listExclusions.Where(s => s.TvdbId == report.TvdbId).SingleOrDefault(); if (excludedSeries != null) { _logger.Debug("{0} [{1}] Rejected due to list exlcusion", report.TvdbId, report.Title); continue; } // Append Series if not already in DB or already on add list if (seriesToAdd.All(s => s.TvdbId != report.TvdbId)) { var monitored = importList.ShouldMonitor != MonitorTypes.None; seriesToAdd.Add(new Series { TvdbId = report.TvdbId, Title = report.Title, Year = report.Year, Monitored = monitored, RootFolderPath = importList.RootFolderPath, QualityProfileId = importList.QualityProfileId, LanguageProfileId = importList.LanguageProfileId, SeriesType = importList.SeriesType, SeasonFolder = importList.SeasonFolder, Tags = importList.Tags, AddOptions = new AddSeriesOptions { SearchForMissingEpisodes = monitored, Monitor = importList.ShouldMonitor } }); } } _addSeriesService.AddSeries(seriesToAdd, true); var message = string.Format("Import List Sync Completed. Items found: {0}, Series added: {1}", reports.Count, seriesToAdd.Count); _logger.ProgressInfo(message); }
private List <Album> ProcessReports(List <ImportListItemInfo> reports) { var processed = new List <Album>(); var artistsToAdd = new List <Artist>(); _logger.ProgressInfo("Processing {0} list items", reports.Count); var reportNumber = 1; var listExclusions = _importListExclusionService.All(); foreach (var report in reports) { _logger.ProgressTrace("Processing list item {0}/{1}", reportNumber, reports.Count); reportNumber++; var importList = _importListFactory.Get(report.ImportListId); // Map MBid if we only have an album title if (report.AlbumMusicBrainzId.IsNullOrWhiteSpace() && report.Album.IsNotNullOrWhiteSpace()) { var mappedAlbum = _albumSearchService.SearchForNewAlbum(report.Album, report.Artist) .FirstOrDefault(); if (mappedAlbum == null) { continue; // Break if we are looking for an album and cant find it. This will avoid us from adding the artist and possibly getting it wrong. } report.AlbumMusicBrainzId = mappedAlbum.ForeignAlbumId; report.Album = mappedAlbum.Title; report.Artist = mappedAlbum.ArtistMetadata?.Value?.Name; report.ArtistMusicBrainzId = mappedAlbum?.ArtistMetadata?.Value?.ForeignArtistId; } // Map MBid if we only have a artist name if (report.ArtistMusicBrainzId.IsNullOrWhiteSpace() && report.Artist.IsNotNullOrWhiteSpace()) { var mappedArtist = _artistSearchService.SearchForNewArtist(report.Artist) .FirstOrDefault(); report.ArtistMusicBrainzId = mappedArtist?.Metadata.Value?.ForeignArtistId; report.Artist = mappedArtist?.Metadata.Value?.Name; } // Check to see if artist in DB var existingArtist = _artistService.FindById(report.ArtistMusicBrainzId); // Check to see if artist excluded var excludedArtist = listExclusions.Where(s => s.ForeignId == report.ArtistMusicBrainzId).SingleOrDefault(); if (excludedArtist != null) { _logger.Debug("{0} [{1}] Rejected due to list exlcusion", report.ArtistMusicBrainzId, report.Artist); } // Append Artist if not already in DB or already on add list if (existingArtist == null && excludedArtist == null && artistsToAdd.All(s => s.Metadata.Value.ForeignArtistId != report.ArtistMusicBrainzId)) { var monitored = importList.ShouldMonitor != ImportListMonitorType.None; artistsToAdd.Add(new Artist { Metadata = new ArtistMetadata { ForeignArtistId = report.ArtistMusicBrainzId, Name = report.Artist }, Monitored = monitored, RootFolderPath = importList.RootFolderPath, QualityProfileId = importList.ProfileId, MetadataProfileId = importList.MetadataProfileId, Tags = importList.Tags, AlbumFolder = true, AddOptions = new AddArtistOptions { SearchForMissingAlbums = monitored, Monitored = monitored, Monitor = monitored ? MonitorTypes.All : MonitorTypes.None } }); } // Add Album so we know what to monitor if (report.AlbumMusicBrainzId.IsNotNullOrWhiteSpace() && artistsToAdd.Any(s => s.Metadata.Value.ForeignArtistId == report.ArtistMusicBrainzId) && importList.ShouldMonitor == ImportListMonitorType.SpecificAlbum) { artistsToAdd.Find(s => s.Metadata.Value.ForeignArtistId == report.ArtistMusicBrainzId).AddOptions.AlbumsToMonitor.Add(report.AlbumMusicBrainzId); } } _addArtistService.AddArtists(artistsToAdd); var message = string.Format("Import List Sync Completed. Reports found: {0}, Reports grabbed: {1}", reports.Count, processed.Count); _logger.ProgressInfo(message); return(processed); }