mirror of https://github.com/lidarr/Lidarr
Fixed: Search Criteria parsing returns bad results (Abba/Black Sabbath)
This commit is contained in:
parent
882e8a575e
commit
66d3fd17e9
|
@ -1,5 +1,9 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Music;
|
||||
using NzbDrone.Core.Parser;
|
||||
using NzbDrone.Core.Qualities;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
@ -10,6 +14,23 @@ namespace NzbDrone.Core.Test.ParserTests
|
|||
[TestFixture]
|
||||
public class ParserFixture : CoreTest
|
||||
{
|
||||
Artist _artist = new Artist();
|
||||
private List<Album> _albums = new List<Album>{new Album()};
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_artist = Builder<Artist>
|
||||
.CreateNew()
|
||||
.Build();
|
||||
}
|
||||
|
||||
private void GivenSearchCriteria(string artistName, string albumTitle)
|
||||
{
|
||||
_artist.Name = artistName;
|
||||
_albums.First().Title = albumTitle;
|
||||
}
|
||||
|
||||
[TestCase("Bad Format", "badformat")]
|
||||
public void should_parse_artist_name(string postTitle, string title)
|
||||
{
|
||||
|
@ -102,5 +123,25 @@ namespace NzbDrone.Core.Test.ParserTests
|
|||
parseResult.AlbumTitle.Should().Be(title);
|
||||
parseResult.Discography.Should().Be(discography);
|
||||
}
|
||||
|
||||
[TestCase("Black Sabbath - Black Sabbath FLAC")]
|
||||
[TestCase("Black Sabbath Black Sabbath FLAC")]
|
||||
[TestCase("BlaCk SabBaTh Black SabBatH FLAC")]
|
||||
[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");
|
||||
var parseResult = Parser.Parser.ParseAlbumTitleWithSearchCriteria(releaseTitle, _artist, _albums);
|
||||
parseResult.ArtistName.ToLowerInvariant().Should().Be("black sabbath");
|
||||
parseResult.AlbumTitle.ToLowerInvariant().Should().Be("black sabbath");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_parse_artist_name_and_album_title_by_incorrect_search_criteria()
|
||||
{
|
||||
GivenSearchCriteria("Abba", "Abba");
|
||||
var parseResult = Parser.Parser.ParseAlbumTitleWithSearchCriteria("Black Sabbath Black Sabbath FLAC", _artist, _albums);
|
||||
parseResult.Should().BeNull();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -346,32 +346,48 @@ namespace NzbDrone.Core.Parser
|
|||
|
||||
simpleTitle = CleanTorrentSuffixRegex.Replace(simpleTitle, string.Empty);
|
||||
|
||||
var result = new ParsedAlbumInfo();
|
||||
var releaseRegex = new Regex(@"\b(?<artist>" + artist.Name + @")\b.*\b(?<album>"+ string.Join("|",album.Select(s=>s.Title).ToList()) + @")\b",
|
||||
RegexOptions.IgnoreCase | RegexOptions.Compiled);
|
||||
|
||||
if (simpleTitle.ToLowerInvariant().Contains(artist.Name.ToLowerInvariant()))
|
||||
var match = releaseRegex.Matches(simpleTitle);
|
||||
|
||||
if (match.Count != 0)
|
||||
{
|
||||
result.ArtistName = artist.Name;
|
||||
var artistRegex = new Regex(Regex.Escape(artist.Name.ToLowerInvariant()));
|
||||
var albumReleaseString = artistRegex.Replace(simpleTitle.ToLowerInvariant(), string.Empty, 1);
|
||||
|
||||
var selectedAlbum = album.FirstOrDefault(s => albumReleaseString.Contains(s.Title.ToLowerInvariant()));
|
||||
|
||||
if (selectedAlbum != null)
|
||||
try
|
||||
{
|
||||
result.AlbumTitle = selectedAlbum.Title;
|
||||
var result = ParseAlbumMatchCollection(match);
|
||||
|
||||
if (result != null)
|
||||
{
|
||||
result.Language = LanguageParser.ParseLanguage(releaseTitle);
|
||||
Logger.Debug("Language parsed: {0}", result.Language);
|
||||
|
||||
result.Quality = QualityParser.ParseQuality(title, null, 0);
|
||||
Logger.Debug("Quality parsed: {0}", result.Quality);
|
||||
|
||||
result.ReleaseGroup = ParseReleaseGroup(releaseTitle);
|
||||
|
||||
var subGroup = GetSubGroup(match);
|
||||
if (!subGroup.IsNullOrWhiteSpace())
|
||||
{
|
||||
result.ReleaseGroup = subGroup;
|
||||
}
|
||||
|
||||
Logger.Debug("Release Group parsed: {0}", result.ReleaseGroup);
|
||||
|
||||
result.ReleaseHash = GetReleaseHash(match);
|
||||
if (!result.ReleaseHash.IsNullOrWhiteSpace())
|
||||
{
|
||||
Logger.Debug("Release Hash parsed: {0}", result.ReleaseHash);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
catch (InvalidDateException ex)
|
||||
{
|
||||
Logger.Debug(ex, ex.Message);
|
||||
}
|
||||
|
||||
result.Language = LanguageParser.ParseLanguage(releaseTitle);
|
||||
Logger.Debug("Language parsed: {0}", result.Language);
|
||||
|
||||
result.Quality = QualityParser.ParseQuality(title, null, 0);
|
||||
Logger.Debug("Quality parsed: {0}", result.Quality);
|
||||
|
||||
result.ReleaseGroup = ParseReleaseGroup(releaseTitle);
|
||||
|
||||
Logger.Debug("Release Group parsed: {0}", result.ReleaseGroup);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
|
|
Loading…
Reference in New Issue