using System.IO; using System.Text.RegularExpressions; using Emby.Naming.Common; namespace Emby.Naming.TV { /// /// Used to resolve information about series from path. /// public static class SeriesResolver { /// /// Regex that matches strings of at least 2 characters separated by a dot or underscore. /// Used for removing separators between words, i.e turns "The_show" into "The show" while /// preserving namings like "S.H.O.W". /// private static readonly Regex _seriesNameRegex = new Regex(@"((?[^\._]{2,})[\._]*)|([\._](?[^\._]{2,}))", RegexOptions.Compiled); /// /// Resolve information about series from path. /// /// object passed to . /// Path to series. /// SeriesInfo. public static SeriesInfo Resolve(NamingOptions options, string path) { string seriesName = Path.GetFileName(path); SeriesPathParserResult result = SeriesPathParser.Parse(options, path); if (result.Success) { if (!string.IsNullOrEmpty(result.SeriesName)) { seriesName = result.SeriesName; } } if (!string.IsNullOrEmpty(seriesName)) { seriesName = _seriesNameRegex.Replace(seriesName, "${a} ${b}").Trim(); } return new SeriesInfo(path) { Name = seriesName }; } } }