MusicAlbum.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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 = 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. /// <summary>
  62. /// Override this to true if class should be grouped under a container in indicies
  63. /// The container class should be defined via IndexContainer
  64. /// </summary>
  65. /// <value><c>true</c> if [group in index]; otherwise, <c>false</c>.</value>
  66. [IgnoreDataMember]
  67. public override bool GroupInIndex
  68. {
  69. get
  70. {
  71. return true;
  72. }
  73. }
  74. /// <summary>
  75. /// The unknwon artist
  76. /// </summary>
  77. private static readonly MusicArtist UnknwonArtist = new MusicArtist { Name = "<Unknown>" };
  78. /// <summary>
  79. /// Override this to return the folder that should be used to construct a container
  80. /// for this item in an index. GroupInIndex should be true as well.
  81. /// </summary>
  82. /// <value>The index container.</value>
  83. [IgnoreDataMember]
  84. public override Folder IndexContainer
  85. {
  86. get { return Parent as MusicArtist ?? UnknwonArtist; }
  87. }
  88. /// <summary>
  89. /// Determines whether the specified artist has artist.
  90. /// </summary>
  91. /// <param name="artist">The artist.</param>
  92. /// <returns><c>true</c> if the specified artist has artist; otherwise, <c>false</c>.</returns>
  93. public bool HasArtist(string artist)
  94. {
  95. return string.Equals(AlbumArtist, artist, StringComparison.OrdinalIgnoreCase)
  96. || Artists.Contains(artist, StringComparer.OrdinalIgnoreCase);
  97. }
  98. public string AlbumArtist { get; set; }
  99. public List<string> Artists { get; set; }
  100. /// <summary>
  101. /// Gets the user data key.
  102. /// </summary>
  103. /// <returns>System.String.</returns>
  104. public override string GetUserDataKey()
  105. {
  106. var id = this.GetProviderId(MetadataProviders.MusicBrainzReleaseGroup);
  107. if (!string.IsNullOrEmpty(id))
  108. {
  109. return "MusicAlbum-MusicBrainzReleaseGroup-" + id;
  110. }
  111. id = this.GetProviderId(MetadataProviders.MusicBrainzAlbum);
  112. if (!string.IsNullOrEmpty(id))
  113. {
  114. return "MusicAlbum-Musicbrainz-" + id;
  115. }
  116. return base.GetUserDataKey();
  117. }
  118. protected override bool GetBlockUnratedValue(UserConfiguration config)
  119. {
  120. return config.BlockUnratedItems.Contains(UnratedItem.Music);
  121. }
  122. public AlbumInfo GetLookupInfo()
  123. {
  124. var id = GetItemLookupInfo<AlbumInfo>();
  125. id.AlbumArtist = AlbumArtist;
  126. var artist = Parents.OfType<MusicArtist>().FirstOrDefault();
  127. if (artist != null)
  128. {
  129. id.ArtistProviderIds = artist.ProviderIds;
  130. }
  131. id.SongInfos = RecursiveChildren.OfType<Audio>()
  132. .Select(i => i.GetLookupInfo())
  133. .ToList();
  134. return id;
  135. }
  136. }
  137. public class MusicAlbumDisc : Folder
  138. {
  139. }
  140. }