diff --git a/src/NzbDrone.Common.Test/PathExtensionFixture.cs b/src/NzbDrone.Common.Test/PathExtensionFixture.cs index 4b8c355dd..734b15e13 100644 --- a/src/NzbDrone.Common.Test/PathExtensionFixture.cs +++ b/src/NzbDrone.Common.Test/PathExtensionFixture.cs @@ -136,6 +136,23 @@ namespace NzbDrone.Common.Test parentPath.IsParentPath(childPath).Should().Be(expectedResult); } + [TestCase(@"C:\Test\mydir", @"C:\Test")] + [TestCase(@"C:\Test\", @"C:")] + [TestCase(@"C:\", null)] + public void path_should_return_parent(string path, string parentPath) + { + path.GetParentPath().Should().Be(parentPath); + } + + [Test] + public void path_should_return_parent_for_oversized_path() + { + var path = @"/media/2e168617-f2ae-43fb-b88c-3663af1c8eea/downloads/sabnzbd/nzbdrone/Some.Real.Big.Thing/With.Alot.Of.Nested.Directories/Some.Real.Big.Thing/With.Alot.Of.Nested.Directories/Some.Real.Big.Thing/With.Alot.Of.Nested.Directories/Some.Real.Big.Thing/With.Alot.Of.Nested.Directories/Some.Real.Big.Thing/With.Alot.Of.Nested.Directories"; + var parentPath = @"/media/2e168617-f2ae-43fb-b88c-3663af1c8eea/downloads/sabnzbd/nzbdrone/Some.Real.Big.Thing/With.Alot.Of.Nested.Directories/Some.Real.Big.Thing/With.Alot.Of.Nested.Directories/Some.Real.Big.Thing/With.Alot.Of.Nested.Directories/Some.Real.Big.Thing/With.Alot.Of.Nested.Directories/Some.Real.Big.Thing"; + + path.GetParentPath().Should().Be(parentPath); + } + [Test] [Ignore] public void should_not_be_parent_when_it_is_grandparent() diff --git a/src/NzbDrone.Common/PathExtensions.cs b/src/NzbDrone.Common/PathExtensions.cs index 7598f84f8..f57051f61 100644 --- a/src/NzbDrone.Common/PathExtensions.cs +++ b/src/NzbDrone.Common/PathExtensions.cs @@ -53,6 +53,22 @@ namespace NzbDrone.Common return childPath.Substring(parentPath.Length).Trim(Path.DirectorySeparatorChar); } + public static string GetParentPath(this string childPath) + { + var parentPath = childPath.TrimEnd('\\', '/'); + + var index = parentPath.LastIndexOfAny(new[] { '\\', '/' }); + + if (index != -1) + { + return parentPath.Substring(0, index); + } + else + { + return null; + } + } + public static bool IsParentPath(this string parentPath, string childPath) { parentPath = parentPath.TrimEnd(Path.DirectorySeparatorChar); diff --git a/src/NzbDrone.Core.Test/ParserTests/CrapParserFixture.cs b/src/NzbDrone.Core.Test/ParserTests/CrapParserFixture.cs index 83c9315e7..71699402c 100644 --- a/src/NzbDrone.Core.Test/ParserTests/CrapParserFixture.cs +++ b/src/NzbDrone.Core.Test/ParserTests/CrapParserFixture.cs @@ -32,6 +32,7 @@ namespace NzbDrone.Core.Test.ParserTests [TestCase("0e895c37245186812cb08aab1529cf8ee389dd05.mkv")] [TestCase("08bbc153931ce3ca5fcafe1b92d3297285feb061.mkv")] [TestCase("185d86a343e39f3341e35c4dad3ff159")] + [TestCase("ah63jka93jf0jh26ahjas961.mkv")] public void should_not_parse_crap(string title) { Parser.Parser.ParseTitle(title).Should().BeNull(); diff --git a/src/NzbDrone.Core/Download/Clients/Sabnzbd/Sabnzbd.cs b/src/NzbDrone.Core/Download/Clients/Sabnzbd/Sabnzbd.cs index 5c5a05e31..2ce1bef1f 100644 --- a/src/NzbDrone.Core/Download/Clients/Sabnzbd/Sabnzbd.cs +++ b/src/NzbDrone.Core/Download/Clients/Sabnzbd/Sabnzbd.cs @@ -161,10 +161,10 @@ namespace NzbDrone.Core.Download.Clients.Sabnzbd if (!sabHistoryItem.Storage.IsNullOrWhiteSpace()) { - var parent = Directory.GetParent(sabHistoryItem.Storage); - if (parent != null && parent.Name == sabHistoryItem.Title) + var parent = sabHistoryItem.Storage.GetParentPath(); + if (parent != null && Path.GetFileName(parent) == sabHistoryItem.Title) { - historyItem.OutputPath = parent.FullName; + historyItem.OutputPath = parent; } else { diff --git a/src/NzbDrone.Core/Download/CompletedDownloadService.cs b/src/NzbDrone.Core/Download/CompletedDownloadService.cs index 7ae4b422b..37c77f290 100644 --- a/src/NzbDrone.Core/Download/CompletedDownloadService.cs +++ b/src/NzbDrone.Core/Download/CompletedDownloadService.cs @@ -77,7 +77,7 @@ namespace NzbDrone.Core.Download { trackedDownload.State = TrackedDownloadState.Imported; - _logger.Debug("Already added to history as imported: " + trackedDownload.DownloadItem.Title); + _logger.Trace("Already added to history as imported: " + trackedDownload.DownloadItem.Title); } else { @@ -137,13 +137,13 @@ namespace NzbDrone.Core.Download importedItems.First().Data[DownloadTrackingService.DOWNLOAD_CLIENT_ID] = grabbedItems.First().Data[DownloadTrackingService.DOWNLOAD_CLIENT_ID]; _historyService.UpdateHistoryData(importedItems.First().Id, importedItems.First().Data); - _logger.Debug("Storage path does not exist, but found probable drone factory ImportEvent: " + trackedDownload.DownloadItem.Title); + _logger.Trace("Storage path does not exist, but found probable drone factory ImportEvent: " + trackedDownload.DownloadItem.Title); return; } } } - _logger.Debug("Storage path does not exist: " + trackedDownload.DownloadItem.Title); + _logger.Trace("Storage path does not exist: " + trackedDownload.DownloadItem.Title); return; } } diff --git a/src/NzbDrone.Core/Download/FailedDownloadService.cs b/src/NzbDrone.Core/Download/FailedDownloadService.cs index cc25cf872..a883b2e63 100644 --- a/src/NzbDrone.Core/Download/FailedDownloadService.cs +++ b/src/NzbDrone.Core/Download/FailedDownloadService.cs @@ -54,7 +54,7 @@ namespace NzbDrone.Core.Download if (!grabbedItems.Any()) { - _logger.Debug("Download was not grabbed by drone, ignoring."); + _logger.Trace("Download was not grabbed by drone, ignoring download: " + trackedDownload.DownloadItem.Title); return; } @@ -64,7 +64,7 @@ namespace NzbDrone.Core.Download if (failedItems.Any()) { - _logger.Debug("Already added to history as failed"); + _logger.Trace("Already added to history as failed: " + trackedDownload.DownloadItem.Title); } else { @@ -78,7 +78,7 @@ namespace NzbDrone.Core.Download if (!grabbedItems.Any()) { - _logger.Debug("Download was not grabbed by drone, ignoring."); + _logger.Trace("Download was not grabbed by drone, ignoring download: " + trackedDownload.DownloadItem.Title); return; } @@ -86,13 +86,13 @@ namespace NzbDrone.Core.Download if (trackedDownload.DownloadItem.Message.Equals("Unpacking failed, write error or disk is full?", StringComparison.InvariantCultureIgnoreCase)) { - _logger.Debug("Failed due to lack of disk space, do not blacklist"); + _logger.Trace("Failed due to lack of disk space, do not blacklist: " + trackedDownload.DownloadItem.Title); return; } if (FailedDownloadForRecentRelease(downloadClient, trackedDownload, grabbedItems)) { - _logger.Debug("Recent release Failed, do not blacklist"); + _logger.Trace("Recent release Failed, do not blacklist: " + trackedDownload.DownloadItem.Title); return; } @@ -102,7 +102,7 @@ namespace NzbDrone.Core.Download if (failedItems.Any()) { - _logger.Debug("Already added to history as failed"); + _logger.Trace("Already added to history as failed: " + trackedDownload.DownloadItem.Title); } else { @@ -110,6 +110,18 @@ namespace NzbDrone.Core.Download } } + if (trackedDownload.DownloadItem.Status != DownloadItemStatus.Failed && trackedDownload.State == TrackedDownloadState.Downloading) + { + var grabbedItems = GetHistoryItems(grabbedHistory, trackedDownload.DownloadItem.DownloadClientId); + var failedItems = GetHistoryItems(failedHistory, trackedDownload.DownloadItem.DownloadClientId); + + if (grabbedItems.Any() && failedItems.Any()) + { + _logger.Trace("Already added to history as failed, updating tracked state: " + trackedDownload.DownloadItem.Title); + trackedDownload.State = TrackedDownloadState.DownloadFailed; + } + } + if (_configService.RemoveFailedDownloads && trackedDownload.State == TrackedDownloadState.DownloadFailed) { try @@ -121,7 +133,7 @@ namespace NzbDrone.Core.Download } catch (NotSupportedException) { - _logger.Debug("Removing item not supported by your download client"); + _logger.Trace("Removing item not supported by your download client"); } } } @@ -132,25 +144,25 @@ namespace NzbDrone.Core.Download if (!Double.TryParse(matchingHistoryItems.First().Data.GetValueOrDefault("ageHours"), out ageHours)) { - _logger.Debug("Unable to determine age of failed download"); + _logger.Debug("Unable to determine age of failed download: " + trackedDownload.DownloadItem.Title); return false; } if (ageHours > _configService.BlacklistGracePeriod) { - _logger.Debug("Failed download is older than the grace period"); + _logger.Debug("Failed download is older than the grace period: " + trackedDownload.DownloadItem.Title); return false; } if (trackedDownload.RetryCount >= _configService.BlacklistRetryLimit) { - _logger.Debug("Retry limit reached"); + _logger.Debug("Retry limit reached: " + trackedDownload.DownloadItem.Title); return false; } if (trackedDownload.RetryCount == 0 || trackedDownload.LastRetry.AddMinutes(_configService.BlacklistRetryInterval) < DateTime.UtcNow) { - _logger.Debug("Retrying failed release"); + _logger.Debug("Retrying failed release: " + trackedDownload.DownloadItem.Title); trackedDownload.LastRetry = DateTime.UtcNow; trackedDownload.RetryCount++; diff --git a/src/NzbDrone.Core/Parser/Parser.cs b/src/NzbDrone.Core/Parser/Parser.cs index 8abafb430..cb92c57ba 100644 --- a/src/NzbDrone.Core/Parser/Parser.cs +++ b/src/NzbDrone.Core/Parser/Parser.cs @@ -112,6 +112,9 @@ namespace NzbDrone.Core.Parser { // Generic match for md5 and mixed-case hashes. new Regex(@"^[0-9a-zA-Z]{32}", RegexOptions.Compiled), + + // Generic match for shorter lower-case hashes. + new Regex(@"^[a-z0-9]{24}$", RegexOptions.Compiled), // Format seen on some NZBGeek releases new Regex(@"^[A-Z]{11}\d{3}$", RegexOptions.Compiled) diff --git a/src/UI/Calendar/CalendarFeedView.js b/src/UI/Calendar/CalendarFeedView.js index cf18cb711..c626a56ee 100644 --- a/src/UI/Calendar/CalendarFeedView.js +++ b/src/UI/Calendar/CalendarFeedView.js @@ -15,7 +15,7 @@ define( templateHelpers: { icalHttpUrl : window.location.protocol + '//' + window.location.host + StatusModel.get('urlBase') + '/feed/calendar/NzbDrone.ics?apikey=' + window.NzbDrone.ApiKey, - icalWebCalUrl : 'webcal://' + window.location.host + StatusModel.get('urlBase') + '/feed/calendar/NzbDrone.ics' + icalWebCalUrl : 'webcal://' + window.location.host + StatusModel.get('urlBase') + '/feed/calendar/NzbDrone.ics?apikey=' + window.NzbDrone.ApiKey }, onShow: function () { diff --git a/src/UI/Calendar/CalendarFeedViewTemplate.html b/src/UI/Calendar/CalendarFeedViewTemplate.html index 56ba9eb61..b217a953e 100644 --- a/src/UI/Calendar/CalendarFeedViewTemplate.html +++ b/src/UI/Calendar/CalendarFeedViewTemplate.html @@ -5,27 +5,19 @@

NzbDrone Calendar feed