diff --git a/src/Lidarr.Api.V1/Indexers/ReleasePushController.cs b/src/Lidarr.Api.V1/Indexers/ReleasePushController.cs index 21b4fb473..6bda6be2c 100644 --- a/src/Lidarr.Api.V1/Indexers/ReleasePushController.cs +++ b/src/Lidarr.Api.V1/Indexers/ReleasePushController.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.Linq; using FluentValidation; @@ -5,6 +6,7 @@ using Lidarr.Http; using Microsoft.AspNetCore.Mvc; using NLog; +using NzbDrone.Common.Composition; using NzbDrone.Common.Extensions; using NzbDrone.Core.Datastore; using NzbDrone.Core.DecisionEngine; @@ -22,6 +24,7 @@ public class ReleasePushController : ReleaseControllerBase private readonly IProcessDownloadDecisions _downloadDecisionProcessor; private readonly IIndexerFactory _indexerFactory; private readonly IDownloadClientFactory _downloadClientFactory; + private readonly KnownTypes _knownTypes; private readonly Logger _logger; private static readonly object PushLock = new object(); @@ -31,6 +34,7 @@ public ReleasePushController(IMakeDownloadDecision downloadDecisionMaker, IIndexerFactory indexerFactory, IDownloadClientFactory downloadClientFactory, IQualityProfileService qualityProfileService, + KnownTypes knownTypes, Logger logger) : base(qualityProfileService) { @@ -38,6 +42,7 @@ public ReleasePushController(IMakeDownloadDecision downloadDecisionMaker, _downloadDecisionProcessor = downloadDecisionProcessor; _indexerFactory = indexerFactory; _downloadClientFactory = downloadClientFactory; + _knownTypes = knownTypes; _logger = logger; PostValidator.RuleFor(s => s.Title).NotEmpty(); @@ -59,6 +64,7 @@ public ActionResult Create(ReleaseResource release) info.Guid = "PUSH-" + info.DownloadUrl; + ResolveDownloadProtocol(info); ResolveIndexer(info); var downloadClientId = ResolveDownloadClientId(release); @@ -138,5 +144,20 @@ private void ResolveIndexer(ReleaseInfo release) return release.DownloadClientId; } + + private void ResolveDownloadProtocol(ReleaseInfo release) + { + var knownDownloadProtocols = _knownTypes.GetImplementations(typeof(IDownloadProtocol)).ToArray(); + + if (knownDownloadProtocols.Any(downloadProtocol => downloadProtocol.Name == release.DownloadProtocol)) + { + return; + } + + var downloadProtocol = knownDownloadProtocols + .Single(c => c.Name.Replace("DownloadProtocol", "").Equals(release.DownloadProtocol, StringComparison.InvariantCultureIgnoreCase)); + + release.DownloadProtocol = downloadProtocol.Name; + } } }