diff --git a/src/NzbDrone.Core.Test/ParserTests/LanguageParserFixture.cs b/src/NzbDrone.Core.Test/ParserTests/LanguageParserFixture.cs index 34c65f0d9..306e5290b 100644 --- a/src/NzbDrone.Core.Test/ParserTests/LanguageParserFixture.cs +++ b/src/NzbDrone.Core.Test/ParserTests/LanguageParserFixture.cs @@ -1,4 +1,4 @@ -using FluentAssertions; +using FluentAssertions; using NUnit.Framework; using NzbDrone.Core.Parser; using NzbDrone.Core.Test.Framework; @@ -47,6 +47,8 @@ public class LanguageParserFixture : CoreTest [TestCase("Castle.2009.S01E14.HDTV.XviD.ENG.HUN-LOL", Language.Hungarian)] [TestCase("Castle.2009.S01E14.HDTV.XviD.HUN-LOL", Language.Hungarian)] [TestCase("Avatar.The.Last.Airbender.S01-03.DVDRip.HebDub",Language.Hebrew)] + [TestCase("Prison.Break.S05E01.WEBRip.x264.AC3.LT.EN-CNN", Language.Lithuanian)] + [TestCase("The.​Walking.​Dead.​S07E11.​WEB Rip.​XviD.​Louige-​CZ.​EN.​5.​1", Language.Czech)] public void should_parse_language(string postTitle, Language language) { var result = LanguageParser.ParseLanguage(postTitle); diff --git a/src/NzbDrone.Core/Parser/IsoLanguages.cs b/src/NzbDrone.Core/Parser/IsoLanguages.cs index 7aeee15df..b87b7ea5b 100644 --- a/src/NzbDrone.Core/Parser/IsoLanguages.cs +++ b/src/NzbDrone.Core/Parser/IsoLanguages.cs @@ -29,7 +29,9 @@ public static class IsoLanguages new IsoLanguage("el", "ell", Language.Greek), new IsoLanguage("ko", "kor", Language.Korean), new IsoLanguage("hu", "hun", Language.Hungarian), - new IsoLanguage("he", "heb", Language.Hebrew) + new IsoLanguage("he", "heb", Language.Hebrew), + new IsoLanguage("lt", "lit", Language.Lithuanian), + new IsoLanguage("cs", "ces", Language.Czech) }; public static IsoLanguage Find(string isoCode) diff --git a/src/NzbDrone.Core/Parser/Language.cs b/src/NzbDrone.Core/Parser/Language.cs index e720890e7..0e9623377 100644 --- a/src/NzbDrone.Core/Parser/Language.cs +++ b/src/NzbDrone.Core/Parser/Language.cs @@ -25,6 +25,8 @@ public enum Language Greek = 20, Korean = 21, Hungarian = 22, - Hebrew = 23 + Hebrew = 23, + Lithuanian = 24, + Czech = 25 } } diff --git a/src/NzbDrone.Core/Parser/LanguageParser.cs b/src/NzbDrone.Core/Parser/LanguageParser.cs index 2889589b4..024a15c70 100644 --- a/src/NzbDrone.Core/Parser/LanguageParser.cs +++ b/src/NzbDrone.Core/Parser/LanguageParser.cs @@ -14,6 +14,10 @@ public static class LanguageParser private static readonly Regex LanguageRegex = new Regex(@"(?:\W|_)(?\b(?:ita|italian)\b)|(?german\b|videomann)|(?flemish)|(?greek)|(?(?:\W|_)(?:FR|VOSTFR)(?:\W|_))|(?\brus\b)|(?nl\W?subs?)|(?\b(?:HUNDUB|HUN)\b)|(?\bHebDub\b)", RegexOptions.IgnoreCase | RegexOptions.Compiled); + private static readonly Regex CaseSensitiveLanguageRegex = new Regex(@"(?\bLT\b)|(?\bCZ\b)", + RegexOptions.Compiled); + + private static readonly Regex SubtitleLanguageRegex = new Regex(".+?[-_. ](?[a-z]{2,3})$", RegexOptions.Compiled | RegexOptions.IgnoreCase); public static Language ParseLanguage(string title) @@ -80,34 +84,12 @@ public static Language ParseLanguage(string title) if (lowerTitle.Contains("hebrew")) return Language.Hebrew; - var match = LanguageRegex.Match(title); + var regexLanguage = RegexLanguage(title); - if (match.Groups["italian"].Captures.Cast().Any()) - return Language.Italian; - - if (match.Groups["german"].Captures.Cast().Any()) - return Language.German; - - if (match.Groups["flemish"].Captures.Cast().Any()) - return Language.Flemish; - - if (match.Groups["greek"].Captures.Cast().Any()) - return Language.Greek; - - if (match.Groups["french"].Success) - return Language.French; - - if (match.Groups["russian"].Success) - return Language.Russian; - - if (match.Groups["dutch"].Success) - return Language.Dutch; - - if (match.Groups["hungarian"].Success) - return Language.Hungarian; - - if (match.Groups["hebrew"].Success) - return Language.Hebrew; + if (regexLanguage != Language.Unknown) + { + return regexLanguage; + } return Language.English; } @@ -146,5 +128,49 @@ public static Language ParseSubtitleLanguage(string fileName) return Language.Unknown; } + + private static Language RegexLanguage(string title) + { + // Case sensitive + var caseSensitiveMatch = CaseSensitiveLanguageRegex.Match(title); + + if (caseSensitiveMatch.Groups["lithuanian"].Captures.Cast().Any()) + return Language.Lithuanian; + + if (caseSensitiveMatch.Groups["czech"].Captures.Cast().Any()) + return Language.Czech; + + // Case insensitive + var match = LanguageRegex.Match(title); + + if (match.Groups["italian"].Captures.Cast().Any()) + return Language.Italian; + + if (match.Groups["german"].Captures.Cast().Any()) + return Language.German; + + if (match.Groups["flemish"].Captures.Cast().Any()) + return Language.Flemish; + + if (match.Groups["greek"].Captures.Cast().Any()) + return Language.Greek; + + if (match.Groups["french"].Success) + return Language.French; + + if (match.Groups["russian"].Success) + return Language.Russian; + + if (match.Groups["dutch"].Success) + return Language.Dutch; + + if (match.Groups["hungarian"].Success) + return Language.Hungarian; + + if (match.Groups["hebrew"].Success) + return Language.Hebrew; + + return Language.Unknown; + } } }