1
0
Fork 0
mirror of https://github.com/lidarr/Lidarr synced 2025-02-25 23:32:41 +00:00

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
parent cb19fd3ea6
commit 42252bf9c2
2 changed files with 26 additions and 7 deletions

View file

@ -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.Parser;
using NzbDrone.Core.Qualities;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Core.Parser.Model;
namespace NzbDrone.Core.Test.ParserTests
{
@ -171,7 +169,6 @@ public void should_parse_quality_from_extension(string title)
[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 @@ public void should_escape_artists(string artist, string album, string releaseTit
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");
}
}
}

View file

@ -343,7 +343,7 @@ public static ParsedAlbumInfo ParseAlbumTitleWithSearchCriteria(string title, Ar
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 @@ public static ParsedAlbumInfo ParseAlbumTitleWithSearchCriteria(string title, Ar
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)