Audio.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. using MediaBrowser.Model.Configuration;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Runtime.Serialization;
  6. namespace MediaBrowser.Controller.Entities.Audio
  7. {
  8. /// <summary>
  9. /// Class Audio
  10. /// </summary>
  11. public class Audio : BaseItem, IHasMediaStreams, IHasAlbumArtist, IHasArtist, IHasMusicGenres
  12. {
  13. public Audio()
  14. {
  15. Artists = new List<string>();
  16. }
  17. /// <summary>
  18. /// Gets or sets a value indicating whether this instance has embedded image.
  19. /// </summary>
  20. /// <value><c>true</c> if this instance has embedded image; otherwise, <c>false</c>.</value>
  21. public bool HasEmbeddedImage { get; set; }
  22. /// <summary>
  23. /// Override this to true if class should be grouped under a container in indicies
  24. /// The container class should be defined via IndexContainer
  25. /// </summary>
  26. /// <value><c>true</c> if [group in index]; otherwise, <c>false</c>.</value>
  27. [IgnoreDataMember]
  28. public override bool GroupInIndex
  29. {
  30. get
  31. {
  32. return true;
  33. }
  34. }
  35. /// <summary>
  36. /// The unknown album
  37. /// </summary>
  38. private static readonly MusicAlbum UnknownAlbum = new MusicAlbum { Name = "<Unknown>" };
  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 Parent is MusicAlbum ? Parent : Album != null ? new MusicAlbum { Name = Album, PrimaryImagePath = PrimaryImagePath } : UnknownAlbum;
  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. /// <summary>
  58. /// Gets or sets the album.
  59. /// </summary>
  60. /// <value>The album.</value>
  61. public string Album { get; set; }
  62. /// <summary>
  63. /// Gets or sets the album artist.
  64. /// </summary>
  65. /// <value>The album artist.</value>
  66. public string AlbumArtist { get; set; }
  67. /// <summary>
  68. /// Gets the type of the media.
  69. /// </summary>
  70. /// <value>The type of the media.</value>
  71. public override string MediaType
  72. {
  73. get
  74. {
  75. return Model.Entities.MediaType.Audio;
  76. }
  77. }
  78. /// <summary>
  79. /// Creates the name of the sort.
  80. /// </summary>
  81. /// <returns>System.String.</returns>
  82. protected override string CreateSortName()
  83. {
  84. return (ParentIndexNumber != null ? ParentIndexNumber.Value.ToString("0000 - ") : "")
  85. + (IndexNumber != null ? IndexNumber.Value.ToString("0000 - ") : "") + Name;
  86. }
  87. /// <summary>
  88. /// Determines whether the specified name has artist.
  89. /// </summary>
  90. /// <param name="name">The name.</param>
  91. /// <returns><c>true</c> if the specified name has artist; otherwise, <c>false</c>.</returns>
  92. public bool HasArtist(string name)
  93. {
  94. return Artists.Contains(name, StringComparer.OrdinalIgnoreCase) || string.Equals(AlbumArtist, name, StringComparison.OrdinalIgnoreCase);
  95. }
  96. /// <summary>
  97. /// Gets the user data key.
  98. /// </summary>
  99. /// <returns>System.String.</returns>
  100. public override string GetUserDataKey()
  101. {
  102. var parent = Parent as MusicAlbum;
  103. if (parent != null)
  104. {
  105. var parentKey = parent.GetUserDataKey();
  106. if (IndexNumber.HasValue)
  107. {
  108. var songKey = (ParentIndexNumber != null ? ParentIndexNumber.Value.ToString("0000 - ") : "")
  109. + (IndexNumber.Value.ToString("0000 - "));
  110. return parentKey + songKey;
  111. }
  112. }
  113. return base.GetUserDataKey();
  114. }
  115. protected override bool GetBlockUnratedValue(UserConfiguration config)
  116. {
  117. return config.BlockUnratedMusic;
  118. }
  119. }
  120. }