SeasonResolver.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using MediaBrowser.Controller.Configuration;
  2. using MediaBrowser.Controller.Entities.TV;
  3. using MediaBrowser.Controller.Library;
  4. using MediaBrowser.Naming.Common;
  5. using MediaBrowser.Naming.TV;
  6. namespace MediaBrowser.Server.Implementations.Library.Resolvers.TV
  7. {
  8. /// <summary>
  9. /// Class SeasonResolver
  10. /// </summary>
  11. public class SeasonResolver : FolderResolver<Season>
  12. {
  13. /// <summary>
  14. /// The _config
  15. /// </summary>
  16. private readonly IServerConfigurationManager _config;
  17. private readonly ILibraryManager _libraryManager;
  18. /// <summary>
  19. /// Initializes a new instance of the <see cref="SeasonResolver"/> class.
  20. /// </summary>
  21. /// <param name="config">The config.</param>
  22. public SeasonResolver(IServerConfigurationManager config, ILibraryManager libraryManager)
  23. {
  24. _config = config;
  25. _libraryManager = libraryManager;
  26. }
  27. /// <summary>
  28. /// Resolves the specified args.
  29. /// </summary>
  30. /// <param name="args">The args.</param>
  31. /// <returns>Season.</returns>
  32. protected override Season Resolve(ItemResolveArgs args)
  33. {
  34. if (args.Parent is Series && args.IsDirectory)
  35. {
  36. var namingOptions = ((LibraryManager)_libraryManager).GetNamingOptions();
  37. var season = new Season
  38. {
  39. IndexNumber = new SeasonPathParser(namingOptions, new RegexProvider()).Parse(args.Path, true, true).SeasonNumber
  40. };
  41. if (season.IndexNumber.HasValue && season.IndexNumber.Value == 0)
  42. {
  43. season.Name = _config.Configuration.SeasonZeroDisplayName;
  44. }
  45. return season;
  46. }
  47. return null;
  48. }
  49. }
  50. }