FlagParser.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using System;
  2. using System.IO;
  3. using Emby.Naming.Common;
  4. namespace Emby.Naming.Video
  5. {
  6. /// <summary>
  7. /// Parses list of flags from filename based on delimiters.
  8. /// </summary>
  9. public class FlagParser
  10. {
  11. private readonly NamingOptions _options;
  12. /// <summary>
  13. /// Initializes a new instance of the <see cref="FlagParser"/> class.
  14. /// </summary>
  15. /// <param name="options"><see cref="NamingOptions"/> object containing VideoFlagDelimiters.</param>
  16. public FlagParser(NamingOptions options)
  17. {
  18. _options = options;
  19. }
  20. /// <summary>
  21. /// Calls GetFlags function with _options.VideoFlagDelimiters parameter.
  22. /// </summary>
  23. /// <param name="path">Path to file.</param>
  24. /// <returns>List of found flags.</returns>
  25. public string[] GetFlags(string path)
  26. {
  27. return GetFlags(path, _options.VideoFlagDelimiters);
  28. }
  29. /// <summary>
  30. /// Parses flags from filename based on delimiters.
  31. /// </summary>
  32. /// <param name="path">Path to file.</param>
  33. /// <param name="delimiters">Delimiters used to extract flags.</param>
  34. /// <returns>List of found flags.</returns>
  35. public string[] GetFlags(string path, char[] delimiters)
  36. {
  37. if (string.IsNullOrEmpty(path))
  38. {
  39. return Array.Empty<string>();
  40. }
  41. // Note: the tags need be be surrounded be either a space ( ), hyphen -, dot . or underscore _.
  42. var file = Path.GetFileName(path);
  43. return file.Split(delimiters, StringSplitOptions.RemoveEmptyEntries);
  44. }
  45. }
  46. }