jellyfin/Emby.Naming/Video/FlagParser.cs

54 lines
1.7 KiB
C#
Raw Normal View History

using System;
2018-09-12 10:26:21 -07:00
using System.IO;
2019-01-13 12:17:29 -07:00
using Emby.Naming.Common;
2018-09-12 10:26:21 -07:00
namespace Emby.Naming.Video
{
2020-11-10 11:23:10 -07:00
/// <summary>
/// Parses list of flags from filename based on delimiters.
/// </summary>
2018-09-12 10:26:21 -07:00
public class FlagParser
{
private readonly NamingOptions _options;
2020-11-10 11:23:10 -07:00
/// <summary>
/// Initializes a new instance of the <see cref="FlagParser"/> class.
/// </summary>
/// <param name="options"><see cref="NamingOptions"/> object containing VideoFlagDelimiters.</param>
2018-09-12 10:26:21 -07:00
public FlagParser(NamingOptions options)
{
_options = options;
}
2020-11-10 11:23:10 -07:00
/// <summary>
/// Calls GetFlags function with _options.VideoFlagDelimiters parameter.
/// </summary>
/// <param name="path">Path to file.</param>
/// <returns>List of found flags.</returns>
2018-09-12 10:26:21 -07:00
public string[] GetFlags(string path)
{
return GetFlags(path, _options.VideoFlagDelimiters);
}
2020-11-10 11:23:10 -07:00
/// <summary>
/// Parses flags from filename based on delimiters.
/// </summary>
/// <param name="path">Path to file.</param>
/// <param name="delimiters">Delimiters used to extract flags.</param>
/// <returns>List of found flags.</returns>
2020-11-01 03:19:22 -07:00
public string[] GetFlags(string path, char[] delimiters)
2018-09-12 10:26:21 -07:00
{
if (string.IsNullOrEmpty(path))
{
2020-11-05 08:59:15 -07:00
return Array.Empty<string>();
2018-09-12 10:26:21 -07:00
}
// Note: the tags need be be surrounded be either a space ( ), hyphen -, dot . or underscore _.
var file = Path.GetFileName(path);
2020-11-01 03:19:22 -07:00
return file.Split(delimiters, StringSplitOptions.RemoveEmptyEntries);
2018-09-12 10:26:21 -07:00
}
}
}