|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using NLog;
|
|
|
|
|
using NzbDrone.Common.Messaging;
|
|
|
|
|
using NzbDrone.Core.DecisionEngine;
|
|
|
|
|
using NzbDrone.Core.Download;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Indexers
|
|
|
|
|
{
|
|
|
|
|
public interface IRssSyncService
|
|
|
|
|
{
|
|
|
|
|
void Sync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class RssSyncService : IRssSyncService, IExecute<RssSyncCommand>
|
|
|
|
|
{
|
|
|
|
|
private readonly IFetchAndParseRss _rssFetcherAndParser;
|
|
|
|
|
private readonly IMakeDownloadDecision _downloadDecisionMaker;
|
|
|
|
|
private readonly IDownloadApprovedReportsService _downloadApprovedReportsService;
|
|
|
|
|
private readonly Logger _logger;
|
|
|
|
|
|
|
|
|
|
public RssSyncService(IFetchAndParseRss rssFetcherAndParser,
|
|
|
|
|
IMakeDownloadDecision downloadDecisionMaker,
|
|
|
|
|
IDownloadApprovedReportsService downloadApprovedReportsService,
|
|
|
|
|
Logger logger)
|
|
|
|
|
{
|
|
|
|
|
_rssFetcherAndParser = rssFetcherAndParser;
|
|
|
|
|
_downloadDecisionMaker = downloadDecisionMaker;
|
|
|
|
|
_downloadApprovedReportsService = downloadApprovedReportsService;
|
|
|
|
|
_logger = logger;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void Sync()
|
|
|
|
|
{
|
|
|
|
|
_logger.Info("Starting RSS Sync");
|
|
|
|
|
|
|
|
|
|
var reports = _rssFetcherAndParser.Fetch();
|
|
|
|
|
var decisions = _downloadDecisionMaker.GetRssDecision(reports);
|
|
|
|
|
var qualifiedReports = _downloadApprovedReportsService.DownloadApproved(decisions);
|
|
|
|
|
|
|
|
|
|
_logger.Info("RSS Sync Completed. Reports found: {0}, Fetches attempted: {1}", reports.Count, qualifiedReports.Count());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Execute(RssSyncCommand message)
|
|
|
|
|
{
|
|
|
|
|
Sync();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|