Audio.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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, IHasLanguage
  12. {
  13. public Audio()
  14. {
  15. Artists = new List<string>();
  16. }
  17. /// <summary>
  18. /// Gets or sets the language.
  19. /// </summary>
  20. /// <value>The language.</value>
  21. public string Language { get; set; }
  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. /// The unknown album
  42. /// </summary>
  43. private static readonly MusicAlbum UnknownAlbum = new MusicAlbum { Name = "<Unknown>" };
  44. /// <summary>
  45. /// Override this to return the folder that should be used to construct a container
  46. /// for this item in an index. GroupInIndex should be true as well.
  47. /// </summary>
  48. /// <value>The index container.</value>
  49. [IgnoreDataMember]
  50. public override Folder IndexContainer
  51. {
  52. get
  53. {
  54. return Parent is MusicAlbum ? Parent : Album != null ? new MusicAlbum { Name = Album, PrimaryImagePath = PrimaryImagePath } : UnknownAlbum;
  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 = Parent as 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. }
  125. }