Added SeasonSearchCommand

pull/3113/head
Mark McDowall 12 years ago
parent 7ebcd2b75e
commit 8ee0789c62

@ -19,7 +19,11 @@ namespace NzbDrone.Api.Indexers
private readonly IDownloadService _downloadService;
private readonly IParsingService _parsingService;
public ReleaseModule(IFetchAndParseRss rssFetcherAndParser, ISearchForNzb nzbSearchService, IMakeDownloadDecision downloadDecisionMaker, IDownloadService downloadService, IParsingService parsingService)
public ReleaseModule(IFetchAndParseRss rssFetcherAndParser,
ISearchForNzb nzbSearchService,
IMakeDownloadDecision downloadDecisionMaker,
IDownloadService downloadService,
IParsingService parsingService)
{
_rssFetcherAndParser = rssFetcherAndParser;
_nzbSearchService = nzbSearchService;
@ -40,7 +44,6 @@ namespace NzbDrone.Api.Indexers
return release;
}
private List<ReleaseResource> GetReleases()
{
if (Request.Query.episodeId != null)

@ -0,0 +1,59 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NLog;
using NzbDrone.Core.DecisionEngine;
namespace NzbDrone.Core.Download
{
public interface IDownloadApprovedReportsService
{
List<DownloadDecision> DownloadApproved(List<DownloadDecision> decisions);
}
public class DownloadApprovedReportsService : IDownloadApprovedReportsService
{
private readonly IDownloadService _downloadService;
private readonly Logger _logger;
public DownloadApprovedReportsService(IDownloadService downloadService, Logger logger)
{
_downloadService = downloadService;
_logger = logger;
}
public List<DownloadDecision> DownloadApproved(List<DownloadDecision> decisions)
{
var qualifiedReports = decisions
.Where(c => c.Approved)
.ToList();
var remoteEpisodes = qualifiedReports
.Select(c => c.RemoteEpisode)
.OrderByDescending(c => c.ParsedEpisodeInfo.Quality)
.ThenBy(c => c.Episodes.Select(e => e.EpisodeNumber).MinOrDefault())
.ThenBy(c => c.Report.Age)
.ToList();
var downloadedReports = new List<int>();
foreach (var episodeParseResult in remoteEpisodes)
{
try
{
if (downloadedReports.Intersect(episodeParseResult.Episodes.Select(e => e.Id)).Any()) continue;
_downloadService.DownloadReport(episodeParseResult);
downloadedReports.AddRange(episodeParseResult.Episodes.Select(e => e.Id));
}
catch (Exception e)
{
_logger.WarnException("Couldn't add report to download queue. " + episodeParseResult, e);
}
}
return qualifiedReports;
}
}
}

@ -28,7 +28,13 @@ namespace NzbDrone.Core.IndexerSearch
private readonly IMakeDownloadDecision _makeDownloadDecision;
private readonly Logger _logger;
public NzbSearchService(IIndexerService indexerService, IFetchFeedFromIndexers feedFetcher, ISceneMappingService sceneMapping, ISeriesService seriesService, IEpisodeService episodeService, IMakeDownloadDecision makeDownloadDecision, Logger logger)
public NzbSearchService(IIndexerService indexerService,
IFetchFeedFromIndexers feedFetcher,
ISceneMappingService sceneMapping,
ISeriesService seriesService,
IEpisodeService episodeService,
IMakeDownloadDecision makeDownloadDecision,
Logger logger)
{
_indexerService = indexerService;
_feedFetcher = feedFetcher;
@ -39,8 +45,6 @@ namespace NzbDrone.Core.IndexerSearch
_logger = logger;
}
public List<DownloadDecision> EpisodeSearch(int episodeId)
{
var episode = _episodeService.GetEpisode(episodeId);
@ -54,7 +58,6 @@ namespace NzbDrone.Core.IndexerSearch
return SearchSingle(episode.SeriesId, episode.SeasonNumber, episode.EpisodeNumber);
}
private List<DownloadDecision> SearchSingle(int seriesId, int seasonNumber, int episodeNumber)
{
var searchSpec = Get<SingleEpisodeSearchCriteria>(seriesId, seasonNumber);

@ -0,0 +1,10 @@
using NzbDrone.Common.Messaging;
namespace NzbDrone.Core.IndexerSearch
{
public class SeasonSearchCommand : ICommand
{
public int SeriesId { get; set; }
public int SeasonNumber { get; set; }
}
}

@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NzbDrone.Common.Messaging;
using NzbDrone.Core.Download;
namespace NzbDrone.Core.IndexerSearch
{
public class SeasonSearchService : IExecute<SeasonSearchCommand>
{
private readonly ISearchForNzb _nzbSearchService;
private readonly IDownloadApprovedReportsService _downloadApprovedReportsService;
public SeasonSearchService(ISearchForNzb nzbSearchService, IDownloadApprovedReportsService downloadApprovedReportsService)
{
_nzbSearchService = nzbSearchService;
_downloadApprovedReportsService = downloadApprovedReportsService;
}
public void Execute(SeasonSearchCommand message)
{
var decisions = _nzbSearchService.SeasonSearch(message.SeriesId, message.SeasonNumber);
var qualified = _downloadApprovedReportsService.DownloadApproved(decisions);
}
}
}

@ -17,14 +17,17 @@ namespace NzbDrone.Core.Indexers
{
private readonly IFetchAndParseRss _rssFetcherAndParser;
private readonly IMakeDownloadDecision _downloadDecisionMaker;
private readonly IDownloadService _downloadService;
private readonly IDownloadApprovedReportsService _downloadApprovedReportsService;
private readonly Logger _logger;
public RssSyncService(IFetchAndParseRss rssFetcherAndParser, IMakeDownloadDecision downloadDecisionMaker, IDownloadService downloadService, Logger logger)
public RssSyncService(IFetchAndParseRss rssFetcherAndParser,
IMakeDownloadDecision downloadDecisionMaker,
IDownloadApprovedReportsService downloadApprovedReportsService,
Logger logger)
{
_rssFetcherAndParser = rssFetcherAndParser;
_downloadDecisionMaker = downloadDecisionMaker;
_downloadService = downloadService;
_downloadApprovedReportsService = downloadApprovedReportsService;
_logger = logger;
}
@ -35,30 +38,7 @@ namespace NzbDrone.Core.Indexers
var reports = _rssFetcherAndParser.Fetch();
var decisions = _downloadDecisionMaker.GetRssDecision(reports);
var qualifiedReports = decisions
.Where(c => c.Approved)
.Select(c => c.RemoteEpisode)
.OrderByDescending(c => c.ParsedEpisodeInfo.Quality)
.ThenBy(c => c.Episodes.Select(e => e.EpisodeNumber).MinOrDefault())
.ThenBy(c => c.Report.Age);
var downloadedReports = new List<int>();
foreach (var episodeParseResult in qualifiedReports)
{
try
{
if (downloadedReports.Intersect(episodeParseResult.Episodes.Select(e => e.Id)).Any()) continue;
_downloadService.DownloadReport(episodeParseResult);
downloadedReports.AddRange(episodeParseResult.Episodes.Select(e => e.Id));
}
catch (Exception e)
{
_logger.WarnException("Couldn't add report to download queue. " + episodeParseResult, e);
}
}
var qualifiedReports = _downloadApprovedReportsService.DownloadApproved(decisions);
_logger.Info("RSS Sync Completed. Reports found: {0}, Fetches attempted: {1}", reports.Count, qualifiedReports.Count());
}

Loading…
Cancel
Save