Audio.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. using MediaBrowser.Controller.Providers;
  2. using MediaBrowser.Model.Configuration;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Runtime.Serialization;
  7. namespace MediaBrowser.Controller.Entities.Audio
  8. {
  9. /// <summary>
  10. /// Class Audio
  11. /// </summary>
  12. public class Audio : BaseItem, IHasMediaStreams, IHasAlbumArtist, IHasArtist, IHasMusicGenres, IHasLookupInfo<SongInfo>
  13. {
  14. public Audio()
  15. {
  16. Artists = new List<string>();
  17. }
  18. /// <summary>
  19. /// Gets or sets a value indicating whether this instance has embedded image.
  20. /// </summary>
  21. /// <value><c>true</c> if this instance has embedded image; otherwise, <c>false</c>.</value>
  22. public bool HasEmbeddedImage { get; set; }
  23. /// <summary>
  24. /// Override this to true if class should be grouped under a container in indicies
  25. /// The container class should be defined via IndexContainer
  26. /// </summary>
  27. /// <value><c>true</c> if [group in index]; otherwise, <c>false</c>.</value>
  28. [IgnoreDataMember]
  29. public override bool GroupInIndex
  30. {
  31. get
  32. {
  33. return true;
  34. }
  35. }
  36. /// <summary>
  37. /// Override this to return the folder that should be used to construct a container
  38. /// for this item in an index. GroupInIndex should be true as well.
  39. /// </summary>
  40. /// <value>The index container.</value>
  41. [IgnoreDataMember]
  42. public override Folder IndexContainer
  43. {
  44. get
  45. {
  46. return Parents.OfType<MusicAlbum>().FirstOrDefault() ?? new MusicAlbum { Name = "<Unknown>" };
  47. }
  48. }
  49. /// <summary>
  50. /// Gets or sets the artist.
  51. /// </summary>
  52. /// <value>The artist.</value>
  53. public List<string> Artists { get; set; }
  54. [IgnoreDataMember]
  55. public List<string> AllArtists
  56. {
  57. get
  58. {
  59. var list = new List<string>();
  60. if (!string.IsNullOrEmpty(AlbumArtist))
  61. {
  62. list.Add(AlbumArtist);
  63. }
  64. list.AddRange(Artists);
  65. return list;
  66. }
  67. }
  68. /// <summary>
  69. /// Gets or sets the album.
  70. /// </summary>
  71. /// <value>The album.</value>
  72. public string Album { get; set; }
  73. /// <summary>
  74. /// Gets or sets the album artist.
  75. /// </summary>
  76. /// <value>The album artist.</value>
  77. public string AlbumArtist { get; set; }
  78. /// <summary>
  79. /// Gets the type of the media.
  80. /// </summary>
  81. /// <value>The type of the media.</value>
  82. public override string MediaType
  83. {
  84. get
  85. {
  86. return Model.Entities.MediaType.Audio;
  87. }
  88. }
  89. /// <summary>
  90. /// Creates the name of the sort.
  91. /// </summary>
  92. /// <returns>System.String.</returns>
  93. protected override string CreateSortName()
  94. {
  95. return (ParentIndexNumber != null ? ParentIndexNumber.Value.ToString("0000 - ") : "")
  96. + (IndexNumber != null ? IndexNumber.Value.ToString("0000 - ") : "") + Name;
  97. }
  98. /// <summary>
  99. /// Determines whether the specified name has artist.
  100. /// </summary>
  101. /// <param name="name">The name.</param>
  102. /// <returns><c>true</c> if the specified name has artist; otherwise, <c>false</c>.</returns>
  103. public bool HasArtist(string name)
  104. {
  105. return Artists.Contains(name, StringComparer.OrdinalIgnoreCase) || string.Equals(AlbumArtist, name, StringComparison.OrdinalIgnoreCase);
  106. }
  107. /// <summary>
  108. /// Gets the user data key.
  109. /// </summary>
  110. /// <returns>System.String.</returns>
  111. public override string GetUserDataKey()
  112. {
  113. var parent = FindParent<MusicAlbum>();
  114. if (parent != null)
  115. {
  116. var parentKey = parent.GetUserDataKey();
  117. if (IndexNumber.HasValue)
  118. {
  119. var songKey = (ParentIndexNumber != null ? ParentIndexNumber.Value.ToString("0000 - ") : "")
  120. + (IndexNumber.Value.ToString("0000 - "));
  121. return parentKey + songKey;
  122. }
  123. }
  124. return base.GetUserDataKey();
  125. }
  126. protected override bool GetBlockUnratedValue(UserConfiguration config)
  127. {
  128. return config.BlockUnratedItems.Contains(UnratedItem.Music);
  129. }
  130. public SongInfo GetLookupInfo()
  131. {
  132. var info = GetItemLookupInfo<SongInfo>();
  133. info.AlbumArtist = AlbumArtist;
  134. info.Album = Album;
  135. info.Artists = Artists;
  136. return info;
  137. }
  138. }
  139. }