Fixed: Search fails for many artist and albums with specials (#466)

* Fixed: Search fails for many artist/albums with specials

* fixup! Replace & with space

* fixup! Add two more test cases

* fixup! Add last test case

* fixup: Newznab test case
pull/6/head
Qstick 6 years ago committed by GitHub
parent 23bc5b11cf
commit 812af82fae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -3,22 +3,36 @@ using System.Linq;
using FluentAssertions; using FluentAssertions;
using NUnit.Framework; using NUnit.Framework;
using NzbDrone.Core.IndexerSearch.Definitions; using NzbDrone.Core.IndexerSearch.Definitions;
using NzbDrone.Core.Music;
using NzbDrone.Core.Test.Framework; using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test.IndexerSearchTests namespace NzbDrone.Core.Test.IndexerSearchTests
{ {
public class SearchDefinitionFixture : CoreTest<AlbumSearchCriteria> public class AlbumSearchDefinitionFixture : CoreTest<AlbumSearchCriteria>
{ {
[TestCase("Betty White's Off Their Rockers", "Betty+Whites+Off+Their+Rockers")] [TestCase("Mötley Crüe", "Motley+Crue")]
[TestCase("Star Wars: The Clone Wars", "Star+Wars+The+Clone+Wars")] [TestCase("방탄소년단", "방탄소년단")]
[TestCase("Hawaii Five-0", "Hawaii+Five+0")] public void should_replace_some_special_characters_artist(string artist, string expected)
[TestCase("Franklin & Bash", "Franklin+and+Bash")]
[TestCase("Chicago P.D.", "Chicago+PD")]
[TestCase("Kourtney And Khlo\u00E9 Take The Hamptons", "Kourtney+And+Khloe+Take+The+Hamptons")]
public void should_replace_some_special_characters(string input, string expected)
{ {
Subject.SceneTitles = new List<string> { input }; Subject.Artist = new Artist { Name = artist };
Subject.QueryTitles.First().Should().Be(expected); Subject.ArtistQuery.Should().Be(expected);
}
[TestCase("…and Justice for All", "and+Justice+for+All")]
[TestCase("American III: Solitary Man", "American+III+Solitary+Man")]
[TestCase("Sad Clowns & Hillbillies", "Sad+Clowns+Hillbillies")]
[TestCase("¿Quién sabe?", "Quien+sabe")]
public void should_replace_some_special_characters(string album, string expected)
{
Subject.AlbumTitle = album;
Subject.AlbumQuery.Should().Be(expected);
}
[TestCase("+", "+")]
public void should_not_replace_some_special_characters_if_result_empty_string(string album, string expected)
{
Subject.AlbumTitle = album;
Subject.AlbumQuery.Should().Be(expected);
} }
} }
} }

@ -1,4 +1,4 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using FluentAssertions; using FluentAssertions;
using Moq; using Moq;
@ -60,7 +60,7 @@ namespace NzbDrone.Core.Test.IndexerTests.NewznabTests
var page = results.GetAllTiers().First().First(); var page = results.GetAllTiers().First().First();
page.Url.Query.Should().Contain("artist=Alien Ant Farm"); page.Url.Query.Should().Contain("artist=Alien%20Ant%20Farm");
page.Url.Query.Should().Contain("album=TruANT"); page.Url.Query.Should().Contain("album=TruANT");
} }
} }

