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 | 60 +++++++------------ 1 file changed, 23 insertions(+), 37 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 @@ -27,16 +27,35 @@ namespace NzbDrone.Core.NetImport } public List Fetch(int listId, bool onlyEnableAuto) + { + return MovieListSearch(listId, onlyEnableAuto); + } + + public List FetchAndFilter(int listId, bool onlyEnableAuto) + { + var existingMovies = _movieService.GetAllMovies(); + + var movies = MovieListSearch(listId, onlyEnableAuto); + + // 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.Where(x => !existingMovies.Contains(x)).ToList(); + } + + 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); + 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); @@ -49,38 +68,5 @@ namespace NzbDrone.Core.NetImport return movies; } - - public List FetchAndFilter(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()); - } - - // 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(); - } } }