From 8e8c4ff49786e6d5f04a72f586b08baa74b7ce5f Mon Sep 17 00:00:00 2001 From: Leonardo Galli Date: Wed, 11 Jan 2017 21:49:59 +0100 Subject: [PATCH] Update parser to recognize [] and year at the beginning. Fixes #155, fixes #137 and fixes #136. --- .../DecisionEngine/DownloadDecisionMaker.cs | 1 - .../MetadataSource/SkyHook/SkyHookProxy.cs | 2 +- src/NzbDrone.Core/Parser/Parser.cs | 22 ++++++++++++++++--- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/NzbDrone.Core/DecisionEngine/DownloadDecisionMaker.cs b/src/NzbDrone.Core/DecisionEngine/DownloadDecisionMaker.cs index 5e3b0d824..ec7513482 100644 --- a/src/NzbDrone.Core/DecisionEngine/DownloadDecisionMaker.cs +++ b/src/NzbDrone.Core/DecisionEngine/DownloadDecisionMaker.cs @@ -265,7 +265,6 @@ namespace NzbDrone.Core.DecisionEngine e.Data.Add("parsed", remoteEpisode.ParsedEpisodeInfo.ToJson()); _logger.Error(e, "Couldn't evaluate decision on " + remoteEpisode.Release.Title + ", with spec: " + spec.GetType().Name); return new Rejection(string.Format("{0}: {1}", spec.GetType().Name, e.Message));//TODO UPDATE SPECS! - return null; } return null; diff --git a/src/NzbDrone.Core/MetadataSource/SkyHook/SkyHookProxy.cs b/src/NzbDrone.Core/MetadataSource/SkyHook/SkyHookProxy.cs index 478b6dd13..4eb97e1ab 100644 --- a/src/NzbDrone.Core/MetadataSource/SkyHook/SkyHookProxy.cs +++ b/src/NzbDrone.Core/MetadataSource/SkyHook/SkyHookProxy.cs @@ -189,7 +189,7 @@ namespace NzbDrone.Core.MetadataSource.SkyHook { var lowerTitle = title.ToLower(); - var parserResult = Parser.Parser.ParseMovieTitle(title); + var parserResult = Parser.Parser.ParseMovieTitle(title, true); var yearTerm = ""; diff --git a/src/NzbDrone.Core/Parser/Parser.cs b/src/NzbDrone.Core/Parser/Parser.cs index 2120c3add..f807a1be6 100644 --- a/src/NzbDrone.Core/Parser/Parser.cs +++ b/src/NzbDrone.Core/Parser/Parser.cs @@ -36,6 +36,15 @@ namespace NzbDrone.Core.Parser //PassThePopcorn Torrent names: Star.Wars[PassThePopcorn] new Regex(@"^(?.+?)?(?:(?:[-_\W](?<![()\[!]))*(?<year>(\[\w *\])))+(\W+|_|$)(?!\\)", RegexOptions.IgnoreCase | RegexOptions.Compiled), + //That did not work? Maybe some tool uses [] for years. Who would do that? + 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[] + { + //When year comes first. + new Regex(@"^(?:(?:[-_\W](?<![)!]))*(?<year>(19|20)\d{2}(?!p|i|\d+|\W\d+)))+(\W+|_|$)(?<title>.+?)?$") }; private static readonly Regex[] ReportTitleRegex = new[] @@ -327,7 +336,7 @@ namespace NzbDrone.Core.Parser { var fileInfo = new FileInfo(path); - var result = ParseMovieTitle(fileInfo.Name); + var result = ParseMovieTitle(fileInfo.Name, true); if (result == null) { @@ -345,7 +354,7 @@ namespace NzbDrone.Core.Parser } - public static ParsedMovieInfo ParseMovieTitle(string title) + public static ParsedMovieInfo ParseMovieTitle(string title, bool isDir = false) { ParsedMovieInfo realResult = null; @@ -376,7 +385,14 @@ namespace NzbDrone.Core.Parser simpleTitle = CleanTorrentSuffixRegex.Replace(simpleTitle, string.Empty); - foreach (var regex in ReportMovieTitleRegex) + var allRegexes = ReportMovieTitleRegex.ToList(); + + if (isDir) + { + allRegexes.AddRange(ReportMovieTitleFolderRegex); + } + + foreach (var regex in allRegexes) { var match = regex.Matches(simpleTitle);