@ -1,4 +1,4 @@
using System; using System;
namespace NzbDrone.Core.IndexerSearch.Definitions namespace NzbDrone.Core.IndexerSearch.Definitions
{ {
@ -8,6 +8,8 @@ namespace NzbDrone.Core.IndexerSearch.Definitions
public string AlbumTitle { get; set; } public string AlbumTitle { get; set; }
public int AlbumYear { get; set; } public int AlbumYear { get; set; }
public string AlbumQuery => GetQueryTitle(AlbumTitle);
public override string ToString() public override string ToString()
{ {
return string.Format("[{0} - {1} ({2})]", Artist.Name, AlbumTitle, AlbumYear); return string.Format("[{0} - {1} ({2})]", Artist.Name, AlbumTitle, AlbumYear);

@ -13,9 +13,6 @@ namespace NzbDrone.Core.IndexerSearch.Definitions
private static readonly Regex NonWord = new Regex(@"[\W]", RegexOptions.IgnoreCase | RegexOptions.Compiled); private static readonly Regex NonWord = new Regex(@"[\W]", RegexOptions.IgnoreCase | RegexOptions.Compiled);
private static readonly Regex BeginningThe = new Regex(@"^the\s", RegexOptions.IgnoreCase | RegexOptions.Compiled); private static readonly Regex BeginningThe = new Regex(@"^the\s", RegexOptions.IgnoreCase | RegexOptions.Compiled);
[System.Obsolete("Sonarr TV Stuff -- Shouldn't be needed for Lidarr")]
public List<string> SceneTitles { get; set; }
public virtual bool MonitoredEpisodesOnly { get; set; } public virtual bool MonitoredEpisodesOnly { get; set; }
public virtual bool UserInvokedSearch { get; set; } public virtual bool UserInvokedSearch { get; set; }
public virtual bool InteractiveSearch { get; set; } public virtual bool InteractiveSearch { get; set; }
@ -24,7 +21,7 @@ namespace NzbDrone.Core.IndexerSearch.Definitions
public List<Album> Albums { get; set; } public List<Album> Albums { get; set; }
public List<Track> Tracks { get; set; } public List<Track> Tracks { get; set; }
public List<string> QueryTitles => SceneTitles.Select(GetQueryTitle).ToList(); public string ArtistQuery => GetQueryTitle(Artist.Name);
public static string GetQueryTitle(string title) public static string GetQueryTitle(string title)
{ {
@ -32,14 +29,16 @@ namespace NzbDrone.Core.IndexerSearch.Definitions
var cleanTitle = BeginningThe.Replace(title, string.Empty); var cleanTitle = BeginningThe.Replace(title, string.Empty);
cleanTitle = cleanTitle.Replace("&", "and"); cleanTitle = cleanTitle.Replace(" & ", " ");
cleanTitle = SpecialCharacter.Replace(cleanTitle, ""); cleanTitle = SpecialCharacter.Replace(cleanTitle, "");
cleanTitle = NonWord.Replace(cleanTitle, "+"); cleanTitle = NonWord.Replace(cleanTitle, "+");
//remove any repeating +s //remove any repeating +s
cleanTitle = Regex.Replace(cleanTitle, @"\+{2,}", "+"); cleanTitle = Regex.Replace(cleanTitle, @"\+{2,}", "+");
cleanTitle = cleanTitle.RemoveAccent(); cleanTitle = cleanTitle.RemoveAccent();
return cleanTitle.Trim('+', ' '); cleanTitle = cleanTitle.Trim('+', ' ');
return cleanTitle.Length == 0 ? title : cleanTitle;
} }
} }
} }

@ -30,14 +30,14 @@ namespace NzbDrone.Core.Indexers.Gazelle
public IndexerPageableRequestChain GetSearchRequests(AlbumSearchCriteria searchCriteria) public IndexerPageableRequestChain GetSearchRequests(AlbumSearchCriteria searchCriteria)
{ {
var pageableRequests = new IndexerPageableRequestChain(); var pageableRequests = new IndexerPageableRequestChain();
pageableRequests.Add(GetRequest(string.Format("&artistname={0}&groupname={1}", searchCriteria.Artist.Name, searchCriteria.AlbumTitle))); pageableRequests.Add(GetRequest(string.Format("&artistname={0}&groupname={1}", searchCriteria.ArtistQuery, searchCriteria.AlbumQuery)));
return pageableRequests; return pageableRequests;
} }
public IndexerPageableRequestChain GetSearchRequests(ArtistSearchCriteria searchCriteria) public IndexerPageableRequestChain GetSearchRequests(ArtistSearchCriteria searchCriteria)
{ {
var pageableRequests = new IndexerPageableRequestChain(); var pageableRequests = new IndexerPageableRequestChain();
pageableRequests.Add(GetRequest(string.Format("&artistname={0}",searchCriteria.Artist.Name))); pageableRequests.Add(GetRequest(string.Format("&artistname={0}",searchCriteria.ArtistQuery)));
return pageableRequests; return pageableRequests;
} }

@ -40,8 +40,8 @@ namespace NzbDrone.Core.Indexers.Headphones
pageableRequests.Add(GetPagedRequests(MaxPages, Settings.Categories, "search", pageableRequests.Add(GetPagedRequests(MaxPages, Settings.Categories, "search",
string.Format("&q={0}", string.Format("&q={0}",
NewsnabifyTitle(string.Format("{0} {1}", NewsnabifyTitle(string.Format("{0} {1}",
searchCriteria.Artist.Name, searchCriteria.ArtistQuery,
searchCriteria.AlbumTitle))))); searchCriteria.AlbumQuery)))));
return pageableRequests; return pageableRequests;
} }
@ -54,7 +54,7 @@ namespace NzbDrone.Core.Indexers.Headphones
pageableRequests.Add(GetPagedRequests(MaxPages, Settings.Categories, "search", pageableRequests.Add(GetPagedRequests(MaxPages, Settings.Categories, "search",
string.Format("&q={0}", string.Format("&q={0}",
NewsnabifyTitle(searchCriteria.Artist.Name)))); NewsnabifyTitle(searchCriteria.ArtistQuery))));
return pageableRequests; return pageableRequests;
} }

