From aab425ee5bc53f9bf2d2be2b3471abbbb1ced3dd Mon Sep 17 00:00:00 2001 From: Devin Buhl Date: Fri, 3 Mar 2017 21:32:52 -0500 Subject: [PATCH] Patch/onedr0p updates (#998) * few small things * update var names * Validate Root Folder, Minimum Avability and ProfileId on List import. --- src/NzbDrone.Api/NetImport/NetImportModule.cs | 13 +- src/NzbDrone.Api/ProviderModuleBase.cs | 2 +- .../MissingMoviesSearchCommand.cs | 4 - .../IndexerSearch/MoviesSearchService.cs | 158 +++++++++--------- .../MediaFiles/MediaFileService.cs | 14 +- .../Edit/NetImportEditViewTemplate.hbs | 10 +- src/UI/Wanted/Cutoff/CutoffUnmetLayout.js | 7 +- 7 files changed, 109 insertions(+), 99 deletions(-) diff --git a/src/NzbDrone.Api/NetImport/NetImportModule.cs b/src/NzbDrone.Api/NetImport/NetImportModule.cs index e29ef59c0..0a92184e3 100644 --- a/src/NzbDrone.Api/NetImport/NetImportModule.cs +++ b/src/NzbDrone.Api/NetImport/NetImportModule.cs @@ -1,16 +1,17 @@ -using NzbDrone.Api.ClientSchema; +using FluentValidation; +using NzbDrone.Api.ClientSchema; using NzbDrone.Core.NetImport; -using NzbDrone.Core.Profiles; +using NzbDrone.Core.Validation.Paths; namespace NzbDrone.Api.NetImport { public class NetImportModule : ProviderModuleBase { - private readonly IProfileService _profileService; - public NetImportModule(NetImportFactory indexerFactory, IProfileService profileService) - : base(indexerFactory, "netimport") + public NetImportModule(NetImportFactory netImportFactory) : base(netImportFactory, "netimport") { - _profileService = profileService; + PostValidator.RuleFor(c => c.RootFolderPath).NotNull(); + PostValidator.RuleFor(c => c.MinimumAvailability).NotNull(); + PostValidator.RuleFor(c => c.ProfileId).NotNull(); } protected override void MapToResource(NetImportResource resource, NetImportDefinition definition) diff --git a/src/NzbDrone.Api/ProviderModuleBase.cs b/src/NzbDrone.Api/ProviderModuleBase.cs index b45727227..c62e55d21 100644 --- a/src/NzbDrone.Api/ProviderModuleBase.cs +++ b/src/NzbDrone.Api/ProviderModuleBase.cs @@ -119,7 +119,7 @@ namespace NzbDrone.Api resource.Fields = SchemaBuilder.ToSchema(definition.Settings); - resource.InfoLink = string.Format("https://github.com/Sonarr/Sonarr/wiki/Supported-{0}#{1}", + resource.InfoLink = string.Format("https://github.com/Radarr/Radarr/wiki/Supported-{0}#{1}", typeof(TProviderResource).Name.Replace("Resource", "s"), definition.Implementation.ToLower()); } diff --git a/src/NzbDrone.Core/IndexerSearch/MissingMoviesSearchCommand.cs b/src/NzbDrone.Core/IndexerSearch/MissingMoviesSearchCommand.cs index 55fdd1a59..f6f15610b 100644 --- a/src/NzbDrone.Core/IndexerSearch/MissingMoviesSearchCommand.cs +++ b/src/NzbDrone.Core/IndexerSearch/MissingMoviesSearchCommand.cs @@ -1,8 +1,4 @@ using NzbDrone.Core.Messaging.Commands; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; namespace NzbDrone.Core.IndexerSearch { diff --git a/src/NzbDrone.Core/IndexerSearch/MoviesSearchService.cs b/src/NzbDrone.Core/IndexerSearch/MoviesSearchService.cs index a938cc4e4..e771f5ff6 100644 --- a/src/NzbDrone.Core/IndexerSearch/MoviesSearchService.cs +++ b/src/NzbDrone.Core/IndexerSearch/MoviesSearchService.cs @@ -1,41 +1,79 @@ -using System; -using System.Linq; -using System.Collections.Generic; -using NLog; -using NzbDrone.Common.Instrumentation.Extensions; -using NzbDrone.Core.Download; -using NzbDrone.Core.Messaging.Commands; -using NzbDrone.Core.Tv; -using NzbDrone.Core.Datastore; -using NzbDrone.Core.Queue; -using NzbDrone.Core.DecisionEngine; - -namespace NzbDrone.Core.IndexerSearch -{ - public class MovieSearchService : IExecute, IExecute - { - private readonly IMovieService _movieService; - private readonly ISearchForNzb _nzbSearchService; - private readonly IProcessDownloadDecisions _processDownloadDecisions; - private readonly IQueueService _queueService; - private readonly Logger _logger; - - public MovieSearchService(IMovieService movieService, - ISearchForNzb nzbSearchService, - IProcessDownloadDecisions processDownloadDecisions, - IQueueService queueService, - Logger logger) - { - _movieService = movieService; - _nzbSearchService = nzbSearchService; - _processDownloadDecisions = processDownloadDecisions; - _queueService = queueService; - _logger = logger; +using System; +using System.Linq; +using System.Collections.Generic; +using NLog; +using NzbDrone.Common.Instrumentation.Extensions; +using NzbDrone.Core.Download; +using NzbDrone.Core.Messaging.Commands; +using NzbDrone.Core.Tv; +using NzbDrone.Core.Datastore; +using NzbDrone.Core.Queue; +using NzbDrone.Core.DecisionEngine; + +namespace NzbDrone.Core.IndexerSearch +{ + public class MovieSearchService : IExecute, IExecute + { + private readonly IMovieService _movieService; + private readonly ISearchForNzb _nzbSearchService; + private readonly IProcessDownloadDecisions _processDownloadDecisions; + private readonly IQueueService _queueService; + private readonly Logger _logger; + + public MovieSearchService(IMovieService movieService, + ISearchForNzb nzbSearchService, + IProcessDownloadDecisions processDownloadDecisions, + IQueueService queueService, + Logger logger) + { + _movieService = movieService; + _nzbSearchService = nzbSearchService; + _processDownloadDecisions = processDownloadDecisions; + _queueService = queueService; + _logger = logger; + } + + public void Execute(MoviesSearchCommand message) + { + var downloadedCount = 0; + foreach (var movieId in message.MovieIds) + { + var movies = _movieService.GetMovie(movieId); + + if (!movies.Monitored) + { + _logger.Debug("Movie {0} is not monitored, skipping search", movies.Title); + } + + 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); } - private void SearchForMissingMovies(List movies, bool userInvokedSearch) + public void Execute(MissingMoviesSearchCommand message) { - _logger.ProgressInfo("Performing missing search for {0} movies", movies.Count); + List movies = _movieService.MoviesWithoutFiles(new PagingSpec + { + Page = 1, + PageSize = 100000, + SortDirection = SortDirection.Ascending, + SortKey = "Id", + FilterExpression = _movieService.ConstructFilterExpression(message.FilterKey, message.FilterValue) + }).Records.ToList(); + + + var queue = _queueService.GetQueue().Select(q => q.Movie.Id); + var missing = movies.Where(e => !queue.Contains(e.Id)).ToList(); + + SearchForMissingMovies(missing, message.Trigger == CommandTrigger.Manual); + + } + + private void SearchForMissingMovies(List movies, bool userInvokedSearch) + { + _logger.ProgressInfo("Performing missing search for {0} movies", movies.Count); var downloadedCount = 0; foreach (var movieId in movies.GroupBy(e => e.Id)) @@ -59,47 +97,9 @@ namespace NzbDrone.Core.IndexerSearch } _logger.ProgressInfo("Completed missing search for {0} movies. {1} reports downloaded.", movies.Count, downloadedCount); - } - - public void Execute(MoviesSearchCommand message) - { - 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(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) - { - List movies; - - movies = _movieService.MoviesWithoutFiles(new PagingSpec - { - Page = 1, - PageSize = 100000, - SortDirection = SortDirection.Ascending, - SortKey = "Id", - FilterExpression = _movieService.ConstructFilterExpression(message.FilterKey, message.FilterValue) - }).Records.ToList(); - - - var queue = _queueService.GetQueue().Select(q => q.Movie.Id); - var missing = movies.Where(e => !queue.Contains(e.Id)).ToList(); - - SearchForMissingMovies(missing, message.Trigger == CommandTrigger.Manual); - - } - - } -} + } + + + + } +} diff --git a/src/NzbDrone.Core/MediaFiles/MediaFileService.cs b/src/NzbDrone.Core/MediaFiles/MediaFileService.cs index 2bf40995f..52c327757 100644 --- a/src/NzbDrone.Core/MediaFiles/MediaFileService.cs +++ b/src/NzbDrone.Core/MediaFiles/MediaFileService.cs @@ -74,14 +74,14 @@ namespace NzbDrone.Core.MediaFiles _eventAggregator.PublishEvent(new EpisodeFileDeletedEvent(episodeFile, reason)); } - public void Delete(MovieFile episodeFile, DeleteMediaFileReason reason) + public void Delete(MovieFile movieFile, DeleteMediaFileReason reason) { //Little hack so we have the episodes and series attached for the event consumers - episodeFile.Movie.LazyLoad(); - episodeFile.Path = Path.Combine(episodeFile.Movie.Value.Path, episodeFile.RelativePath); + movieFile.Movie.LazyLoad(); + movieFile.Path = Path.Combine(movieFile.Movie.Value.Path, movieFile.RelativePath); - _movieFileRepository.Delete(episodeFile); - _eventAggregator.PublishEvent(new MovieFileDeletedEvent(episodeFile, reason)); + _movieFileRepository.Delete(movieFile); + _eventAggregator.PublishEvent(new MovieFileDeletedEvent(movieFile, reason)); } public List GetFilesBySeries(int seriesId) @@ -153,9 +153,9 @@ namespace NzbDrone.Core.MediaFiles return addedFile; } - public void Update(MovieFile episodeFile) + public void Update(MovieFile movieFile) { - _movieFileRepository.Update(episodeFile); + _movieFileRepository.Update(movieFile); } public MovieFile GetMovie(int id) diff --git a/src/UI/Settings/NetImport/Edit/NetImportEditViewTemplate.hbs b/src/UI/Settings/NetImport/Edit/NetImportEditViewTemplate.hbs index e0534295b..e28717312 100644 --- a/src/UI/Settings/NetImport/Edit/NetImportEditViewTemplate.hbs +++ b/src/UI/Settings/NetImport/Edit/NetImportEditViewTemplate.hbs @@ -89,7 +89,15 @@
- {{> RootFolderSelectionPartial rootFolders}} +
diff --git a/src/UI/Wanted/Cutoff/CutoffUnmetLayout.js b/src/UI/Wanted/Cutoff/CutoffUnmetLayout.js index 036cb335c..e326c514d 100644 --- a/src/UI/Wanted/Cutoff/CutoffUnmetLayout.js +++ b/src/UI/Wanted/Cutoff/CutoffUnmetLayout.js @@ -103,7 +103,7 @@ module.exports = Marionette.Layout.extend({ icon : 'icon-sonarr-search', callback : this._searchMissing, ownerContext : this, - className : 'x-search-missing' + className : 'x-search-cutoff' }, ] }; @@ -182,6 +182,11 @@ module.exports = Marionette.Layout.extend({ name : 'moviesSearch' } }); + + CommandController.bindToCommand({ + element : this.$('.x-search-cutoff'), + command : { name : 'missingMoviesSearch' } + }); }, _setFilter : function(buttonContext) {