@ -9,7 +9,7 @@ namespace NzbDrone.Core.Download
{
public interface IProvideDownloadClient
{
IDownloadClient GetDownloadClient ( DownloadProtocol downloadProtocol , int indexerId = 0 );
IDownloadClient GetDownloadClient ( DownloadProtocol downloadProtocol , int indexerId = 0 , bool filterBlockedClients = false );
IEnumerable < IDownloadClient > GetDownloadClients ( bool filterBlockedClients = false ) ;
IDownloadClient Get ( int id ) ;
}
@ -35,8 +35,9 @@ namespace NzbDrone.Core.Download
_lastUsedDownloadClient = cacheManager . GetCache < int > ( GetType ( ) , "lastDownloadClientId" ) ;
}
public IDownloadClient GetDownloadClient ( DownloadProtocol downloadProtocol , int indexerId = 0 )
public IDownloadClient GetDownloadClient ( DownloadProtocol downloadProtocol , int indexerId = 0 , bool filterBlockedClients = false )
{
var blockedProviders = new HashSet < int > ( _downloadClientStatusService . GetBlockedProviders ( ) . Select ( v = > v . ProviderId ) ) ;
var availableProviders = _downloadClientFactory . GetAvailableProviders ( ) . Where ( v = > v . Protocol = = downloadProtocol ) . ToList ( ) ;
if ( ! availableProviders . Any ( ) )
@ -52,12 +53,15 @@ namespace NzbDrone.Core.Download
{
var client = availableProviders . SingleOrDefault ( d = > d . Definition . Id = = indexer . DownloadClientId ) ;
return client ? ? throw new DownloadClientUnavailableException ( $"Indexer specified download client is not available" ) ;
if ( client = = null | | ( filterBlockedClients & & blockedProviders . Contains ( client . Definition . Id ) ) )
{
throw new DownloadClientUnavailableException ( $"Indexer specified download client is not available" ) ;
}
return client ;
}
}
var blockedProviders = new HashSet < int > ( _downloadClientStatusService . GetBlockedProviders ( ) . Select ( v = > v . ProviderId ) ) ;
if ( blockedProviders . Any ( ) )
{
var nonBlockedProviders = availableProviders . Where ( v = > ! blockedProviders . Contains ( v . Definition . Id ) ) . ToList ( ) ;
@ -66,6 +70,10 @@ namespace NzbDrone.Core.Download
{
availableProviders = nonBlockedProviders ;
}
else if ( filterBlockedClients )
{
throw new DownloadClientUnavailableException ( $"All download clients for {downloadProtocol} are not available" ) ;
}
else
{
_logger . Trace ( "No non-blocked Download Client available, retrying blocked one." ) ;