@ -71,8 +71,8 @@ namespace NzbDrone.Core.Indexers.Newznab
{ {
AddAudioPageableRequests(pageableRequests, searchCriteria, AddAudioPageableRequests(pageableRequests, searchCriteria,
string.Format("&artist={0}&album={1}", string.Format("&artist={0}&album={1}",
NewsnabifyTitle(searchCriteria.Artist.Name), NewsnabifyTitle(searchCriteria.ArtistQuery),
NewsnabifyTitle(searchCriteria.AlbumTitle))); NewsnabifyTitle(searchCriteria.AlbumQuery)));
} }
if (SupportsSearch) if (SupportsSearch)
@ -82,8 +82,8 @@ namespace NzbDrone.Core.Indexers.Newznab
pageableRequests.Add(GetPagedRequests(MaxPages, Settings.Categories, "search", pageableRequests.Add(GetPagedRequests(MaxPages, Settings.Categories, "search",
string.Format("&q={0}", string.Format("&q={0}",
NewsnabifyTitle(string.Format("{0} {1}", NewsnabifyTitle(string.Format("{0} {1}",
searchCriteria.Artist.Name, searchCriteria.ArtistQuery,
searchCriteria.AlbumTitle))))); searchCriteria.AlbumQuery)))));
} }

@ -31,8 +31,8 @@ namespace NzbDrone.Core.Indexers.Omgwtfnzbs
pageableRequests.Add(GetPagedRequests(string.Format("{0}+{1}", pageableRequests.Add(GetPagedRequests(string.Format("{0}+{1}",
searchCriteria.Artist.Name, searchCriteria.ArtistQuery,
searchCriteria.AlbumTitle))); searchCriteria.AlbumQuery)));
return pageableRequests; return pageableRequests;
@ -44,7 +44,7 @@ namespace NzbDrone.Core.Indexers.Omgwtfnzbs
pageableRequests.Add(GetPagedRequests(string.Format("{0}", pageableRequests.Add(GetPagedRequests(string.Format("{0}",
searchCriteria.Artist.Name))); searchCriteria.ArtistQuery)));
return pageableRequests; return pageableRequests;

@ -29,7 +29,7 @@ namespace NzbDrone.Core.Indexers.Rarbg
{ {
var pageableRequests = new IndexerPageableRequestChain(); var pageableRequests = new IndexerPageableRequestChain();
pageableRequests.Add(GetPagedRequests("search", null, "{0}+{1}", searchCriteria.Artist.Name, searchCriteria.AlbumTitle)); pageableRequests.Add(GetPagedRequests("search", null, "{0}+{1}", searchCriteria.ArtistQuery, searchCriteria.AlbumQuery));
return pageableRequests; return pageableRequests;
} }
@ -38,7 +38,7 @@ namespace NzbDrone.Core.Indexers.Rarbg
{ {
var pageableRequests = new IndexerPageableRequestChain(); var pageableRequests = new IndexerPageableRequestChain();
pageableRequests.Add(GetPagedRequests("search", null, "{0}", searchCriteria.Artist.Name)); pageableRequests.Add(GetPagedRequests("search", null, "{0}", searchCriteria.ArtistQuery));
return pageableRequests; return pageableRequests;
} }

@ -30,7 +30,7 @@ namespace NzbDrone.Core.Indexers.Waffles
{ {
var pageableRequests = new IndexerPageableRequestChain(); var pageableRequests = new IndexerPageableRequestChain();
pageableRequests.Add(GetPagedRequests(MaxPages, string.Format("&q=artist:{0} album:{1}",searchCriteria.Artist.Name,searchCriteria.AlbumTitle))); pageableRequests.Add(GetPagedRequests(MaxPages, string.Format("&q=artist:{0} album:{1}",searchCriteria.ArtistQuery,searchCriteria.AlbumQuery)));
return pageableRequests; return pageableRequests;
} }
@ -39,7 +39,7 @@ namespace NzbDrone.Core.Indexers.Waffles
{ {
var pageableRequests = new IndexerPageableRequestChain(); var pageableRequests = new IndexerPageableRequestChain();
pageableRequests.Add(GetPagedRequests(MaxPages, string.Format("&q=artist:{0}", searchCriteria.Artist.Name))); pageableRequests.Add(GetPagedRequests(MaxPages, string.Format("&q=artist:{0}", searchCriteria.ArtistQuery)));
return pageableRequests; return pageableRequests;
} }

Loading…
Cancel
Save