EpisodeExpression.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using System;
  2. using System.Text.RegularExpressions;
  3. namespace Emby.Naming.Common
  4. {
  5. /// <summary>
  6. /// Regular expressions for parsing TV Episodes.
  7. /// </summary>
  8. public class EpisodeExpression
  9. {
  10. private string _expression;
  11. private Regex? _regex;
  12. /// <summary>
  13. /// Initializes a new instance of the <see cref="EpisodeExpression"/> class.
  14. /// </summary>
  15. /// <param name="expression">Regular expressions.</param>
  16. /// <param name="byDate">True if date is expected.</param>
  17. public EpisodeExpression(string expression, bool byDate = false)
  18. {
  19. _expression = expression;
  20. IsByDate = byDate;
  21. DateTimeFormats = Array.Empty<string>();
  22. SupportsAbsoluteEpisodeNumbers = true;
  23. }
  24. /// <summary>
  25. /// Gets or sets raw expressions string.
  26. /// </summary>
  27. public string Expression
  28. {
  29. get => _expression;
  30. set
  31. {
  32. _expression = value;
  33. _regex = null;
  34. }
  35. }
  36. /// <summary>
  37. /// Gets or sets a value indicating whether gets or sets property indicating if date can be find in expression.
  38. /// </summary>
  39. public bool IsByDate { get; set; }
  40. /// <summary>
  41. /// Gets or sets a value indicating whether gets or sets property indicating if expression is optimistic.
  42. /// </summary>
  43. public bool IsOptimistic { get; set; }
  44. /// <summary>
  45. /// Gets or sets a value indicating whether gets or sets property indicating if expression is named.
  46. /// </summary>
  47. public bool IsNamed { get; set; }
  48. /// <summary>
  49. /// Gets or sets a value indicating whether gets or sets property indicating if expression supports episodes with absolute numbers.
  50. /// </summary>
  51. public bool SupportsAbsoluteEpisodeNumbers { get; set; }
  52. /// <summary>
  53. /// Gets or sets optional list of date formats used for date parsing.
  54. /// </summary>
  55. public string[] DateTimeFormats { get; set; }
  56. /// <summary>
  57. /// Gets a <see cref="Regex"/> expressions objects (creates it if null).
  58. /// </summary>
  59. public Regex Regex => _regex ??= new Regex(Expression, RegexOptions.IgnoreCase | RegexOptions.Compiled);
  60. }
  61. }