mirror of
https://github.com/Prowlarr/Prowlarr.git
synced 2026-04-24 22:55:21 -04:00
New: Add download client per indexer setting
This commit is contained in:
@@ -2,13 +2,14 @@
|
||||
using System.Linq;
|
||||
using NLog;
|
||||
using NzbDrone.Common.Cache;
|
||||
using NzbDrone.Core.Download.Clients;
|
||||
using NzbDrone.Core.Indexers;
|
||||
|
||||
namespace NzbDrone.Core.Download
|
||||
{
|
||||
public interface IProvideDownloadClient
|
||||
{
|
||||
IDownloadClient GetDownloadClient(DownloadProtocol downloadProtocol);
|
||||
IDownloadClient GetDownloadClient(DownloadProtocol downloadProtocol, int indexerId = 0);
|
||||
IEnumerable<IDownloadClient> GetDownloadClients();
|
||||
IDownloadClient Get(int id);
|
||||
}
|
||||
@@ -18,17 +19,23 @@ namespace NzbDrone.Core.Download
|
||||
private readonly Logger _logger;
|
||||
private readonly IDownloadClientFactory _downloadClientFactory;
|
||||
private readonly IDownloadClientStatusService _downloadClientStatusService;
|
||||
private readonly IIndexerFactory _indexerFactory;
|
||||
private readonly ICached<int> _lastUsedDownloadClient;
|
||||
|
||||
public DownloadClientProvider(IDownloadClientStatusService downloadClientStatusService, IDownloadClientFactory downloadClientFactory, ICacheManager cacheManager, Logger logger)
|
||||
public DownloadClientProvider(IDownloadClientStatusService downloadClientStatusService,
|
||||
IDownloadClientFactory downloadClientFactory,
|
||||
IIndexerFactory indexerFactory,
|
||||
ICacheManager cacheManager,
|
||||
Logger logger)
|
||||
{
|
||||
_logger = logger;
|
||||
_downloadClientFactory = downloadClientFactory;
|
||||
_downloadClientStatusService = downloadClientStatusService;
|
||||
_indexerFactory = indexerFactory;
|
||||
_lastUsedDownloadClient = cacheManager.GetCache<int>(GetType(), "lastDownloadClientId");
|
||||
}
|
||||
|
||||
public IDownloadClient GetDownloadClient(DownloadProtocol downloadProtocol)
|
||||
public IDownloadClient GetDownloadClient(DownloadProtocol downloadProtocol, int indexerId = 0)
|
||||
{
|
||||
var availableProviders = _downloadClientFactory.GetAvailableProviders().Where(v => v.Protocol == downloadProtocol).ToList();
|
||||
|
||||
@@ -37,6 +44,23 @@ namespace NzbDrone.Core.Download
|
||||
return null;
|
||||
}
|
||||
|
||||
if (indexerId > 0)
|
||||
{
|
||||
var indexer = _indexerFactory.Find(indexerId);
|
||||
|
||||
if (indexer is { DownloadClientId: > 0 })
|
||||
{
|
||||
var client = availableProviders.SingleOrDefault(d => d.Definition.Id == indexer.DownloadClientId);
|
||||
|
||||
if (client == null)
|
||||
{
|
||||
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())
|
||||
@@ -54,7 +78,7 @@ namespace NzbDrone.Core.Download
|
||||
}
|
||||
|
||||
// Use the first priority clients first
|
||||
availableProviders = availableProviders.GroupBy(v => (v.Definition as DownloadClientDefinition).Priority)
|
||||
availableProviders = availableProviders.GroupBy(v => ((DownloadClientDefinition)v.Definition).Priority)
|
||||
.OrderBy(v => v.Key)
|
||||
.First().OrderBy(v => v.Definition.Id).ToList();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user