@ -1,4 +1,4 @@
using System ;
using System ;
using System.Collections.Generic ;
using System.Net ;
using NLog ;
@ -72,7 +72,13 @@ namespace NzbDrone.Core.Download.Clients.QBittorrent
. Post ( )
. 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 )
@ -81,7 +87,13 @@ namespace NzbDrone.Core.Download.Clients.QBittorrent
. Post ( )
. 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 )
@ -90,7 +102,7 @@ namespace NzbDrone.Core.Download.Clients.QBittorrent
. Post ( )
. AddFormParameter ( "hashes" , hash ) ;
ProcessRequest <object > (request , settings ) ;
ProcessRequest (request , settings ) ;
}
public void SetTorrentLabel ( string hash , string label , QBittorrentSettings settings )
@ -101,7 +113,7 @@ namespace NzbDrone.Core.Download.Clients.QBittorrent
. AddFormParameter ( "category" , label ) ;
try
{
ProcessRequest <object > (setCategoryRequest , settings ) ;
ProcessRequest (setCategoryRequest , settings ) ;
}
catch ( DownloadClientException ex )
{
@ -112,7 +124,8 @@ namespace NzbDrone.Core.Download.Clients.QBittorrent
. Post ( )
. AddFormParameter ( "hashes" , hash )
. AddFormParameter ( "label" , label ) ;
ProcessRequest < object > ( setLabelRequest , settings ) ;
ProcessRequest ( setLabelRequest , settings ) ;
}
}
}
@ -125,7 +138,7 @@ namespace NzbDrone.Core.Download.Clients.QBittorrent
try
{
var response = ProcessRequest < object > ( request , settings ) ;
ProcessRequest ( request , settings ) ;
}
catch ( DownloadClientException ex )
{
@ -152,10 +165,18 @@ namespace NzbDrone.Core.Download.Clients.QBittorrent
private TResult ProcessRequest < TResult > ( HttpRequestBuilder requestBuilder , QBittorrentSettings settings )
where TResult : new ( )
{
var responseContent = ProcessRequest ( requestBuilder , settings ) ;
return Json . Deserialize < TResult > ( responseContent ) ;
}
private string ProcessRequest ( HttpRequestBuilder requestBuilder , QBittorrentSettings settings )
{
AuthenticateClient ( requestBuilder , settings ) ;
var request = requestBuilder . Build ( ) ;
request . LogResponseContent = true ;
HttpResponse response ;
try
@ -176,15 +197,15 @@ namespace NzbDrone.Core.Download.Clients.QBittorrent
}
else
{
throw new DownloadClientException ( "Failed to connect to qBit T orrent, check your settings.", ex ) ;
throw new DownloadClientException ( "Failed to connect to qBit t orrent, check your settings.", ex ) ;
}
}
catch ( WebException ex )
{
throw new DownloadClientException ( "Failed to connect to qBit T orrent, please check your settings.", ex ) ;
throw new DownloadClientException ( "Failed to connect to qBit t orrent, please check your settings.", ex ) ;
}
return Json. Deserialize < TResult > ( response. Content ) ;
return response. Content ;
}
private void AuthenticateClient ( HttpRequestBuilder requestBuilder , QBittorrentSettings settings , bool reauthenticate = false )
@ -218,23 +239,23 @@ namespace NzbDrone.Core.Download.Clients.QBittorrent
_logger . Debug ( "qbitTorrent authentication failed." ) ;
if ( ex . Response . StatusCode = = HttpStatusCode . Forbidden )
{
throw new DownloadClientAuthenticationException ( "Failed to authenticate with q bitT orrent.", ex ) ;
throw new DownloadClientAuthenticationException ( "Failed to authenticate with q Bitt orrent.", ex ) ;
}
throw new DownloadClientException ( "Failed to connect to qBit T orrent, please check your settings.", ex ) ;
throw new DownloadClientException ( "Failed to connect to qBit t orrent, please check your settings.", ex ) ;
}
catch ( WebException ex )
{
throw new DownloadClientException ( "Failed to connect to qBit T orrent, please check your settings.", ex ) ;
throw new DownloadClientException ( "Failed to connect to qBit t orrent, please check your settings.", ex ) ;
}
if ( response . Content ! = "Ok." ) // returns "Fails." on bad login
{
_logger . Debug ( "qbitTorrent authentication failed." ) ;
throw new DownloadClientAuthenticationException ( "Failed to authenticate with q bitT orrent.") ;
throw new DownloadClientAuthenticationException ( "Failed to authenticate with q Bitt orrent.") ;
}
_logger . Debug ( "q bitT orrent authentication succeeded.") ;
_logger . Debug ( "q Bitt orrent authentication succeeded.") ;
cookies = response . GetCookies ( ) ;