From bc1a47ff5a5c9f46e06bce93df28d497648d8ce0 Mon Sep 17 00:00:00 2001 From: Leonardo Galli Date: Fri, 10 Feb 2017 19:00:16 +0100 Subject: [PATCH] Fixed a few parser issues. Also added some tests. Fixes #549 --- .../ParserTests/ParserFixture.cs | 19 +++++++++++ src/NzbDrone.Core/Parser/Parser.cs | 34 +++++++++++++++++-- 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/src/NzbDrone.Core.Test/ParserTests/ParserFixture.cs b/src/NzbDrone.Core.Test/ParserTests/ParserFixture.cs index 2712c8dbf..0ceee3cc2 100644 --- a/src/NzbDrone.Core.Test/ParserTests/ParserFixture.cs +++ b/src/NzbDrone.Core.Test/ParserTests/ParserFixture.cs @@ -62,5 +62,24 @@ namespace NzbDrone.Core.Test.ParserTests { Parser.Parser.ParseTitle(postTitle).SeriesTitle.Should().Be(title); } + + [TestCase("The.Man.from.U.N.C.L.E.2015.1080p.BluRay.x264-SPARKS", "The Man from U.N.C.L.E.")] + [TestCase("1941.1979.EXTENDED.720p.BluRay.X264-AMIABLE", "1941")] + [TestCase("MY MOVIE (2016) [R][Action, Horror][720p.WEB-DL.AVC.8Bit.6ch.AC3].mkv", "MY MOVIE")] + [TestCase("R.I.P.D.2013.720p.BluRay.x264-SPARKS", "R.I.P.D.")] + [TestCase("V.H.S.2.2013.LIMITED.720p.BluRay.x264-GECKOS", "V.H.S. 2")] + [TestCase("This Is A Movie (1999) [IMDB #] {ACTORS} !DIRECTOR +MORE_SILLY_STUFF_NO_ONE_NEEDS ?", "This Is A Movie")] + [TestCase("R.I.P.D.2013.720p.BluRay.x264-SPARKS", "R.I.P.D.")] + [TestCase("(500).Days.Of.Summer.(2009).DTS.1080p.BluRay.x264.NLsubs", "(500) Days Of Summer")] + public void should_parse_movie_title(string postTitle, string title) + { + Parser.Parser.ParseMovieTitle(postTitle).MovieTitle.Should().Be(title); + } + + [TestCase("1941.1979.EXTENDED.720p.BluRay.X264-AMIABLE", 1979)] + public void should_parse_movie_year(string postTitle, int year) + { + Parser.Parser.ParseMovieTitle(postTitle).Year.Should().Be(year); + } } } diff --git a/src/NzbDrone.Core/Parser/Parser.cs b/src/NzbDrone.Core/Parser/Parser.cs index ddaabf37e..75e9bfeba 100644 --- a/src/NzbDrone.Core/Parser/Parser.cs +++ b/src/NzbDrone.Core/Parser/Parser.cs @@ -33,6 +33,11 @@ namespace NzbDrone.Core.Parser //That did not work? Maybe some tool uses [] for years. Who would do that? new Regex(@"^(?(?![(\[]).+?)?(?:(?:[-_\W](?<![)!]))*(?<year>(19|20)\d{2}(?!p|i|\d+|\W\d+)))+(\W+|_|$)(?!\\)", RegexOptions.IgnoreCase | RegexOptions.Compiled), + + //As a last resort for movies that have ( or [ in their title. + new Regex(@"^(?<title>.+?)?(?:(?:[-_\W](?<![)\[!]))*(?<year>(19|20)\d{2}(?!p|i|\d+|\]|\W\d+)))+(\W+|_|$)(?!\\)", + RegexOptions.IgnoreCase | RegexOptions.Compiled), + }; private static readonly Regex[] ReportMovieTitleFolderRegex = new[] @@ -357,7 +362,7 @@ namespace NzbDrone.Core.Parser { if (!ValidateBeforeParsing(title)) return null; - title = title.Replace(" ", "."); //TODO: Determine if this breaks something. However, it shouldn't. + //title = title.Replace(" ", "."); //TODO: Determine if this breaks something. However, it shouldn't. Logger.Debug("Parsing string '{0}'", title); @@ -704,9 +709,34 @@ namespace NzbDrone.Core.Parser } - var seriesName = matchCollection[0].Groups["title"].Value.Replace('.', ' ').Replace('_', ' '); + var seriesName = matchCollection[0].Groups["title"].Value./*Replace('.', ' ').*/Replace('_', ' '); seriesName = RequestInfoRegex.Replace(seriesName, "").Trim(' '); + var parts = seriesName.Split('.'); + seriesName = ""; + int n; + bool previousAcronym = false; + foreach (var part in parts) + { + if (part.Length == 1 && part.ToLower() != "a" && !int.TryParse(part, out n)) + { + seriesName += part + "."; + previousAcronym = true; + } + else + { + if (previousAcronym) + { + seriesName += " "; + previousAcronym = false; + } + seriesName += part + " "; + } + + } + + seriesName = seriesName.Trim(' '); + int airYear; int.TryParse(matchCollection[0].Groups["year"].Value, out airYear);