| | 1 | | using Emby.Naming.Common; |
| | 2 | |
|
| | 3 | | namespace Emby.Naming.TV |
| | 4 | | { |
| | 5 | | /// <summary> |
| | 6 | | /// Used to parse information about series from paths containing more information that only the series name. |
| | 7 | | /// Uses the same regular expressions as the EpisodePathParser but have different success criteria. |
| | 8 | | /// </summary> |
| | 9 | | public static class SeriesPathParser |
| | 10 | | { |
| | 11 | | /// <summary> |
| | 12 | | /// Parses information about series from path. |
| | 13 | | /// </summary> |
| | 14 | | /// <param name="options"><see cref="NamingOptions"/> object containing EpisodeExpressions and MultipleEpisodeEx |
| | 15 | | /// <param name="path">Path.</param> |
| | 16 | | /// <returns>Returns <see cref="SeriesPathParserResult"/> object.</returns> |
| | 17 | | public static SeriesPathParserResult Parse(NamingOptions options, string path) |
| | 18 | | { |
| 19 | 19 | | SeriesPathParserResult? result = null; |
| | 20 | |
|
| 839 | 21 | | foreach (var expression in options.EpisodeExpressions) |
| | 22 | | { |
| 409 | 23 | | var currentResult = Parse(path, expression); |
| 409 | 24 | | if (currentResult.Success) |
| | 25 | | { |
| 17 | 26 | | result = currentResult; |
| 17 | 27 | | break; |
| | 28 | | } |
| | 29 | | } |
| | 30 | |
|
| 19 | 31 | | if (result is not null) |
| | 32 | | { |
| 17 | 33 | | if (!string.IsNullOrEmpty(result.SeriesName)) |
| | 34 | | { |
| 17 | 35 | | result.SeriesName = result.SeriesName.Trim(' ', '_', '.', '-'); |
| | 36 | | } |
| | 37 | | } |
| | 38 | |
|
| 19 | 39 | | return result ?? new SeriesPathParserResult(); |
| | 40 | | } |
| | 41 | |
|
| | 42 | | private static SeriesPathParserResult Parse(string name, EpisodeExpression expression) |
| | 43 | | { |
| 409 | 44 | | var result = new SeriesPathParserResult(); |
| | 45 | |
|
| 409 | 46 | | var match = expression.Regex.Match(name); |
| | 47 | |
|
| 409 | 48 | | if (match.Success && match.Groups.Count >= 3) |
| | 49 | | { |
| 19 | 50 | | if (expression.IsNamed) |
| | 51 | | { |
| 19 | 52 | | result.SeriesName = match.Groups["seriesname"].Value; |
| 19 | 53 | | result.Success = !string.IsNullOrEmpty(result.SeriesName) && !match.Groups["seasonnumber"].ValueSpan |
| | 54 | | } |
| | 55 | | } |
| | 56 | |
|
| 409 | 57 | | return result; |
| | 58 | | } |
| | 59 | | } |
| | 60 | | } |