2
0

MusicAlbum.cs 4.6 KB

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