2017-01-03 10:59:03 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using NLog;
|
|
|
|
|
using NzbDrone.Common.Instrumentation.Extensions;
|
|
|
|
|
using NzbDrone.Core.Download;
|
|
|
|
|
using NzbDrone.Core.Messaging.Commands;
|
|
|
|
|
using NzbDrone.Core.Tv;
|
2017-01-21 21:43:58 +00:00
|
|
|
|
using NzbDrone.Core.Datastore;
|
2017-01-03 10:59:03 +00:00
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.IndexerSearch
|
|
|
|
|
{
|
2017-01-21 21:43:58 +00:00
|
|
|
|
public class MovieSearchService : IExecute<MoviesSearchCommand>, IExecute<MissingMoviesSearchCommand>
|
2017-01-03 10:59:03 +00:00
|
|
|
|
{
|
2017-01-21 21:43:58 +00:00
|
|
|
|
private readonly IMovieService _movieService;
|
2017-01-03 10:59:03 +00:00
|
|
|
|
private readonly ISearchForNzb _nzbSearchService;
|
|
|
|
|
private readonly IProcessDownloadDecisions _processDownloadDecisions;
|
|
|
|
|
private readonly Logger _logger;
|
|
|
|
|
|
2017-01-21 21:43:58 +00:00
|
|
|
|
public MovieSearchService(IMovieService movieService,
|
2017-01-03 10:59:03 +00:00
|
|
|
|
ISearchForNzb nzbSearchService,
|
|
|
|
|
IProcessDownloadDecisions processDownloadDecisions,
|
|
|
|
|
Logger logger)
|
|
|
|
|
{
|
2017-01-21 21:43:58 +00:00
|
|
|
|
_movieService = movieService;
|
2017-01-03 10:59:03 +00:00
|
|
|
|
_nzbSearchService = nzbSearchService;
|
|
|
|
|
_processDownloadDecisions = processDownloadDecisions;
|
|
|
|
|
_logger = logger;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Execute(MoviesSearchCommand message)
|
|
|
|
|
{
|
|
|
|
|
var downloadedCount = 0;
|
2017-01-21 21:43:58 +00:00
|
|
|
|
foreach (var movieId in message.MovieIds)
|
|
|
|
|
{
|
|
|
|
|
var series = _movieService.GetMovie(movieId);
|
|
|
|
|
|
2017-01-03 10:59:03 +00:00
|
|
|
|
if (!series.Monitored)
|
|
|
|
|
{
|
|
|
|
|
_logger.Debug("Movie {0} is not monitored, skipping search", series.Title);
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-21 21:43:58 +00:00
|
|
|
|
var decisions = _nzbSearchService.MovieSearch(movieId, false);//_nzbSearchService.SeasonSearch(message.MovieId, season.SeasonNumber, false, message.Trigger == CommandTrigger.Manual);
|
2017-01-03 10:59:03 +00:00
|
|
|
|
downloadedCount += _processDownloadDecisions.ProcessDecisions(decisions).Grabbed.Count;
|
|
|
|
|
|
2017-01-21 21:43:58 +00:00
|
|
|
|
}
|
2017-01-03 10:59:03 +00:00
|
|
|
|
_logger.ProgressInfo("Movie search completed. {0} reports downloaded.", downloadedCount);
|
|
|
|
|
}
|
2017-01-21 21:43:58 +00:00
|
|
|
|
|
|
|
|
|
public void Execute(MissingMoviesSearchCommand message)
|
|
|
|
|
{
|
|
|
|
|
var movies = _movieService.MoviesWithoutFiles(new PagingSpec<Movie>
|
|
|
|
|
{
|
|
|
|
|
Page = 1,
|
|
|
|
|
PageSize = 100000,
|
|
|
|
|
SortDirection = SortDirection.Ascending,
|
|
|
|
|
SortKey = "Id",
|
|
|
|
|
FilterExpression =
|
|
|
|
|
v =>
|
|
|
|
|
v.Monitored == true
|
|
|
|
|
}).Records.ToList();
|
|
|
|
|
}
|
2017-01-03 10:59:03 +00:00
|
|
|
|
}
|
|
|
|
|
}
|