Season.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. using MediaBrowser.Controller.Library;
  2. using MediaBrowser.Controller.Localization;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.IO;
  6. using System.Runtime.Serialization;
  7. namespace MediaBrowser.Controller.Entities.TV
  8. {
  9. /// <summary>
  10. /// Class Season
  11. /// </summary>
  12. public class Season : Folder
  13. {
  14. /// <summary>
  15. /// Seasons are just containers
  16. /// </summary>
  17. /// <value><c>true</c> if [include in index]; otherwise, <c>false</c>.</value>
  18. [IgnoreDataMember]
  19. public override bool IncludeInIndex
  20. {
  21. get
  22. {
  23. return false;
  24. }
  25. }
  26. /// <summary>
  27. /// We want to group into our Series
  28. /// </summary>
  29. /// <value><c>true</c> if [group in index]; otherwise, <c>false</c>.</value>
  30. [IgnoreDataMember]
  31. public override bool GroupInIndex
  32. {
  33. get
  34. {
  35. return true;
  36. }
  37. }
  38. /// <summary>
  39. /// Override this to return the folder that should be used to construct a container
  40. /// for this item in an index. GroupInIndex should be true as well.
  41. /// </summary>
  42. /// <value>The index container.</value>
  43. [IgnoreDataMember]
  44. public override Folder IndexContainer
  45. {
  46. get
  47. {
  48. return Series;
  49. }
  50. }
  51. // Genre, Rating and Stuido will all be the same
  52. protected override Dictionary<string, Func<User, IEnumerable<BaseItem>>> GetIndexByOptions()
  53. {
  54. return new Dictionary<string, Func<User, IEnumerable<BaseItem>>> {
  55. {LocalizedStrings.Instance.GetString("NoneDispPref"), null},
  56. {LocalizedStrings.Instance.GetString("PerformerDispPref"), GetIndexByPerformer},
  57. {LocalizedStrings.Instance.GetString("DirectorDispPref"), GetIndexByDirector},
  58. {LocalizedStrings.Instance.GetString("YearDispPref"), GetIndexByYear},
  59. };
  60. }
  61. /// <summary>
  62. /// Gets the user data key.
  63. /// </summary>
  64. /// <returns>System.String.</returns>
  65. public override string GetUserDataKey()
  66. {
  67. if (Series != null)
  68. {
  69. var seasonNo = IndexNumber ?? 0;
  70. return Series.GetUserDataKey() + seasonNo.ToString("000");
  71. }
  72. return base.GetUserDataKey();
  73. }
  74. /// <summary>
  75. /// The _series
  76. /// </summary>
  77. private Series _series;
  78. /// <summary>
  79. /// This Episode's Series Instance
  80. /// </summary>
  81. /// <value>The series.</value>
  82. [IgnoreDataMember]
  83. public Series Series
  84. {
  85. get { return _series ?? (_series = FindParent<Series>()); }
  86. }
  87. /// <summary>
  88. /// Our rating comes from our series
  89. /// </summary>
  90. public override string OfficialRating
  91. {
  92. get { return Series != null ? Series.OfficialRating : base.OfficialRating; }
  93. set
  94. {
  95. base.OfficialRating = value;
  96. }
  97. }
  98. /// <summary>
  99. /// Our rating comes from our series
  100. /// </summary>
  101. public override string CustomRating
  102. {
  103. get { return Series != null ? Series.CustomRating : base.CustomRating; }
  104. set
  105. {
  106. base.CustomRating = value;
  107. }
  108. }
  109. /// <summary>
  110. /// Add files from the metadata folder to ResolveArgs
  111. /// </summary>
  112. /// <param name="args">The args.</param>
  113. public static void AddMetadataFiles(ItemResolveArgs args)
  114. {
  115. var folder = args.GetFileSystemEntryByName("metadata");
  116. if (folder != null)
  117. {
  118. args.AddMetadataFiles(new DirectoryInfo(folder.FullName).EnumerateFiles());
  119. }
  120. }
  121. /// <summary>
  122. /// Creates ResolveArgs on demand
  123. /// </summary>
  124. /// <param name="pathInfo">The path info.</param>
  125. /// <returns>ItemResolveArgs.</returns>
  126. protected internal override ItemResolveArgs CreateResolveArgs(FileSystemInfo pathInfo = null)
  127. {
  128. var args = base.CreateResolveArgs(pathInfo);
  129. AddMetadataFiles(args);
  130. return args;
  131. }
  132. /// <summary>
  133. /// Creates the name of the sort.
  134. /// </summary>
  135. /// <returns>System.String.</returns>
  136. protected override string CreateSortName()
  137. {
  138. return IndexNumber != null ? IndexNumber.Value.ToString("0000") : Name;
  139. }
  140. }
  141. }