2013-06-09 13:50:57 -07:00
|
|
|
using NLog;
|
2013-04-23 18:56:00 -07:00
|
|
|
using NzbDrone.Common.Messaging;
|
2013-04-14 18:41:39 -07:00
|
|
|
using NzbDrone.Core.Parser.Model;
|
2013-03-31 23:22:16 -07:00
|
|
|
|
|
|
|
namespace NzbDrone.Core.Download
|
|
|
|
{
|
|
|
|
public interface IDownloadService
|
|
|
|
{
|
2013-06-09 13:50:57 -07:00
|
|
|
bool DownloadReport(RemoteEpisode remoteEpisode);
|
2013-03-31 23:22:16 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public class DownloadService : IDownloadService
|
|
|
|
{
|
|
|
|
private readonly IProvideDownloadClient _downloadClientProvider;
|
2013-04-23 18:56:00 -07:00
|
|
|
private readonly IMessageAggregator _messageAggregator;
|
2013-03-31 23:22:16 -07:00
|
|
|
private readonly Logger _logger;
|
|
|
|
|
|
|
|
|
2013-05-19 16:17:32 -07:00
|
|
|
public DownloadService(IProvideDownloadClient downloadClientProvider,
|
2013-04-23 18:56:00 -07:00
|
|
|
IMessageAggregator messageAggregator, Logger logger)
|
2013-03-31 23:22:16 -07:00
|
|
|
{
|
|
|
|
_downloadClientProvider = downloadClientProvider;
|
2013-04-23 18:56:00 -07:00
|
|
|
_messageAggregator = messageAggregator;
|
2013-03-31 23:22:16 -07:00
|
|
|
_logger = logger;
|
|
|
|
}
|
|
|
|
|
2013-06-09 13:50:57 -07:00
|
|
|
public bool DownloadReport(RemoteEpisode remoteEpisode)
|
2013-03-31 23:22:16 -07:00
|
|
|
{
|
2013-06-09 13:50:57 -07:00
|
|
|
var downloadTitle = remoteEpisode.Report.Title;
|
2013-03-31 23:22:16 -07:00
|
|
|
|
|
|
|
var provider = _downloadClientProvider.GetDownloadClient();
|
|
|
|
|
2013-06-09 13:50:57 -07:00
|
|
|
bool success = provider.DownloadNzb(remoteEpisode.Report.NzbUrl, downloadTitle, remoteEpisode.IsRecentEpisode());
|
2013-03-31 23:22:16 -07:00
|
|
|
|
|
|
|
if (success)
|
|
|
|
{
|
2013-04-07 00:30:37 -07:00
|
|
|
_logger.Info("Report sent to download client. {0}", downloadTitle);
|
2013-06-09 13:50:57 -07:00
|
|
|
_messageAggregator.PublishEvent(new EpisodeGrabbedEvent(remoteEpisode));
|
2013-03-31 23:22:16 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
2013-06-09 13:50:57 -07:00
|
|
|
|
2013-03-31 23:22:16 -07:00
|
|
|
}
|
|
|
|
}
|