diff --git a/src/NzbDrone.Core.Test/Download/DownloadClientTests/Blackhole/UsenetBlackholeFixture.cs b/src/NzbDrone.Core.Test/Download/DownloadClientTests/Blackhole/UsenetBlackholeFixture.cs index 0e858be68..f1f224e0a 100644 --- a/src/NzbDrone.Core.Test/Download/DownloadClientTests/Blackhole/UsenetBlackholeFixture.cs +++ b/src/NzbDrone.Core.Test/Download/DownloadClientTests/Blackhole/UsenetBlackholeFixture.cs @@ -1,3 +1,4 @@ +using System; using System.IO; using System.Net; using System.Linq; @@ -35,12 +36,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole }; } - protected void WithSuccessfulDownload() - { - - } - - protected void WithFailedDownload() + protected void GivenFailedDownload() { Mocker.GetMock() .Setup(c => c.DownloadFile(It.IsAny(), It.IsAny())) @@ -110,5 +106,15 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole result.Status.Should().Be(DownloadItemStatus.Downloading); } + + [Test] + public void should_return_status_with_outputdirs() + { + var result = Subject.GetStatus(); + + result.IsLocalhost.Should().BeTrue(); + result.OutputRootFolders.Should().NotBeNull(); + result.OutputRootFolders.First().Should().Be(_completedDownloadFolder); + } } } diff --git a/src/NzbDrone.Core.Test/Download/DownloadClientTests/NzbgetTests/NzbgetFixture.cs b/src/NzbDrone.Core.Test/Download/DownloadClientTests/NzbgetTests/NzbgetFixture.cs index 15e90536a..be5f6e3e7 100644 --- a/src/NzbDrone.Core.Test/Download/DownloadClientTests/NzbgetTests/NzbgetFixture.cs +++ b/src/NzbDrone.Core.Test/Download/DownloadClientTests/NzbgetTests/NzbgetFixture.cs @@ -92,26 +92,26 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.NzbgetTests .Returns(configItems); } - protected void WithMountPoint(String mountPath) + protected void GivenMountPoint(String mountPath) { (Subject.Definition.Settings as NzbgetSettings).TvCategoryLocalPath = mountPath; } - protected void WithFailedDownload() + protected void GivenFailedDownload() { Mocker.GetMock() .Setup(s => s.DownloadNzb(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) .Returns((String)null); } - protected void WithSuccessfulDownload() + protected void GivenSuccessfulDownload() { Mocker.GetMock() .Setup(s => s.DownloadNzb(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) .Returns(Guid.NewGuid().ToString().Replace("-", "")); } - protected virtual void WithQueue(NzbgetQueueItem queue) + protected virtual void GivenQueue(NzbgetQueueItem queue) { var list = new List(); @@ -129,7 +129,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.NzbgetTests .Returns(new List()); } - protected virtual void WithHistory(NzbgetHistoryItem history) + protected virtual void GivenHistory(NzbgetHistoryItem history) { var list = new List(); @@ -146,8 +146,8 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.NzbgetTests [Test] public void GetItems_should_return_no_items_when_queue_is_empty() { - WithQueue(null); - WithHistory(null); + GivenQueue(null); + GivenHistory(null); Subject.GetItems().Should().BeEmpty(); } @@ -157,8 +157,8 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.NzbgetTests { _queued.ActiveDownloads = 0; - WithQueue(_queued); - WithHistory(null); + GivenQueue(_queued); + GivenHistory(null); var result = Subject.GetItems().Single(); @@ -170,8 +170,8 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.NzbgetTests { _queued.PausedSizeLo = _queued.RemainingSizeLo; - WithQueue(_queued); - WithHistory(null); + GivenQueue(_queued); + GivenHistory(null); var result = Subject.GetItems().Single(); @@ -183,8 +183,8 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.NzbgetTests { _queued.ActiveDownloads = 1; - WithQueue(_queued); - WithHistory(null); + GivenQueue(_queued); + GivenHistory(null); var result = Subject.GetItems().Single(); @@ -194,8 +194,8 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.NzbgetTests [Test] public void completed_download_should_have_required_properties() { - WithQueue(null); - WithHistory(_completed); + GivenQueue(null); + GivenHistory(_completed); var result = Subject.GetItems().Single(); @@ -205,8 +205,8 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.NzbgetTests [Test] public void failed_item_should_have_required_properties() { - WithQueue(null); - WithHistory(_failed); + GivenQueue(null); + GivenHistory(_failed); var result = Subject.GetItems().Single(); @@ -216,7 +216,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.NzbgetTests [Test] public void Download_should_return_unique_id() { - WithSuccessfulDownload(); + GivenSuccessfulDownload(); var remoteEpisode = CreateRemoteEpisode(); @@ -230,8 +230,8 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.NzbgetTests { _completed.Category = "mycat"; - WithQueue(null); - WithHistory(_completed); + GivenQueue(null); + GivenHistory(_completed); var items = Subject.GetItems(); @@ -251,7 +251,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.NzbgetTests [Test] public void should_return_status_with_mounted_outputdir() { - WithMountPoint(@"O:\mymount".AsOsAgnostic()); + GivenMountPoint(@"O:\mymount".AsOsAgnostic()); var result = Subject.GetStatus(); @@ -263,10 +263,10 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.NzbgetTests [Test] public void should_remap_storage_if_mounted() { - WithMountPoint(@"O:\mymount".AsOsAgnostic()); + GivenMountPoint(@"O:\mymount".AsOsAgnostic()); - WithQueue(null); - WithHistory(_completed); + GivenQueue(null); + GivenHistory(_completed); var result = Subject.GetItems().Single(); diff --git a/src/NzbDrone.Core.Test/Download/DownloadClientTests/SabnzbdTests/SabnzbdFixture.cs b/src/NzbDrone.Core.Test/Download/DownloadClientTests/SabnzbdTests/SabnzbdFixture.cs index 8e73da554..730ec9ff2 100644 --- a/src/NzbDrone.Core.Test/Download/DownloadClientTests/SabnzbdTests/SabnzbdFixture.cs +++ b/src/NzbDrone.Core.Test/Download/DownloadClientTests/SabnzbdTests/SabnzbdFixture.cs @@ -106,19 +106,19 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.SabnzbdTests .Returns(_config); } - protected void WithMountPoint(String mountPath) + protected void GivenMountPoint(String mountPath) { (Subject.Definition.Settings as SabnzbdSettings).TvCategoryLocalPath = mountPath; } - protected void WithFailedDownload() + protected void GivenFailedDownload() { Mocker.GetMock() .Setup(s => s.DownloadNzb(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) .Returns((SabnzbdAddResponse)null); } - protected void WithSuccessfulDownload() + protected void GivenSuccessfulDownload() { Mocker.GetMock() .Setup(s => s.DownloadNzb(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) @@ -129,7 +129,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.SabnzbdTests }); } - protected virtual void WithQueue(SabnzbdQueue queue) + protected virtual void GivenQueue(SabnzbdQueue queue) { if (queue == null) { @@ -145,7 +145,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.SabnzbdTests .Returns(queue); } - protected virtual void WithHistory(SabnzbdHistory history) + protected virtual void GivenHistory(SabnzbdHistory history) { if (history == null) history = new SabnzbdHistory() { Items = new List() }; @@ -158,8 +158,8 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.SabnzbdTests [Test] public void GetItems_should_return_no_items_when_queue_is_empty() { - WithQueue(null); - WithHistory(null); + GivenQueue(null); + GivenHistory(null); Subject.GetItems().Should().BeEmpty(); } @@ -170,8 +170,8 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.SabnzbdTests { _queued.Items.First().Status = status; - WithQueue(_queued); - WithHistory(null); + GivenQueue(_queued); + GivenHistory(null); var result = Subject.GetItems().Single(); @@ -184,8 +184,8 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.SabnzbdTests { _queued.Items.First().Status = status; - WithQueue(_queued); - WithHistory(null); + GivenQueue(_queued); + GivenHistory(null); var result = Subject.GetItems().Single(); @@ -205,8 +205,8 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.SabnzbdTests { _queued.Items.First().Status = status; - WithQueue(_queued); - WithHistory(null); + GivenQueue(_queued); + GivenHistory(null); var result = Subject.GetItems().Single(); @@ -217,8 +217,8 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.SabnzbdTests [Test] public void completed_download_should_have_required_properties() { - WithQueue(null); - WithHistory(_completed); + GivenQueue(null); + GivenHistory(_completed); var result = Subject.GetItems().Single(); @@ -230,8 +230,8 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.SabnzbdTests { _completed.Items.First().Status = SabnzbdDownloadStatus.Failed; - WithQueue(null); - WithHistory(_completed); + GivenQueue(null); + GivenHistory(_completed); var result = Subject.GetItems().Single(); @@ -241,7 +241,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.SabnzbdTests [Test] public void Download_should_return_unique_id() { - WithSuccessfulDownload(); + GivenSuccessfulDownload(); var remoteEpisode = CreateRemoteEpisode(); @@ -255,8 +255,8 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.SabnzbdTests { _completed.Items.First().Category = "myowncat"; - WithQueue(null); - WithHistory(_completed); + GivenQueue(null); + GivenHistory(_completed); var items = Subject.GetItems(); @@ -292,8 +292,8 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.SabnzbdTests _completed.Items.First().Title = title; _completed.Items.First().Storage = (@"C:\sorted\" + title + @"\" + storage).AsOsAgnostic(); - WithQueue(null); - WithHistory(_completed); + GivenQueue(null); + GivenHistory(_completed); var result = Subject.GetItems().Single(); @@ -303,10 +303,10 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.SabnzbdTests [Test] public void should_remap_storage_if_mounted() { - WithMountPoint(@"O:\mymount".AsOsAgnostic()); + GivenMountPoint(@"O:\mymount".AsOsAgnostic()); - WithQueue(null); - WithHistory(_completed); + GivenQueue(null); + GivenHistory(_completed); var result = Subject.GetItems().Single(); @@ -318,8 +318,8 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.SabnzbdTests { _completed.Items.First().Storage = @"C:\".AsOsAgnostic(); - WithQueue(null); - WithHistory(_completed); + GivenQueue(null); + GivenHistory(_completed); var result = Subject.GetItems().Single(); @@ -331,8 +331,8 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.SabnzbdTests { _completed.Items.First().Storage = @"C:\sorted\somewhere\asdfasdf\asdfasdf.mkv".AsOsAgnostic(); - WithQueue(null); - WithHistory(_completed); + GivenQueue(null); + GivenHistory(_completed); var result = Subject.GetItems().Single(); @@ -349,7 +349,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.SabnzbdTests _config.Misc.complete_dir = completeDir; _config.Categories.First().Dir = categoryDir; - WithQueue(null); + GivenQueue(null); var result = Subject.GetStatus(); @@ -361,9 +361,9 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.SabnzbdTests [Test] public void should_return_status_with_mounted_outputdir() { - WithMountPoint(@"O:\mymount".AsOsAgnostic()); + GivenMountPoint(@"O:\mymount".AsOsAgnostic()); - WithQueue(null); + GivenQueue(null); var result = Subject.GetStatus(); diff --git a/src/NzbDrone.Core.Test/IndexerTests/BasicRssParserFixture.cs b/src/NzbDrone.Core.Test/IndexerTests/BasicRssParserFixture.cs index 30bfeadb0..efdcfab32 100644 --- a/src/NzbDrone.Core.Test/IndexerTests/BasicRssParserFixture.cs +++ b/src/NzbDrone.Core.Test/IndexerTests/BasicRssParserFixture.cs @@ -16,7 +16,7 @@ namespace NzbDrone.Core.Test.IndexerTests [TestCase("845 MB", 886046720)] public void parse_size(string sizeString, long expectedSize) { - var result = RssParserBase.ParseSize(sizeString); + var result = RssParserBase.ParseSize(sizeString, true); result.Should().Be(expectedSize); } diff --git a/src/NzbDrone.Core/Download/Clients/UsenetBlackhole/UsenetBlackhole.cs b/src/NzbDrone.Core/Download/Clients/UsenetBlackhole/UsenetBlackhole.cs index 4e0560764..2a7f20b80 100644 --- a/src/NzbDrone.Core/Download/Clients/UsenetBlackhole/UsenetBlackhole.cs +++ b/src/NzbDrone.Core/Download/Clients/UsenetBlackhole/UsenetBlackhole.cs @@ -1,9 +1,7 @@ using System; -using System.Collections.Generic; using System.IO; using System.Linq; -using FluentValidation.Results; -using NLog; +using System.Collections.Generic; using NzbDrone.Common; using NzbDrone.Common.Disk; using NzbDrone.Common.Http; @@ -13,6 +11,9 @@ using NzbDrone.Core.Organizer; using NzbDrone.Core.Parser; using NzbDrone.Core.Parser.Model; using NzbDrone.Core.MediaFiles; +using NLog; +using Omu.ValueInjecter; +using FluentValidation.Results; namespace NzbDrone.Core.Download.Clients.UsenetBlackhole { @@ -115,6 +116,7 @@ namespace NzbDrone.Core.Download.Clients.UsenetBlackhole else { historyItem.Status = DownloadItemStatus.Completed; + historyItem.RemainingTime = TimeSpan.Zero; } historyItem.RemoteEpisode = GetRemoteEpisode(historyItem.Title); diff --git a/src/NzbDrone.Core/Download/FailedDownloadService.cs b/src/NzbDrone.Core/Download/FailedDownloadService.cs index 775f6f619..29057f183 100644 --- a/src/NzbDrone.Core/Download/FailedDownloadService.cs +++ b/src/NzbDrone.Core/Download/FailedDownloadService.cs @@ -106,8 +106,9 @@ namespace NzbDrone.Core.Download else { //TODO: Make this more configurable (ignore failure reasons) to support changes and other failures that should be ignored - if (trackedDownload.DownloadItem.Message.Equals("Unpacking failed, write error or disk is full?", - StringComparison.InvariantCultureIgnoreCase)) + if (!trackedDownload.DownloadItem.Message.IsNullOrWhiteSpace() && + trackedDownload.DownloadItem.Message.Equals("Unpacking failed, write error or disk is full?", + StringComparison.InvariantCultureIgnoreCase)) { UpdateStatusMessage(trackedDownload, LogLevel.Error, "Download failed due to lack of disk space, not blacklisting."); return; diff --git a/src/NzbDrone.Core/Indexers/Newznab/NewznabParser.cs b/src/NzbDrone.Core/Indexers/Newznab/NewznabParser.cs index cc1919c80..6dae6d50a 100644 --- a/src/NzbDrone.Core/Indexers/Newznab/NewznabParser.cs +++ b/src/NzbDrone.Core/Indexers/Newznab/NewznabParser.cs @@ -45,7 +45,7 @@ namespace NzbDrone.Core.Indexers.Newznab return Convert.ToInt64(sizeElement.Attribute("value").Value); } - return ParseSize(item.Description()); + return ParseSize(item.Description(), true); } public override IEnumerable Process(string xml, string url) diff --git a/src/NzbDrone.Core/Indexers/Omgwtfnzbs/OmgwtfnzbsParser.cs b/src/NzbDrone.Core/Indexers/Omgwtfnzbs/OmgwtfnzbsParser.cs index afaeb3890..95852ce67 100644 --- a/src/NzbDrone.Core/Indexers/Omgwtfnzbs/OmgwtfnzbsParser.cs +++ b/src/NzbDrone.Core/Indexers/Omgwtfnzbs/OmgwtfnzbsParser.cs @@ -23,7 +23,7 @@ namespace NzbDrone.Core.Indexers.Omgwtfnzbs protected override long GetSize(XElement item) { var sizeString = Regex.Match(item.Description(), @"(?:Size:\<\/b\>\s\d+\.)\d{1,2}\s\w{2}(?:\
)", RegexOptions.IgnoreCase | RegexOptions.Compiled).Value; - return ParseSize(sizeString); + return ParseSize(sizeString, true); } } } \ No newline at end of file diff --git a/src/NzbDrone.Core/Indexers/RssParserBase.cs b/src/NzbDrone.Core/Indexers/RssParserBase.cs index befce4f50..85c3ba557 100644 --- a/src/NzbDrone.Core/Indexers/RssParserBase.cs +++ b/src/NzbDrone.Core/Indexers/RssParserBase.cs @@ -31,7 +31,7 @@ namespace NzbDrone.Core.Indexers { PreProcess(xml, url); - using (var xmlTextReader = XmlReader.Create(new StringReader(xml), new XmlReaderSettings { DtdProcessing = DtdProcessing.Parse, IgnoreComments = true })) + using (var xmlTextReader = XmlReader.Create(new StringReader(xml), new XmlReaderSettings { DtdProcessing = DtdProcessing.Ignore, IgnoreComments = true })) { var document = XDocument.Load(xmlTextReader); @@ -124,7 +124,7 @@ namespace NzbDrone.Core.Indexers private static readonly Regex ReportSizeRegex = new Regex(@"(?\d+\.\d{1,2}|\d+\,\d+\.\d{1,2}|\d+)\W?(?GB|MB|GiB|MiB)", RegexOptions.IgnoreCase | RegexOptions.Compiled); - public static long ParseSize(string sizeString) + public static Int64 ParseSize(String sizeString, Boolean defaultToBinaryPrefix) { var match = ReportSizeRegex.Matches(sizeString); @@ -133,26 +133,33 @@ namespace NzbDrone.Core.Indexers var cultureInfo = new CultureInfo("en-US"); var value = Decimal.Parse(Regex.Replace(match[0].Groups["value"].Value, "\\,", ""), cultureInfo); - var unit = match[0].Groups["unit"].Value; + var unit = match[0].Groups["unit"].Value.ToLower(); - if (unit.Equals("MB", StringComparison.InvariantCultureIgnoreCase) || - unit.Equals("MiB", StringComparison.InvariantCultureIgnoreCase)) + switch (unit) { - return ConvertToBytes(Convert.ToDouble(value), 2); - } - - if (unit.Equals("GB", StringComparison.InvariantCultureIgnoreCase) || - unit.Equals("GiB", StringComparison.InvariantCultureIgnoreCase)) - { - return ConvertToBytes(Convert.ToDouble(value), 3); + case "kb": + return ConvertToBytes(Convert.ToDouble(value), 1, defaultToBinaryPrefix); + case "mb": + return ConvertToBytes(Convert.ToDouble(value), 2, defaultToBinaryPrefix); + case "gb": + return ConvertToBytes(Convert.ToDouble(value), 3, defaultToBinaryPrefix); + case "kib": + return ConvertToBytes(Convert.ToDouble(value), 1, true); + case "mib": + return ConvertToBytes(Convert.ToDouble(value), 2, true); + case "gib": + return ConvertToBytes(Convert.ToDouble(value), 3, true); + default: + return (Int64)value; } } return 0; } - private static long ConvertToBytes(double value, int power) + private static Int64 ConvertToBytes(Double value, Int32 power, Boolean binaryPrefix) { - var multiplier = Math.Pow(1024, power); + var prefix = binaryPrefix ? 1024 : 1000; + var multiplier = Math.Pow(prefix, power); var result = value * multiplier; return Convert.ToInt64(result); diff --git a/src/NzbDrone.Core/Rest/RestSharpExtensions.cs b/src/NzbDrone.Core/Rest/RestSharpExtensions.cs index 4f9c64e3b..50bf89d2d 100644 --- a/src/NzbDrone.Core/Rest/RestSharpExtensions.cs +++ b/src/NzbDrone.Core/Rest/RestSharpExtensions.cs @@ -49,6 +49,11 @@ namespace NzbDrone.Core.Rest { restResponse.ValidateResponse(restClient); + if (restResponse.Content != null) + { + Logger.Trace("Response: " + restResponse.Content); + } + return Json.Deserialize(restResponse.Content); }