MusicAlbum.cs 5.0 KB

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