Audio.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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>, IHasSeries
  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. [IgnoreDataMember]
  50. public string SeriesName
  51. {
  52. get
  53. {
  54. return Album;
  55. }
  56. }
  57. /// <summary>
  58. /// Gets or sets the artist.
  59. /// </summary>
  60. /// <value>The artist.</value>
  61. public List<string> Artists { get; set; }
  62. [IgnoreDataMember]
  63. public List<string> AllArtists
  64. {
  65. get
  66. {
  67. var list = new List<string>();
  68. if (!string.IsNullOrEmpty(AlbumArtist))
  69. {
  70. list.Add(AlbumArtist);
  71. }
  72. list.AddRange(Artists);
  73. return list;
  74. }
  75. }
  76. /// <summary>
  77. /// Gets or sets the album.
  78. /// </summary>
  79. /// <value>The album.</value>
  80. public string Album { get; set; }
  81. /// <summary>
  82. /// Gets or sets the album artist.
  83. /// </summary>
  84. /// <value>The album artist.</value>
  85. public string AlbumArtist { get; set; }
  86. /// <summary>
  87. /// Gets the type of the media.
  88. /// </summary>
  89. /// <value>The type of the media.</value>
  90. public override string MediaType
  91. {
  92. get
  93. {
  94. return Model.Entities.MediaType.Audio;
  95. }
  96. }
  97. /// <summary>
  98. /// Creates the name of the sort.
  99. /// </summary>
  100. /// <returns>System.String.</returns>
  101. protected override string CreateSortName()
  102. {
  103. return (ParentIndexNumber != null ? ParentIndexNumber.Value.ToString("0000 - ") : "")
  104. + (IndexNumber != null ? IndexNumber.Value.ToString("0000 - ") : "") + Name;
  105. }
  106. /// <summary>
  107. /// Determines whether the specified name has artist.
  108. /// </summary>
  109. /// <param name="name">The name.</param>
  110. /// <returns><c>true</c> if the specified name has artist; otherwise, <c>false</c>.</returns>
  111. public bool HasArtist(string name)
  112. {
  113. return Artists.Contains(name, StringComparer.OrdinalIgnoreCase) || string.Equals(AlbumArtist, name, StringComparison.OrdinalIgnoreCase);
  114. }
  115. /// <summary>
  116. /// Gets the user data key.
  117. /// </summary>
  118. /// <returns>System.String.</returns>
  119. public override string GetUserDataKey()
  120. {
  121. var parent = FindParent<MusicAlbum>();
  122. if (parent != null)
  123. {
  124. var parentKey = parent.GetUserDataKey();
  125. if (IndexNumber.HasValue)
  126. {
  127. var songKey = (ParentIndexNumber != null ? ParentIndexNumber.Value.ToString("0000 - ") : "")
  128. + (IndexNumber.Value.ToString("0000 - "));
  129. return parentKey + songKey;
  130. }
  131. }
  132. return base.GetUserDataKey();
  133. }
  134. protected override bool GetBlockUnratedValue(UserConfiguration config)
  135. {
  136. return config.BlockUnratedItems.Contains(UnratedItem.Music);
  137. }
  138. public SongInfo GetLookupInfo()
  139. {
  140. var info = GetItemLookupInfo<SongInfo>();
  141. info.AlbumArtist = AlbumArtist;
  142. info.Album = Album;
  143. info.Artists = Artists;
  144. return info;
  145. }
  146. }
  147. }