diff --git a/src/NzbDrone.Core.Test/MediaFiles/MovieImport/Aggregation/Aggregators/AggregateLanguageFixture.cs b/src/NzbDrone.Core.Test/MediaFiles/MovieImport/Aggregation/Aggregators/AggregateLanguageFixture.cs index ca14001c4..b24ec9359 100644 --- a/src/NzbDrone.Core.Test/MediaFiles/MovieImport/Aggregation/Aggregators/AggregateLanguageFixture.cs +++ b/src/NzbDrone.Core.Test/MediaFiles/MovieImport/Aggregation/Aggregators/AggregateLanguageFixture.cs @@ -24,18 +24,24 @@ namespace NzbDrone.Core.Test.MediaFiles.MovieImport.Aggregation.Aggregators .Build(); } - private ParsedMovieInfo GetParsedMovieInfo(Language language) + private ParsedMovieInfo GetParsedMovieInfo(List languages) { return new ParsedMovieInfo { - Languages = new List { language } + Languages = languages }; } + [Test] + public void should_return_default_if_no_info_is_known() + { + Subject.Aggregate(_localMovie, false).Languages.Should().Contain(Language.English); + } + [Test] public void should_return_file_language_when_only_file_info_is_known() { - _localMovie.FileMovieInfo = GetParsedMovieInfo(Language.English); + _localMovie.FileMovieInfo = GetParsedMovieInfo(new List { Language.English }); Subject.Aggregate(_localMovie, false).Languages.Should().Contain(_localMovie.FileMovieInfo.Languages); } @@ -43,8 +49,8 @@ namespace NzbDrone.Core.Test.MediaFiles.MovieImport.Aggregation.Aggregators [Test] public void should_return_folder_language_when_folder_info_is_known() { - _localMovie.FolderMovieInfo = GetParsedMovieInfo(Language.English); - _localMovie.FileMovieInfo = GetParsedMovieInfo(Language.English); + _localMovie.FolderMovieInfo = GetParsedMovieInfo(new List { Language.English }); + _localMovie.FileMovieInfo = GetParsedMovieInfo(new List { Language.English }); Subject.Aggregate(_localMovie, false).Languages.Should().Contain(_localMovie.FolderMovieInfo.Languages); } @@ -52,9 +58,9 @@ namespace NzbDrone.Core.Test.MediaFiles.MovieImport.Aggregation.Aggregators [Test] public void should_return_download_client_item_language_when_download_client_item_info_is_known() { - _localMovie.DownloadClientMovieInfo = GetParsedMovieInfo(Language.English); - _localMovie.FolderMovieInfo = GetParsedMovieInfo(Language.English); - _localMovie.FileMovieInfo = GetParsedMovieInfo(Language.English); + _localMovie.DownloadClientMovieInfo = GetParsedMovieInfo(new List { Language.English }); + _localMovie.FolderMovieInfo = GetParsedMovieInfo(new List { Language.English }); + _localMovie.FileMovieInfo = GetParsedMovieInfo(new List { Language.English }); Subject.Aggregate(_localMovie, false).Languages.Should().Contain(_localMovie.DownloadClientMovieInfo.Languages); } @@ -62,11 +68,21 @@ namespace NzbDrone.Core.Test.MediaFiles.MovieImport.Aggregation.Aggregators [Test] public void should_return_file_language_when_file_language_is_higher_than_others() { - _localMovie.DownloadClientMovieInfo = GetParsedMovieInfo(Language.English); - _localMovie.FolderMovieInfo = GetParsedMovieInfo(Language.English); - _localMovie.FileMovieInfo = GetParsedMovieInfo(Language.French); + _localMovie.DownloadClientMovieInfo = GetParsedMovieInfo(new List { Language.English }); + _localMovie.FolderMovieInfo = GetParsedMovieInfo(new List { Language.English }); + _localMovie.FileMovieInfo = GetParsedMovieInfo(new List { Language.French }); Subject.Aggregate(_localMovie, false).Languages.Should().Contain(_localMovie.FileMovieInfo.Languages); } + + [Test] + public void should_return_multi_language() + { + _localMovie.DownloadClientMovieInfo = GetParsedMovieInfo(new List { Language.English }); + _localMovie.FolderMovieInfo = GetParsedMovieInfo(new List { Language.English, Language.German }); + _localMovie.FileMovieInfo = GetParsedMovieInfo(new List { Language.English }); + + Subject.Aggregate(_localMovie, false).Languages.Should().Contain(_localMovie.FolderMovieInfo.Languages); + } } } diff --git a/src/NzbDrone.Core/MediaFiles/MovieImport/Aggregation/Aggregators/AggregateLanguage.cs b/src/NzbDrone.Core/MediaFiles/MovieImport/Aggregation/Aggregators/AggregateLanguage.cs index cdac2a0df..e4560f850 100644 --- a/src/NzbDrone.Core/MediaFiles/MovieImport/Aggregation/Aggregators/AggregateLanguage.cs +++ b/src/NzbDrone.Core/MediaFiles/MovieImport/Aggregation/Aggregators/AggregateLanguage.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.Linq; using NLog; +using NzbDrone.Common.Extensions; using NzbDrone.Core.Languages; using NzbDrone.Core.Parser.Model; @@ -22,15 +23,26 @@ namespace NzbDrone.Core.MediaFiles.MovieImport.Aggregation.Aggregators // between parsed languages the more preferred item will be used. var languages = new List(); - languages.AddRange(GetLanguage(localMovie.DownloadClientMovieInfo)); - languages.AddRange(GetLanguage(localMovie.FolderMovieInfo)); - languages.AddRange(GetLanguage(localMovie.FileMovieInfo)); + languages.AddRange(localMovie.DownloadClientMovieInfo?.Languages ?? new List()); - var language = new List { languages.FirstOrDefault(l => l != Language.English) ?? Language.English }; + if (!languages.Any(l => l != Language.English)) + { + languages.AddRange(localMovie.FolderMovieInfo?.Languages ?? new List()); + } + + if (!languages.Any(l => l != Language.English)) + { + languages.AddRange(localMovie.FileMovieInfo?.Languages ?? new List()); + } + + if (!languages.Any()) + { + languages.Add(Language.English); + } - _logger.Debug("Using language: {0}", language.First()); + _logger.Debug("Using languages: {0}", languages.Select(l => l.Name).ToList().Join(",")); - localMovie.Languages = language; + localMovie.Languages = languages; return localMovie; }