2019-01-13 19:54:44 +00:00
|
|
|
using System;
|
2018-09-12 17:26:21 +00:00
|
|
|
using System.IO;
|
2019-01-13 19:17:29 +00:00
|
|
|
using Emby.Naming.Common;
|
2018-09-12 17:26:21 +00:00
|
|
|
|
|
|
|
namespace Emby.Naming.Video
|
|
|
|
{
|
2020-11-10 18:23:10 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Parses list of flags from filename based on delimiters.
|
|
|
|
/// </summary>
|
2018-09-12 17:26:21 +00:00
|
|
|
public class FlagParser
|
|
|
|
{
|
|
|
|
private readonly NamingOptions _options;
|
|
|
|
|
2020-11-10 18:23:10 +00: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 17:26:21 +00:00
|
|
|
public FlagParser(NamingOptions options)
|
|
|
|
{
|
|
|
|
_options = options;
|
|
|
|
}
|
|
|
|
|
2020-11-10 18:23:10 +00: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 17:26:21 +00:00
|
|
|
public string[] GetFlags(string path)
|
|
|
|
{
|
|
|
|
return GetFlags(path, _options.VideoFlagDelimiters);
|
|
|
|
}
|
|
|
|
|
2020-11-10 18:23:10 +00: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 10:19:22 +00:00
|
|
|
public string[] GetFlags(string path, char[] delimiters)
|
2018-09-12 17:26:21 +00:00
|
|
|
{
|
|
|
|
if (string.IsNullOrEmpty(path))
|
|
|
|
{
|
2020-11-05 15:59:15 +00:00
|
|
|
return Array.Empty<string>();
|
2018-09-12 17:26:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Note: the tags need be be surrounded be either a space ( ), hyphen -, dot . or underscore _.
|
|
|
|
|
|
|
|
var file = Path.GetFileName(path);
|
|
|
|
|
2020-11-01 10:19:22 +00:00
|
|
|
return file.Split(delimiters, StringSplitOptions.RemoveEmptyEntries);
|
2018-09-12 17:26:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|