diff --git a/src/NzbDrone.Core/Download/Clients/BlackholeProvider.cs b/src/NzbDrone.Core/Download/Clients/BlackholeProvider.cs index 1598ee647..2fe37fe78 100644 --- a/src/NzbDrone.Core/Download/Clients/BlackholeProvider.cs +++ b/src/NzbDrone.Core/Download/Clients/BlackholeProvider.cs @@ -22,7 +22,7 @@ public BlackholeProvider(IConfigService configService, IHttpProvider httpProvide _logger = logger; } - public void DownloadNzb(RemoteEpisode remoteEpisode) + public string DownloadNzb(RemoteEpisode remoteEpisode) { var url = remoteEpisode.Release.DownloadUrl; var title = remoteEpisode.Release.Title; @@ -34,8 +34,9 @@ public void DownloadNzb(RemoteEpisode remoteEpisode) _logger.Trace("Downloading NZB from: {0} to: {1}", url, filename); _httpProvider.DownloadFile(url, filename); - _logger.Trace("NZB Download succeeded, saved to: {0}", filename); + + return null; } public bool IsConfigured diff --git a/src/NzbDrone.Core/Download/Clients/Nzbget/NzbgetClient.cs b/src/NzbDrone.Core/Download/Clients/Nzbget/NzbgetClient.cs index f3d692d32..9e1d7d7b4 100644 --- a/src/NzbDrone.Core/Download/Clients/Nzbget/NzbgetClient.cs +++ b/src/NzbDrone.Core/Download/Clients/Nzbget/NzbgetClient.cs @@ -24,7 +24,7 @@ public NzbgetClient(IConfigService configService, IHttpProvider httpProvider, IP _logger = logger; } - public void DownloadNzb(RemoteEpisode remoteEpisode) + public string DownloadNzb(RemoteEpisode remoteEpisode) { var url = remoteEpisode.Release.DownloadUrl; var title = remoteEpisode.Release.Title + ".nzb"; @@ -46,6 +46,7 @@ public void DownloadNzb(RemoteEpisode remoteEpisode) var success = Json.Deserialize(response).Result; _logger.Debug("Queue Response: [{0}]", success); + return null; } public bool IsConfigured diff --git a/src/NzbDrone.Core/Download/Clients/PneumaticClient.cs b/src/NzbDrone.Core/Download/Clients/PneumaticClient.cs index 537683243..3cef9b226 100644 --- a/src/NzbDrone.Core/Download/Clients/PneumaticClient.cs +++ b/src/NzbDrone.Core/Download/Clients/PneumaticClient.cs @@ -26,7 +26,7 @@ public PneumaticClient(IConfigService configService, IHttpProvider httpProvider, _diskProvider = diskProvider; } - public void DownloadNzb(RemoteEpisode remoteEpisode) + public string DownloadNzb(RemoteEpisode remoteEpisode) { var url = remoteEpisode.Release.DownloadUrl; var title = remoteEpisode.Release.Title; @@ -41,8 +41,6 @@ public void DownloadNzb(RemoteEpisode remoteEpisode) //Save to the Pneumatic directory (The user will need to ensure its accessible by XBMC) var filename = Path.Combine(_configService.PneumaticFolder, title + ".nzb"); - - logger.Trace("Downloading NZB from: {0} to: {1}", url, filename); _httpProvider.DownloadFile(url, filename); @@ -50,6 +48,8 @@ public void DownloadNzb(RemoteEpisode remoteEpisode) var contents = String.Format("plugin://plugin.program.pneumatic/?mode=strm&type=add_file&nzb={0}&nzbname={1}", filename, title); _diskProvider.WriteAllText(Path.Combine(_configService.DownloadedEpisodesFolder, title + ".strm"), contents); + + return null; } public bool IsConfigured diff --git a/src/NzbDrone.Core/Download/Clients/Sabnzbd/SabnzbdClient.cs b/src/NzbDrone.Core/Download/Clients/Sabnzbd/SabnzbdClient.cs index c7ae37e34..0eddaea99 100644 --- a/src/NzbDrone.Core/Download/Clients/Sabnzbd/SabnzbdClient.cs +++ b/src/NzbDrone.Core/Download/Clients/Sabnzbd/SabnzbdClient.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Web; using Newtonsoft.Json.Linq; using NLog; @@ -13,43 +14,6 @@ namespace NzbDrone.Core.Download.Clients.Sabnzbd { - public class SabRequestBuilder - { - private readonly IConfigService _configService; - - public SabRequestBuilder(IConfigService configService) - { - _configService = configService; - } - - public IRestRequest AddToQueueRequest(RemoteEpisode remoteEpisode) - { - string cat = _configService.SabTvCategory; - int priority = (int)_configService.SabRecentTvPriority; - - string name = remoteEpisode.Release.DownloadUrl.Replace("&", "%26"); - string nzbName = HttpUtility.UrlEncode(remoteEpisode.Release.Title); - - string action = string.Format("mode=addurl&name={0}&priority={1}&pp=3&cat={2}&nzbname={3}&output=json", - name, priority, cat, nzbName); - - string request = GetSabRequest(action); - - return new RestRequest(request); - } - - private string GetSabRequest(string action) - { - return string.Format(@"http://{0}:{1}/api?{2}&apikey={3}&ma_username={4}&ma_password={5}", - _configService.SabHost, - _configService.SabPort, - action, - _configService.SabApiKey, - _configService.SabUsername, - _configService.SabPassword); - } - } - public class SabnzbdClient : IDownloadClient { private readonly IConfigService _configService; @@ -74,7 +38,7 @@ public SabnzbdClient(IConfigService configService, _logger = logger; } - public void DownloadNzb(RemoteEpisode remoteEpisode) + public string DownloadNzb(RemoteEpisode remoteEpisode) { var url = remoteEpisode.Release.DownloadUrl; var title = remoteEpisode.Release.Title; @@ -84,9 +48,11 @@ public void DownloadNzb(RemoteEpisode remoteEpisode) using (var nzb = _httpProvider.DownloadStream(url)) { _logger.Info("Adding report [{0}] to the queue.", title); - var response = _sabCommunicationProxy.DownloadNzb(nzb, title, category, priority); + var response = Json.Deserialize(_sabCommunicationProxy.DownloadNzb(nzb, title, category, priority)); - _logger.Debug("Queue Response: [{0}]", response); + _logger.Debug("Queue Response: [{0}]", response.Status); + + return response.Ids.First(); } } diff --git a/src/NzbDrone.Core/Download/DownloadService.cs b/src/NzbDrone.Core/Download/DownloadService.cs index f41acdafa..05dfd4737 100644 --- a/src/NzbDrone.Core/Download/DownloadService.cs +++ b/src/NzbDrone.Core/Download/DownloadService.cs @@ -1,4 +1,5 @@ -using NLog; +using System; +using NLog; using NzbDrone.Common.EnsureThat; using NzbDrone.Core.Instrumentation; using NzbDrone.Core.Messaging.Events; @@ -40,10 +41,17 @@ public void DownloadReport(RemoteEpisode remoteEpisode) return; } - downloadClient.DownloadNzb(remoteEpisode); + var downloadClientId = downloadClient.DownloadNzb(remoteEpisode); + var episodeGrabbedEvent = new EpisodeGrabbedEvent(remoteEpisode); + + if (!String.IsNullOrWhiteSpace(downloadClientId)) + { + episodeGrabbedEvent.DownloadClient = downloadClient.GetType().Name; + episodeGrabbedEvent.DownloadClientId = downloadClientId; + } _logger.ProgressInfo("Report sent to download client. {0}", downloadTitle); - _eventAggregator.PublishEvent(new EpisodeGrabbedEvent(remoteEpisode)); + _eventAggregator.PublishEvent(episodeGrabbedEvent); } } } \ No newline at end of file diff --git a/src/NzbDrone.Core/Download/EpisodeGrabbedEvent.cs b/src/NzbDrone.Core/Download/EpisodeGrabbedEvent.cs index cd6fc46cc..a6a9f0b52 100644 --- a/src/NzbDrone.Core/Download/EpisodeGrabbedEvent.cs +++ b/src/NzbDrone.Core/Download/EpisodeGrabbedEvent.cs @@ -1,4 +1,5 @@ -using NzbDrone.Common.Messaging; +using System; +using NzbDrone.Common.Messaging; using NzbDrone.Core.Parser.Model; namespace NzbDrone.Core.Download @@ -6,6 +7,8 @@ namespace NzbDrone.Core.Download public class EpisodeGrabbedEvent : IEvent { public RemoteEpisode Episode { get; private set; } + public String DownloadClient { get; set; } + public String DownloadClientId { get; set; } public EpisodeGrabbedEvent(RemoteEpisode episode) { diff --git a/src/NzbDrone.Core/Download/IDownloadClient.cs b/src/NzbDrone.Core/Download/IDownloadClient.cs index ce32b62b2..5270b62b4 100644 --- a/src/NzbDrone.Core/Download/IDownloadClient.cs +++ b/src/NzbDrone.Core/Download/IDownloadClient.cs @@ -5,7 +5,7 @@ namespace NzbDrone.Core.Download { public interface IDownloadClient { - void DownloadNzb(RemoteEpisode remoteEpisode); + string DownloadNzb(RemoteEpisode remoteEpisode); bool IsConfigured { get; } IEnumerable GetQueue(); } diff --git a/src/NzbDrone.Core/History/HistoryService.cs b/src/NzbDrone.Core/History/HistoryService.cs index 09b372b2c..568cc3058 100644 --- a/src/NzbDrone.Core/History/HistoryService.cs +++ b/src/NzbDrone.Core/History/HistoryService.cs @@ -75,6 +75,12 @@ public void Handle(EpisodeGrabbedEvent message) history.Data.Add("ReleaseGroup", message.Episode.Release.ReleaseGroup); history.Data.Add("Age", message.Episode.Release.Age.ToString()); + if (!String.IsNullOrWhiteSpace(message.DownloadClientId)) + { + history.Data.Add("DownloadClient", message.DownloadClient); + history.Data.Add("DownloadClientId", message.DownloadClientId); + } + _historyRepository.Insert(history); } }