diff --git a/src/NzbDrone.Core.Test/Download/Aggregation/Aggregators/AggregateLanguagesFixture.cs b/src/NzbDrone.Core.Test/Download/Aggregation/Aggregators/AggregateLanguagesFixture.cs index 50d09a154..9d738a80a 100644 --- a/src/NzbDrone.Core.Test/Download/Aggregation/Aggregators/AggregateLanguagesFixture.cs +++ b/src/NzbDrone.Core.Test/Download/Aggregation/Aggregators/AggregateLanguagesFixture.cs @@ -65,16 +65,17 @@ namespace NzbDrone.Core.Test.Download.Aggregation.Aggregators } [Test] - public void should_return_multi_languages_when_indexer_has_multi_languages_configuration() + public void should_return_multi_languages_when_indexer_id_has_multi_languages_configuration() { var releaseTitle = "Series.Title.S01E01.MULTi.1080p.WEB.H265-RlsGroup"; var indexerDefinition = new IndexerDefinition { + Id = 1, Settings = new TorrentRssIndexerSettings { MultiLanguages = new List { Language.Original.Id, Language.French.Id } } }; Mocker.GetMock() - .Setup(v => v.Get(1)) - .Returns(indexerDefinition); + .Setup(v => v.All()) + .Returns(new List() { indexerDefinition }); _remoteEpisode.ParsedEpisodeInfo = GetParsedEpisodeInfo(new List { }, releaseTitle); _remoteEpisode.Release.IndexerId = 1; @@ -83,17 +84,40 @@ namespace NzbDrone.Core.Test.Download.Aggregation.Aggregators Subject.Aggregate(_remoteEpisode).Languages.Should().BeEquivalentTo(new List { _series.OriginalLanguage, Language.French }); } + [Test] + public void should_return_multi_languages_when_indexer_name_has_multi_languages_configuration() + { + var releaseTitle = "Series.Title.S01E01.MULTi.1080p.WEB.H265-RlsGroup"; + var indexerDefinition = new IndexerDefinition + { + Id = 1, + Name = "MyIndexer (Prowlarr)", + Settings = new TorrentRssIndexerSettings { MultiLanguages = new List { Language.Original.Id, Language.French.Id } } + }; + + Mocker.GetMock() + .Setup(v => v.All()) + .Returns(new List() { indexerDefinition }); + + _remoteEpisode.ParsedEpisodeInfo = GetParsedEpisodeInfo(new List { }, releaseTitle); + _remoteEpisode.Release.Indexer = "MyIndexer (Prowlarr)"; + _remoteEpisode.Release.Title = releaseTitle; + + Subject.Aggregate(_remoteEpisode).Languages.Should().BeEquivalentTo(new List { _series.OriginalLanguage, Language.French }); + } + [Test] public void should_return_multi_languages_when_release_as_unknown_as_default_language_and_indexer_has_multi_languages_configuration() { var releaseTitle = "Series.Title.S01E01.MULTi.1080p.WEB.H265-RlsGroup"; var indexerDefinition = new IndexerDefinition { + Id = 1, Settings = new TorrentRssIndexerSettings { MultiLanguages = new List { Language.Original.Id, Language.French.Id } } }; Mocker.GetMock() - .Setup(v => v.Get(1)) - .Returns(indexerDefinition); + .Setup(v => v.All()) + .Returns(new List() { indexerDefinition }); _remoteEpisode.ParsedEpisodeInfo = GetParsedEpisodeInfo(new List { Language.Unknown }, releaseTitle); _remoteEpisode.Release.IndexerId = 1; @@ -108,11 +132,12 @@ namespace NzbDrone.Core.Test.Download.Aggregation.Aggregators var releaseTitle = "Series.Title.S01E01.MULTi.1080p.WEB.H265-RlsGroup"; var indexerDefinition = new IndexerDefinition { + Id = 1, Settings = new TorrentRssIndexerSettings { } }; Mocker.GetMock() - .Setup(v => v.Get(1)) - .Returns(indexerDefinition); + .Setup(v => v.All()) + .Returns(new List() { indexerDefinition }); _remoteEpisode.ParsedEpisodeInfo = GetParsedEpisodeInfo(new List { }, releaseTitle); _remoteEpisode.Release.IndexerId = 1; @@ -121,6 +146,25 @@ namespace NzbDrone.Core.Test.Download.Aggregation.Aggregators Subject.Aggregate(_remoteEpisode).Languages.Should().BeEquivalentTo(new List { _series.OriginalLanguage }); } + [Test] + public void should_return_original_when_no_indexer_value() + { + var releaseTitle = "Series.Title.S01E01.MULTi.1080p.WEB.H265-RlsGroup"; + var indexerDefinition = new IndexerDefinition + { + Id = 1, + Settings = new TorrentRssIndexerSettings { } + }; + Mocker.GetMock() + .Setup(v => v.All()) + .Returns(new List() { indexerDefinition }); + + _remoteEpisode.ParsedEpisodeInfo = GetParsedEpisodeInfo(new List { }, releaseTitle); + _remoteEpisode.Release.Title = releaseTitle; + + Subject.Aggregate(_remoteEpisode).Languages.Should().BeEquivalentTo(new List { _series.OriginalLanguage }); + } + [Test] public void should_exclude_language_that_is_part_of_episode_title_when_release_tokens_contains_episode_title() { diff --git a/src/NzbDrone.Core.Test/Download/TrackedDownloads/TrackedDownloadServiceFixture.cs b/src/NzbDrone.Core.Test/Download/TrackedDownloads/TrackedDownloadServiceFixture.cs index 3e541c404..0c07b6386 100644 --- a/src/NzbDrone.Core.Test/Download/TrackedDownloads/TrackedDownloadServiceFixture.cs +++ b/src/NzbDrone.Core.Test/Download/TrackedDownloads/TrackedDownloadServiceFixture.cs @@ -7,6 +7,8 @@ using NzbDrone.Core.Download; using NzbDrone.Core.Download.TrackedDownloads; using NzbDrone.Core.History; using NzbDrone.Core.Indexers; +using NzbDrone.Core.Indexers.TorrentRss; +using NzbDrone.Core.Languages; using NzbDrone.Core.Parser; using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Test.Framework; @@ -84,6 +86,80 @@ namespace NzbDrone.Core.Test.Download.TrackedDownloads trackedDownload.RemoteEpisode.MappedSeasonNumber.Should().Be(1); } + [Test] + public void should_set_indexer() + { + var episodeHistory = new EpisodeHistory() + { + DownloadId = "35238", + SourceTitle = "TV Series S01", + SeriesId = 5, + EpisodeId = 4, + EventType = EpisodeHistoryEventType.Grabbed, + }; + episodeHistory.Data.Add("indexer", "MyIndexer (Prowlarr)"); + Mocker.GetMock() + .Setup(s => s.FindByDownloadId(It.Is(sr => sr == "35238"))) + .Returns(new List() + { + episodeHistory + }); + + var indexerDefinition = new IndexerDefinition + { + Id = 1, + Name = "MyIndexer (Prowlarr)", + Settings = new TorrentRssIndexerSettings { MultiLanguages = new List { Language.Original.Id, Language.French.Id } } + }; + Mocker.GetMock() + .Setup(v => v.Get(indexerDefinition.Id)) + .Returns(indexerDefinition); + Mocker.GetMock() + .Setup(v => v.All()) + .Returns(new List() { indexerDefinition }); + + var remoteEpisode = new RemoteEpisode + { + Series = new Series() { Id = 5 }, + Episodes = new List { new Episode { Id = 4 } }, + ParsedEpisodeInfo = new ParsedEpisodeInfo() + { + SeriesTitle = "TV Series", + SeasonNumber = 1 + }, + MappedSeasonNumber = 1 + }; + + Mocker.GetMock() + .Setup(s => s.Map(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), null)) + .Returns(remoteEpisode); + + var client = new DownloadClientDefinition() + { + Id = 1, + Protocol = DownloadProtocol.Torrent + }; + + var item = new DownloadClientItem() + { + Title = "TV.Series.S01.MULTi.1080p.WEB.H265-RlsGroup", + DownloadId = "35238", + DownloadClientInfo = new DownloadClientItemClientInfo + { + Protocol = client.Protocol, + Id = client.Id, + Name = client.Name + } + }; + + var trackedDownload = Subject.TrackDownload(client, item); + + trackedDownload.Should().NotBeNull(); + trackedDownload.RemoteEpisode.Should().NotBeNull(); + trackedDownload.RemoteEpisode.Release.Should().NotBeNull(); + trackedDownload.RemoteEpisode.Release.Indexer.Should().Be("MyIndexer (Prowlarr)"); + } + [Test] public void should_parse_as_special_when_source_title_parsing_fails() { diff --git a/src/NzbDrone.Core/Download/Aggregation/Aggregators/AggregateLanguages.cs b/src/NzbDrone.Core/Download/Aggregation/Aggregators/AggregateLanguages.cs index 77c9c9170..8c38dc5c9 100644 --- a/src/NzbDrone.Core/Download/Aggregation/Aggregators/AggregateLanguages.cs +++ b/src/NzbDrone.Core/Download/Aggregation/Aggregators/AggregateLanguages.cs @@ -76,9 +76,14 @@ namespace NzbDrone.Core.Download.Aggregation.Aggregators languages = languages.Except(languagesToRemove).ToList(); } - if ((languages.Count == 0 || (languages.Count == 1 && languages.First() == Language.Unknown)) && releaseInfo is { IndexerId: > 0 } && releaseInfo.Title.IsNotNullOrWhiteSpace()) + if ((languages.Count == 0 || (languages.Count == 1 && languages.First() == Language.Unknown)) && + releaseInfo?.Title?.IsNotNullOrWhiteSpace() == true && + (releaseInfo is { IndexerId: > 0 } || releaseInfo.Indexer?.IsNotNullOrWhiteSpace() == true)) { - var indexer = _indexerFactory.Get(releaseInfo.IndexerId); + var indexer = _indexerFactory.All() + .FirstOrDefault(v => + (releaseInfo is { IndexerId: > 0 } && releaseInfo.IndexerId == v.Id) || + (releaseInfo.Indexer?.IsNotNullOrWhiteSpace() == true && v.Name.EqualsIgnoreCase(releaseInfo.Indexer))); if (indexer?.Settings is IIndexerSettings settings && settings.MultiLanguages.Any() && Parser.Parser.HasMultipleLanguages(releaseInfo.Title)) { diff --git a/src/NzbDrone.Core/Download/TrackedDownloads/TrackedDownloadService.cs b/src/NzbDrone.Core/Download/TrackedDownloads/TrackedDownloadService.cs index 608221e70..bf5eda8f5 100644 --- a/src/NzbDrone.Core/Download/TrackedDownloads/TrackedDownloadService.cs +++ b/src/NzbDrone.Core/Download/TrackedDownloads/TrackedDownloadService.cs @@ -120,8 +120,6 @@ namespace NzbDrone.Core.Download.TrackedDownloads if (parsedEpisodeInfo != null) { trackedDownload.RemoteEpisode = _parsingService.Map(parsedEpisodeInfo, 0, 0, null); - - _aggregationService.Augment(trackedDownload.RemoteEpisode); } var downloadHistory = _downloadHistoryService.GetLatestDownloadHistoryItem(downloadItem.DownloadId); @@ -158,17 +156,24 @@ namespace NzbDrone.Core.Download.TrackedDownloads } } - if (trackedDownload.RemoteEpisode != null && - Enum.TryParse(grabbedEvent?.Data?.GetValueOrDefault("indexerFlags"), true, out IndexerFlags flags)) + if (trackedDownload.RemoteEpisode != null) { trackedDownload.RemoteEpisode.Release ??= new ReleaseInfo(); - trackedDownload.RemoteEpisode.Release.IndexerFlags = flags; + trackedDownload.RemoteEpisode.Release.Indexer = trackedDownload.Indexer; + trackedDownload.RemoteEpisode.Release.Title = trackedDownload.RemoteEpisode.ParsedEpisodeInfo?.ReleaseTitle; + + if (Enum.TryParse(grabbedEvent?.Data?.GetValueOrDefault("indexerFlags"), true, out IndexerFlags flags)) + { + trackedDownload.RemoteEpisode.Release.IndexerFlags = flags; + } } } - // Calculate custom formats if (trackedDownload.RemoteEpisode != null) { + _aggregationService.Augment(trackedDownload.RemoteEpisode); + + // Calculate custom formats trackedDownload.RemoteEpisode.CustomFormats = _formatCalculator.ParseCustomFormat(trackedDownload.RemoteEpisode, downloadItem.TotalSize); }