MusicAlbum.cs 2.9 KB

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