| | 1 | | using System.Collections.Generic; |
| | 2 | | using System.Globalization; |
| | 3 | | using System.Text.RegularExpressions; |
| | 4 | |
|
| | 5 | | namespace Emby.Naming.Video |
| | 6 | | { |
| | 7 | | /// <summary> |
| | 8 | | /// <see href="http://kodi.wiki/view/Advancedsettings.xml#video" />. |
| | 9 | | /// </summary> |
| | 10 | | public static class CleanDateTimeParser |
| | 11 | | { |
| | 12 | | /// <summary> |
| | 13 | | /// Attempts to clean the name. |
| | 14 | | /// </summary> |
| | 15 | | /// <param name="name">Name of video.</param> |
| | 16 | | /// <param name="cleanDateTimeRegexes">Optional list of regexes to clean the name.</param> |
| | 17 | | /// <returns>Returns <see cref="CleanDateTimeResult"/> object.</returns> |
| | 18 | | public static CleanDateTimeResult Clean(string name, IReadOnlyList<Regex> cleanDateTimeRegexes) |
| | 19 | | { |
| 271 | 20 | | CleanDateTimeResult result = new CleanDateTimeResult(name); |
| 271 | 21 | | if (string.IsNullOrEmpty(name)) |
| | 22 | | { |
| 1 | 23 | | return result; |
| | 24 | | } |
| | 25 | |
|
| 270 | 26 | | var len = cleanDateTimeRegexes.Count; |
| 1210 | 27 | | for (int i = 0; i < len; i++) |
| | 28 | | { |
| 441 | 29 | | if (TryClean(name, cleanDateTimeRegexes[i], ref result)) |
| | 30 | | { |
| 106 | 31 | | return result; |
| | 32 | | } |
| | 33 | | } |
| | 34 | |
|
| 164 | 35 | | return result; |
| | 36 | | } |
| | 37 | |
|
| | 38 | | private static bool TryClean(string name, Regex expression, ref CleanDateTimeResult result) |
| | 39 | | { |
| 441 | 40 | | var match = expression.Match(name); |
| | 41 | |
|
| 441 | 42 | | if (match.Success |
| 441 | 43 | | && match.Groups.Count == 5 |
| 441 | 44 | | && match.Groups[1].Success |
| 441 | 45 | | && match.Groups[2].Success |
| 441 | 46 | | && int.TryParse(match.Groups[2].ValueSpan, NumberStyles.Integer, CultureInfo.InvariantCulture, out var y |
| | 47 | | { |
| 106 | 48 | | result = new CleanDateTimeResult(match.Groups[1].Value.TrimEnd(), year); |
| 106 | 49 | | return true; |
| | 50 | | } |
| | 51 | |
|
| 335 | 52 | | return false; |
| | 53 | | } |
| | 54 | | } |
| | 55 | | } |