1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-16 11:37:58 +02:00
Sonarr/NzbDrone.Core/IndexerSearch/SeriesSearchService.cs
2013-09-12 15:42:01 -07:00

47 lines
1.7 KiB
C#

using System.Linq;
using NLog;
using NzbDrone.Core.Download;
using NzbDrone.Core.Instrumentation;
using NzbDrone.Core.Messaging;
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;
private readonly Logger _logger;
public SeriesSearchService(ISeasonService seasonService,
ISearchForNzb nzbSearchService,
IDownloadApprovedReports downloadApprovedReports,
Logger logger)
{
_seasonService = seasonService;
_nzbSearchService = nzbSearchService;
_downloadApprovedReports = downloadApprovedReports;
_logger = logger;
}
public void Execute(SeriesSearchCommand message)
{
var seasons = _seasonService.GetSeasonsBySeries(message.SeriesId)
.Where(s => s.SeasonNumber > 0)
.OrderBy(s => s.SeasonNumber)
.ToList();
var downloadedCount = 0;
foreach (var season in seasons)
{
var decisions = _nzbSearchService.SeasonSearch(message.SeriesId, season.SeasonNumber);
downloadedCount += _downloadApprovedReports.DownloadApproved(decisions).Count;
}
_logger.ProgressInfo("Series search completed. {0} reports downloaded.", downloadedCount);
}
}
}