Audio.cs 5.0 KB

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