diff --git a/src/Radarr.Api.V3/Indexers/ReleasePushController.cs b/src/Radarr.Api.V3/Indexers/ReleasePushController.cs index 2c15feaab..5da9aa1c2 100644 --- a/src/Radarr.Api.V3/Indexers/ReleasePushController.cs +++ b/src/Radarr.Api.V3/Indexers/ReleasePushController.cs @@ -21,6 +21,7 @@ namespace Radarr.Api.V3.Indexers private readonly IMakeDownloadDecision _downloadDecisionMaker; private readonly IProcessDownloadDecisions _downloadDecisionProcessor; private readonly IIndexerFactory _indexerFactory; + private readonly IDownloadClientFactory _downloadClientFactory; private readonly Logger _logger; private static readonly object PushLock = new object(); @@ -28,6 +29,7 @@ namespace Radarr.Api.V3.Indexers public ReleasePushController(IMakeDownloadDecision downloadDecisionMaker, IProcessDownloadDecisions downloadDecisionProcessor, IIndexerFactory indexerFactory, + IDownloadClientFactory downloadClientFactory, IQualityProfileService qualityProfileService, Logger logger) : base(qualityProfileService) @@ -35,6 +37,7 @@ namespace Radarr.Api.V3.Indexers _downloadDecisionMaker = downloadDecisionMaker; _downloadDecisionProcessor = downloadDecisionProcessor; _indexerFactory = indexerFactory; + _downloadClientFactory = downloadClientFactory; _logger = logger; PostValidator.RuleFor(s => s.Title).NotEmpty(); @@ -57,6 +60,8 @@ namespace Radarr.Api.V3.Indexers ResolveIndexer(info); + var downloadClientId = ResolveDownloadClientId(release); + DownloadDecision decision; lock (PushLock) @@ -65,12 +70,12 @@ namespace Radarr.Api.V3.Indexers decision = decisions.FirstOrDefault(); - _downloadDecisionProcessor.ProcessDecision(decision, release.DownloadClientId).GetAwaiter().GetResult(); + _downloadDecisionProcessor.ProcessDecision(decision, downloadClientId).GetAwaiter().GetResult(); } if (decision?.RemoteMovie.ParsedMovieInfo == null) { - throw new ValidationException(new List { new ValidationFailure("Title", "Unable to parse", release.Title) }); + throw new ValidationException(new List { new ("Title", "Unable to parse", release.Title) }); } return MapDecisions(new[] { decision }); @@ -110,5 +115,26 @@ namespace Radarr.Api.V3.Indexers _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; + } } } diff --git a/src/Radarr.Api.V3/Indexers/ReleaseResource.cs b/src/Radarr.Api.V3/Indexers/ReleaseResource.cs index e931e29b1..89d155570 100644 --- a/src/Radarr.Api.V3/Indexers/ReleaseResource.cs +++ b/src/Radarr.Api.V3/Indexers/ReleaseResource.cs @@ -61,6 +61,9 @@ namespace Radarr.Api.V3.Indexers [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public int? DownloadClientId { get; set; } + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public string DownloadClient { get; set; } + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public bool? ShouldOverride { get; set; } }