From 29ae088a3d312b629d6e637fc531e92175298f91 Mon Sep 17 00:00:00 2001 From: Vlad Ilies Date: Sat, 21 Jan 2017 23:43:58 +0200 Subject: [PATCH] search selected button in wanted tab works * switched MoviesSearchCommand to a list of id's * adapted the MovieSearchService * adapted UI files to use the new command --- .../RedownloadFailedDownloadService.cs | 3 +- .../MissingMoviesSearchCommand.cs | 13 +++++++ .../IndexerSearch/MoviesSearchCommand.cs | 3 +- .../IndexerSearch/MoviesSearchService.cs | 34 ++++++++++++++----- src/NzbDrone.Core/NzbDrone.Core.csproj | 1 + src/NzbDrone.Core/Tv/MovieScannedHandler.cs | 3 +- src/UI/Movies/Details/MoviesDetailsLayout.js | 2 +- src/UI/Wanted/Missing/MissingLayout.js | 16 ++++----- 8 files changed, 54 insertions(+), 21 deletions(-) create mode 100644 src/NzbDrone.Core/IndexerSearch/MissingMoviesSearchCommand.cs diff --git a/src/NzbDrone.Core/Download/RedownloadFailedDownloadService.cs b/src/NzbDrone.Core/Download/RedownloadFailedDownloadService.cs index 0e5b3a13a..f49f3772e 100644 --- a/src/NzbDrone.Core/Download/RedownloadFailedDownloadService.cs +++ b/src/NzbDrone.Core/Download/RedownloadFailedDownloadService.cs @@ -5,6 +5,7 @@ using NzbDrone.Core.IndexerSearch; using NzbDrone.Core.Messaging.Commands; using NzbDrone.Core.Messaging.Events; using NzbDrone.Core.Tv; +using System.Collections.Generic; namespace NzbDrone.Core.Download { @@ -38,7 +39,7 @@ namespace NzbDrone.Core.Download { _logger.Debug("Failed download contains a movie, searching again."); - _commandQueueManager.Push(new MoviesSearchCommand { MovieId = message.MovieId }); + _commandQueueManager.Push(new MoviesSearchCommand { MovieIds = new List { message.MovieId } }); return; } diff --git a/src/NzbDrone.Core/IndexerSearch/MissingMoviesSearchCommand.cs b/src/NzbDrone.Core/IndexerSearch/MissingMoviesSearchCommand.cs new file mode 100644 index 000000000..7c53532c3 --- /dev/null +++ b/src/NzbDrone.Core/IndexerSearch/MissingMoviesSearchCommand.cs @@ -0,0 +1,13 @@ +using NzbDrone.Core.Messaging.Commands; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace NzbDrone.Core.IndexerSearch +{ + public class MissingMoviesSearchCommand : Command + { + public override bool SendUpdatesToClient => true; + } +} diff --git a/src/NzbDrone.Core/IndexerSearch/MoviesSearchCommand.cs b/src/NzbDrone.Core/IndexerSearch/MoviesSearchCommand.cs index da0b9a8c1..214c59d6b 100644 --- a/src/NzbDrone.Core/IndexerSearch/MoviesSearchCommand.cs +++ b/src/NzbDrone.Core/IndexerSearch/MoviesSearchCommand.cs @@ -1,10 +1,11 @@ using NzbDrone.Core.Messaging.Commands; +using System.Collections.Generic; namespace NzbDrone.Core.IndexerSearch { public class MoviesSearchCommand : Command { - public int MovieId { get; set; } + public List MovieIds { get; set; } public override bool SendUpdatesToClient => true; } diff --git a/src/NzbDrone.Core/IndexerSearch/MoviesSearchService.cs b/src/NzbDrone.Core/IndexerSearch/MoviesSearchService.cs index 656423178..5b8e4dd37 100644 --- a/src/NzbDrone.Core/IndexerSearch/MoviesSearchService.cs +++ b/src/NzbDrone.Core/IndexerSearch/MoviesSearchService.cs @@ -4,22 +4,23 @@ using NzbDrone.Common.Instrumentation.Extensions; using NzbDrone.Core.Download; using NzbDrone.Core.Messaging.Commands; using NzbDrone.Core.Tv; +using NzbDrone.Core.Datastore; namespace NzbDrone.Core.IndexerSearch { - public class MovieSearchService : IExecute + public class MovieSearchService : IExecute, IExecute { - private readonly IMovieService _seriesService; + private readonly IMovieService _movieService; private readonly ISearchForNzb _nzbSearchService; private readonly IProcessDownloadDecisions _processDownloadDecisions; private readonly Logger _logger; - public MovieSearchService(IMovieService seriesService, + public MovieSearchService(IMovieService movieService, ISearchForNzb nzbSearchService, IProcessDownloadDecisions processDownloadDecisions, Logger logger) { - _seriesService = seriesService; + _movieService = movieService; _nzbSearchService = nzbSearchService; _processDownloadDecisions = processDownloadDecisions; _logger = logger; @@ -27,20 +28,35 @@ namespace NzbDrone.Core.IndexerSearch public void Execute(MoviesSearchCommand message) { - var series = _seriesService.GetMovie(message.MovieId); - var downloadedCount = 0; - + foreach (var movieId in message.MovieIds) + { + var series = _movieService.GetMovie(movieId); + if (!series.Monitored) { _logger.Debug("Movie {0} is not monitored, skipping search", series.Title); } - var decisions = _nzbSearchService.MovieSearch(message.MovieId, false);//_nzbSearchService.SeasonSearch(message.MovieId, season.SeasonNumber, false, message.Trigger == CommandTrigger.Manual); + var decisions = _nzbSearchService.MovieSearch(movieId, false);//_nzbSearchService.SeasonSearch(message.MovieId, season.SeasonNumber, false, message.Trigger == CommandTrigger.Manual); downloadedCount += _processDownloadDecisions.ProcessDecisions(decisions).Grabbed.Count; - + } _logger.ProgressInfo("Movie search completed. {0} reports downloaded.", downloadedCount); } + + public void Execute(MissingMoviesSearchCommand message) + { + var movies = _movieService.MoviesWithoutFiles(new PagingSpec + { + Page = 1, + PageSize = 100000, + SortDirection = SortDirection.Ascending, + SortKey = "Id", + FilterExpression = + v => + v.Monitored == true + }).Records.ToList(); + } } } diff --git a/src/NzbDrone.Core/NzbDrone.Core.csproj b/src/NzbDrone.Core/NzbDrone.Core.csproj index 1db0a9581..6f7eee5c0 100644 --- a/src/NzbDrone.Core/NzbDrone.Core.csproj +++ b/src/NzbDrone.Core/NzbDrone.Core.csproj @@ -583,6 +583,7 @@ + diff --git a/src/NzbDrone.Core/Tv/MovieScannedHandler.cs b/src/NzbDrone.Core/Tv/MovieScannedHandler.cs index 151ef0559..2eba01239 100644 --- a/src/NzbDrone.Core/Tv/MovieScannedHandler.cs +++ b/src/NzbDrone.Core/Tv/MovieScannedHandler.cs @@ -3,6 +3,7 @@ using NzbDrone.Core.IndexerSearch; using NzbDrone.Core.MediaFiles.Events; using NzbDrone.Core.Messaging.Commands; using NzbDrone.Core.Messaging.Events; +using System.Collections.Generic; namespace NzbDrone.Core.Tv { @@ -37,7 +38,7 @@ namespace NzbDrone.Core.Tv if (movie.AddOptions.SearchForMovie) { - _commandQueueManager.Push(new MoviesSearchCommand { MovieId = movie.Id}); + _commandQueueManager.Push(new MoviesSearchCommand { MovieIds = new List { movie.Id } }); } movie.AddOptions = null; diff --git a/src/UI/Movies/Details/MoviesDetailsLayout.js b/src/UI/Movies/Details/MoviesDetailsLayout.js index 119c6bd71..77f710890 100644 --- a/src/UI/Movies/Details/MoviesDetailsLayout.js +++ b/src/UI/Movies/Details/MoviesDetailsLayout.js @@ -209,7 +209,7 @@ module.exports = Marionette.Layout.extend({ _moviesSearch : function() { CommandController.Execute('moviesSearch', { name : 'moviesSearch', - movieId : this.model.id + movieIds : [this.model.id] }); }, diff --git a/src/UI/Wanted/Missing/MissingLayout.js b/src/UI/Wanted/Missing/MissingLayout.js index b3aa9e378..1a7e6711f 100644 --- a/src/UI/Wanted/Missing/MissingLayout.js +++ b/src/UI/Wanted/Missing/MissingLayout.js @@ -165,11 +165,11 @@ module.exports = Marionette.Layout.extend({ })); CommandController.bindToCommand({ element : this.$('.x-search-selected'), - command : { name : 'episodeSearch' } + command : { name : 'moviesSearch' } }); CommandController.bindToCommand({ element : this.$('.x-search-missing'), - command : { name : 'missingEpisodeSearch' } + command : { name : 'missingMoviesSearch' } }); }, @@ -187,20 +187,20 @@ module.exports = Marionette.Layout.extend({ if (selected.length === 0) { Messenger.show({ type : 'error', - message : 'No episodes selected' + message : 'No movies selected' }); return; } var ids = _.pluck(selected, 'id'); - CommandController.Execute('episodeSearch', { - name : 'episodeSearch', - episodeIds : ids + CommandController.Execute('moviesSearch', { + name : 'moviesSearch', + movieIds : ids }); }, _searchMissing : function() { if (window.confirm('Are you sure you want to search for {0} missing movies? '.format(this.collection.state.totalRecords) + 'One API request to each indexer will be used for each movie. ' + 'This cannot be stopped once started.')) { - CommandController.Execute('missingEpisodeSearch', { name : 'missingEpisodeSearch' }); + CommandController.Execute('missingMoviesSearch', { name : 'missingMoviesSearch' }); } }, _toggleMonitoredOfSelected : function() { @@ -209,7 +209,7 @@ module.exports = Marionette.Layout.extend({ if (selected.length === 0) { Messenger.show({ type : 'error', - message : 'No episodes selected' + message : 'No movies selected' }); return; }