Audio.cs 5.0 KB

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