From 4002cb764b1892796f493fad531dd4bb6bcc7938 Mon Sep 17 00:00:00 2001 From: Qstick Date: Sun, 1 May 2022 16:41:48 -0500 Subject: [PATCH] New: Auto map known legacy BaseUrls for non-Cardigann --- src/NzbDrone.Core/Datastore/TableMapping.cs | 1 + .../Definitions/BroadcastheNet/BroadcastheNet.cs | 2 ++ .../Indexers/Definitions/Cardigann/Cardigann.cs | 1 + src/NzbDrone.Core/Indexers/HttpIndexerBase.cs | 1 + src/NzbDrone.Core/Indexers/IIndexer.cs | 1 + src/NzbDrone.Core/Indexers/IndexerBase.cs | 13 +++++++++++-- src/NzbDrone.Core/Indexers/IndexerDefinition.cs | 1 + src/NzbDrone.Core/Indexers/IndexerFactory.cs | 2 ++ src/Prowlarr.Api.V1/Indexers/IndexerResource.cs | 2 ++ 9 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/NzbDrone.Core/Datastore/TableMapping.cs b/src/NzbDrone.Core/Datastore/TableMapping.cs index 85ab151de..126c02740 100644 --- a/src/NzbDrone.Core/Datastore/TableMapping.cs +++ b/src/NzbDrone.Core/Datastore/TableMapping.cs @@ -50,6 +50,7 @@ namespace NzbDrone.Core.Datastore .Ignore(i => i.Language) .Ignore(i => i.Encoding) .Ignore(i => i.IndexerUrls) + .Ignore(i => i.LegacyUrls) .Ignore(i => i.Protocol) .Ignore(i => i.Privacy) .Ignore(i => i.SupportsRss) diff --git a/src/NzbDrone.Core/Indexers/Definitions/BroadcastheNet/BroadcastheNet.cs b/src/NzbDrone.Core/Indexers/Definitions/BroadcastheNet/BroadcastheNet.cs index a7c9c00dd..45f036260 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/BroadcastheNet/BroadcastheNet.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/BroadcastheNet/BroadcastheNet.cs @@ -20,6 +20,8 @@ namespace NzbDrone.Core.Indexers.BroadcastheNet public override TimeSpan RateLimit => TimeSpan.FromSeconds(5); public override string[] IndexerUrls => new string[] { "https://api.broadcasthe.net/" }; + public override string[] LegacyUrls => new string[] { "http://api.broadcasthe.net/" }; + public override string Description => "BroadcasTheNet (BTN) is an invite-only torrent tracker focused on TV shows"; public BroadcastheNet(IIndexerHttpClient httpClient, IEventAggregator eventAggregator, IIndexerStatusService indexerStatusService, IConfigService configService, Logger logger) diff --git a/src/NzbDrone.Core/Indexers/Definitions/Cardigann/Cardigann.cs b/src/NzbDrone.Core/Indexers/Definitions/Cardigann/Cardigann.cs index 6f4797c77..23285b6c3 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/Cardigann/Cardigann.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/Cardigann/Cardigann.cs @@ -126,6 +126,7 @@ namespace NzbDrone.Core.Indexers.Cardigann Description = definition.Description, Implementation = GetType().Name, IndexerUrls = definition.Links.ToArray(), + LegacyUrls = definition.Legacylinks.ToArray(), Settings = new CardigannSettings { DefinitionFile = definition.File }, Protocol = DownloadProtocol.Torrent, Privacy = definition.Type switch diff --git a/src/NzbDrone.Core/Indexers/HttpIndexerBase.cs b/src/NzbDrone.Core/Indexers/HttpIndexerBase.cs index f69755bc3..0e0d435fb 100644 --- a/src/NzbDrone.Core/Indexers/HttpIndexerBase.cs +++ b/src/NzbDrone.Core/Indexers/HttpIndexerBase.cs @@ -33,6 +33,7 @@ namespace NzbDrone.Core.Indexers public override Encoding Encoding => Encoding.UTF8; public override string Language => "en-US"; + public override string[] LegacyUrls => new string[] { }; public override bool FollowRedirect => false; public override IndexerCapabilities Capabilities { get; protected set; } diff --git a/src/NzbDrone.Core/Indexers/IIndexer.cs b/src/NzbDrone.Core/Indexers/IIndexer.cs index 1e02c896d..f2bf11c6e 100644 --- a/src/NzbDrone.Core/Indexers/IIndexer.cs +++ b/src/NzbDrone.Core/Indexers/IIndexer.cs @@ -14,6 +14,7 @@ namespace NzbDrone.Core.Indexers IndexerCapabilities Capabilities { get; } string[] IndexerUrls { get; } + string[] LegacyUrls { get; } string Description { get; } Encoding Encoding { get; } string Language { get; } diff --git a/src/NzbDrone.Core/Indexers/IndexerBase.cs b/src/NzbDrone.Core/Indexers/IndexerBase.cs index 9f29f8bdd..655f6e534 100644 --- a/src/NzbDrone.Core/Indexers/IndexerBase.cs +++ b/src/NzbDrone.Core/Indexers/IndexerBase.cs @@ -22,6 +22,7 @@ namespace NzbDrone.Core.Indexers public abstract string Name { get; } public abstract string[] IndexerUrls { get; } + public abstract string[] LegacyUrls { get; } public abstract string Description { get; } public abstract Encoding Encoding { get; } public abstract string Language { get; } @@ -147,9 +148,17 @@ namespace NzbDrone.Core.Indexers protected TSettings GetDefaultBaseUrl(TSettings settings) { - if (settings.BaseUrl.IsNullOrWhiteSpace() && IndexerUrls.First().IsNotNullOrWhiteSpace()) + var defaultLink = IndexerUrls.FirstOrDefault(); + + if (settings.BaseUrl.IsNullOrWhiteSpace() && defaultLink.IsNotNullOrWhiteSpace()) + { + settings.BaseUrl = defaultLink; + } + + if (settings.BaseUrl.IsNotNullOrWhiteSpace() && LegacyUrls.Contains(settings.BaseUrl)) { - settings.BaseUrl = IndexerUrls.First(); + _logger.Debug(string.Format("Changing legacy site link from {0} to {1}", settings.BaseUrl, defaultLink)); + settings.BaseUrl = defaultLink; } return settings; diff --git a/src/NzbDrone.Core/Indexers/IndexerDefinition.cs b/src/NzbDrone.Core/Indexers/IndexerDefinition.cs index 597ac0d2e..4979bf32b 100644 --- a/src/NzbDrone.Core/Indexers/IndexerDefinition.cs +++ b/src/NzbDrone.Core/Indexers/IndexerDefinition.cs @@ -11,6 +11,7 @@ namespace NzbDrone.Core.Indexers public class IndexerDefinition : ProviderDefinition { public string[] IndexerUrls { get; set; } + public string[] LegacyUrls { get; set; } public string Description { get; set; } public Encoding Encoding { get; set; } public string Language { get; set; } diff --git a/src/NzbDrone.Core/Indexers/IndexerFactory.cs b/src/NzbDrone.Core/Indexers/IndexerFactory.cs index d08d57031..022b203b4 100644 --- a/src/NzbDrone.Core/Indexers/IndexerFactory.cs +++ b/src/NzbDrone.Core/Indexers/IndexerFactory.cs @@ -110,6 +110,7 @@ namespace NzbDrone.Core.Indexers } definition.IndexerUrls = defFile.Links.ToArray(); + definition.LegacyUrls = defFile.Legacylinks.ToArray(); definition.Description = defFile.Description; definition.Language = defFile.Language; definition.Encoding = Encoding.GetEncoding(defFile.Encoding); @@ -205,6 +206,7 @@ namespace NzbDrone.Core.Indexers if (definition.Implementation != typeof(Cardigann.Cardigann).Name) { definition.IndexerUrls = provider.IndexerUrls; + definition.LegacyUrls = provider.LegacyUrls; definition.Privacy = provider.Privacy; definition.Description = provider.Description; definition.Encoding = provider.Encoding; diff --git a/src/Prowlarr.Api.V1/Indexers/IndexerResource.cs b/src/Prowlarr.Api.V1/Indexers/IndexerResource.cs index 4dc7cbb08..eb1e88c97 100644 --- a/src/Prowlarr.Api.V1/Indexers/IndexerResource.cs +++ b/src/Prowlarr.Api.V1/Indexers/IndexerResource.cs @@ -15,6 +15,7 @@ namespace Prowlarr.Api.V1.Indexers public class IndexerResource : ProviderResource { public string[] IndexerUrls { get; set; } + public string[] LegacyUrls { get; set; } public string DefinitionName { get; set; } public string Description { get; set; } public string Language { get; set; } @@ -81,6 +82,7 @@ namespace Prowlarr.Api.V1.Indexers resource.InfoLink = string.Format("https://wiki.servarr.com/prowlarr/supported-indexers#{0}", infoLinkName.ToLower().Replace(' ', '-')); resource.AppProfileId = definition.AppProfileId; resource.IndexerUrls = definition.IndexerUrls; + resource.LegacyUrls = definition.LegacyUrls; resource.Description = definition.Description; resource.Language = definition.Language; resource.Encoding = definition.Encoding?.EncodingName ?? null;