jellyfin-server/Emby.Naming/Common/EpisodeExpression.cs

71 lines
2.3 KiB
C#
Raw Normal View History

using System;
2019-01-13 19:17:29 +00:00
using System.Text.RegularExpressions;
2018-09-12 17:26:21 +00:00
namespace Emby.Naming.Common
{
2020-11-10 16:11:48 +00:00
/// <summary>
/// Regular expressions for parsing TV Episodes.
/// </summary>
2018-09-12 17:26:21 +00:00
public class EpisodeExpression
{
private string _expression;
2020-11-01 09:47:31 +00:00
private Regex? _regex;
2019-05-10 18:37:42 +00:00
2020-11-10 16:11:48 +00:00
/// <summary>
/// Initializes a new instance of the <see cref="EpisodeExpression"/> class.
/// </summary>
/// <param name="expression">Regular expressions.</param>
/// <param name="byDate">True if date is expected.</param>
public EpisodeExpression(string expression, bool byDate = false)
2020-01-22 21:18:56 +00:00
{
2020-11-01 09:47:31 +00:00
_expression = expression;
2020-01-22 21:18:56 +00:00
IsByDate = byDate;
DateTimeFormats = Array.Empty<string>();
SupportsAbsoluteEpisodeNumbers = true;
}
2020-11-10 16:11:48 +00:00
/// <summary>
/// Gets or sets raw expressions string.
/// </summary>
2019-05-10 18:37:42 +00:00
public string Expression
{
get => _expression;
set
{
_expression = value;
_regex = null;
}
}
2018-09-12 17:26:21 +00:00
2020-11-10 16:11:48 +00:00
/// <summary>
/// Gets or sets a value indicating whether gets or sets property indicating if date can be find in expression.
/// </summary>
2018-09-12 17:26:21 +00:00
public bool IsByDate { get; set; }
2019-05-10 18:37:42 +00:00
2020-11-10 16:11:48 +00:00
/// <summary>
/// Gets or sets a value indicating whether gets or sets property indicating if expression is optimistic.
/// </summary>
2018-09-12 17:26:21 +00:00
public bool IsOptimistic { get; set; }
2019-05-10 18:37:42 +00:00
2020-11-10 16:11:48 +00:00
/// <summary>
/// Gets or sets a value indicating whether gets or sets property indicating if expression is named.
/// </summary>
2018-09-12 17:26:21 +00:00
public bool IsNamed { get; set; }
2019-05-10 18:37:42 +00:00
2020-11-10 16:11:48 +00:00
/// <summary>
/// Gets or sets a value indicating whether gets or sets property indicating if expression supports episodes with absolute numbers.
/// </summary>
2018-09-12 17:26:21 +00:00
public bool SupportsAbsoluteEpisodeNumbers { get; set; }
2020-11-10 16:11:48 +00:00
/// <summary>
/// Gets or sets optional list of date formats used for date parsing.
/// </summary>
2018-09-12 17:26:21 +00:00
public string[] DateTimeFormats { get; set; }
2020-11-10 16:11:48 +00:00
/// <summary>
/// Gets a <see cref="Regex"/> expressions objects (creates it if null).
/// </summary>
2020-04-19 09:57:03 +00:00
public Regex Regex => _regex ??= new Regex(Expression, RegexOptions.IgnoreCase | RegexOptions.Compiled);
2018-09-12 17:26:21 +00:00
}
}