@ -101,6 +101,24 @@ namespace NzbDrone.Core.Download.Clients.QBittorrent
return response ;
}
public bool IsTorrentLoaded ( string hash , QBittorrentSettings settings )
{
var request = BuildRequest ( settings ) . Resource ( "/api/v2/torrents/properties" )
. AddQueryParam ( "hash" , hash ) ;
request . LogHttpError = false ;
try
{
ProcessRequest ( request , settings ) ;
return true ;
}
catch
{
return false ;
}
}
public QBittorrentTorrentProperties GetTorrentProperties ( string hash , QBittorrentSettings settings )
{
var request = BuildRequest ( settings ) . Resource ( "/api/v2/torrents/properties" )
@ -141,7 +159,7 @@ namespace NzbDrone.Core.Download.Clients.QBittorrent
if ( seedConfiguration ! = null )
{
AddTorrentSeedingFormParameters ( request , seedConfiguration , settings );
AddTorrentSeedingFormParameters ( request , seedConfiguration );
}
var result = ProcessRequest ( request , settings ) ;
@ -176,7 +194,7 @@ namespace NzbDrone.Core.Download.Clients.QBittorrent
if ( seedConfiguration ! = null )
{
AddTorrentSeedingFormParameters ( request , seedConfiguration , settings );
AddTorrentSeedingFormParameters ( request , seedConfiguration );
}
var result = ProcessRequest ( request , settings ) ;
@ -225,17 +243,17 @@ namespace NzbDrone.Core.Download.Clients.QBittorrent
return Json . Deserialize < Dictionary < string , QBittorrentLabel > > ( ProcessRequest ( request , settings ) ) ;
}
private void AddTorrentSeedingFormParameters ( HttpRequestBuilder request , TorrentSeedConfiguration seedConfiguration , QBittorrentSettings settings )
private void AddTorrentSeedingFormParameters ( HttpRequestBuilder request , TorrentSeedConfiguration seedConfiguration , bool always = false )
{
var ratioLimit = seedConfiguration . Ratio . HasValue ? seedConfiguration . Ratio : - 2 ;
var seedingTimeLimit = seedConfiguration . SeedTime . HasValue ? ( long ) seedConfiguration . SeedTime . Value . TotalMinutes : - 2 ;
if ( ratioLimit ! = - 2 )
if ( ratioLimit ! = - 2 | | always )
{
request . AddFormParameter ( "ratioLimit" , ratioLimit ) ;
}
if ( seedingTimeLimit ! = - 2 )
if ( seedingTimeLimit ! = - 2 | | always )
{
request . AddFormParameter ( "seedingTimeLimit" , seedingTimeLimit ) ;
}
@ -247,7 +265,7 @@ namespace NzbDrone.Core.Download.Clients.QBittorrent
. Post ( )
. AddFormParameter ( "hashes" , hash ) ;
AddTorrentSeedingFormParameters ( request , seedConfiguration , settings ) ;
AddTorrentSeedingFormParameters ( request , seedConfiguration , true ) ;
try
{
@ -336,15 +354,14 @@ namespace NzbDrone.Core.Download.Clients.QBittorrent
var request = requestBuilder . Build ( ) ;
request . LogResponseContent = true ;
request . SuppressHttpErrorStatusCodes = new [ ] { HttpStatusCode . Forbidden } ;
HttpResponse response ;
try
{
response = _httpClient . Execute ( request ) ;
}
catch ( HttpException ex )
{
if ( ex . Response . StatusCode = = HttpStatusCode . Forbidden )
if ( response . StatusCode = = HttpStatusCode . Forbidden )
{
_logger . Debug ( "Authentication required, logging in." ) ;
@ -354,10 +371,10 @@ namespace NzbDrone.Core.Download.Clients.QBittorrent
response = _httpClient . Execute ( request ) ;
}
else
{
throw new DownloadClientException ( "Failed to connect to qBittorrent, check your settings." , ex ) ;
}
}
catch ( HttpException ex )
{
throw new DownloadClientException ( "Failed to connect to qBittorrent, check your settings." , ex ) ;
}
catch ( WebException ex )
{