Files
Readarr/src/NzbDrone.Core/IndexerSearch/Definitions/SearchCriteriaBase.cs
T

51 lines
1.9 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System.Collections.Generic;
using System.Text.RegularExpressions;
using NzbDrone.Common.EnsureThat;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.Books;
namespace NzbDrone.Core.IndexerSearch.Definitions
{
public abstract class SearchCriteriaBase
{
private static readonly Regex SpecialCharacter = new Regex(@"[`']", 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);
public virtual bool MonitoredBooksOnly { get; set; }
public virtual bool UserInvokedSearch { get; set; }
public virtual bool InteractiveSearch { get; set; }
public Author Author { get; set; }
public List<Book> Books { get; set; }
public string AuthorQuery => GetQueryTitle(Author.Name);
public static string GetQueryTitle(string title)
{
Ensure.That(title, () => title).IsNotNullOrWhiteSpace();
// Most VA albums are listed as VA, not Various Artists
// TODO: Needed in Readarr??
if (title == "Various Artists")
{
title = "VA";
}
var cleanTitle = BeginningThe.Replace(title, string.Empty);
cleanTitle = cleanTitle.Replace(" & ", " ");
cleanTitle = cleanTitle.Replace(".", " ");
cleanTitle = SpecialCharacter.Replace(cleanTitle, "");
cleanTitle = NonWord.Replace(cleanTitle, "+");
//remove any repeating +s
cleanTitle = Regex.Replace(cleanTitle, @"\+{2,}", "+");
cleanTitle = cleanTitle.RemoveAccent();
cleanTitle = cleanTitle.Trim('+', ' ');
return cleanTitle.Length == 0 ? title : cleanTitle;
}
}
}