Audio.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Runtime.Serialization;
  5. namespace MediaBrowser.Controller.Entities.Audio
  6. {
  7. /// <summary>
  8. /// Class Audio
  9. /// </summary>
  10. public class Audio : BaseItem, IHasMediaStreams, IHasAlbumArtist, IHasArtist, IHasMusicGenres, IHasLanguage
  11. {
  12. public Audio()
  13. {
  14. Artists = new List<string>();
  15. }
  16. /// <summary>
  17. /// Gets or sets the language.
  18. /// </summary>
  19. /// <value>The language.</value>
  20. public string Language { get; set; }
  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. /// The unknown album
  41. /// </summary>
  42. private static readonly MusicAlbum UnknownAlbum = new MusicAlbum { Name = "<Unknown>" };
  43. /// <summary>
  44. /// Override this to return the folder that should be used to construct a container
  45. /// for this item in an index. GroupInIndex should be true as well.
  46. /// </summary>
  47. /// <value>The index container.</value>
  48. [IgnoreDataMember]
  49. public override Folder IndexContainer
  50. {
  51. get
  52. {
  53. return Parent is MusicAlbum ? Parent : Album != null ? new MusicAlbum { Name = Album, PrimaryImagePath = PrimaryImagePath } : UnknownAlbum;
  54. }
  55. }
  56. /// <summary>
  57. /// Gets or sets the artist.
  58. /// </summary>
  59. /// <value>The artist.</value>
  60. public List<string> Artists { get; set; }
  61. /// <summary>
  62. /// Gets or sets the album.
  63. /// </summary>
  64. /// <value>The album.</value>
  65. public string Album { get; set; }
  66. /// <summary>
  67. /// Gets or sets the album artist.
  68. /// </summary>
  69. /// <value>The album artist.</value>
  70. public string AlbumArtist { get; set; }
  71. /// <summary>
  72. /// Gets the type of the media.
  73. /// </summary>
  74. /// <value>The type of the media.</value>
  75. public override string MediaType
  76. {
  77. get
  78. {
  79. return Model.Entities.MediaType.Audio;
  80. }
  81. }
  82. /// <summary>
  83. /// Creates the name of the sort.
  84. /// </summary>
  85. /// <returns>System.String.</returns>
  86. protected override string CreateSortName()
  87. {
  88. return (ParentIndexNumber != null ? ParentIndexNumber.Value.ToString("0000 - ") : "")
  89. + (IndexNumber != null ? IndexNumber.Value.ToString("0000 - ") : "") + Name;
  90. }
  91. /// <summary>
  92. /// Determines whether the specified name has artist.
  93. /// </summary>
  94. /// <param name="name">The name.</param>
  95. /// <returns><c>true</c> if the specified name has artist; otherwise, <c>false</c>.</returns>
  96. public bool HasArtist(string name)
  97. {
  98. return Artists.Contains(name, StringComparer.OrdinalIgnoreCase) || string.Equals(AlbumArtist, name, StringComparison.OrdinalIgnoreCase);
  99. }
  100. /// <summary>
  101. /// Gets the user data key.
  102. /// </summary>
  103. /// <returns>System.String.</returns>
  104. public override string GetUserDataKey()
  105. {
  106. var parent = Parent as MusicAlbum;
  107. if (parent != null)
  108. {
  109. var parentKey = parent.GetUserDataKey();
  110. if (IndexNumber.HasValue)
  111. {
  112. var songKey = (ParentIndexNumber != null ? ParentIndexNumber.Value.ToString("0000 - ") : "")
  113. + (IndexNumber.Value.ToString("0000 - "));
  114. return parentKey + songKey;
  115. }
  116. }
  117. return base.GetUserDataKey();
  118. }
  119. }
  120. }