Audio.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. /// <summary>
  63. /// Gets or sets the album.
  64. /// </summary>
  65. /// <value>The album.</value>
  66. public string Album { get; set; }
  67. /// <summary>
  68. /// Gets or sets the album artist.
  69. /// </summary>
  70. /// <value>The album artist.</value>
  71. public string AlbumArtist { get; set; }
  72. /// <summary>
  73. /// Gets the type of the media.
  74. /// </summary>
  75. /// <value>The type of the media.</value>
  76. public override string MediaType
  77. {
  78. get
  79. {
  80. return Model.Entities.MediaType.Audio;
  81. }
  82. }
  83. /// <summary>
  84. /// Creates the name of the sort.
  85. /// </summary>
  86. /// <returns>System.String.</returns>
  87. protected override string CreateSortName()
  88. {
  89. return (ParentIndexNumber != null ? ParentIndexNumber.Value.ToString("0000 - ") : "")
  90. + (IndexNumber != null ? IndexNumber.Value.ToString("0000 - ") : "") + Name;
  91. }
  92. /// <summary>
  93. /// Determines whether the specified name has artist.
  94. /// </summary>
  95. /// <param name="name">The name.</param>
  96. /// <returns><c>true</c> if the specified name has artist; otherwise, <c>false</c>.</returns>
  97. public bool HasArtist(string name)
  98. {
  99. return Artists.Contains(name, StringComparer.OrdinalIgnoreCase) || string.Equals(AlbumArtist, name, StringComparison.OrdinalIgnoreCase);
  100. }
  101. /// <summary>
  102. /// Gets the user data key.
  103. /// </summary>
  104. /// <returns>System.String.</returns>
  105. public override string GetUserDataKey()
  106. {
  107. var parent = FindParent<MusicAlbum>();
  108. if (parent != null)
  109. {
  110. var parentKey = parent.GetUserDataKey();
  111. if (IndexNumber.HasValue)
  112. {
  113. var songKey = (ParentIndexNumber != null ? ParentIndexNumber.Value.ToString("0000 - ") : "")
  114. + (IndexNumber.Value.ToString("0000 - "));
  115. return parentKey + songKey;
  116. }
  117. }
  118. return base.GetUserDataKey();
  119. }
  120. protected override bool GetBlockUnratedValue(UserConfiguration config)
  121. {
  122. return config.BlockUnratedMusic;
  123. }
  124. public SongInfo GetLookupInfo()
  125. {
  126. var info = GetItemLookupInfo<SongInfo>();
  127. info.AlbumArtist = AlbumArtist;
  128. info.Album = Album;
  129. info.Artists = Artists;
  130. return info;
  131. }
  132. }
  133. }