mirror of
https://github.com/fergalmoran/Readarr.git
synced 2025-12-26 11:29:25 +00:00
New: Resolve download client by name using 'downloadClient' for pushed releases
Closes #3053
This commit is contained in:
@@ -20,6 +20,7 @@ namespace Readarr.Api.V1.Indexers
|
|||||||
private readonly IMakeDownloadDecision _downloadDecisionMaker;
|
private readonly IMakeDownloadDecision _downloadDecisionMaker;
|
||||||
private readonly IProcessDownloadDecisions _downloadDecisionProcessor;
|
private readonly IProcessDownloadDecisions _downloadDecisionProcessor;
|
||||||
private readonly IIndexerFactory _indexerFactory;
|
private readonly IIndexerFactory _indexerFactory;
|
||||||
|
private readonly IDownloadClientFactory _downloadClientFactory;
|
||||||
private readonly Logger _logger;
|
private readonly Logger _logger;
|
||||||
|
|
||||||
private static readonly object PushLock = new object();
|
private static readonly object PushLock = new object();
|
||||||
@@ -27,11 +28,13 @@ namespace Readarr.Api.V1.Indexers
|
|||||||
public ReleasePushController(IMakeDownloadDecision downloadDecisionMaker,
|
public ReleasePushController(IMakeDownloadDecision downloadDecisionMaker,
|
||||||
IProcessDownloadDecisions downloadDecisionProcessor,
|
IProcessDownloadDecisions downloadDecisionProcessor,
|
||||||
IIndexerFactory indexerFactory,
|
IIndexerFactory indexerFactory,
|
||||||
|
IDownloadClientFactory downloadClientFactory,
|
||||||
Logger logger)
|
Logger logger)
|
||||||
{
|
{
|
||||||
_downloadDecisionMaker = downloadDecisionMaker;
|
_downloadDecisionMaker = downloadDecisionMaker;
|
||||||
_downloadDecisionProcessor = downloadDecisionProcessor;
|
_downloadDecisionProcessor = downloadDecisionProcessor;
|
||||||
_indexerFactory = indexerFactory;
|
_indexerFactory = indexerFactory;
|
||||||
|
_downloadClientFactory = downloadClientFactory;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
|
|
||||||
PostValidator.RuleFor(s => s.Title).NotEmpty();
|
PostValidator.RuleFor(s => s.Title).NotEmpty();
|
||||||
@@ -53,6 +56,8 @@ namespace Readarr.Api.V1.Indexers
|
|||||||
|
|
||||||
ResolveIndexer(info);
|
ResolveIndexer(info);
|
||||||
|
|
||||||
|
var downloadClientId = ResolveDownloadClientId(release);
|
||||||
|
|
||||||
DownloadDecision decision;
|
DownloadDecision decision;
|
||||||
|
|
||||||
lock (PushLock)
|
lock (PushLock)
|
||||||
@@ -61,7 +66,7 @@ namespace Readarr.Api.V1.Indexers
|
|||||||
|
|
||||||
decision = decisions.FirstOrDefault();
|
decision = decisions.FirstOrDefault();
|
||||||
|
|
||||||
_downloadDecisionProcessor.ProcessDecision(decision, release.DownloadClientId).GetAwaiter().GetResult();
|
_downloadDecisionProcessor.ProcessDecision(decision, downloadClientId).GetAwaiter().GetResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (decision?.RemoteBook.ParsedBookInfo == null)
|
if (decision?.RemoteBook.ParsedBookInfo == null)
|
||||||
@@ -106,5 +111,26 @@ namespace Readarr.Api.V1.Indexers
|
|||||||
_logger.Debug("Push Release {0} not associated with an indexer.", release.Title);
|
_logger.Debug("Push Release {0} not associated with an indexer.", release.Title);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int? ResolveDownloadClientId(ReleaseResource release)
|
||||||
|
{
|
||||||
|
var downloadClientId = release.DownloadClientId.GetValueOrDefault();
|
||||||
|
|
||||||
|
if (downloadClientId == 0 && release.DownloadClient.IsNotNullOrWhiteSpace())
|
||||||
|
{
|
||||||
|
var downloadClient = _downloadClientFactory.All().FirstOrDefault(v => v.Name.EqualsIgnoreCase(release.DownloadClient));
|
||||||
|
|
||||||
|
if (downloadClient != null)
|
||||||
|
{
|
||||||
|
_logger.Debug("Push Release {0} associated with download client {1} - {2}.", release.Title, downloadClientId, release.DownloadClient);
|
||||||
|
|
||||||
|
return downloadClient.Id;
|
||||||
|
}
|
||||||
|
|
||||||
|
_logger.Debug("Push Release {0} not associated with known download client {1}.", release.Title, release.DownloadClient);
|
||||||
|
}
|
||||||
|
|
||||||
|
return release.DownloadClientId;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,6 +59,9 @@ namespace Readarr.Api.V1.Indexers
|
|||||||
|
|
||||||
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
|
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
|
||||||
public int? DownloadClientId { get; set; }
|
public int? DownloadClientId { get; set; }
|
||||||
|
|
||||||
|
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
|
||||||
|
public string DownloadClient { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class ReleaseResourceMapper
|
public static class ReleaseResourceMapper
|
||||||
|
|||||||
Reference in New Issue
Block a user