Skip to content

Commit

Permalink
Fixed: Remove Indexer if categories were changed to not include in sync
Browse files Browse the repository at this point in the history
Applies to Full Sync Update

Fixes #912
  • Loading branch information
Qstick committed Apr 16, 2022
1 parent cf01c52 commit 302ed91
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -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<IndexerCapabilitiesCategories>
{
[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);
}
}
}
12 changes: 11 additions & 1 deletion src/NzbDrone.Core/Applications/Lidarr/Lidarr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,17 @@ public override void UpdateIndexer(IndexerDefinition indexer)

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
Expand Down
12 changes: 11 additions & 1 deletion src/NzbDrone.Core/Applications/Radarr/Radarr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,17 @@ public override void UpdateIndexer(IndexerDefinition indexer)

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
Expand Down
12 changes: 11 additions & 1 deletion src/NzbDrone.Core/Applications/Readarr/Readarr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,17 @@ public override void UpdateIndexer(IndexerDefinition indexer)

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
Expand Down
12 changes: 11 additions & 1 deletion src/NzbDrone.Core/Applications/Sonarr/Sonarr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,17 @@ public override void UpdateIndexer(IndexerDefinition indexer)

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
Expand Down
20 changes: 15 additions & 5 deletions src/NzbDrone.Core/Applications/Whisparr/Whisparr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,17 +114,27 @@ public override void UpdateIndexer(IndexerDefinition indexer)
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);

if (remoteIndexer != null)
{
_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
Expand All @@ -134,8 +144,8 @@ public override void UpdateIndexer(IndexerDefinition indexer)
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
Expand Down

0 comments on commit 302ed91

Please sign in to comment.