mirror of
https://github.com/Readarr/Readarr.git
synced 2026-04-20 21:54:25 -04:00
51 lines
1.9 KiB
C#
51 lines
1.9 KiB
C#
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;
|
||
}
|
||
}
|
||
}
|