Ejemplo n.º 1
0
        private void SyncList(ImportListDefinition definition)
        {
            _logger.ProgressInfo(string.Format("Starting Import List Refresh for List {0}", definition.Name));

            var result = _listFetcherAndParser.FetchSingleList(definition);

            ProcessReports(result);
        }
Ejemplo n.º 2
0
        private void ProcessAuthorReport(ImportListDefinition importList, ImportListItemInfo report, List <ImportListExclusion> listExclusions, List <Author> authorsToAdd)
        {
            if (report.AuthorGoodreadsId == null)
            {
                return;
            }

            // Check to see if author in DB
            var existingAuthor = _authorService.FindById(report.AuthorGoodreadsId);

            // Check to see if author excluded
            var excludedAuthor = listExclusions.Where(s => s.ForeignId == report.AuthorGoodreadsId).SingleOrDefault();

            if (excludedAuthor != null)
            {
                _logger.Debug("{0} [{1}] Rejected due to list exlcusion", report.AuthorGoodreadsId, report.Author);
                return;
            }

            if (existingAuthor != null)
            {
                _logger.Debug("{0} [{1}] Rejected, Author Exists in DB.  Ensuring Author monitored", report.AuthorGoodreadsId, report.Author);

                if (!existingAuthor.Monitored)
                {
                    existingAuthor.Monitored = true;
                    _authorService.UpdateAuthor(existingAuthor);
                }

                return;
            }

            // Append Author if not already in DB or already on add list
            if (authorsToAdd.All(s => s.Metadata.Value.ForeignAuthorId != report.AuthorGoodreadsId))
            {
                var monitored = importList.ShouldMonitor != ImportListMonitorType.None;

                authorsToAdd.Add(new Author
                {
                    Metadata = new AuthorMetadata
                    {
                        ForeignAuthorId = report.AuthorGoodreadsId,
                        Name            = report.Author
                    },
                    Monitored         = monitored,
                    RootFolderPath    = importList.RootFolderPath,
                    QualityProfileId  = importList.ProfileId,
                    MetadataProfileId = importList.MetadataProfileId,
                    Tags       = importList.Tags,
                    AddOptions = new AddAuthorOptions
                    {
                        SearchForMissingBooks = importList.ShouldSearch,
                        Monitored             = monitored,
                        Monitor = monitored ? MonitorTypes.All : MonitorTypes.None
                    }
                });
            }
        }
Ejemplo n.º 3
0
        private List <Book> SyncList(ImportListDefinition definition)
        {
            _logger.ProgressInfo(string.Format("Starting Import List Refresh for List {0}", definition.Name));

            var rssReleases = _listFetcherAndParser.FetchSingleList(definition);

            var reports = rssReleases.ToList();

            return(ProcessReports(reports));
        }
Ejemplo n.º 4
0
        private void ProcessArtistReport(ImportListDefinition importList, ImportListItemInfo report, List <ImportListExclusion> listExclusions, List <Artist> artistsToAdd)
        {
            if (report.ArtistMusicBrainzId == null)
            {
                return;
            }

            // Check to see if artist in DB
            var existingArtist = _artistService.FindById(report.ArtistMusicBrainzId);

            if (existingArtist != null)
            {
                _logger.Debug("{0} [{1}] Rejected, Artist Exists in DB", report.ArtistMusicBrainzId, report.Artist);
                return;
            }

            // 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);
                return;
            }

            // Append Artist if not already in DB or already on add list
            if (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,
                    AddOptions = new AddArtistOptions
                    {
                        SearchForMissingAlbums = monitored,
                        Monitored = monitored,
                        Monitor   = monitored ? MonitorTypes.All : MonitorTypes.None
                    }
                });
            }
        }
