2013-07-22 02:52:53 +00:00
|
|
|
|
using System.Linq;
|
2013-09-04 05:01:28 +00:00
|
|
|
|
using NLog;
|
|
|
|
|
using NzbDrone.Common.Instrumentation;
|
2013-07-22 02:52:53 +00:00
|
|
|
|
using NzbDrone.Core.Download;
|
2013-09-11 06:33:47 +00:00
|
|
|
|
using NzbDrone.Core.Instrumentation;
|
|
|
|
|
using NzbDrone.Core.Messaging;
|
2013-07-22 02:52:53 +00:00
|
|
|
|
using NzbDrone.Core.Tv;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.IndexerSearch
|
|
|
|
|
{
|
|
|
|
|
public class SeriesSearchService : IExecute<SeriesSearchCommand>
|
|
|
|
|
{
|
|
|
|
|
private readonly ISeasonService _seasonService;
|
|
|
|
|
private readonly ISearchForNzb _nzbSearchService;
|
|
|
|
|
private readonly IDownloadApprovedReports _downloadApprovedReports;
|
2013-09-04 05:01:28 +00:00
|
|
|
|
private readonly Logger _logger;
|
2013-07-22 02:52:53 +00:00
|
|
|
|
|
|
|
|
|
public SeriesSearchService(ISeasonService seasonService,
|
|
|
|
|
ISearchForNzb nzbSearchService,
|
2013-09-04 05:01:28 +00:00
|
|
|
|
IDownloadApprovedReports downloadApprovedReports,
|
|
|
|
|
Logger logger)
|
2013-07-22 02:52:53 +00:00
|
|
|
|
{
|
|
|
|
|
_seasonService = seasonService;
|
|
|
|
|
_nzbSearchService = nzbSearchService;
|
|
|
|
|
_downloadApprovedReports = downloadApprovedReports;
|
2013-09-04 05:01:28 +00:00
|
|
|
|
_logger = logger;
|
2013-07-22 02:52:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Execute(SeriesSearchCommand message)
|
|
|
|
|
{
|
|
|
|
|
var seasons = _seasonService.GetSeasonsBySeries(message.SeriesId)
|
|
|
|
|
.Where(s => s.SeasonNumber > 0)
|
|
|
|
|
.OrderBy(s => s.SeasonNumber)
|
|
|
|
|
.ToList();
|
|
|
|
|
|
2013-09-04 05:01:28 +00:00
|
|
|
|
var downloadedCount = 0;
|
|
|
|
|
|
2013-07-22 02:52:53 +00:00
|
|
|
|
foreach (var season in seasons)
|
|
|
|
|
{
|
|
|
|
|
var decisions = _nzbSearchService.SeasonSearch(message.SeriesId, season.SeasonNumber);
|
2013-09-04 05:01:28 +00:00
|
|
|
|
downloadedCount += _downloadApprovedReports.DownloadApproved(decisions).Count;
|
2013-07-22 02:52:53 +00:00
|
|
|
|
}
|
2013-09-04 05:01:28 +00:00
|
|
|
|
|
2013-09-11 06:33:47 +00:00
|
|
|
|
_logger.ProgressInfo("Series search completed. {0} reports downloaded.", downloadedCount);
|
2013-07-22 02:52:53 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|