SeasonResolver.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 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. SeriesSortName = series.SortName,
  43. SeriesName = series.Name
  44. };
  45. if (season.IndexNumber.HasValue && season.IndexNumber.Value == 0)
  46. {
  47. season.Name = _config.Configuration.SeasonZeroDisplayName;
  48. }
  49. return season;
  50. }
  51. return null;
  52. }
  53. }
  54. }