diff --git a/src/NzbDrone.Core.Test/Download/Aggregation/Aggregators/AggregateLanguagesFixture.cs b/src/NzbDrone.Core.Test/Download/Aggregation/Aggregators/AggregateLanguagesFixture.cs index db353fa69..638ea8401 100644 --- a/src/NzbDrone.Core.Test/Download/Aggregation/Aggregators/AggregateLanguagesFixture.cs +++ b/src/NzbDrone.Core.Test/Download/Aggregation/Aggregators/AggregateLanguagesFixture.cs @@ -74,7 +74,7 @@ public void should_return_multi_languages_when_indexer_id_has_multi_languages_co Settings = new TorrentRssIndexerSettings { MultiLanguages = new List { Language.Original.Id, Language.French.Id } } }; Mocker.GetMock() - .Setup(v => v.Get(1)) + .Setup(v => v.Find(1)) .Returns(indexerDefinition); _remoteMovie.ParsedMovieInfo = GetParsedMovieInfo(new List { }, releaseTitle); @@ -82,7 +82,7 @@ public void should_return_multi_languages_when_indexer_id_has_multi_languages_co _remoteMovie.Release.Title = releaseTitle; Subject.Aggregate(_remoteMovie).Languages.Should().BeEquivalentTo(new List { _movie.MovieMetadata.Value.OriginalLanguage, Language.French }); - Mocker.GetMock().Verify(c => c.Get(1), Times.Once()); + Mocker.GetMock().Verify(c => c.Find(1), Times.Once()); Mocker.GetMock().VerifyNoOtherCalls(); } @@ -104,7 +104,7 @@ public void should_return_multi_languages_from_indexer_with_id_when_indexer_id_a }; Mocker.GetMock() - .Setup(v => v.Get(1)) + .Setup(v => v.Find(1)) .Returns(indexerDefinition1); Mocker.GetMock() @@ -117,7 +117,7 @@ public void should_return_multi_languages_from_indexer_with_id_when_indexer_id_a _remoteMovie.Release.Title = releaseTitle; Subject.Aggregate(_remoteMovie).Languages.Should().BeEquivalentTo(new List { _movie.MovieMetadata.Value.OriginalLanguage, Language.French }); - Mocker.GetMock().Verify(c => c.Get(1), Times.Once()); + Mocker.GetMock().Verify(c => c.Find(1), Times.Once()); Mocker.GetMock().VerifyNoOtherCalls(); } @@ -155,7 +155,7 @@ public void should_return_multi_languages_when_release_as_unknown_as_default_lan Settings = new TorrentRssIndexerSettings { MultiLanguages = new List { Language.Original.Id, Language.French.Id } } }; Mocker.GetMock() - .Setup(v => v.Get(1)) + .Setup(v => v.Find(1)) .Returns(indexerDefinition); _remoteMovie.ParsedMovieInfo = GetParsedMovieInfo(new List { Language.Unknown }, releaseTitle); @@ -163,7 +163,7 @@ public void should_return_multi_languages_when_release_as_unknown_as_default_lan _remoteMovie.Release.Title = releaseTitle; Subject.Aggregate(_remoteMovie).Languages.Should().BeEquivalentTo(new List { _movie.MovieMetadata.Value.OriginalLanguage, Language.French }); - Mocker.GetMock().Verify(c => c.Get(1), Times.Once()); + Mocker.GetMock().Verify(c => c.Find(1), Times.Once()); Mocker.GetMock().VerifyNoOtherCalls(); } @@ -177,7 +177,7 @@ public void should_return_original_when_indexer_has_no_multi_languages_configura Settings = new TorrentRssIndexerSettings { } }; Mocker.GetMock() - .Setup(v => v.Get(1)) + .Setup(v => v.Find(1)) .Returns(indexerDefinition); _remoteMovie.ParsedMovieInfo = GetParsedMovieInfo(new List { }, releaseTitle); @@ -185,7 +185,7 @@ public void should_return_original_when_indexer_has_no_multi_languages_configura _remoteMovie.Release.Title = releaseTitle; Subject.Aggregate(_remoteMovie).Languages.Should().BeEquivalentTo(new List { _movie.MovieMetadata.Value.OriginalLanguage }); - Mocker.GetMock().Verify(c => c.Get(1), Times.Once()); + Mocker.GetMock().Verify(c => c.Find(1), Times.Once()); Mocker.GetMock().VerifyNoOtherCalls(); } @@ -248,5 +248,85 @@ public void should_use_reparse_language_after_determining_languages_that_are_in_ Subject.Aggregate(_remoteMovie).Languages.Should().Equal(Language.Greek); } + + [Test] + public void should_return_multi_languages_from_indexer_with_name_when_indexer_id_does_not_exist() + { + var releaseTitle = "Series.Title.S01E01.MULTi.1080p.WEB.H265-RlsGroup"; + var indexerDefinition1 = new IndexerDefinition + { + Id = 1, + Name = "MyIndexer1", + Settings = new TorrentRssIndexerSettings { MultiLanguages = new List { Language.Original.Id, Language.French.Id } } + }; + var indexerDefinition2 = new IndexerDefinition + { + Id = 2, + Name = "MyIndexer2", + Settings = new TorrentRssIndexerSettings { MultiLanguages = new List { Language.Original.Id, Language.German.Id } } + }; + + Mocker.GetMock() + .Setup(v => v.Find(1)) + .Returns(null as IndexerDefinition); + + Mocker.GetMock() + .Setup(v => v.FindByName("MyIndexer1")) + .Returns(indexerDefinition1); + + Mocker.GetMock() + .Setup(v => v.All()) + .Returns(new List() { indexerDefinition1, indexerDefinition2 }); + + _remoteMovie.ParsedMovieInfo = GetParsedMovieInfo(new List { }, releaseTitle); + _remoteMovie.Release.IndexerId = 10; + _remoteMovie.Release.Indexer = "MyIndexer1"; + _remoteMovie.Release.Title = releaseTitle; + + Subject.Aggregate(_remoteMovie).Languages.Should().BeEquivalentTo(new List { _movie.MovieMetadata.Value.OriginalLanguage, Language.French }); + Mocker.GetMock().Verify(c => c.Find(10), Times.Once()); + Mocker.GetMock().Verify(c => c.FindByName("MyIndexer1"), Times.Once()); + Mocker.GetMock().VerifyNoOtherCalls(); + } + + [Test] + public void should_return_multi_languages_from_indexer_with_name_when_indexer_id_not_available() + { + var releaseTitle = "Series.Title.S01E01.MULTi.1080p.WEB.H265-RlsGroup"; + var indexerDefinition1 = new IndexerDefinition + { + Id = 1, + Name = "MyIndexer1", + Settings = new TorrentRssIndexerSettings { MultiLanguages = new List { Language.Original.Id, Language.French.Id } } + }; + var indexerDefinition2 = new IndexerDefinition + { + Id = 2, + Name = "MyIndexer2", + Settings = new TorrentRssIndexerSettings { MultiLanguages = new List { Language.Original.Id, Language.German.Id } } + }; + + Mocker.GetMock() + .Setup(v => v.Find(1)) + .Returns(null as IndexerDefinition); + + Mocker.GetMock() + .Setup(v => v.FindByName("MyIndexer1")) + .Returns(indexerDefinition1); + + Mocker.GetMock() + .Setup(v => v.All()) + .Returns(new List() { indexerDefinition1, indexerDefinition2 }); + + _remoteMovie.ParsedMovieInfo = GetParsedMovieInfo(new List { }, releaseTitle); + _remoteMovie.Release.IndexerId = 0; + _remoteMovie.Release.Indexer = "MyIndexer1"; + _remoteMovie.Release.Title = releaseTitle; + + Subject.Aggregate(_remoteMovie).Languages.Should().BeEquivalentTo(new List { _movie.MovieMetadata.Value.OriginalLanguage, Language.French }); + Mocker.GetMock().Verify(c => c.Find(10), Times.Never()); + Mocker.GetMock().Verify(c => c.FindByName("MyIndexer1"), Times.Once()); + Mocker.GetMock().VerifyNoOtherCalls(); + } } } diff --git a/src/NzbDrone.Core/Download/Aggregation/Aggregators/AggregateLanguages.cs b/src/NzbDrone.Core/Download/Aggregation/Aggregators/AggregateLanguages.cs index 33bd341d6..5b89aa82e 100644 --- a/src/NzbDrone.Core/Download/Aggregation/Aggregators/AggregateLanguages.cs +++ b/src/NzbDrone.Core/Download/Aggregation/Aggregators/AggregateLanguages.cs @@ -77,9 +77,10 @@ public RemoteMovie Aggregate(RemoteMovie remoteMovie) if (releaseInfo is { IndexerId: > 0 }) { - indexer = _indexerFactory.Get(releaseInfo.IndexerId); + indexer = _indexerFactory.Find(releaseInfo.IndexerId); } - else if (releaseInfo.Indexer?.IsNotNullOrWhiteSpace() == true) + + if (indexer == null && releaseInfo.Indexer?.IsNotNullOrWhiteSpace() == true) { indexer = _indexerFactory.FindByName(releaseInfo.Indexer); }