Ejemplo n.º 5
0
        private void ProcessMovieReport(ImportListDefinition importList, ImportListMovie report, List <ImportExclusion> listExclusions, List <int> dbMovies, List <Movie> moviesToAdd)
        {
            if (report.TmdbId == 0 || !importList.EnableAuto)
            {
                return;
            }

            // Check to see if movie in DB
            if (dbMovies.Contains(report.TmdbId))
            {
                _logger.Debug("{0} [{1}] Rejected, Movie Exists in DB", report.TmdbId, report.Title);

                AddTagsToExistingMovie(importList, report);

                return;
            }

            // Check to see if movie excluded
            var excludedMovie = listExclusions.Where(s => s.TmdbId == report.TmdbId).SingleOrDefault();

            if (excludedMovie != null)
            {
                _logger.Debug("{0} [{1}] Rejected due to list exlcusion", report.TmdbId, report.Title);
                return;
            }

            // Append Artist if not already in DB or already on add list
            if (moviesToAdd.All(s => s.TmdbId != report.TmdbId))
            {
                var monitored = importList.ShouldMonitor;

                moviesToAdd.Add(new Movie
                {
                    Monitored           = monitored,
                    RootFolderPath      = importList.RootFolderPath,
                    ProfileId           = importList.ProfileId,
                    MinimumAvailability = importList.MinimumAvailability,
                    Tags       = importList.Tags,
                    TmdbId     = report.TmdbId,
                    Title      = report.Title,
                    Year       = report.Year,
                    ImdbId     = report.ImdbId,
                    AddOptions = new AddMovieOptions
                    {
                        SearchForMovie = monitored && importList.SearchOnAdd,
                    }
                });
            }
        }
        public ImportListFetchResult FetchSingleList(ImportListDefinition definition)
        {
            var result = new ImportListFetchResult();

            var importList = _importListFactory.GetInstance(definition);

            if (importList == null || !definition.Enable)
            {
                _logger.Debug("Import list {0} is not enabled. No Movies will be added");
                return(result);
            }

            var importListLocal = importList;

            try
            {
                var importListReports = importListLocal.Fetch();

                lock (result)
                {
                    _logger.Debug("Found {0} from {1}", importListReports.Movies.Count, importList.Name);

                    if (!importListReports.AnyFailure)
                    {
                        // TODO some opportunity to bulk map here if we had the tmdbIds
                        var listMovies = importListReports.Movies.Select(x =>
                        {
                            return(MapMovieReport(x));
                        }).Where(x => x.TmdbId > 0).ToList();

                        listMovies = listMovies.DistinctBy(x => x.TmdbId).ToList();

                        result.Movies.AddRange(listMovies);
                        _listMovieService.SyncMoviesForList(listMovies, importList.Definition.Id);
                    }

                    result.AnyFailure |= importListReports.AnyFailure;
                }
            }
            catch (Exception e)
            {
                _logger.Error(e, "Error during Import List Sync for list {0}", importList.Name);
            }

            _logger.Debug("Found {0} reports for list {1}", result.Movies.Count, importList.Name);

            return(result);
        }
        public List <ImportListItemInfo> FetchSingleList(ImportListDefinition definition)
        {
            var result = new List <ImportListItemInfo>();

            var importList = _importListFactory.GetInstance(definition);

            if (importList == null || !definition.EnableAutomaticAdd)
            {
                _logger.Debug("Import list not enabled, skipping.");
                return(result);
            }

            var taskList    = new List <Task>();
            var taskFactory = new TaskFactory(TaskCreationOptions.LongRunning, TaskContinuationOptions.None);

            var importListLocal = importList;

            var task = taskFactory.StartNew(() =>
            {
                try
                {
                    var importListReports = importListLocal.Fetch();

                    lock (result)
                    {
                        _logger.Debug("Found {0} from {1}", importListReports.Count, importList.Name);

                        result.AddRange(importListReports);
                    }
                }
                catch (Exception e)
                {
                    _logger.Error(e, "Error during Import List Sync");
                }
            }).LogExceptions();

            taskList.Add(task);


            Task.WaitAll(taskList.ToArray());

            result = result.DistinctBy(r => new { r.TvdbId, r.Title }).ToList();

            return(result);
        }
Ejemplo n.º 8
0
        private void AddTagsToExistingMovie(ImportListDefinition importList, ImportListMovie report)
        {
            _logger.Debug("{0} [{1}] Checking if necessary to add new tag/s to existing Movie.", report.TmdbId, report.Title);

            var movie = _movieService.FindByTmdbId(report.TmdbId);

            if (movie != null)
            {
                foreach (var tag in importList.Tags)
                {
                    if (!movie.Tags.Contains(tag))
                    {
                        movie.Tags.Add(tag);
                    }
                }

                _movieService.UpdateMovie(movie);
            }
        }
