Fixed: Search Monitored to work with accent (#583)

* Fixed: Search Monitored to work with accent

Replace accent in Album/Artist when parsing results from indexer
Fix regex to match for multiple albums

* add test cases
This commit is contained in:
gismo2004 2019-01-10 03:04:40 +01:00 committed by Qstick
commit 42252bf9c2
2 changed files with 26 additions and 7 deletions

View file

@ -1,5 +1,4 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using FizzWare.NBuilder; using FizzWare.NBuilder;
using FluentAssertions; using FluentAssertions;
using NUnit.Framework; using NUnit.Framework;
@ -7,7 +6,6 @@ using NzbDrone.Core.Music;
using NzbDrone.Core.Parser; using NzbDrone.Core.Parser;
using NzbDrone.Core.Qualities; using NzbDrone.Core.Qualities;
using NzbDrone.Core.Test.Framework; using NzbDrone.Core.Test.Framework;
using NzbDrone.Core.Parser.Model;
namespace NzbDrone.Core.Test.ParserTests namespace NzbDrone.Core.Test.ParserTests
{ {
@ -171,7 +169,6 @@ namespace NzbDrone.Core.Test.ParserTests
[TestCase("Metallica - ...And Justice for All (1988) [FLAC Lossless]", "Metallica", "...And Justice for All")] [TestCase("Metallica - ...And Justice for All (1988) [FLAC Lossless]", "Metallica", "...And Justice for All")]
public void should_parse_artist_name_and_album_title(string postTitle, string name, string title, bool discography = false) public void should_parse_artist_name_and_album_title(string postTitle, string name, string title, bool discography = false)
{ {
var parseResult = Parser.Parser.ParseAlbumTitle(postTitle); var parseResult = Parser.Parser.ParseAlbumTitle(postTitle);
parseResult.ArtistName.Should().Be(name); parseResult.ArtistName.Should().Be(name);
parseResult.AlbumTitle.Should().Be(title); parseResult.AlbumTitle.Should().Be(title);
@ -237,5 +234,28 @@ namespace NzbDrone.Core.Test.ParserTests
var parseResult = Parser.Parser.ParseAlbumTitleWithSearchCriteria(releaseTitle, _artist, _albums); var parseResult = Parser.Parser.ParseAlbumTitleWithSearchCriteria(releaseTitle, _artist, _albums);
parseResult.ArtistName.Should().Be(artist); parseResult.ArtistName.Should().Be(artist);
} }
[TestCase("Michael Bubl\u00E9", "Michael Bubl\u00E9", @"Michael Buble Michael Buble CD FLAC 2003 PERFECT")]
public void should_match_with_accent_in_artist_and_album(string artist, string album, string releaseTitle)
{
GivenSearchCriteria(artist, album);
var parseResult = Parser.Parser.ParseAlbumTitleWithSearchCriteria(releaseTitle, _artist, _albums);
parseResult.ArtistName.Should().Be("Michael Buble");
parseResult.AlbumTitle.Should().Be("Michael Buble");
}
[Test]
public void should_find_result_if_multiple_albums_in_searchcriteria()
{
GivenSearchCriteria("Michael Bubl\u00E9", "Call Me Irresponsible");
GivenSearchCriteria("Michael Bubl\u00E9", "Michael Bubl\u00E9");
GivenSearchCriteria("Michael Bubl\u00E9", "love");
GivenSearchCriteria("Michael Bubl\u00E9", "Christmas");
GivenSearchCriteria("Michael Bubl\u00E9", "To Be Loved");
var parseResult = Parser.Parser.ParseAlbumTitleWithSearchCriteria(
"Michael Buble Christmas (Deluxe Special Edition) CD FLAC 2012 UNDERTONE iNT", _artist, _albums);
parseResult.ArtistName.Should().Be("Michael Buble");
parseResult.AlbumTitle.Should().Be("Christmas");
}
} }
} }

View file

@ -343,7 +343,7 @@ namespace NzbDrone.Core.Parser
if (!ValidateBeforeParsing(title)) return null; if (!ValidateBeforeParsing(title)) return null;
Logger.Debug("Parsing string '{0}' using search criteria artist: '{1}' album: '{2}'", Logger.Debug("Parsing string '{0}' using search criteria artist: '{1}' album: '{2}'",
title, artist.Name, string.Join(", ", album.Select(a => a.Title))); title, artist.Name.RemoveAccent(), string.Join(", ", album.Select(a => a.Title.RemoveAccent())));
if (ReversedTitleRegex.IsMatch(title)) if (ReversedTitleRegex.IsMatch(title))
{ {
@ -363,12 +363,11 @@ namespace NzbDrone.Core.Parser
simpleTitle = CleanTorrentSuffixRegex.Replace(simpleTitle, string.Empty); simpleTitle = CleanTorrentSuffixRegex.Replace(simpleTitle, string.Empty);
var escapedArtist = Regex.Escape(artist.Name).Replace(@"\ ", @"[\W_]"); var escapedArtist = Regex.Escape(artist.Name.RemoveAccent()).Replace(@"\ ", @"[\W_]");
var escapedAlbums = Regex.Escape(string.Join("|", album.Select(s => s.Title).ToList())).Replace(@"\ ", @"[\W_]");; var escapedAlbums = string.Join("|", album.Select(s => Regex.Escape(s.Title.RemoveAccent())).ToList()).Replace(@"\ ", @"[\W_]");
var releaseRegex = new Regex(@"^(\W*|\b)(?<artist>" + escapedArtist + @")(\W*|\b).*(\W*|\b)(?<album>" + escapedAlbums + @")(\W*|\b)", RegexOptions.IgnoreCase); var releaseRegex = new Regex(@"^(\W*|\b)(?<artist>" + escapedArtist + @")(\W*|\b).*(\W*|\b)(?<album>" + escapedAlbums + @")(\W*|\b)", RegexOptions.IgnoreCase);
var match = releaseRegex.Matches(simpleTitle); var match = releaseRegex.Matches(simpleTitle);
if (match.Count != 0) if (match.Count != 0)