diff --git a/src/NzbDrone.Core.Test/IndexerTests/IndexerCapabilitiesCategoriesFixture.cs b/src/NzbDrone.Core.Test/IndexerTests/IndexerCapabilitiesCategoriesFixture.cs new file mode 100644 index 000000000..a571e0477 --- /dev/null +++ b/src/NzbDrone.Core.Test/IndexerTests/IndexerCapabilitiesCategoriesFixture.cs @@ -0,0 +1,87 @@ +using System.Linq; +using FluentAssertions; +using NUnit.Framework; +using NzbDrone.Core.Indexers; +using NzbDrone.Core.Test.Framework; + +namespace NzbDrone.Core.Test.IndexerTests +{ + [TestFixture] + public class IndexerCapabilitiesCategoriesFixture : CoreTest + { + [Test] + public void should_support_parent_if_child_mapping() + { + Subject.AddCategoryMapping(1, NewznabStandardCategory.MoviesSD, "Filme SD"); + + var categories = new int[] { 2000 }; + + var supported = Subject.SupportedCategories(categories); + + supported.Should().HaveCount(1); + } + + [Test] + public void should_support_category_if_mapped() + { + Subject.AddCategoryMapping(1, NewznabStandardCategory.MoviesSD, "Filme SD"); + + var categories = new int[] { 2030 }; + + var supported = Subject.SupportedCategories(categories); + + supported.Should().HaveCount(1); + } + + [Test] + public void should_not_support_category_if_not_mapped() + { + Subject.AddCategoryMapping(1, NewznabStandardCategory.MoviesSD, "Filme SD"); + + var categories = new int[] { 2040 }; + + var supported = Subject.SupportedCategories(categories); + + supported.Should().HaveCount(0); + } + + [Test] + public void should_get_tracker_category_list() + { + Subject.AddCategoryMapping(1, NewznabStandardCategory.MoviesSD, "Filme SD"); + Subject.AddCategoryMapping(2, NewznabStandardCategory.MoviesHD, "Filme HD"); + + var supported = Subject.GetTrackerCategories(); + + supported.Should().HaveCount(2); + supported.First().Should().NotBeNull(); + supported.First().Should().Be("1"); + } + + [Test] + public void should_get_category_by_tracker_id() + { + Subject.AddCategoryMapping(1, NewznabStandardCategory.MoviesSD, "Filme SD"); + Subject.AddCategoryMapping(2, NewznabStandardCategory.MoviesHD, "Filme HD"); + + var supported = Subject.MapTrackerCatToNewznab(2.ToString()); + + supported.Should().HaveCount(2); + supported.First().Should().NotBeNull(); + supported.First().Id.Should().Be(NewznabStandardCategory.MoviesHD.Id); + } + + [Test] + public void should_get_category_by_tracker_desc() + { + Subject.AddCategoryMapping(1, NewznabStandardCategory.MoviesSD, "Filme SD"); + Subject.AddCategoryMapping(2, NewznabStandardCategory.MoviesHD, "Filme HD"); + + var supported = Subject.MapTrackerCatDescToNewznab("Filme HD"); + + supported.Should().HaveCount(2); + supported.First().Should().NotBeNull(); + supported.First().Id.Should().Be(NewznabStandardCategory.MoviesHD.Id); + } + } +} diff --git a/src/NzbDrone.Core/Applications/Lidarr/Lidarr.cs b/src/NzbDrone.Core/Applications/Lidarr/Lidarr.cs index 1af2b7901..e275f8d09 100644 --- a/src/NzbDrone.Core/Applications/Lidarr/Lidarr.cs +++ b/src/NzbDrone.Core/Applications/Lidarr/Lidarr.cs @@ -124,7 +124,17 @@ namespace NzbDrone.Core.Applications.Lidarr if (!lidarrIndexer.Equals(remoteIndexer)) { - _lidarrV1Proxy.UpdateIndexer(lidarrIndexer, Settings); + if (indexer.Capabilities.Categories.SupportedCategories(Settings.SyncCategories.ToArray()).Any()) + { + // Update the indexer if it still has categories that match + _lidarrV1Proxy.UpdateIndexer(lidarrIndexer, Settings); + } + else + { + // Else remove it, it no longer should be used + _lidarrV1Proxy.RemoveIndexer(remoteIndexer.Id, Settings); + _appIndexerMapService.Delete(indexerMapping.Id); + } } } else diff --git a/src/NzbDrone.Core/Applications/Radarr/Radarr.cs b/src/NzbDrone.Core/Applications/Radarr/Radarr.cs index e5c8c25ab..e5719736e 100644 --- a/src/NzbDrone.Core/Applications/Radarr/Radarr.cs +++ b/src/NzbDrone.Core/Applications/Radarr/Radarr.cs @@ -124,7 +124,17 @@ namespace NzbDrone.Core.Applications.Radarr if (!radarrIndexer.Equals(remoteIndexer)) { - _radarrV3Proxy.UpdateIndexer(radarrIndexer, Settings); + if (indexer.Capabilities.Categories.SupportedCategories(Settings.SyncCategories.ToArray()).Any()) + { + // Update the indexer if it still has categories that match + _radarrV3Proxy.UpdateIndexer(radarrIndexer, Settings); + } + else + { + // Else remove it, it no longer should be used + _radarrV3Proxy.RemoveIndexer(remoteIndexer.Id, Settings); + _appIndexerMapService.Delete(indexerMapping.Id); + } } } else diff --git a/src/NzbDrone.Core/Applications/Readarr/Readarr.cs b/src/NzbDrone.Core/Applications/Readarr/Readarr.cs index f3603886d..606304a11 100644 --- a/src/NzbDrone.Core/Applications/Readarr/Readarr.cs +++ b/src/NzbDrone.Core/Applications/Readarr/Readarr.cs @@ -124,7 +124,17 @@ namespace NzbDrone.Core.Applications.Readarr if (!readarrIndexer.Equals(remoteIndexer)) { - _readarrV1Proxy.UpdateIndexer(readarrIndexer, Settings); + if (indexer.Capabilities.Categories.SupportedCategories(Settings.SyncCategories.ToArray()).Any()) + { + // Update the indexer if it still has categories that match + _readarrV1Proxy.UpdateIndexer(readarrIndexer, Settings); + } + else + { + // Else remove it, it no longer should be used + _readarrV1Proxy.RemoveIndexer(remoteIndexer.Id, Settings); + _appIndexerMapService.Delete(indexerMapping.Id); + } } } else diff --git a/src/NzbDrone.Core/Applications/Sonarr/Sonarr.cs b/src/NzbDrone.Core/Applications/Sonarr/Sonarr.cs index 196b6f14a..9538cee90 100644 --- a/src/NzbDrone.Core/Applications/Sonarr/Sonarr.cs +++ b/src/NzbDrone.Core/Applications/Sonarr/Sonarr.cs @@ -124,7 +124,17 @@ namespace NzbDrone.Core.Applications.Sonarr if (!sonarrIndexer.Equals(remoteIndexer)) { - _sonarrV3Proxy.UpdateIndexer(sonarrIndexer, Settings); + if (indexer.Capabilities.Categories.SupportedCategories(Settings.SyncCategories.ToArray()).Any() || indexer.Capabilities.Categories.SupportedCategories(Settings.AnimeSyncCategories.ToArray()).Any()) + { + // Update the indexer if it still has categories that match + _sonarrV3Proxy.UpdateIndexer(sonarrIndexer, Settings); + } + else + { + // Else remove it, it no longer should be used + _sonarrV3Proxy.RemoveIndexer(remoteIndexer.Id, Settings); + _appIndexerMapService.Delete(indexerMapping.Id); + } } } else diff --git a/src/NzbDrone.Core/Applications/Whisparr/Whisparr.cs b/src/NzbDrone.Core/Applications/Whisparr/Whisparr.cs index f665905cc..a9a45c06a 100644 --- a/src/NzbDrone.Core/Applications/Whisparr/Whisparr.cs +++ b/src/NzbDrone.Core/Applications/Whisparr/Whisparr.cs @@ -114,7 +114,7 @@ namespace NzbDrone.Core.Applications.Whisparr var appMappings = _appIndexerMapService.GetMappingsForApp(Definition.Id); var indexerMapping = appMappings.FirstOrDefault(m => m.IndexerId == indexer.Id); - var radarrIndexer = BuildWhisparrIndexer(indexer, indexer.Protocol, indexerMapping?.RemoteIndexerId ?? 0); + var whisparrIndexer = BuildWhisparrIndexer(indexer, indexer.Protocol, indexerMapping?.RemoteIndexerId ?? 0); var remoteIndexer = _whisparrV3Proxy.GetIndexer(indexerMapping.RemoteIndexerId, Settings); @@ -122,9 +122,19 @@ namespace NzbDrone.Core.Applications.Whisparr { _logger.Debug("Remote indexer found, syncing with current settings"); - if (!radarrIndexer.Equals(remoteIndexer)) + if (!whisparrIndexer.Equals(remoteIndexer)) { - _whisparrV3Proxy.UpdateIndexer(radarrIndexer, Settings); + if (indexer.Capabilities.Categories.SupportedCategories(Settings.SyncCategories.ToArray()).Any()) + { + // Update the indexer if it still has categories that match + _whisparrV3Proxy.UpdateIndexer(whisparrIndexer, Settings); + } + else + { + // Else remove it, it no longer should be used + _whisparrV3Proxy.RemoveIndexer(remoteIndexer.Id, Settings); + _appIndexerMapService.Delete(indexerMapping.Id); + } } } else @@ -134,8 +144,8 @@ namespace NzbDrone.Core.Applications.Whisparr if (indexer.Capabilities.Categories.SupportedCategories(Settings.SyncCategories.ToArray()).Any()) { _logger.Debug("Remote indexer not found, re-adding {0} to Whisparr", indexer.Name); - radarrIndexer.Id = 0; - var newRemoteIndexer = _whisparrV3Proxy.AddIndexer(radarrIndexer, Settings); + whisparrIndexer.Id = 0; + var newRemoteIndexer = _whisparrV3Proxy.AddIndexer(whisparrIndexer, Settings); _appIndexerMapService.Insert(new AppIndexerMap { AppId = Definition.Id, IndexerId = indexer.Id, RemoteIndexerId = newRemoteIndexer.Id }); } else