1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-16 11:37:58 +02:00
Sonarr/NzbDrone.Core/Download/DownloadService.cs

46 lines
1.3 KiB
C#
Raw Normal View History

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