From 6f46a1211e529ae1243b327f6a9013e34beca1f9 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Tue, 26 Apr 2011 23:27:15 -0700 Subject: [PATCH] Added DownloadFile method to HttpProvider. Fixed Link that is returned from NzbMatrixProvider.NzbDownloadUrl. IndexerProvider will now download the NZB to the disk if SABnzbd is not configured. --- NzbDrone.Core/Providers/Core/HttpProvider.cs | 16 +++++++++++++- .../Providers/Indexer/IndexerProviderBase.cs | 21 +++++++++++++++---- .../Providers/Indexer/NzbMatrixProvider.cs | 2 +- 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/NzbDrone.Core/Providers/Core/HttpProvider.cs b/NzbDrone.Core/Providers/Core/HttpProvider.cs index 6e440632d..55a8485a6 100644 --- a/NzbDrone.Core/Providers/Core/HttpProvider.cs +++ b/NzbDrone.Core/Providers/Core/HttpProvider.cs @@ -50,6 +50,20 @@ public virtual Stream DownloadStream(string url, NetworkCredential credential) return response.GetResponseStream(); } - + public virtual bool DownloadFile(string address, string fileName) + { + try + { + var webClient = new WebClient(); + webClient.DownloadFile(address, fileName); + return true; + } + catch (Exception ex) + { + Logger.Warn("Failed to get response from: {0}", address); + Logger.TraceException(ex.Message, ex); + return false; + } + } } } \ No newline at end of file diff --git a/NzbDrone.Core/Providers/Indexer/IndexerProviderBase.cs b/NzbDrone.Core/Providers/Indexer/IndexerProviderBase.cs index 6c7f85a0a..0f391e5f8 100644 --- a/NzbDrone.Core/Providers/Indexer/IndexerProviderBase.cs +++ b/NzbDrone.Core/Providers/Indexer/IndexerProviderBase.cs @@ -154,14 +154,27 @@ internal void ProcessItem(SyndicationItem feedItem) parseResult.EpisodeTitle = episodes[0].Title; var sabTitle = _sabProvider.GetSabTitle(parseResult); - if (_sabProvider.IsInQueue(sabTitle)) + if (Convert.ToBoolean(_configProvider.UseBlackhole)) { - return; + var blackholeDir = _configProvider.BlackholeDirectory; + var folder = !String.IsNullOrEmpty(blackholeDir) ? blackholeDir : Path.Combine(CentralDispatch.AppPath, "App_Data"); + var fileName = Path.Combine(folder, sabTitle + ".nzb"); + _logger.Info("Downloading NZB: {0}", sabTitle); + _httpProvider.DownloadFile(NzbDownloadUrl(feedItem), fileName); } - if (!_sabProvider.AddByUrl(NzbDownloadUrl(feedItem), sabTitle)) + //else send to SAB + else { - return; + if (_sabProvider.IsInQueue(sabTitle)) + { + return; + } + + if (!_sabProvider.AddByUrl(NzbDownloadUrl(feedItem), sabTitle)) + { + return; + } } foreach (var episode in episodes) diff --git a/NzbDrone.Core/Providers/Indexer/NzbMatrixProvider.cs b/NzbDrone.Core/Providers/Indexer/NzbMatrixProvider.cs index 686fbddd1..371f6d479 100644 --- a/NzbDrone.Core/Providers/Indexer/NzbMatrixProvider.cs +++ b/NzbDrone.Core/Providers/Indexer/NzbMatrixProvider.cs @@ -34,7 +34,7 @@ public override string Name protected override string NzbDownloadUrl(SyndicationItem item) { - return item.Links[0].ToString(); + return item.Links[0].Uri.ToString(); } } } \ No newline at end of file