From c8713a73b30be74fe1e4c5722fa476039e13ff9e Mon Sep 17 00:00:00 2001 From: Bogdan Date: Wed, 4 Dec 2024 20:12:04 +0200 Subject: [PATCH] fixup! New: Plugin support --- .../Indexers/ReleasePushController.cs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) 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 FluentValidation.Results; 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 @@ namespace Lidarr.Api.V1.Indexers 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 @@ namespace Lidarr.Api.V1.Indexers IIndexerFactory indexerFactory, IDownloadClientFactory downloadClientFactory, IQualityProfileService qualityProfileService, + KnownTypes knownTypes, Logger logger) : base(qualityProfileService) { @@ -38,6 +42,7 @@ namespace Lidarr.Api.V1.Indexers _downloadDecisionProcessor = downloadDecisionProcessor; _indexerFactory = indexerFactory; _downloadClientFactory = downloadClientFactory; + _knownTypes = knownTypes; _logger = logger; PostValidator.RuleFor(s => s.Title).NotEmpty(); @@ -59,6 +64,7 @@ namespace Lidarr.Api.V1.Indexers info.Guid = "PUSH-" + info.DownloadUrl; + ResolveDownloadProtocol(info); ResolveIndexer(info); var downloadClientId = ResolveDownloadClientId(release); @@ -138,5 +144,20 @@ namespace Lidarr.Api.V1.Indexers 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; + } } }