Fixed: Multi Language lost on Import

Fixes #4313
pull/2/head
Qstick 4 years ago
parent f073f0c35c
commit 0142c45210

@ -24,18 +24,24 @@ namespace NzbDrone.Core.Test.MediaFiles.MovieImport.Aggregation.Aggregators
.Build();
}
private ParsedMovieInfo GetParsedMovieInfo(Language language)
private ParsedMovieInfo GetParsedMovieInfo(List<Language> languages)
{
return new ParsedMovieInfo
{
Languages = new List<Language> { 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> { 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> { Language.English });
_localMovie.FileMovieInfo = GetParsedMovieInfo(new List<Language> { 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> { Language.English });
_localMovie.FolderMovieInfo = GetParsedMovieInfo(new List<Language> { Language.English });
_localMovie.FileMovieInfo = GetParsedMovieInfo(new List<Language> { 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> { Language.English });
_localMovie.FolderMovieInfo = GetParsedMovieInfo(new List<Language> { Language.English });
_localMovie.FileMovieInfo = GetParsedMovieInfo(new List<Language> { 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> { Language.English });
_localMovie.FolderMovieInfo = GetParsedMovieInfo(new List<Language> { Language.English, Language.German });
_localMovie.FileMovieInfo = GetParsedMovieInfo(new List<Language> { Language.English });
Subject.Aggregate(_localMovie, false).Languages.Should().Contain(_localMovie.FolderMovieInfo.Languages);
}
}
}

@ -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<Language>();
languages.AddRange(GetLanguage(localMovie.DownloadClientMovieInfo));
languages.AddRange(GetLanguage(localMovie.FolderMovieInfo));
languages.AddRange(GetLanguage(localMovie.FileMovieInfo));
languages.AddRange(localMovie.DownloadClientMovieInfo?.Languages ?? new List<Language>());
var language = new List<Language> { languages.FirstOrDefault(l => l != Language.English) ?? Language.English };
if (!languages.Any(l => l != Language.English))
{
languages.AddRange(localMovie.FolderMovieInfo?.Languages ?? new List<Language>());
}
if (!languages.Any(l => l != Language.English))
{
languages.AddRange(localMovie.FileMovieInfo?.Languages ?? new List<Language>());
}
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;
}

Loading…
Cancel
Save