diff --git a/src/NzbDrone.Core.Test/OrganizerTests/FileNameBuilderTests/FileNameBuilderFixture.cs b/src/NzbDrone.Core.Test/OrganizerTests/FileNameBuilderTests/FileNameBuilderFixture.cs index 4218503b0..088ffcb3c 100644 --- a/src/NzbDrone.Core.Test/OrganizerTests/FileNameBuilderTests/FileNameBuilderFixture.cs +++ b/src/NzbDrone.Core.Test/OrganizerTests/FileNameBuilderTests/FileNameBuilderFixture.cs @@ -364,7 +364,7 @@ namespace NzbDrone.Core.Test.OrganizerTests.FileNameBuilderTests { _namingConfig.StandardMovieFormat = "{Movie.Title}.{MEDIAINFO.FULL}"; - _movieFile.MediaInfo = new Core.MediaFiles.MediaInfo.MediaInfoModel() + _movieFile.MediaInfo = new MediaInfoModel() { VideoFormat = "AVC", AudioFormat = "DTS", @@ -376,12 +376,33 @@ namespace NzbDrone.Core.Test.OrganizerTests.FileNameBuilderTests .Should().Be("South.Park.H264.DTS[EN+ES].[EN+ES+IT]"); } + [TestCase("Norwegian Bokmal", "NB")] + [TestCase("Swedis", "SV")] + [TestCase("Chinese", "ZH")] + public void should_format_languagecodes_properly(string language, string code) + { + _namingConfig.StandardMovieFormat = "{Movie.Title}.{MEDIAINFO.FULL}"; + + _movieFile.MediaInfo = new MediaInfoModel() + { + VideoCodec = "AVC", + AudioFormat = "DTS", + AudioChannels = 6, + AudioLanguages = "English", + Subtitles = language, + SchemaRevision = 3 + }; + + Subject.BuildFileName(_movie, _movieFile) + .Should().Be($"South.Park.X264.DTS.[{code}]"); + } + [Test] public void should_exclude_english_in_mediainfo_audio_language() { _namingConfig.StandardMovieFormat = "{Movie.Title}.{MEDIAINFO.FULL}"; - _movieFile.MediaInfo = new Core.MediaFiles.MediaInfo.MediaInfoModel() + _movieFile.MediaInfo = new MediaInfoModel() { VideoFormat = "AVC", AudioFormat = "DTS", @@ -398,7 +419,7 @@ namespace NzbDrone.Core.Test.OrganizerTests.FileNameBuilderTests { _namingConfig.StandardMovieFormat = "{Movie.Title}.{MEDIAINFO.3D}.{MediaInfo.Simple}"; - _movieFile.MediaInfo = new Core.MediaFiles.MediaInfo.MediaInfoModel() + _movieFile.MediaInfo = new MediaInfoModel() { VideoFormat = "AVC", VideoMultiViewCount = 2, diff --git a/src/NzbDrone.Core/Organizer/FileNameBuilder.cs b/src/NzbDrone.Core/Organizer/FileNameBuilder.cs index b3385e478..d5e4205f0 100644 --- a/src/NzbDrone.Core/Organizer/FileNameBuilder.cs +++ b/src/NzbDrone.Core/Organizer/FileNameBuilder.cs @@ -6,6 +6,7 @@ using System.Linq; using System.Text.RegularExpressions; using NLog; using NzbDrone.Common.EnsureThat; +using NzbDrone.Common.EnvironmentInfo; using NzbDrone.Common.Extensions; using NzbDrone.Core.CustomFormats; using NzbDrone.Core.MediaFiles; @@ -414,9 +415,23 @@ namespace NzbDrone.Core.Organizer var cultures = CultureInfo.GetCultures(CultureTypes.NeutralCultures); for (int i = 0; i < tokens.Count; i++) { + if (tokens[i] == "Swedis") + { + // Probably typo in mediainfo (should be 'Swedish') + tokens[i] = "SV"; + continue; + } + + if (tokens[i] == "Chinese" && OsInfo.IsNotWindows) + { + // Mono only has 'Chinese (Simplified)' & 'Chinese (Traditional)' + tokens[i] = "ZH"; + continue; + } + try { - var cultureInfo = cultures.FirstOrDefault(p => p.EnglishName == tokens[i]); + var cultureInfo = cultures.FirstOrDefault(p => p.EnglishName.RemoveAccent() == tokens[i]); if (cultureInfo != null) {