jellyfin/Emby.Naming/Common/EpisodeExpression.cs

71 lines
2.3 KiB
C#
Raw Normal View History

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