Audio.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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>, IHasTags
  13. {
  14. public string FormatName { get; set; }
  15. public long? Size { get; set; }
  16. public string Container { get; set; }
  17. public int? TotalBitrate { get; set; }
  18. public List<string> Tags { get; set; }
  19. public Audio()
  20. {
  21. Artists = new List<string>();
  22. Tags = new List<string>();
  23. }
  24. /// <summary>
  25. /// Gets or sets a value indicating whether this instance has embedded image.
  26. /// </summary>
  27. /// <value><c>true</c> if this instance has embedded image; otherwise, <c>false</c>.</value>
  28. public bool HasEmbeddedImage { get; set; }
  29. /// <summary>
  30. /// Override this to true if class should be grouped under a container in indicies
  31. /// The container class should be defined via IndexContainer
  32. /// </summary>
  33. /// <value><c>true</c> if [group in index]; otherwise, <c>false</c>.</value>
  34. [IgnoreDataMember]
  35. public override bool GroupInIndex
  36. {
  37. get
  38. {
  39. return true;
  40. }
  41. }
  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
  51. {
  52. return Parents.OfType<MusicAlbum>().FirstOrDefault() ?? new MusicAlbum { Name = "<Unknown>" };
  53. }
  54. }
  55. /// <summary>
  56. /// Gets or sets the artist.
  57. /// </summary>
  58. /// <value>The artist.</value>
  59. public List<string> Artists { get; set; }
  60. [IgnoreDataMember]
  61. public List<string> AllArtists
  62. {
  63. get
  64. {
  65. var list = new List<string>();
  66. if (!string.IsNullOrEmpty(AlbumArtist))
  67. {
  68. list.Add(AlbumArtist);
  69. }
  70. list.AddRange(Artists);
  71. return list;
  72. }
  73. }
  74. /// <summary>
  75. /// Gets or sets the album.
  76. /// </summary>
  77. /// <value>The album.</value>
  78. public string Album { get; set; }
  79. /// <summary>
  80. /// Gets or sets the album artist.
  81. /// </summary>
  82. /// <value>The album artist.</value>
  83. public string AlbumArtist { get; set; }
  84. /// <summary>
  85. /// Gets the type of the media.
  86. /// </summary>
  87. /// <value>The type of the media.</value>
  88. public override string MediaType
  89. {
  90. get
  91. {
  92. return Model.Entities.MediaType.Audio;
  93. }
  94. }
  95. /// <summary>
  96. /// Creates the name of the sort.
  97. /// </summary>
  98. /// <returns>System.String.</returns>
  99. protected override string CreateSortName()
  100. {
  101. return (ParentIndexNumber != null ? ParentIndexNumber.Value.ToString("0000 - ") : "")
  102. + (IndexNumber != null ? IndexNumber.Value.ToString("0000 - ") : "") + Name;
  103. }
  104. /// <summary>
  105. /// Determines whether the specified name has artist.
  106. /// </summary>
  107. /// <param name="name">The name.</param>
  108. /// <returns><c>true</c> if the specified name has artist; otherwise, <c>false</c>.</returns>
  109. public bool HasArtist(string name)
  110. {
  111. return Artists.Contains(name, StringComparer.OrdinalIgnoreCase) || string.Equals(AlbumArtist, name, StringComparison.OrdinalIgnoreCase);
  112. }
  113. /// <summary>
  114. /// Gets the user data key.
  115. /// </summary>
  116. /// <returns>System.String.</returns>
  117. public override string GetUserDataKey()
  118. {
  119. var parent = FindParent<MusicAlbum>();
  120. if (parent != null)
  121. {
  122. var parentKey = parent.GetUserDataKey();
  123. if (IndexNumber.HasValue)
  124. {
  125. var songKey = (ParentIndexNumber != null ? ParentIndexNumber.Value.ToString("0000 - ") : "")
  126. + (IndexNumber.Value.ToString("0000 - "));
  127. return parentKey + songKey;
  128. }
  129. }
  130. return base.GetUserDataKey();
  131. }
  132. protected override bool GetBlockUnratedValue(UserConfiguration config)
  133. {
  134. return config.BlockUnratedItems.Contains(UnratedItem.Music);
  135. }
  136. public SongInfo GetLookupInfo()
  137. {
  138. var info = GetItemLookupInfo<SongInfo>();
  139. info.AlbumArtist = AlbumArtist;
  140. info.Album = Album;
  141. info.Artists = Artists;
  142. return info;
  143. }
  144. }
  145. }