MusicAlbum.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using System.Runtime.Serialization;
  4. using MediaBrowser.Model.Entities;
  5. namespace MediaBrowser.Controller.Entities.Audio
  6. {
  7. /// <summary>
  8. /// Class MusicAlbum
  9. /// </summary>
  10. public class MusicAlbum : Folder
  11. {
  12. /// <summary>
  13. /// Songs will group into us so don't also include us in the index
  14. /// </summary>
  15. /// <value><c>true</c> if [include in index]; otherwise, <c>false</c>.</value>
  16. [IgnoreDataMember]
  17. public override bool IncludeInIndex
  18. {
  19. get
  20. {
  21. return false;
  22. }
  23. }
  24. /// <summary>
  25. /// Override this to true if class should be grouped under a container in indicies
  26. /// The container class should be defined via IndexContainer
  27. /// </summary>
  28. /// <value><c>true</c> if [group in index]; otherwise, <c>false</c>.</value>
  29. [IgnoreDataMember]
  30. public override bool GroupInIndex
  31. {
  32. get
  33. {
  34. return true;
  35. }
  36. }
  37. /// <summary>
  38. /// The unknwon artist
  39. /// </summary>
  40. private static readonly MusicArtist UnknwonArtist = new MusicArtist { Name = "<Unknown>" };
  41. /// <summary>
  42. /// Override this to return the folder that should be used to construct a container
  43. /// for this item in an index. GroupInIndex should be true as well.
  44. /// </summary>
  45. /// <value>The index container.</value>
  46. [IgnoreDataMember]
  47. public override Folder IndexContainer
  48. {
  49. get { return Parent as MusicArtist ?? UnknwonArtist; }
  50. }
  51. /// <summary>
  52. /// Override to point to first child (song)
  53. /// </summary>
  54. /// <value>The production year.</value>
  55. public override int? ProductionYear
  56. {
  57. get
  58. {
  59. var child = Children.FirstOrDefault();
  60. return child == null ? base.ProductionYear : child.ProductionYear;
  61. }
  62. set
  63. {
  64. base.ProductionYear = value;
  65. }
  66. }
  67. /// <summary>
  68. /// Override to point to first child (song)
  69. /// </summary>
  70. /// <value>The genres.</value>
  71. public override List<string> Genres
  72. {
  73. get
  74. {
  75. var child = Children.FirstOrDefault();
  76. return child == null ? base.Genres : child.Genres;
  77. }
  78. set
  79. {
  80. base.Genres = value;
  81. }
  82. }
  83. /// <summary>
  84. /// Override to point to first child (song)
  85. /// </summary>
  86. /// <value>The studios.</value>
  87. public override List<string> Studios
  88. {
  89. get
  90. {
  91. var child = Children.FirstOrDefault();
  92. return child == null ? base.Studios : child.Studios;
  93. }
  94. set
  95. {
  96. base.Studios = value;
  97. }
  98. }
  99. /// <summary>
  100. /// Gets or sets the images.
  101. /// </summary>
  102. /// <value>The images.</value>
  103. public override Dictionary<ImageType, string> Images
  104. {
  105. get
  106. {
  107. var images = base.Images;
  108. string primaryImagePath;
  109. if (!images.TryGetValue(ImageType.Primary, out primaryImagePath))
  110. {
  111. var image = Children.Select(c => c.PrimaryImagePath).FirstOrDefault(c => !string.IsNullOrEmpty(c));
  112. if (!string.IsNullOrEmpty(image))
  113. {
  114. images[ImageType.Primary] = image;
  115. }
  116. }
  117. return images;
  118. }
  119. set
  120. {
  121. base.Images = value;
  122. }
  123. }
  124. /// <summary>
  125. /// Determines whether the specified artist has artist.
  126. /// </summary>
  127. /// <param name="artist">The artist.</param>
  128. /// <returns><c>true</c> if the specified artist has artist; otherwise, <c>false</c>.</returns>
  129. public bool HasArtist(string artist)
  130. {
  131. return RecursiveChildren.OfType<Audio>().Any(i => i.HasArtist(artist));
  132. }
  133. /// <summary>
  134. /// Gets or sets the name.
  135. /// </summary>
  136. /// <value>The name.</value>
  137. public override string Name
  138. {
  139. get
  140. {
  141. var song = RecursiveChildren.OfType<Audio>().FirstOrDefault(i => !string.IsNullOrEmpty(i.Album));
  142. return song == null ? base.Name : song.Album;
  143. }
  144. set
  145. {
  146. base.Name = value;
  147. }
  148. }
  149. /// <summary>
  150. /// Gets or sets the music brainz release group id.
  151. /// </summary>
  152. /// <value>The music brainz release group id.</value>
  153. public string MusicBrainzReleaseGroupId { get; set; }
  154. }
  155. }