New: Better matching of books with subtitles

This commit is contained in:
ta264
2021-06-08 21:40:56 +01:00
parent aa45bc3938
commit 7fda41c18b
7 changed files with 101 additions and 4 deletions
+57
View File
@@ -362,6 +362,11 @@ namespace NzbDrone.Core.Parser
var foundBook = GetTitleFuzzy(remainder, bestBook.Title, out _);
if (foundBook == null)
{
foundBook = GetTitleFuzzy(remainder, bestBook.Title.SplitBookTitle(authorName).Item1, out _);
}
Logger.Trace($"Found {foundAuthor} - {foundBook} with fuzzy parser");
if (foundAuthor == null || foundBook == null)
@@ -576,6 +581,58 @@ namespace NzbDrone.Core.Parser
return null;
}
public static (string, string) SplitBookTitle(this string book, string author)
{
// Strip author from title, eg Tom Clancy: Ghost Protocol
if (book.StartsWith($"{author}:"))
{
book = book.Split(':', 2)[1].Trim();
}
var parenthesis = book.IndexOf('(');
var colon = book.IndexOf(':');
string[] parts = null;
if (parenthesis > -1)
{
var endParenthesis = book.IndexOf(')');
if (endParenthesis > -1 && !book.Substring(parenthesis + 1, endParenthesis - parenthesis).Contains(' '))
{
parenthesis = -1;
}
}
if (colon > -1 && parenthesis > -1)
{
if (colon < parenthesis)
{
parts = book.Split(':', 2);
}
else
{
parts = book.Split('(', 2);
parts[1] = parts[1].TrimEnd(')');
}
}
else if (colon > -1)
{
parts = book.Split(':', 2);
}
else if (parenthesis > -1)
{
parts = book.Split('(');
parts[1] = parts[1].TrimEnd(')');
}
if (parts != null)
{
return (parts[0].Trim(), parts[1].TrimEnd(':').Trim());
}
return (book, string.Empty);
}
public static string CleanAuthorName(this string name)
{
// If Title only contains numbers return it as is.