From 3e9a15946696327d92bcec826a1f29865aa92ed5 Mon Sep 17 00:00:00 2001 From: vintage81 Date: Thu, 30 Jun 2016 02:48:18 +0100 Subject: [PATCH] Fixed: Adding label to torrents in qBittorrent v3.3.5 Fixes #1347 --- .../Clients/qBittorrent/QBittorrentProxy.cs | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/NzbDrone.Core/Download/Clients/qBittorrent/QBittorrentProxy.cs b/src/NzbDrone.Core/Download/Clients/qBittorrent/QBittorrentProxy.cs index ba4670ce0..e7533245f 100644 --- a/src/NzbDrone.Core/Download/Clients/qBittorrent/QBittorrentProxy.cs +++ b/src/NzbDrone.Core/Download/Clients/qBittorrent/QBittorrentProxy.cs @@ -94,12 +94,26 @@ namespace NzbDrone.Core.Download.Clients.QBittorrent public void SetTorrentLabel(string hash, string label, QBittorrentSettings settings) { - var request = BuildRequest(settings).Resource("/command/setLabel") - .Post() - .AddFormParameter("hashes", hash) - .AddFormParameter("label", label); - - ProcessRequest(request, settings); + var setCategoryRequest = BuildRequest(settings).Resource("/command/setCategory") + .Post() + .AddFormParameter("hashes", hash) + .AddFormParameter("category", label); + try + { + ProcessRequest(setCategoryRequest, settings); + } + catch(DownloadClientException ex) + { + // if setCategory fails due to method not being found, then try older setLabel command for qbittorent < v.3.3.5 + if (ex.InnerException is HttpException && (ex.InnerException as HttpException).Response.StatusCode == HttpStatusCode.NotFound) + { + var setLabelRequest = BuildRequest(settings).Resource("/command/setLabel") + .Post() + .AddFormParameter("hashes", hash) + .AddFormParameter("label", label); + ProcessRequest(setLabelRequest, settings); + } + } } public void MoveTorrentToTopInQueue(string hash, QBittorrentSettings settings)