SeasonResolver.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 Emby.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 series = ((Series)args.Parent);
  38. var season = new Season
  39. {
  40. IndexNumber = new SeasonPathParser(namingOptions, new RegexProvider()).Parse(args.Path, true, true).SeasonNumber,
  41. SeriesId = series.Id,
  42. SeriesName = series.Name
  43. };
  44. if (season.IndexNumber.HasValue && season.IndexNumber.Value == 0)
  45. {
  46. season.Name = _config.Configuration.SeasonZeroDisplayName;
  47. }
  48. return season;
  49. }
  50. return null;
  51. }
  52. }
  53. }