Ejemplo n.º 9
0
        private void ProcessAlbumReport(ImportListDefinition importList, ImportListItemInfo report, List <ImportListExclusion> listExclusions, List <Book> albumsToAdd)
        {
            if (report.EditionGoodreadsId == null)
            {
                return;
            }

            // Check to see if book in DB
            var existingAlbum = _bookService.FindById(report.EditionGoodreadsId);

            if (existingAlbum != null)
            {
                _logger.Debug("{0} [{1}] Rejected, Book Exists in DB", report.EditionGoodreadsId, report.Book);
                return;
            }

            // Check to see if book excluded
            var excludedAlbum = listExclusions.SingleOrDefault(s => s.ForeignId == report.EditionGoodreadsId);

            if (excludedAlbum != null)
            {
                _logger.Debug("{0} [{1}] Rejected due to list exlcusion", report.EditionGoodreadsId, report.Book);
                return;
            }

            // Check to see if author excluded
            var excludedArtist = listExclusions.SingleOrDefault(s => s.ForeignId == report.AuthorGoodreadsId);

            if (excludedArtist != null)
            {
                _logger.Debug("{0} [{1}] Rejected due to list exlcusion for parent author", report.EditionGoodreadsId, report.Book);
                return;
            }

            // Append Album if not already in DB or already on add list
            if (albumsToAdd.All(s => s.ForeignBookId != report.EditionGoodreadsId))
            {
                var monitored = importList.ShouldMonitor != ImportListMonitorType.None;

                var toAdd = new Book
                {
                    ForeignBookId = report.BookGoodreadsId,
                    Monitored     = monitored,
                    Editions      = new List <Edition>
                    {
                        new Edition
                        {
                            ForeignEditionId = report.EditionGoodreadsId,
                            Monitored        = true
                        }
                    },
                    Author = new Author
                    {
                        Monitored         = monitored,
                        RootFolderPath    = importList.RootFolderPath,
                        QualityProfileId  = importList.ProfileId,
                        MetadataProfileId = importList.MetadataProfileId,
                        Tags       = importList.Tags,
                        AddOptions = new AddAuthorOptions
                        {
                            SearchForMissingBooks = monitored,
                            Monitored             = monitored,
                            Monitor = monitored ? MonitorTypes.All : MonitorTypes.None
                        }
                    },
                };

                if (importList.ShouldMonitor == ImportListMonitorType.SpecificBook)
                {
                    toAdd.Author.Value.AddOptions.BooksToMonitor.Add(toAdd.ForeignBookId);
                }

                albumsToAdd.Add(toAdd);
            }
        }
