Audio.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. /// Override this to return the folder that should be used to construct a container
  37. /// for this item in an index. GroupInIndex should be true as well.
  38. /// </summary>
  39. /// <value>The index container.</value>
  40. [IgnoreDataMember]
  41. public override Folder IndexContainer
  42. {
  43. get
  44. {
  45. return Parents.OfType<MusicAlbum>().FirstOrDefault() ?? new MusicAlbum { Name = "<Unknown>" };
  46. }
  47. }
  48. /// <summary>
  49. /// Gets or sets the artist.
  50. /// </summary>
  51. /// <value>The artist.</value>
  52. public List<string> Artists { get; set; }
  53. /// <summary>
  54. /// Gets or sets the album.
  55. /// </summary>
  56. /// <value>The album.</value>
  57. public string Album { get; set; }
  58. /// <summary>
  59. /// Gets or sets the album artist.
  60. /// </summary>
  61. /// <value>The album artist.</value>
  62. public string AlbumArtist { get; set; }
  63. /// <summary>
  64. /// Gets the type of the media.
  65. /// </summary>
  66. /// <value>The type of the media.</value>
  67. public override string MediaType
  68. {
  69. get
  70. {
  71. return Model.Entities.MediaType.Audio;
  72. }
  73. }
  74. /// <summary>
  75. /// Creates the name of the sort.
  76. /// </summary>
  77. /// <returns>System.String.</returns>
  78. protected override string CreateSortName()
  79. {
  80. return (ParentIndexNumber != null ? ParentIndexNumber.Value.ToString("0000 - ") : "")
  81. + (IndexNumber != null ? IndexNumber.Value.ToString("0000 - ") : "") + Name;
  82. }
  83. /// <summary>
  84. /// Determines whether the specified name has artist.
  85. /// </summary>
  86. /// <param name="name">The name.</param>
  87. /// <returns><c>true</c> if the specified name has artist; otherwise, <c>false</c>.</returns>
  88. public bool HasArtist(string name)
  89. {
  90. return Artists.Contains(name, StringComparer.OrdinalIgnoreCase) || string.Equals(AlbumArtist, name, StringComparison.OrdinalIgnoreCase);
  91. }
  92. /// <summary>
  93. /// Gets the user data key.
  94. /// </summary>
  95. /// <returns>System.String.</returns>
  96. public override string GetUserDataKey()
  97. {
  98. var parent = FindParent<MusicAlbum>();
  99. if (parent != null)
  100. {
  101. var parentKey = parent.GetUserDataKey();
  102. if (IndexNumber.HasValue)
  103. {
  104. var songKey = (ParentIndexNumber != null ? ParentIndexNumber.Value.ToString("0000 - ") : "")
  105. + (IndexNumber.Value.ToString("0000 - "));
  106. return parentKey + songKey;
  107. }
  108. }
  109. return base.GetUserDataKey();
  110. }
  111. protected override bool GetBlockUnratedValue(UserConfiguration config)
  112. {
  113. return config.BlockUnratedMusic;
  114. }
  115. }
  116. }