2019-12-13 14:11:37 -05:00
|
|
|
#pragma warning disable CS1591
|
|
|
|
#pragma warning disable SA1600
|
|
|
|
|
2018-09-12 13:26:21 -04:00
|
|
|
using System.Globalization;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Text.RegularExpressions;
|
2019-01-13 14:17:29 -05:00
|
|
|
using Emby.Naming.Common;
|
2018-09-12 13:26:21 -04:00
|
|
|
|
|
|
|
namespace Emby.Naming.Video
|
|
|
|
{
|
|
|
|
/// <summary>
|
2019-10-25 06:47:20 -04:00
|
|
|
/// <see href="http://kodi.wiki/view/Advancedsettings.xml#video" />.
|
2018-09-12 13:26:21 -04:00
|
|
|
/// </summary>
|
|
|
|
public class CleanDateTimeParser
|
|
|
|
{
|
|
|
|
private readonly NamingOptions _options;
|
|
|
|
|
|
|
|
public CleanDateTimeParser(NamingOptions options)
|
|
|
|
{
|
|
|
|
_options = options;
|
|
|
|
}
|
|
|
|
|
|
|
|
public CleanDateTimeResult Clean(string name)
|
2020-01-11 14:31:59 -05:00
|
|
|
=> _options.CleanDateTimeRegexes.Select(i => Clean(name, i))
|
2018-09-12 13:26:21 -04:00
|
|
|
.FirstOrDefault(i => i.HasChanged) ??
|
2020-01-11 14:31:59 -05:00
|
|
|
new CleanDateTimeResult { Name = name };
|
2018-09-12 13:26:21 -04:00
|
|
|
|
2019-01-06 15:50:43 -05:00
|
|
|
private static CleanDateTimeResult Clean(string name, Regex expression)
|
2018-09-12 13:26:21 -04:00
|
|
|
{
|
|
|
|
var result = new CleanDateTimeResult();
|
|
|
|
|
|
|
|
var match = expression.Match(name);
|
|
|
|
|
2019-05-10 14:37:42 -04:00
|
|
|
if (match.Success
|
2020-01-11 14:25:06 -05:00
|
|
|
&& match.Groups.Count == 5
|
2019-05-10 14:37:42 -04:00
|
|
|
&& match.Groups[1].Success
|
|
|
|
&& match.Groups[2].Success
|
|
|
|
&& int.TryParse(match.Groups[2].Value, NumberStyles.Integer, CultureInfo.InvariantCulture, out var year))
|
2018-09-12 13:26:21 -04:00
|
|
|
{
|
2020-01-11 14:25:06 -05:00
|
|
|
name = match.Groups[1].Value.TrimEnd();
|
2019-05-10 14:37:42 -04:00
|
|
|
result.Year = year;
|
|
|
|
result.HasChanged = true;
|
2018-09-12 13:26:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
result.Name = name;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|