MusicAlbum.cs 5.1 KB

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