MusicAlbum.cs 4.9 KB

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