From a552389ee87ce4e963f137c867e9a559e0564e6e Mon Sep 17 00:00:00 2001 From: Qstick Date: Fri, 10 Jul 2020 22:02:55 -0400 Subject: [PATCH] Fixed: Don't duplicate languages from MediaInfo --- .../AugmentLanguageFromMediaInfoFixture.cs | 111 ++++++++++++++++++ .../Language/AugmentLanguageFromMediaInfo.cs | 2 +- 2 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 src/NzbDrone.Core.Test/MediaFiles/MovieImport/Aggregation/Aggregators/Augmenters/Language/AugmentLanguageFromMediaInfoFixture.cs diff --git a/src/NzbDrone.Core.Test/MediaFiles/MovieImport/Aggregation/Aggregators/Augmenters/Language/AugmentLanguageFromMediaInfoFixture.cs b/src/NzbDrone.Core.Test/MediaFiles/MovieImport/Aggregation/Aggregators/Augmenters/Language/AugmentLanguageFromMediaInfoFixture.cs new file mode 100644 index 000000000..e7bd14bc1 --- /dev/null +++ b/src/NzbDrone.Core.Test/MediaFiles/MovieImport/Aggregation/Aggregators/Augmenters/Language/AugmentLanguageFromMediaInfoFixture.cs @@ -0,0 +1,111 @@ +using FizzWare.NBuilder; +using FluentAssertions; +using NUnit.Framework; +using NzbDrone.Core.Languages; +using NzbDrone.Core.MediaFiles.MediaInfo; +using NzbDrone.Core.MediaFiles.MovieImport.Aggregation.Aggregators.Augmenters.Language; +using NzbDrone.Core.Parser; +using NzbDrone.Core.Parser.Model; +using NzbDrone.Core.Test.Framework; + +namespace NzbDrone.Core.Test.MediaFiles.MovieImport.Aggregation.Aggregators.Augmenters.Language +{ + [TestFixture] + public class AugmentLanguageFromMediaInfoFixture : CoreTest + { + [Test] + public void should_return_null_if_media_info_is_null() + { + var localMovie = Builder.CreateNew() + .With(l => l.MediaInfo = null) + .Build(); + + Subject.AugmentLanguage(localMovie).Should().Be(null); + } + + [Test] + public void should_return_language_for_single_known_language() + { + var mediaInfo = Builder.CreateNew() + .With(m => m.AudioLanguages = "English") + .Build(); + + var localMovie = Builder.CreateNew() + .With(l => l.MediaInfo = mediaInfo) + .Build(); + + var result = Subject.AugmentLanguage(localMovie); + + result.Languages.Count.Should().Be(1); + result.Languages.Should().Contain(Core.Languages.Language.English); + } + + [Test] + public void should_only_return_one_when_language_duplicated() + { + var mediaInfo = Builder.CreateNew() + .With(m => m.AudioLanguages = "English / English") + .Build(); + + var localMovie = Builder.CreateNew() + .With(l => l.MediaInfo = mediaInfo) + .Build(); + + var result = Subject.AugmentLanguage(localMovie); + + result.Languages.Count.Should().Be(1); + result.Languages.Should().Contain(Core.Languages.Language.English); + } + + [Test] + public void should_return_null_if_all_unknown() + { + var mediaInfo = Builder.CreateNew() + .With(m => m.AudioLanguages = "Pirate / Pirate") + .Build(); + + var localMovie = Builder.CreateNew() + .With(l => l.MediaInfo = mediaInfo) + .Build(); + + var result = Subject.AugmentLanguage(localMovie); + + result.Should().BeNull(); + } + + [Test] + public void should_return_known_languages_only() + { + var mediaInfo = Builder.CreateNew() + .With(m => m.AudioLanguages = "English / Pirate") + .Build(); + + var localMovie = Builder.CreateNew() + .With(l => l.MediaInfo = mediaInfo) + .Build(); + + var result = Subject.AugmentLanguage(localMovie); + + result.Languages.Count.Should().Be(1); + result.Languages.Should().Contain(Core.Languages.Language.English); + } + + [Test] + public void should_return_multiple_known_languages() + { + var mediaInfo = Builder.CreateNew() + .With(m => m.AudioLanguages = "English / German") + .Build(); + + var localMovie = Builder.CreateNew() + .With(l => l.MediaInfo = mediaInfo) + .Build(); + + var result = Subject.AugmentLanguage(localMovie); + + result.Languages.Count.Should().Be(2); + result.Languages.Should().Contain(Core.Languages.Language.English); + result.Languages.Should().Contain(Core.Languages.Language.German); + } + } +} diff --git a/src/NzbDrone.Core/MediaFiles/MovieImport/Aggregation/Aggregators/Augmenters/Language/AugmentLanguageFromMediaInfo.cs b/src/NzbDrone.Core/MediaFiles/MovieImport/Aggregation/Aggregators/Augmenters/Language/AugmentLanguageFromMediaInfo.cs index 55ec23021..bc22d9f98 100644 --- a/src/NzbDrone.Core/MediaFiles/MovieImport/Aggregation/Aggregators/Augmenters/Language/AugmentLanguageFromMediaInfo.cs +++ b/src/NzbDrone.Core/MediaFiles/MovieImport/Aggregation/Aggregators/Augmenters/Language/AugmentLanguageFromMediaInfo.cs @@ -15,7 +15,7 @@ public AugmentLanguageResult AugmentLanguage(LocalMovie localMovie) return null; } - var audioLanguages = localMovie.MediaInfo.AudioLanguages.Split('/').Distinct().ToList(); + var audioLanguages = localMovie.MediaInfo.AudioLanguages.Split('/').Select(l => l.Trim()).Distinct().ToList(); var languages = new List();