SeriesResolver.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using System.IO;
  2. using System.Text.RegularExpressions;
  3. using Emby.Naming.Common;
  4. namespace Emby.Naming.TV
  5. {
  6. /// <summary>
  7. /// Used to resolve information about series from path.
  8. /// </summary>
  9. public static partial class SeriesResolver
  10. {
  11. /// <summary>
  12. /// Regex that matches strings of at least 2 characters separated by a dot or underscore.
  13. /// Used for removing separators between words, i.e turns "The_show" into "The show" while
  14. /// preserving names like "S.H.O.W".
  15. /// </summary>
  16. [GeneratedRegex(@"((?<a>[^\._]{2,})[\._]*)|([\._](?<b>[^\._]{2,}))")]
  17. private static partial Regex SeriesNameRegex();
  18. /// <summary>
  19. /// Resolve information about series from path.
  20. /// </summary>
  21. /// <param name="options"><see cref="NamingOptions"/> object passed to <see cref="SeriesPathParser"/>.</param>
  22. /// <param name="path">Path to series.</param>
  23. /// <returns>SeriesInfo.</returns>
  24. public static SeriesInfo Resolve(NamingOptions options, string path)
  25. {
  26. string seriesName = Path.GetFileName(path);
  27. SeriesPathParserResult result = SeriesPathParser.Parse(options, path);
  28. if (result.Success)
  29. {
  30. if (!string.IsNullOrEmpty(result.SeriesName))
  31. {
  32. seriesName = result.SeriesName;
  33. }
  34. }
  35. if (!string.IsNullOrEmpty(seriesName))
  36. {
  37. seriesName = SeriesNameRegex().Replace(seriesName, "${a} ${b}").Trim();
  38. }
  39. return new SeriesInfo(path)
  40. {
  41. Name = seriesName
  42. };
  43. }
  44. }
  45. }