SeasonResolver.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using System.Globalization;
  2. using MediaBrowser.Controller.Configuration;
  3. using MediaBrowser.Controller.Entities.TV;
  4. using MediaBrowser.Controller.Library;
  5. using MediaBrowser.Model.Globalization;
  6. using Emby.Naming.Common;
  7. using Emby.Naming.TV;
  8. namespace Emby.Server.Implementations.Library.Resolvers.TV
  9. {
  10. /// <summary>
  11. /// Class SeasonResolver
  12. /// </summary>
  13. public class SeasonResolver : FolderResolver<Season>
  14. {
  15. /// <summary>
  16. /// The _config
  17. /// </summary>
  18. private readonly IServerConfigurationManager _config;
  19. private readonly ILibraryManager _libraryManager;
  20. private static readonly CultureInfo UsCulture = new CultureInfo("en-US");
  21. private readonly ILocalizationManager _localization;
  22. /// <summary>
  23. /// Initializes a new instance of the <see cref="SeasonResolver"/> class.
  24. /// </summary>
  25. /// <param name="config">The config.</param>
  26. public SeasonResolver(IServerConfigurationManager config, ILibraryManager libraryManager, ILocalizationManager localization)
  27. {
  28. _config = config;
  29. _libraryManager = libraryManager;
  30. _localization = localization;
  31. }
  32. /// <summary>
  33. /// Resolves the specified args.
  34. /// </summary>
  35. /// <param name="args">The args.</param>
  36. /// <returns>Season.</returns>
  37. protected override Season Resolve(ItemResolveArgs args)
  38. {
  39. if (args.Parent is Series && args.IsDirectory)
  40. {
  41. var namingOptions = ((LibraryManager)_libraryManager).GetNamingOptions();
  42. var series = ((Series)args.Parent);
  43. var season = new Season
  44. {
  45. IndexNumber = new SeasonPathParser(namingOptions, new RegexProvider()).Parse(args.Path, true, true).SeasonNumber,
  46. SeriesId = series.Id,
  47. SeriesName = series.Name
  48. };
  49. if (season.IndexNumber.HasValue)
  50. {
  51. var seasonNumber = season.IndexNumber.Value;
  52. season.Name = seasonNumber == 0 ?
  53. args.LibraryOptions.SeasonZeroDisplayName :
  54. string.Format(_localization.GetLocalizedString("NameSeasonNumber"), seasonNumber.ToString(UsCulture));
  55. }
  56. return season;
  57. }
  58. return null;
  59. }
  60. }
  61. }