MusicAlbum.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. using MediaBrowser.Controller.Providers;
  2. using MediaBrowser.Model.Configuration;
  3. using MediaBrowser.Model.Entities;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Runtime.Serialization;
  8. namespace MediaBrowser.Controller.Entities.Audio
  9. {
  10. /// <summary>
  11. /// Class MusicAlbum
  12. /// </summary>
  13. public class MusicAlbum : Folder, IHasAlbumArtist, IHasArtist, IHasMusicGenres, IHasTags, IHasLookupInfo<AlbumInfo>
  14. {
  15. public List<Guid> SoundtrackIds { get; set; }
  16. public MusicAlbum()
  17. {
  18. Artists = new List<string>();
  19. SoundtrackIds = new List<Guid>();
  20. Tags = new List<string>();
  21. }
  22. [IgnoreDataMember]
  23. public MusicArtist MusicArtist
  24. {
  25. get
  26. {
  27. return Parents.OfType<MusicArtist>().FirstOrDefault();
  28. }
  29. }
  30. [IgnoreDataMember]
  31. public List<string> AllArtists
  32. {
  33. get
  34. {
  35. var list = AlbumArtists;
  36. list.AddRange(Artists);
  37. return list;
  38. }
  39. }
  40. [IgnoreDataMember]
  41. public List<string> AlbumArtists
  42. {
  43. get
  44. {
  45. var list = new List<string>();
  46. if (!string.IsNullOrEmpty(AlbumArtist))
  47. {
  48. list.Add(AlbumArtist);
  49. }
  50. return list;
  51. }
  52. set
  53. {
  54. AlbumArtist = value.FirstOrDefault();
  55. }
  56. }
  57. /// <summary>
  58. /// Gets or sets the tags.
  59. /// </summary>
  60. /// <value>The tags.</value>
  61. public List<string> Tags { get; set; }
  62. /// <summary>
  63. /// Gets the tracks.
  64. /// </summary>
  65. /// <value>The tracks.</value>
  66. public IEnumerable<Audio> Tracks
  67. {
  68. get
  69. {
  70. return RecursiveChildren.OfType<Audio>();
  71. }
  72. }
  73. protected override IEnumerable<BaseItem> GetEligibleChildrenForRecursiveChildren(User user)
  74. {
  75. return Tracks;
  76. }
  77. /// <summary>
  78. /// Songs will group into us so don't also include us in the index
  79. /// </summary>
  80. /// <value><c>true</c> if [include in index]; otherwise, <c>false</c>.</value>
  81. [IgnoreDataMember]
  82. public override bool IncludeInIndex
  83. {
  84. get
  85. {
  86. return false;
  87. }
  88. }
  89. /// <summary>
  90. /// Override this to true if class should be grouped under a container in indicies
  91. /// The container class should be defined via IndexContainer
  92. /// </summary>
  93. /// <value><c>true</c> if [group in index]; otherwise, <c>false</c>.</value>
  94. [IgnoreDataMember]
  95. public override bool GroupInIndex
  96. {
  97. get
  98. {
  99. return true;
  100. }
  101. }
  102. /// <summary>
  103. /// The unknwon artist
  104. /// </summary>
  105. private static readonly MusicArtist UnknwonArtist = new MusicArtist { Name = "<Unknown>" };
  106. /// <summary>
  107. /// Override this to return the folder that should be used to construct a container
  108. /// for this item in an index. GroupInIndex should be true as well.
  109. /// </summary>
  110. /// <value>The index container.</value>
  111. [IgnoreDataMember]
  112. public override Folder IndexContainer
  113. {
  114. get { return Parent as MusicArtist ?? UnknwonArtist; }
  115. }
  116. /// <summary>
  117. /// Determines whether the specified artist has artist.
  118. /// </summary>
  119. /// <param name="artist">The artist.</param>
  120. /// <returns><c>true</c> if the specified artist has artist; otherwise, <c>false</c>.</returns>
  121. public bool HasArtist(string artist)
  122. {
  123. return AllArtists.Contains(artist, StringComparer.OrdinalIgnoreCase);
  124. }
  125. public string AlbumArtist { get; set; }
  126. public List<string> Artists { get; set; }
  127. /// <summary>
  128. /// Gets the user data key.
  129. /// </summary>
  130. /// <returns>System.String.</returns>
  131. public override string GetUserDataKey()
  132. {
  133. var id = this.GetProviderId(MetadataProviders.MusicBrainzReleaseGroup);
  134. if (!string.IsNullOrEmpty(id))
  135. {
  136. return "MusicAlbum-MusicBrainzReleaseGroup-" + id;
  137. }
  138. id = this.GetProviderId(MetadataProviders.MusicBrainzAlbum);
  139. if (!string.IsNullOrEmpty(id))
  140. {
  141. return "MusicAlbum-Musicbrainz-" + id;
  142. }
  143. return base.GetUserDataKey();
  144. }
  145. protected override bool GetBlockUnratedValue(UserConfiguration config)
  146. {
  147. return config.BlockUnratedItems.Contains(UnratedItem.Music);
  148. }
  149. public AlbumInfo GetLookupInfo()
  150. {
  151. var id = GetItemLookupInfo<AlbumInfo>();
  152. id.AlbumArtists = AlbumArtists;
  153. var artist = Parents.OfType<MusicArtist>().FirstOrDefault();
  154. if (artist != null)
  155. {
  156. id.ArtistProviderIds = artist.ProviderIds;
  157. }
  158. id.SongInfos = RecursiveChildren.OfType<Audio>()
  159. .Select(i => i.GetLookupInfo())
  160. .ToList();
  161. return id;
  162. }
  163. }
  164. [Obsolete]
  165. public class MusicAlbumDisc : Folder
  166. {
  167. }
  168. }