Ejemplo n.º 10
0
        private void ProcessBookReport(ImportListDefinition importList, ImportListItemInfo report, List <ImportListExclusion> listExclusions, List <Book> booksToAdd, List <Author> authorsToAdd)
        {
            if (report.EditionGoodreadsId == null)
            {
                return;
            }

            // Check to see if book in DB
            var existingBook = _bookService.FindById(report.BookGoodreadsId);

            // Check to see if book excluded
            var excludedBook = listExclusions.SingleOrDefault(s => s.ForeignId == report.BookGoodreadsId);

            // Check to see if author excluded
            var excludedAuthor = listExclusions.SingleOrDefault(s => s.ForeignId == report.AuthorGoodreadsId);

            if (excludedBook != null)
            {
                _logger.Debug("{0} [{1}] Rejected due to list exclusion", report.EditionGoodreadsId, report.Book);
                return;
            }

            if (excludedAuthor != null)
            {
                _logger.Debug("{0} [{1}] Rejected due to list exclusion for parent author", report.EditionGoodreadsId, report.Book);
                return;
            }

            if (existingBook != null)
            {
                _logger.Debug("{0} [{1}] Rejected, Book Exists in DB.  Ensuring Book and Author monitored.", report.EditionGoodreadsId, report.Book);

                if (importList.ShouldMonitorExisting && importList.ShouldMonitor != ImportListMonitorType.None)
                {
                    if (!existingBook.Monitored)
                    {
                        _bookService.SetBookMonitored(existingBook.Id, true);

                        if (importList.ShouldMonitor == ImportListMonitorType.SpecificBook)
                        {
                            _commandQueueManager.Push(new BookSearchCommand(new List <int> {
                                existingBook.Id
                            }));
                        }
                    }

                    var existingAuthor = existingBook.Author.Value;
                    var doSearch       = false;

                    if (importList.ShouldMonitor == ImportListMonitorType.EntireAuthor)
                    {
                        if (existingAuthor.Books.Value.Any(x => !x.Monitored))
                        {
                            doSearch = true;
                            _bookService.SetMonitored(existingAuthor.Books.Value.Select(x => x.Id), true);
                        }
                    }

                    if (!existingAuthor.Monitored)
                    {
                        doSearch = true;
                        existingAuthor.Monitored = true;
                        _authorService.UpdateAuthor(existingAuthor);
                    }

                    if (doSearch)
                    {
                        _commandQueueManager.Push(new MissingBookSearchCommand(existingAuthor.Id));
                    }
                }

                return;
            }

            // Append Book if not already in DB or already on add list
            if (booksToAdd.All(s => s.ForeignBookId != report.BookGoodreadsId))
            {
                var monitored = importList.ShouldMonitor != ImportListMonitorType.None;

                var toAddAuthor = new Author
                {
                    Monitored         = monitored,
                    MonitorNewItems   = importList.MonitorNewItems,
                    RootFolderPath    = importList.RootFolderPath,
                    QualityProfileId  = importList.ProfileId,
                    MetadataProfileId = importList.MetadataProfileId,
                    Tags       = importList.Tags,
                    AddOptions = new AddAuthorOptions
                    {
                        SearchForMissingBooks = importList.ShouldSearch,
                        Monitored             = monitored,
                        Monitor = monitored ? MonitorTypes.All : MonitorTypes.None
                    }
                };

                if (report.AuthorGoodreadsId != null && report.Author != null)
                {
                    toAddAuthor = ProcessAuthorReport(importList, report, listExclusions, authorsToAdd);
                }

                var toAdd = new Book
                {
                    ForeignBookId = report.BookGoodreadsId,
                    Monitored     = monitored,
                    AnyEditionOk  = true,
                    Editions      = new List <Edition>
                    {
                        new Edition
                        {
                            ForeignEditionId = report.EditionGoodreadsId,
                            Monitored        = true
                        }
                    },
                    Author     = toAddAuthor,
                    AddOptions = new AddBookOptions
                    {
                        // Only search for new book for existing authors
                        // New author searches are triggered by SearchForMissingBooks
                        SearchForNewBook = importList.ShouldSearch && toAddAuthor.Id > 0
                    }
                };

                if (importList.ShouldMonitor == ImportListMonitorType.SpecificBook && toAddAuthor.AddOptions != null)
                {
                    Debug.Assert(toAddAuthor.Id == 0, "new author added but ID is not 0");
                    toAddAuthor.AddOptions.BooksToMonitor.Add(toAdd.ForeignBookId);
                }

                booksToAdd.Add(toAdd);
            }
        }
Ejemplo n.º 11
0
        private void ProcessAlbumReport(ImportListDefinition importList, ImportListItemInfo report, List <ImportListExclusion> listExclusions, List <Album> albumsToAdd)
        {
            if (report.AlbumMusicBrainzId == null)
            {
                return;
            }

            // Check to see if album in DB
            var existingAlbum = _albumService.FindById(report.AlbumMusicBrainzId);

            if (existingAlbum != null)
            {
                _logger.Debug("{0} [{1}] Rejected, Album Exists in DB", report.AlbumMusicBrainzId, report.Album);
                return;
            }

            // Check to see if album excluded
            var excludedAlbum = listExclusions.SingleOrDefault(s => s.ForeignId == report.AlbumMusicBrainzId);

            if (excludedAlbum != null)
            {
                _logger.Debug("{0} [{1}] Rejected due to list exlcusion", report.AlbumMusicBrainzId, report.Album);
                return;
            }

            // Check to see if artist excluded
            var excludedArtist = listExclusions.SingleOrDefault(s => s.ForeignId == report.ArtistMusicBrainzId);

            if (excludedArtist != null)
            {
                _logger.Debug("{0} [{1}] Rejected due to list exlcusion for parent artist", report.AlbumMusicBrainzId, report.Album);
                return;
            }

            // Append Album if not already in DB or already on add list
            if (albumsToAdd.All(s => s.ForeignAlbumId != report.AlbumMusicBrainzId))
            {
                var monitored = importList.ShouldMonitor != ImportListMonitorType.None;

                var toAdd = new Album
                {
                    ForeignAlbumId = report.AlbumMusicBrainzId,
                    Monitored      = monitored,
                    AnyReleaseOk   = true,
                    Artist         = new Artist
                    {
                        Monitored         = monitored,
                        RootFolderPath    = importList.RootFolderPath,
                        QualityProfileId  = importList.ProfileId,
                        MetadataProfileId = importList.MetadataProfileId,
                        Tags       = importList.Tags,
                        AddOptions = new AddArtistOptions
                        {
                            SearchForMissingAlbums = monitored,
                            Monitored = monitored,
                            Monitor   = monitored ? MonitorTypes.All : MonitorTypes.None
                        }
                    },
                    AddOptions = new AddAlbumOptions
                    {
                        SearchForNewAlbum = monitored
                    }
                };

                if (importList.ShouldMonitor == ImportListMonitorType.SpecificAlbum)
                {
                    toAdd.Artist.Value.AddOptions.AlbumsToMonitor.Add(toAdd.ForeignAlbumId);
                }

                albumsToAdd.Add(toAdd);
            }
        }
