Audio.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. using MediaBrowser.Model.Entities;
  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. MediaStreams = new List<MediaStream>();
  16. Artists = new List<string>();
  17. }
  18. /// <summary>
  19. /// Gets or sets the language.
  20. /// </summary>
  21. /// <value>The language.</value>
  22. public string Language { get; set; }
  23. /// <summary>
  24. /// Gets or sets the media streams.
  25. /// </summary>
  26. /// <value>The media streams.</value>
  27. public List<MediaStream> MediaStreams { get; set; }
  28. /// <summary>
  29. /// Override this to true if class should be grouped under a container in indicies
  30. /// The container class should be defined via IndexContainer
  31. /// </summary>
  32. /// <value><c>true</c> if [group in index]; otherwise, <c>false</c>.</value>
  33. [IgnoreDataMember]
  34. public override bool GroupInIndex
  35. {
  36. get
  37. {
  38. return true;
  39. }
  40. }
  41. /// <summary>
  42. /// The unknown album
  43. /// </summary>
  44. private static readonly MusicAlbum UnknownAlbum = new MusicAlbum { Name = "<Unknown>" };
  45. /// <summary>
  46. /// Override this to return the folder that should be used to construct a container
  47. /// for this item in an index. GroupInIndex should be true as well.
  48. /// </summary>
  49. /// <value>The index container.</value>
  50. [IgnoreDataMember]
  51. public override Folder IndexContainer
  52. {
  53. get
  54. {
  55. return Parent is MusicAlbum ? Parent : Album != null ? new MusicAlbum { Name = Album, PrimaryImagePath = PrimaryImagePath } : UnknownAlbum;
  56. }
  57. }
  58. /// <summary>
  59. /// Gets or sets the artist.
  60. /// </summary>
  61. /// <value>The artist.</value>
  62. public List<string> Artists { get; set; }
  63. /// <summary>
  64. /// Gets or sets the album.
  65. /// </summary>
  66. /// <value>The album.</value>
  67. public string Album { get; set; }
  68. /// <summary>
  69. /// Gets or sets the album artist.
  70. /// </summary>
  71. /// <value>The album artist.</value>
  72. public string AlbumArtist { get; set; }
  73. /// <summary>
  74. /// Gets the type of the media.
  75. /// </summary>
  76. /// <value>The type of the media.</value>
  77. public override string MediaType
  78. {
  79. get
  80. {
  81. return Model.Entities.MediaType.Audio;
  82. }
  83. }
  84. /// <summary>
  85. /// Creates the name of the sort.
  86. /// </summary>
  87. /// <returns>System.String.</returns>
  88. protected override string CreateSortName()
  89. {
  90. return (ParentIndexNumber != null ? ParentIndexNumber.Value.ToString("0000 - ") : "")
  91. + (IndexNumber != null ? IndexNumber.Value.ToString("0000 - ") : "") + Name;
  92. }
  93. /// <summary>
  94. /// Determines whether the specified name has artist.
  95. /// </summary>
  96. /// <param name="name">The name.</param>
  97. /// <returns><c>true</c> if the specified name has artist; otherwise, <c>false</c>.</returns>
  98. public bool HasArtist(string name)
  99. {
  100. return Artists.Contains(name, StringComparer.OrdinalIgnoreCase) || string.Equals(AlbumArtist, name, StringComparison.OrdinalIgnoreCase);
  101. }
  102. /// <summary>
  103. /// Gets the user data key.
  104. /// </summary>
  105. /// <returns>System.String.</returns>
  106. public override string GetUserDataKey()
  107. {
  108. var parent = Parent as MusicAlbum;
  109. if (parent != null)
  110. {
  111. var parentKey = parent.GetUserDataKey();
  112. if (IndexNumber.HasValue)
  113. {
  114. var songKey = (ParentIndexNumber != null ? ParentIndexNumber.Value.ToString("0000 - ") : "")
  115. + (IndexNumber.Value.ToString("0000 - "));
  116. return parentKey + songKey;
  117. }
  118. }
  119. return base.GetUserDataKey();
  120. }
  121. }
  122. }