From 2b7afd32724b58ec04088d0907bb80fb502492a9 Mon Sep 17 00:00:00 2001 From: Devin Buhl Date: Mon, 23 Jan 2017 00:29:31 -0500 Subject: [PATCH] remove duplicate code --- .../NetImport/NetImportSearchService.cs | 48 +++++++------------ 1 file changed, 17 insertions(+), 31 deletions(-) diff --git a/src/NzbDrone.Core/NetImport/NetImportSearchService.cs b/src/NzbDrone.Core/NetImport/NetImportSearchService.cs index f5f94eacd..c6aefafae 100644 --- a/src/NzbDrone.Core/NetImport/NetImportSearchService.cs +++ b/src/NzbDrone.Core/NetImport/NetImportSearchService.cs @@ -28,59 +28,45 @@ namespace NzbDrone.Core.NetImport public List Fetch(int listId, bool onlyEnableAuto) { - var movies = new List(); + return MovieListSearch(listId, onlyEnableAuto); + } - // Get all the lists - var importLists = _netImportFactory.GetAvailableProviders(); + public List FetchAndFilter(int listId, bool onlyEnableAuto) + { + var existingMovies = _movieService.GetAllMovies(); - // No listId is set return all movies in all lists - var lists = listId == 0 ? importLists.Where(n => ((NetImportDefinition) n.Definition).Enabled == true) : importLists.Where(n => ((NetImportDefinition) n.Definition).Id == listId); + var movies = MovieListSearch(listId, onlyEnableAuto); - // Only return lists where enabledAuto is truthy - if (onlyEnableAuto) - { - lists = importLists.Where(a => a.EnableAuto == true); - } - - foreach (var list in lists) - { - movies.AddRange(list.Fetch()); - } + // remove from movies list where existMovies (choose one) + // movies.RemoveAll(x => existingMovies.Contains(x)); + // return movies; + //// or + // movies.RemoveAll(a => existingMovies.Exists(w => w.TmdbId == a.TmdbId)); + // return movies; + //// or - return movies; + return movies.Where(x => !existingMovies.Contains(x)).ToList(); } - public List FetchAndFilter(int listId, bool onlyEnableAuto) + public List MovieListSearch(int listId, bool onlyEnableAuto) { var movies = new List(); - // Get all the lists var importLists = _netImportFactory.GetAvailableProviders(); - // No listId is set return all movies in all lists var lists = listId == 0 ? importLists.Where(n => ((NetImportDefinition)n.Definition).Enabled == true) : importLists.Where(n => ((NetImportDefinition)n.Definition).Id == listId); - // Only return lists where enabledAuto is truthy if (onlyEnableAuto) { lists = importLists.Where(a => a.EnableAuto == true); } - // Get all existing movies - var existingMovies = _movieService.GetAllMovies(); - foreach (var list in lists) { - movies.AddRange((List)list.Fetch()); + movies.AddRange(list.Fetch()); } - // remove from movies list where existMovies (choose one) - // movies.RemoveAll(x => existingMovies.Contains(x)); - // return movies; - // movies.RemoveAll(a => existingMovies.Exists(w => w.TmdbId == a.TmdbId)); - // return movies; - - return movies.Where(x => !existingMovies.Contains(x)).ToList(); + return movies; } } }