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
pull/585/head
gismo2004 6 years ago committed by Qstick
parent cb19fd3ea6
commit 42252bf9c2

@ -1,5 +1,4 @@
using System.Collections.Generic;
using System.Linq;
using FizzWare.NBuilder;
using FluentAssertions;
using NUnit.Framework;
@ -7,7 +6,6 @@ using NzbDrone.Core.Music;
using NzbDrone.Core.Parser;
using NzbDrone.Core.Qualities;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Core.Parser.Model;
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")]
public void should_parse_artist_name_and_album_title(string postTitle, string name, string title, bool discography = false)
{
var parseResult = Parser.Parser.ParseAlbumTitle(postTitle);
parseResult.ArtistName.Should().Be(name);
parseResult.AlbumTitle.Should().Be(title);
@ -237,5 +234,28 @@ namespace NzbDrone.Core.Test.ParserTests
var parseResult = Parser.Parser.ParseAlbumTitleWithSearchCriteria(releaseTitle, _artist, _albums);
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");
}
}
}

@ -343,7 +343,7 @@ namespace NzbDrone.Core.Parser
if (!ValidateBeforeParsing(title)) return null;
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))
{
@ -363,12 +363,11 @@ namespace NzbDrone.Core.Parser
simpleTitle = CleanTorrentSuffixRegex.Replace(simpleTitle, string.Empty);
var escapedArtist = Regex.Escape(artist.Name).Replace(@"\ ", @"[\W_]");
var escapedAlbums = Regex.Escape(string.Join("|", album.Select(s => s.Title).ToList())).Replace(@"\ ", @"[\W_]");;
var escapedArtist = Regex.Escape(artist.Name.RemoveAccent()).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 match = releaseRegex.Matches(simpleTitle);
if (match.Count != 0)

Loading…
Cancel
Save