jellyfin/Emby.Naming/Common/EpisodeExpression.cs

71 lines
2.3 KiB
C#
Raw Normal View History

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