MusicAlbum.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. using MediaBrowser.Model.Entities;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Runtime.Serialization;
  6. namespace MediaBrowser.Controller.Entities.Audio
  7. {
  8. /// <summary>
  9. /// Class MusicAlbum
  10. /// </summary>
  11. public class MusicAlbum : Folder
  12. {
  13. /// <summary>
  14. /// Songs will group into us so don't also include us in the index
  15. /// </summary>
  16. /// <value><c>true</c> if [include in index]; otherwise, <c>false</c>.</value>
  17. [IgnoreDataMember]
  18. public override bool IncludeInIndex
  19. {
  20. get
  21. {
  22. return false;
  23. }
  24. }
  25. /// <summary>
  26. /// Override this to true if class should be grouped under a container in indicies
  27. /// The container class should be defined via IndexContainer
  28. /// </summary>
  29. /// <value><c>true</c> if [group in index]; otherwise, <c>false</c>.</value>
  30. [IgnoreDataMember]
  31. public override bool GroupInIndex
  32. {
  33. get
  34. {
  35. return true;
  36. }
  37. }
  38. /// <summary>
  39. /// The unknwon artist
  40. /// </summary>
  41. private static readonly MusicArtist UnknwonArtist = new MusicArtist { Name = "<Unknown>" };
  42. /// <summary>
  43. /// Override this to return the folder that should be used to construct a container
  44. /// for this item in an index. GroupInIndex should be true as well.
  45. /// </summary>
  46. /// <value>The index container.</value>
  47. [IgnoreDataMember]
  48. public override Folder IndexContainer
  49. {
  50. get { return Parent as MusicArtist ?? UnknwonArtist; }
  51. }
  52. /// <summary>
  53. /// Override to point to first child (song)
  54. /// </summary>
  55. /// <value>The genres.</value>
  56. public override List<string> Genres
  57. {
  58. get
  59. {
  60. return Children
  61. .OfType<Audio>()
  62. .SelectMany(i => i.Genres)
  63. .Distinct(StringComparer.OrdinalIgnoreCase)
  64. .ToList();
  65. }
  66. set
  67. {
  68. base.Genres = value;
  69. }
  70. }
  71. /// <summary>
  72. /// Gets or sets the images.
  73. /// </summary>
  74. /// <value>The images.</value>
  75. public override Dictionary<ImageType, string> Images
  76. {
  77. get
  78. {
  79. var images = base.Images;
  80. string primaryImagePath;
  81. if (!images.TryGetValue(ImageType.Primary, out primaryImagePath))
  82. {
  83. var image = Children.Select(c => c.PrimaryImagePath).FirstOrDefault(c => !string.IsNullOrEmpty(c));
  84. if (!string.IsNullOrEmpty(image))
  85. {
  86. images[ImageType.Primary] = image;
  87. }
  88. }
  89. return images;
  90. }
  91. set
  92. {
  93. base.Images = value;
  94. }
  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 RecursiveChildren.OfType<Audio>().Any(i => i.HasArtist(artist));
  104. }
  105. /// <summary>
  106. /// Gets or sets the music brainz release group id.
  107. /// </summary>
  108. /// <value>The music brainz release group id.</value>
  109. public string MusicBrainzReleaseGroupId { get; set; }
  110. }
  111. }