From ec88c2c2ca05ab2d22e193c67faebb167b74e8f7 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Sun, 8 Feb 2015 21:49:44 -0800 Subject: [PATCH] Parsing improvements Fixed: Don't use full path when parsing files New: Support for iTunes library file structure --- .../ParserTests/CrapParserFixture.cs | 1 + .../ParserTests/HashedReleaseFixture.cs | 2 +- .../ParserTests/PathParserFixture.cs | 6 ++++-- .../Specifications/MatchesFolderSpecification.cs | 11 +++++++++-- src/NzbDrone.Core/Parser/Parser.cs | 12 ++++++++---- 5 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/NzbDrone.Core.Test/ParserTests/CrapParserFixture.cs b/src/NzbDrone.Core.Test/ParserTests/CrapParserFixture.cs index ee32d1fc3..e678bf6a1 100644 --- a/src/NzbDrone.Core.Test/ParserTests/CrapParserFixture.cs +++ b/src/NzbDrone.Core.Test/ParserTests/CrapParserFixture.cs @@ -30,6 +30,7 @@ namespace NzbDrone.Core.Test.ParserTests [TestCase("185d86a343e39f3341e35c4dad3ff159")] [TestCase("ah63jka93jf0jh26ahjas961.mkv")] [TestCase("qrdSD3rYzWb7cPdVIGSn4E7")] + [TestCase("QZC4HDl7ncmzyUj9amucWe1ddKU1oFMZDd8r0dEDUsTd")] public void should_not_parse_crap(string title) { Parser.Parser.ParseTitle(title).Should().BeNull(); diff --git a/src/NzbDrone.Core.Test/ParserTests/HashedReleaseFixture.cs b/src/NzbDrone.Core.Test/ParserTests/HashedReleaseFixture.cs index d2fd007a8..168568be9 100644 --- a/src/NzbDrone.Core.Test/ParserTests/HashedReleaseFixture.cs +++ b/src/NzbDrone.Core.Test/ParserTests/HashedReleaseFixture.cs @@ -51,7 +51,7 @@ namespace NzbDrone.Core.Test.ParserTests @"C:\Test\Deadwood.S02E12.1080p.BluRay.x264-SONARR\Backup_72023S02-12.mkv".AsOsAgnostic(), "deadwood", Quality.Bluray1080p, - "SONARR" + null }, new object[] { diff --git a/src/NzbDrone.Core.Test/ParserTests/PathParserFixture.cs b/src/NzbDrone.Core.Test/ParserTests/PathParserFixture.cs index c111e7fda..7da12e07b 100644 --- a/src/NzbDrone.Core.Test/ParserTests/PathParserFixture.cs +++ b/src/NzbDrone.Core.Test/ParserTests/PathParserFixture.cs @@ -26,8 +26,10 @@ namespace NzbDrone.Core.Test.ParserTests [TestCase(@"C:\Test\Unsorted\The.Big.Bang.Theory.S01E01.720p.HDTV\tbbt101.avi", 1, 1)] [TestCase(@"C:\Test\Unsorted\Terminator.The.Sarah.Connor.Chronicles.S02E19.720p.BluRay.x264-SiNNERS-RP\ba27283b17c00d01193eacc02a8ba98eeb523a76.mkv", 2, 19)] [TestCase(@"C:\Test\Unsorted\Terminator.The.Sarah.Connor.Chronicles.S02E18.720p.BluRay.x264-SiNNERS-RP\45a55debe3856da318cc35882ad07e43cd32fd15.mkv", 2, 18)] - [TestCase(@"C:\Test\The.Blacklist.S01E16.720p.HDTV.X264-DIMENSION\XRmZciqkBopq4851Ddbipe\Vh1FvU3bJXw6zs8EEUX4bMo5vbbMdHghxHirc.mkv", 1, 16)] - [TestCase(@"C:\Test\Deadwood.S02E12.1080p.BluRay.x264-SONARR\Backup_72023S02-12\Backup_72023S02-12.mkv", 2, 12)] + [TestCase(@"C:\Test\Series\Season 01\01 Pilot (1080p HD).mkv", 1, 1)] + [TestCase(@"C:\Test\Series\Season 01\1 Pilot (1080p HD).mkv", 1, 1)] + [TestCase(@"C:\Test\Series\Season 1\02 Honor Thy Father (1080p HD).m4v", 1, 2)] + [TestCase(@"C:\Test\Series\Season 1\2 Honor Thy Father (1080p HD).m4v", 1, 2)] public void should_parse_from_path(string path, int season, int episode) { var result = Parser.Parser.ParsePath(path); diff --git a/src/NzbDrone.Core/MediaFiles/EpisodeImport/Specifications/MatchesFolderSpecification.cs b/src/NzbDrone.Core/MediaFiles/EpisodeImport/Specifications/MatchesFolderSpecification.cs index 982ffe94f..5b9cd0fc7 100644 --- a/src/NzbDrone.Core/MediaFiles/EpisodeImport/Specifications/MatchesFolderSpecification.cs +++ b/src/NzbDrone.Core/MediaFiles/EpisodeImport/Specifications/MatchesFolderSpecification.cs @@ -22,7 +22,14 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Specifications return Decision.Accept(); } - var folderInfo = Parser.Parser.ParseTitle(new FileInfo(localEpisode.Path).DirectoryName); + var dirInfo = new FileInfo(localEpisode.Path).Directory; + + if (dirInfo == null) + { + return Decision.Accept(); + } + + var folderInfo = Parser.Parser.ParseTitle(dirInfo.Name); if (folderInfo == null) { @@ -38,7 +45,7 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Specifications if (unexpected.Any()) { - _logger.Debug("Unexpected episode number(s) in file: {0}", unexpected); + _logger.Debug("Unexpected episode number(s) in file: {0}", String.Join(", ", unexpected)); if (unexpected.Count == 1) { diff --git a/src/NzbDrone.Core/Parser/Parser.cs b/src/NzbDrone.Core/Parser/Parser.cs index ab684792b..138b8583c 100644 --- a/src/NzbDrone.Core/Parser/Parser.cs +++ b/src/NzbDrone.Core/Parser/Parser.cs @@ -107,6 +107,10 @@ namespace NzbDrone.Core.Parser new Regex(@"^(?.*?)(?:(?:_|-|\s|\.)S?(?<season>(?<!\d+)\d{1,2}(?!\d+))(?:(?:\-|[ex]){1,2}(?<episode>\d{1}))+)+(\W+|_|$)(?!\\)", RegexOptions.IgnoreCase | RegexOptions.Compiled), + //iTunes Season 1\05 Title (Quality).ext + new Regex(@"^(?:Season(?:_|-|\s|\.)(?<season>(?<!\d+)\d{1,2}(?!\d+)))(?:_|-|\s|\.)(?<episode>(?<!\d+)\d{1,2}(?!\d+))", + RegexOptions.IgnoreCase | RegexOptions.Compiled), + //Anime - Title Absolute Episode Number (e66) new Regex(@"^(?:\[(?<subgroup>.+?)\][-_. ]?)?(?<title>.+?)(?:(?:_|-|\s|\.)+(?:e|ep)(?<absoluteepisode>\d{2,3}))+.*?(?<hash>\[\w{8}\])?(?:$|\.)", RegexOptions.IgnoreCase | RegexOptions.Compiled), @@ -196,14 +200,14 @@ namespace NzbDrone.Core.Parser if (result == null) { - Logger.Debug("Attempting to parse episode info using directory path. {0}", fileInfo.Directory.Name); - result = ParseTitle(fileInfo.Directory.Name + fileInfo.Extension); + Logger.Debug("Attempting to parse episode info using directory and file names. {0}", fileInfo.Directory.Name); + result = ParseTitle(fileInfo.Directory.Name + " " + fileInfo.Name + fileInfo.Extension); } if (result == null) { - Logger.Debug("Attempting to parse episode info using full path. {0}", fileInfo.FullName); - result = ParseTitle(fileInfo.FullName); + Logger.Debug("Attempting to parse episode info using directory name. {0}", fileInfo.Directory.Name); + result = ParseTitle(fileInfo.Directory.Name + fileInfo.Extension); } if (result == null)