Ejemplo n.º 12
0
        private void ProcessBookReport(ImportListDefinition importList, ImportListItemInfo report, List <ImportListExclusion> listExclusions, List <Book> booksToAdd)
        {
            if (report.EditionGoodreadsId == null)
            {
                return;
            }

            // Check to see if book in DB
            var existingBook = _bookService.FindById(report.BookGoodreadsId);

            // Check to see if book excluded
            var excludedBook = listExclusions.SingleOrDefault(s => s.ForeignId == report.BookGoodreadsId);

            // Check to see if author excluded
            var excludedAuthor = listExclusions.SingleOrDefault(s => s.ForeignId == report.AuthorGoodreadsId);

            if (excludedBook != null)
            {
                _logger.Debug("{0} [{1}] Rejected due to list exlcusion", report.EditionGoodreadsId, report.Book);
                return;
            }

            if (excludedAuthor != null)
            {
                _logger.Debug("{0} [{1}] Rejected due to list exlcusion for parent author", report.EditionGoodreadsId, report.Book);
                return;
            }

            if (existingBook != null)
            {
                _logger.Debug("{0} [{1}] Rejected, Book Exists in DB.  Ensuring Book and Author monitored.", report.EditionGoodreadsId, report.Book);

                if (importList.ShouldMonitor != ImportListMonitorType.None)
                {
                    if (!existingBook.Monitored)
                    {
                        _bookService.SetBookMonitored(existingBook.Id, true);
                    }

                    var existingAuthor = existingBook.Author.Value;
                    if (importList.ShouldMonitor == ImportListMonitorType.EntireAuthor)
                    {
                        _bookService.SetMonitored(existingAuthor.Books.Value.Select(x => x.Id), true);
                    }

                    if (!existingAuthor.Monitored)
                    {
                        existingAuthor.Monitored = true;
                        _authorService.UpdateAuthor(existingAuthor);
                    }
                }

                return;
            }

            // Append Book if not already in DB or already on add list
            if (booksToAdd.All(s => s.ForeignBookId != report.BookGoodreadsId))
            {
                var monitored = importList.ShouldMonitor != ImportListMonitorType.None;

                var toAdd = new Book
                {
                    ForeignBookId = report.BookGoodreadsId,
                    Monitored     = monitored,
                    Editions      = new List <Edition>
                    {
                        new Edition
                        {
                            ForeignEditionId = report.EditionGoodreadsId,
                            Monitored        = true
                        }
                    },
                    Author = new Author
                    {
                        Monitored         = monitored,
                        RootFolderPath    = importList.RootFolderPath,
                        QualityProfileId  = importList.ProfileId,
                        MetadataProfileId = importList.MetadataProfileId,
                        Tags       = importList.Tags,
                        AddOptions = new AddAuthorOptions
                        {
                            SearchForMissingBooks = importList.ShouldSearch,
                            Monitored             = monitored,
                            Monitor = monitored ? MonitorTypes.All : MonitorTypes.None
                        }
                    },
                    AddOptions = new AddBookOptions
                    {
                        SearchForNewBook = monitored
                    }
                };

                if (importList.ShouldMonitor == ImportListMonitorType.SpecificBook)
                {
                    toAdd.Author.Value.AddOptions.BooksToMonitor.Add(toAdd.ForeignBookId);
                }

                booksToAdd.Add(toAdd);
            }
        }