From 935b9e5f4e6d29cab1c66284898927add75c3f8b Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Mon, 1 Dec 2014 22:39:27 -0800 Subject: [PATCH] New: Use the ID returned from SABnzbd (0.7.20) during retry --- .../Extensions/TryParseExtensions.cs | 2 +- .../Sabnzbd/Responses/SabnzbdRetryResponse.cs | 12 ++++++++++++ .../Download/Clients/Sabnzbd/Sabnzbd.cs | 7 ++++++- .../Download/Clients/Sabnzbd/SabnzbdProxy.cs | 18 +++++++++++------- 4 files changed, 30 insertions(+), 9 deletions(-) create mode 100644 src/NzbDrone.Core/Download/Clients/Sabnzbd/Responses/SabnzbdRetryResponse.cs diff --git a/src/NzbDrone.Common/Extensions/TryParseExtensions.cs b/src/NzbDrone.Common/Extensions/TryParseExtensions.cs index 4ecfaa95f..c784c6cfc 100644 --- a/src/NzbDrone.Common/Extensions/TryParseExtensions.cs +++ b/src/NzbDrone.Common/Extensions/TryParseExtensions.cs @@ -1,6 +1,6 @@ using System; -namespace NzbDrone.Common +namespace NzbDrone.Common.Extensions { public static class TryParseExtensions { diff --git a/src/NzbDrone.Core/Download/Clients/Sabnzbd/Responses/SabnzbdRetryResponse.cs b/src/NzbDrone.Core/Download/Clients/Sabnzbd/Responses/SabnzbdRetryResponse.cs new file mode 100644 index 000000000..126e9c6ae --- /dev/null +++ b/src/NzbDrone.Core/Download/Clients/Sabnzbd/Responses/SabnzbdRetryResponse.cs @@ -0,0 +1,12 @@ +using Newtonsoft.Json; + +namespace NzbDrone.Core.Download.Clients.Sabnzbd.Responses +{ + public class SabnzbdRetryResponse + { + public bool Status { get; set; } + + [JsonProperty(PropertyName = "nzo_id")] + public string Id { get; set; } + } +} diff --git a/src/NzbDrone.Core/Download/Clients/Sabnzbd/Sabnzbd.cs b/src/NzbDrone.Core/Download/Clients/Sabnzbd/Sabnzbd.cs index f38f20273..02fc4331e 100644 --- a/src/NzbDrone.Core/Download/Clients/Sabnzbd/Sabnzbd.cs +++ b/src/NzbDrone.Core/Download/Clients/Sabnzbd/Sabnzbd.cs @@ -223,7 +223,12 @@ public override String RetryDownload(String id) var otherItemsWithSameTitle = currentHistory.Where(h => h.Title == currentHistoryItem.Title && h.DownloadClientId != currentHistoryItem.DownloadClientId).ToList(); - _proxy.RetryDownload(id, Settings); + var newId = _proxy.RetryDownload(id, Settings); + + if (newId.IsNotNullOrWhiteSpace()) + { + return newId; + } for (int i = 0; i < 3; i++) { diff --git a/src/NzbDrone.Core/Download/Clients/Sabnzbd/SabnzbdProxy.cs b/src/NzbDrone.Core/Download/Clients/Sabnzbd/SabnzbdProxy.cs index ea1da6dcc..ff4948540 100644 --- a/src/NzbDrone.Core/Download/Clients/Sabnzbd/SabnzbdProxy.cs +++ b/src/NzbDrone.Core/Download/Clients/Sabnzbd/SabnzbdProxy.cs @@ -1,10 +1,6 @@ using System; -using System.IO; -using System.Linq; -using System.Collections.Generic; using Newtonsoft.Json.Linq; using NLog; -using NzbDrone.Common; using NzbDrone.Common.Extensions; using NzbDrone.Common.Serializer; using NzbDrone.Core.Rest; @@ -22,7 +18,7 @@ public interface ISabnzbdProxy SabnzbdConfig GetConfig(SabnzbdSettings settings); SabnzbdQueue GetQueue(int start, int limit, SabnzbdSettings settings); SabnzbdHistory GetHistory(int start, int limit, SabnzbdSettings settings); - void RetryDownload(string id, SabnzbdSettings settings); + string RetryDownload(string id, SabnzbdSettings settings); } public class SabnzbdProxy : ISabnzbdProxy @@ -114,12 +110,20 @@ public SabnzbdHistory GetHistory(int start, int limit, SabnzbdSettings settings) return Json.Deserialize(JObject.Parse(response).SelectToken("history").ToString()); } - public void RetryDownload(string id, SabnzbdSettings settings) + public string RetryDownload(string id, SabnzbdSettings settings) { var request = new RestRequest(); var action = String.Format("mode=retry&value={0}", id); - ProcessRequest(request, action, settings); + SabnzbdRetryResponse response; + + if (!Json.TryDeserialize(ProcessRequest(request, action, settings), out response)) + { + response = new SabnzbdRetryResponse(); + response.Status = true; + } + + return response.Id; } private IRestClient BuildClient(string action, SabnzbdSettings settings)