mirror of
https://github.com/Readarr/Readarr
synced 2026-04-29 00:01:17 +02:00
Fixed: Better detection of series in search results
This commit is contained in:
parent
5f1be9e447
commit
17535bd8d6
2 changed files with 33 additions and 16 deletions
|
|
@ -116,5 +116,16 @@ public void should_parse_series_from_title(string query, string series, string p
|
||||||
link.Series.Value.Title.Should().Be(series);
|
link.Series.Value.Title.Should().Be(series);
|
||||||
link.Position.Should().Be(position);
|
link.Position.Should().Be(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestCase("Imperium: A Novel of Ancient Rome (Cicero, #1)", "Imperium: A Novel of Ancient Rome", "Cicero", "1")]
|
||||||
|
[TestCase("Sons of Valor (The Tier One Shared-World Series Book 1)", "Sons of Valor", "Tier One Shared-World", "1")]
|
||||||
|
public void should_map_series_for_search(string title, string titleWithoutSeries, string series, string position)
|
||||||
|
{
|
||||||
|
var result = GoodreadsProxy.MapSearchSeries(title, titleWithoutSeries);
|
||||||
|
|
||||||
|
result.Should().HaveCount(1);
|
||||||
|
result[0].Series.Value.Title.Should().Be(series);
|
||||||
|
result[0].Position.Should().Be(position);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,8 +28,11 @@ public class GoodreadsProxy : IProvideAuthorInfo, ISearchForNewAuthor, IProvideB
|
||||||
private static readonly Regex NoPhotoRegex = new Regex(@"/nophoto/(book|user)/",
|
private static readonly Regex NoPhotoRegex = new Regex(@"/nophoto/(book|user)/",
|
||||||
RegexOptions.IgnoreCase | RegexOptions.Compiled);
|
RegexOptions.IgnoreCase | RegexOptions.Compiled);
|
||||||
|
|
||||||
private static readonly Regex SeriesRegex = new Regex(@"\((?<series>[^,]+),\s+#(?<position>[\w\d\.]+)\)$",
|
private static readonly List<Regex> SeriesRegex = new List<Regex>
|
||||||
RegexOptions.Compiled);
|
{
|
||||||
|
new Regex(@"\((?<series>[^,]+),\s+#(?<position>[\w\d\.]+)\)$", RegexOptions.Compiled),
|
||||||
|
new Regex(@"(The\s+(?<series>.+)\s+Series\s+Book\s+(?<position>[\w\d\.]+)\)$)", RegexOptions.Compiled)
|
||||||
|
};
|
||||||
|
|
||||||
private readonly ICachedHttpResponseService _cachedHttpClient;
|
private readonly ICachedHttpResponseService _cachedHttpClient;
|
||||||
private readonly Logger _logger;
|
private readonly Logger _logger;
|
||||||
|
|
@ -841,31 +844,34 @@ private Book MapJsonSearchResult(SearchJsonResource resource, Action<Edition> ap
|
||||||
return book;
|
return book;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<SeriesBookLink> MapSearchSeries(string title, string titleWithoutSeries)
|
public static List<SeriesBookLink> MapSearchSeries(string title, string titleWithoutSeries)
|
||||||
{
|
{
|
||||||
if (title != titleWithoutSeries &&
|
if (title != titleWithoutSeries &&
|
||||||
title.Substring(0, titleWithoutSeries.Length) == titleWithoutSeries)
|
title.Substring(0, titleWithoutSeries.Length) == titleWithoutSeries)
|
||||||
{
|
{
|
||||||
var seriesText = title.Substring(titleWithoutSeries.Length);
|
var seriesText = title.Substring(titleWithoutSeries.Length);
|
||||||
|
|
||||||
var match = SeriesRegex.Match(seriesText);
|
foreach (var regex in SeriesRegex)
|
||||||
|
|
||||||
if (match.Success)
|
|
||||||
{
|
{
|
||||||
var series = match.Groups["series"].Value;
|
var match = regex.Match(seriesText);
|
||||||
var position = match.Groups["position"].Value;
|
|
||||||
|
|
||||||
return new List<SeriesBookLink>
|
if (match.Success)
|
||||||
{
|
{
|
||||||
new SeriesBookLink
|
var series = match.Groups["series"].Value;
|
||||||
|
var position = match.Groups["position"].Value;
|
||||||
|
|
||||||
|
return new List<SeriesBookLink>
|
||||||
{
|
{
|
||||||
Series = new Series
|
new SeriesBookLink
|
||||||
{
|
{
|
||||||
Title = series
|
Series = new Series
|
||||||
},
|
{
|
||||||
Position = position
|
Title = series
|
||||||
}
|
},
|
||||||
};
|
Position = position
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue