diff --git a/src/NzbDrone.Core/Jobs/TaskManager.cs b/src/NzbDrone.Core/Jobs/TaskManager.cs index 43af20db5..3abee626c 100644 --- a/src/NzbDrone.Core/Jobs/TaskManager.cs +++ b/src/NzbDrone.Core/Jobs/TaskManager.cs @@ -14,6 +14,7 @@ using NzbDrone.Core.Lifecycle; using NzbDrone.Core.MediaFiles.Commands; using NzbDrone.Core.Messaging.Commands; using NzbDrone.Core.Messaging.Events; +using NzbDrone.Core.NetImport; using NzbDrone.Core.Tv.Commands; using NzbDrone.Core.Update.Commands; @@ -64,7 +65,7 @@ namespace NzbDrone.Core.Jobs new ScheduledTask{ Interval = 0.25f, TypeName = typeof(CheckForFinishedDownloadCommand).FullName}, new ScheduledTask{ Interval = 5, TypeName = typeof(MessagingCleanupCommand).FullName}, new ScheduledTask{ Interval = 6*60, TypeName = typeof(ApplicationUpdateCommand).FullName}, - // new ScheduledTask{ Interval = 3*60, TypeName = typeof(UpdateSceneMappingCommand).FullName}, + new ScheduledTask{ Interval = 12*60, TypeName = typeof(NetImportSyncCommand).FullName}, new ScheduledTask{ Interval = 6*60, TypeName = typeof(CheckHealthCommand).FullName}, new ScheduledTask{ Interval = 24*60, TypeName = typeof(RefreshMovieCommand).FullName}, new ScheduledTask{ Interval = 24*60, TypeName = typeof(HousekeepingCommand).FullName}, diff --git a/src/NzbDrone.Core/NetImport/NetImportSearchService.cs b/src/NzbDrone.Core/NetImport/NetImportSearchService.cs index c6aefafae..cf2f407a1 100644 --- a/src/NzbDrone.Core/NetImport/NetImportSearchService.cs +++ b/src/NzbDrone.Core/NetImport/NetImportSearchService.cs @@ -3,6 +3,8 @@ using System.Collections.Generic; using System.Linq; using System.Text; using NLog; +using NzbDrone.Core.Messaging.Commands; +using NzbDrone.Core.Messaging.Events; using NzbDrone.Core.Tv; namespace NzbDrone.Core.NetImport @@ -13,7 +15,7 @@ namespace NzbDrone.Core.NetImport List FetchAndFilter(int listId, bool onlyEnableAuto); } - public class NetImportSearchService : IFetchNetImport + public class NetImportSearchService : IFetchNetImport, IExecute { private readonly Logger _logger; private readonly INetImportFactory _netImportFactory; @@ -26,39 +28,29 @@ namespace NzbDrone.Core.NetImport _logger = logger; } - public List Fetch(int listId, bool onlyEnableAuto) + public List Fetch(int listId, bool onlyEnableAuto = false) { 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(); + return movies.Where(x => !_movieService.MovieExists(x)).ToList(); } - public List MovieListSearch(int listId, bool onlyEnableAuto) + public List MovieListSearch(int listId, bool onlyEnableAuto = false) { var movies = new List(); var importLists = _netImportFactory.GetAvailableProviders(); - 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 : importLists.Where(n => ((NetImportDefinition)n.Definition).Id == listId); if (onlyEnableAuto) { - lists = importLists.Where(a => a.EnableAuto == true); + lists = importLists.Where(a => ((NetImportDefinition)a.Definition).EnableAuto); } foreach (var list in lists) @@ -66,7 +58,16 @@ namespace NzbDrone.Core.NetImport movies.AddRange(list.Fetch()); } + _logger.Debug("Found {0} movies from list(s) {1}", movies.Count, string.Join(", ", lists.Select(l => l.Definition.Name))); + return movies; } + + public void Execute(NetImportSyncCommand message) + { + var movies = FetchAndFilter(2, false); + + _logger.Debug("Found {0} movies on your lists not in your library", movies.Count); + } } } diff --git a/src/NzbDrone.Core/NetImport/NetImportSyncCommand.cs b/src/NzbDrone.Core/NetImport/NetImportSyncCommand.cs new file mode 100644 index 000000000..67d258fc6 --- /dev/null +++ b/src/NzbDrone.Core/NetImport/NetImportSyncCommand.cs @@ -0,0 +1,12 @@ +using NzbDrone.Core.Messaging.Commands; + +namespace NzbDrone.Core.NetImport +{ + public class NetImportSyncCommand : Command + { + + public override bool SendUpdatesToClient => true; + + public int listId = 0; + } +} \ No newline at end of file diff --git a/src/NzbDrone.Core/NzbDrone.Core.csproj b/src/NzbDrone.Core/NzbDrone.Core.csproj index 120818218..704687008 100644 --- a/src/NzbDrone.Core/NzbDrone.Core.csproj +++ b/src/NzbDrone.Core/NzbDrone.Core.csproj @@ -886,6 +886,7 @@ + diff --git a/src/NzbDrone.Core/Tv/MovieRepository.cs b/src/NzbDrone.Core/Tv/MovieRepository.cs index d0c86f7aa..e9cd70af7 100644 --- a/src/NzbDrone.Core/Tv/MovieRepository.cs +++ b/src/NzbDrone.Core/Tv/MovieRepository.cs @@ -15,6 +15,7 @@ namespace NzbDrone.Core.Tv Movie FindByTitle(string cleanTitle); Movie FindByTitle(string cleanTitle, int year); Movie FindByImdbId(string imdbid); + Movie FindByTmdbId(int tmdbid); Movie FindByTitleSlug(string slug); List MoviesBetweenDates(DateTime start, DateTime end, bool includeUnmonitored); List MoviesWithFiles(int movieId); @@ -100,9 +101,46 @@ namespace NzbDrone.Core.Tv { cleanTitle = cleanTitle.ToLowerInvariant(); - return Query.Where(s => s.CleanTitle == cleanTitle) - .AndWhere(s => s.Year == year) - .SingleOrDefault(); + var cleanRoman = cleanTitle; + + var cleanNum = cleanTitle; + + foreach (KeyValuePair entry in romanNumeralsMapper) + { + string num = entry.Key; + string roman = entry.Value.ToLower(); + + cleanRoman = cleanRoman.Replace(num, roman); + + cleanNum = cleanNum.Replace(roman, num); + } + + var results = Query.Where(s => s.CleanTitle == cleanTitle); + + if (results == null) + { + results = Query.Where(s => s.CleanTitle == cleanNum).OrWhere(s => s.CleanTitle == cleanRoman); + + if (results == null) + { + var movies = this.All(); + + var listResults = movies.Where(m => m.AlternativeTitles.Any(t => Parser.Parser.CleanSeriesTitle(t.ToLower()) == cleanTitle || + Parser.Parser.CleanSeriesTitle(t.ToLower()) == cleanRoman || + Parser.Parser.CleanSeriesTitle(t.ToLower()) == cleanNum)); + + return listResults.Where(m => m.Year == year).FirstOrDefault(); + } + else + { + return results.Where(m => m.Year == year).FirstOrDefault(); + } + + } + else + { + return results.Where(m => m.Year == year).FirstOrDefault(); + } } public Movie FindByImdbId(string imdbid) @@ -122,7 +160,7 @@ namespace NzbDrone.Core.Tv public Movie FindByTitleSlug(string slug) { - return Query.Where(m => m.TitleSlug == slug).FirstOrDefault(); + return Query.FirstOrDefault(m => m.TitleSlug == slug); } public List MoviesBetweenDates(DateTime start, DateTime end, bool includeUnmonitored) @@ -161,5 +199,10 @@ namespace NzbDrone.Core.Tv .Skip(pagingSpec.PagingOffset()) .Take(pagingSpec.PageSize); } + + public Movie FindByTmdbId(int tmdbid) + { + return Query.Where(m => m.TmdbId == tmdbid).FirstOrDefault(); + } } } \ No newline at end of file diff --git a/src/NzbDrone.Core/Tv/MovieService.cs b/src/NzbDrone.Core/Tv/MovieService.cs index 24e1d19dd..03ba48e4f 100644 --- a/src/NzbDrone.Core/Tv/MovieService.cs +++ b/src/NzbDrone.Core/Tv/MovieService.cs @@ -26,6 +26,7 @@ namespace NzbDrone.Core.Tv Movie FindByTitle(string title, int year); Movie FindByTitleInexact(string title); Movie FindByTitleSlug(string slug); + bool MovieExists(Movie movie); Movie GetMovieByFileId(int fileId); List GetMoviesBetweenDates(DateTime start, DateTime end, bool includeUnmonitored); PagingSpec MoviesWithoutFiles(PagingSpec pagingSpec); @@ -247,5 +248,39 @@ namespace NzbDrone.Core.Tv return movieResult; } + + public bool MovieExists(Movie movie) + { + Movie result = null; + + if (movie.TmdbId != 0) + { + result = _movieRepository.FindByTmdbId(movie.TmdbId); + if (result != null) + { + return true; + } + } + + if (movie.ImdbId.IsNotNullOrWhiteSpace()) + { + result = _movieRepository.FindByImdbId(movie.ImdbId); + if (result != null) + { + return true; + } + } + + if (movie.Year > 1850) + { + result = _movieRepository.FindByTitle(movie.Title.CleanSeriesTitle(), movie.Year); + if (result != null) + { + return true; + } + } + + return false; + } } }