1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-09 04:22:30 +01:00

Fixed: Category not setting with qBitTorrent 3.3.14 and other api errors. (upstream from Sonarr)

This commit is contained in:
James White 2017-08-06 11:09:16 +01:00 committed by Leonardo Galli
parent b06108fb45
commit 17feedaf53
2 changed files with 39 additions and 18 deletions

View File

@ -1,4 +1,4 @@
using System; using System;
using System.Linq; using System.Linq;
using System.Collections.Generic; using System.Collections.Generic;
using NzbDrone.Common.Disk; using NzbDrone.Common.Disk;
@ -111,7 +111,7 @@ public override IEnumerable<DownloadClientItem> GetItems()
{ {
case "error": // some error occurred, applies to paused torrents case "error": // some error occurred, applies to paused torrents
item.Status = DownloadItemStatus.Failed; item.Status = DownloadItemStatus.Failed;
item.Message = "QBittorrent is reporting an error"; item.Message = "qBittorrent is reporting an error";
break; break;
case "pausedDL": // torrent is paused and has NOT finished downloading case "pausedDL": // torrent is paused and has NOT finished downloading
@ -212,7 +212,7 @@ private ValidationFailure TestConnection()
var config = _proxy.GetConfig(Settings); var config = _proxy.GetConfig(Settings);
if (config.MaxRatioEnabled && config.RemoveOnMaxRatio) if (config.MaxRatioEnabled && config.RemoveOnMaxRatio)
{ {
return new NzbDroneValidationFailure(String.Empty, "QBittorrent is configured to remove torrents when they reach their Share Ratio Limit") return new NzbDroneValidationFailure(String.Empty, "qBittorrent is configured to remove torrents when they reach their Share Ratio Limit")
{ {
DetailedDescription = "Radarr will be unable to perform Completed Download Handling as configured. You can fix this in qBittorrent ('Tools -> Options...' in the menu) by changing 'Options -> BitTorrent -> Share Ratio Limiting' from 'Remove them' to 'Pause them'." DetailedDescription = "Radarr will be unable to perform Completed Download Handling as configured. You can fix this in qBittorrent ('Tools -> Options...' in the menu) by changing 'Options -> BitTorrent -> Share Ratio Limiting' from 'Remove them' to 'Pause them'."
}; };

View File

@ -1,4 +1,4 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Net; using System.Net;
using NLog; using NLog;
@ -72,7 +72,13 @@ public void AddTorrentFromUrl(string torrentUrl, QBittorrentSettings settings)
.Post() .Post()
.AddFormParameter("urls", torrentUrl); .AddFormParameter("urls", torrentUrl);
ProcessRequest<object>(request, settings); var result = ProcessRequest(request, settings);
// Note: Older qbit versions returned nothing, so we can't do != "Ok." here.
if (result == "Fails.")
{
throw new DownloadClientException("Download client failed to add torrent by url");
}
} }
public void AddTorrentFromFile(string fileName, Byte[] fileContent, QBittorrentSettings settings) public void AddTorrentFromFile(string fileName, Byte[] fileContent, QBittorrentSettings settings)
@ -81,7 +87,13 @@ public void AddTorrentFromFile(string fileName, Byte[] fileContent, QBittorrentS
.Post() .Post()
.AddFormUpload("torrents", fileName, fileContent); .AddFormUpload("torrents", fileName, fileContent);
ProcessRequest<object>(request, settings); var result = ProcessRequest(request, settings);
// Note: Current qbit versions return nothing, so we can't do != "Ok." here.
if (result == "Fails.")
{
throw new DownloadClientException("Download client failed to add torrent");
}
} }
public void RemoveTorrent(string hash, Boolean removeData, QBittorrentSettings settings) public void RemoveTorrent(string hash, Boolean removeData, QBittorrentSettings settings)
@ -90,7 +102,7 @@ public void RemoveTorrent(string hash, Boolean removeData, QBittorrentSettings s
.Post() .Post()
.AddFormParameter("hashes", hash); .AddFormParameter("hashes", hash);
ProcessRequest<object>(request, settings); ProcessRequest(request, settings);
} }
public void SetTorrentLabel(string hash, string label, QBittorrentSettings settings) public void SetTorrentLabel(string hash, string label, QBittorrentSettings settings)
@ -101,7 +113,7 @@ public void SetTorrentLabel(string hash, string label, QBittorrentSettings setti
.AddFormParameter("category", label); .AddFormParameter("category", label);
try try
{ {
ProcessRequest<object>(setCategoryRequest, settings); ProcessRequest(setCategoryRequest, settings);
} }
catch(DownloadClientException ex) catch(DownloadClientException ex)
{ {
@ -112,7 +124,8 @@ public void SetTorrentLabel(string hash, string label, QBittorrentSettings setti
.Post() .Post()
.AddFormParameter("hashes", hash) .AddFormParameter("hashes", hash)
.AddFormParameter("label", label); .AddFormParameter("label", label);
ProcessRequest<object>(setLabelRequest, settings);
ProcessRequest(setLabelRequest, settings);
} }
} }
} }
@ -125,7 +138,7 @@ public void MoveTorrentToTopInQueue(string hash, QBittorrentSettings settings)
try try
{ {
var response = ProcessRequest<object>(request, settings); ProcessRequest(request, settings);
} }
catch (DownloadClientException ex) catch (DownloadClientException ex)
{ {
@ -152,10 +165,18 @@ private HttpRequestBuilder BuildRequest(QBittorrentSettings settings)
private TResult ProcessRequest<TResult>(HttpRequestBuilder requestBuilder, QBittorrentSettings settings) private TResult ProcessRequest<TResult>(HttpRequestBuilder requestBuilder, QBittorrentSettings settings)
where TResult : new() where TResult : new()
{
var responseContent = ProcessRequest(requestBuilder, settings);
return Json.Deserialize<TResult>(responseContent);
}
private string ProcessRequest(HttpRequestBuilder requestBuilder, QBittorrentSettings settings)
{ {
AuthenticateClient(requestBuilder, settings); AuthenticateClient(requestBuilder, settings);
var request = requestBuilder.Build(); var request = requestBuilder.Build();
request.LogResponseContent = true;
HttpResponse response; HttpResponse response;
try try
@ -176,15 +197,15 @@ private TResult ProcessRequest<TResult>(HttpRequestBuilder requestBuilder, QBitt
} }
else else
{ {
throw new DownloadClientException("Failed to connect to qBitTorrent, check your settings.", ex); throw new DownloadClientException("Failed to connect to qBittorrent, check your settings.", ex);
} }
} }
catch (WebException ex) catch (WebException ex)
{ {
throw new DownloadClientException("Failed to connect to qBitTorrent, please check your settings.", ex); throw new DownloadClientException("Failed to connect to qBittorrent, please check your settings.", ex);
} }
return Json.Deserialize<TResult>(response.Content); return response.Content;
} }
private void AuthenticateClient(HttpRequestBuilder requestBuilder, QBittorrentSettings settings, bool reauthenticate = false) private void AuthenticateClient(HttpRequestBuilder requestBuilder, QBittorrentSettings settings, bool reauthenticate = false)
@ -218,23 +239,23 @@ private void AuthenticateClient(HttpRequestBuilder requestBuilder, QBittorrentSe
_logger.Debug("qbitTorrent authentication failed."); _logger.Debug("qbitTorrent authentication failed.");
if (ex.Response.StatusCode == HttpStatusCode.Forbidden) if (ex.Response.StatusCode == HttpStatusCode.Forbidden)
{ {
throw new DownloadClientAuthenticationException("Failed to authenticate with qbitTorrent.", ex); throw new DownloadClientAuthenticationException("Failed to authenticate with qBittorrent.", ex);
} }
throw new DownloadClientException("Failed to connect to qBitTorrent, please check your settings.", ex); throw new DownloadClientException("Failed to connect to qBittorrent, please check your settings.", ex);
} }
catch (WebException ex) catch (WebException ex)
{ {
throw new DownloadClientException("Failed to connect to qBitTorrent, please check your settings.", ex); throw new DownloadClientException("Failed to connect to qBittorrent, please check your settings.", ex);
} }
if (response.Content != "Ok.") // returns "Fails." on bad login if (response.Content != "Ok.") // returns "Fails." on bad login
{ {
_logger.Debug("qbitTorrent authentication failed."); _logger.Debug("qbitTorrent authentication failed.");
throw new DownloadClientAuthenticationException("Failed to authenticate with qbitTorrent."); throw new DownloadClientAuthenticationException("Failed to authenticate with qBittorrent.");
} }
_logger.Debug("qbitTorrent authentication succeeded."); _logger.Debug("qBittorrent authentication succeeded.");
cookies = response.GetCookies(); cookies = response.GetCookies();