From d62b4e49f90f0559440305569794c4a8bde431cc Mon Sep 17 00:00:00 2001 From: ta264 Date: Mon, 19 Nov 2018 02:59:54 +0000 Subject: [PATCH] Fixed: Better release parsing (#541) --- .../ParserTests/ParserFixture.cs | 2 ++ .../DecisionEngine/DownloadDecisionMaker.cs | 15 +++++++++++++++ src/NzbDrone.Core/Parser/Parser.cs | 8 ++++---- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/NzbDrone.Core.Test/ParserTests/ParserFixture.cs b/src/NzbDrone.Core.Test/ParserTests/ParserFixture.cs index aaa14c746..18ca21580 100644 --- a/src/NzbDrone.Core.Test/ParserTests/ParserFixture.cs +++ b/src/NzbDrone.Core.Test/ParserTests/ParserFixture.cs @@ -182,6 +182,8 @@ namespace NzbDrone.Core.Test.ParserTests [TestCase("Black Sabbath Black Sabbath FLAC")] [TestCase("BlaCk SabBaTh Black SabBatH FLAC")] [TestCase("Black Sabbath FLAC Black Sabbath")] + [TestCase("Black.Sabbath-FLAC-Black.Sabbath")] + [TestCase("Black_Sabbath-FLAC-Black_Sabbath")] public void should_parse_artist_name_and_album_title_by_search_criteria(string releaseTitle) { GivenSearchCriteria("Black Sabbath", "Black Sabbath"); diff --git a/src/NzbDrone.Core/DecisionEngine/DownloadDecisionMaker.cs b/src/NzbDrone.Core/DecisionEngine/DownloadDecisionMaker.cs index 572469309..069c242ff 100644 --- a/src/NzbDrone.Core/DecisionEngine/DownloadDecisionMaker.cs +++ b/src/NzbDrone.Core/DecisionEngine/DownloadDecisionMaker.cs @@ -89,6 +89,21 @@ namespace NzbDrone.Core.DecisionEngine if (!parsedAlbumInfo.ArtistName.IsNullOrWhiteSpace()) { var remoteAlbum = _parsingService.Map(parsedAlbumInfo, searchCriteria); + + // try parsing again using the search criteria, in case it parsed but parsed incorrectly + if ((remoteAlbum.Artist == null || remoteAlbum.Albums.Empty()) && searchCriteria != null) + { + _logger.Debug("Artist/Album null for {0}, reparsing with search criteria", report.Title); + var parsedAlbumInfoWithCriteria = Parser.Parser.ParseAlbumTitleWithSearchCriteria(report.Title, + searchCriteria.Artist, + searchCriteria.Albums); + + if (parsedAlbumInfoWithCriteria != null && parsedAlbumInfoWithCriteria.ArtistName.IsNotNullOrWhiteSpace()) + { + remoteAlbum = _parsingService.Map(parsedAlbumInfoWithCriteria, searchCriteria); + } + } + remoteAlbum.Release = report; if (remoteAlbum.Artist == null) diff --git a/src/NzbDrone.Core/Parser/Parser.cs b/src/NzbDrone.Core/Parser/Parser.cs index 49183607b..7a92fad90 100644 --- a/src/NzbDrone.Core/Parser/Parser.cs +++ b/src/NzbDrone.Core/Parser/Parser.cs @@ -342,8 +342,8 @@ namespace NzbDrone.Core.Parser { if (!ValidateBeforeParsing(title)) return null; - Logger.Debug("Parsing string '{0}'", title); - + Logger.Debug("Parsing string '{0}' using search criteria artist: '{1}' album: '{2}'", + title, artist.Name, string.Join(", ", album.Select(a => a.Title))); if (ReversedTitleRegex.IsMatch(title)) { @@ -363,8 +363,8 @@ namespace NzbDrone.Core.Parser simpleTitle = CleanTorrentSuffixRegex.Replace(simpleTitle, string.Empty); - var escapedArtist = Regex.Escape(artist.Name); - var escapedAlbums = Regex.Escape(string.Join("|", album.Select(s => s.Title).ToList())); + var escapedArtist = Regex.Escape(artist.Name).Replace(@"\ ", @"[\W_]"); + var escapedAlbums = Regex.Escape(string.Join("|", album.Select(s => s.Title).ToList())).Replace(@"\ ", @"[\W_]");; var releaseRegex = new Regex(@"^(\W*|\b)(?" + escapedArtist + @")(\W*|\b).*(\W*|\b)(?" + escapedAlbums + @")(\W*|\b)", RegexOptions.IgnoreCase);