2
0

Audio.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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
  12. {
  13. /// <summary>
  14. /// Gets or sets the media streams.
  15. /// </summary>
  16. /// <value>The media streams.</value>
  17. public List<MediaStream> MediaStreams { get; set; }
  18. /// <summary>
  19. /// Override this to true if class should be grouped under a container in indicies
  20. /// The container class should be defined via IndexContainer
  21. /// </summary>
  22. /// <value><c>true</c> if [group in index]; otherwise, <c>false</c>.</value>
  23. [IgnoreDataMember]
  24. public override bool GroupInIndex
  25. {
  26. get
  27. {
  28. return true;
  29. }
  30. }
  31. /// <summary>
  32. /// The unknown album
  33. /// </summary>
  34. private static readonly MusicAlbum UnknownAlbum = new MusicAlbum {Name = "<Unknown>"};
  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 Parent is MusicAlbum ? Parent : Album != null ? new MusicAlbum {Name = Album, PrimaryImagePath = PrimaryImagePath } : UnknownAlbum;
  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. /// Initializes a new instance of the <see cref="Audio"/> class.
  76. /// </summary>
  77. public Audio()
  78. {
  79. Artists = new List<string>();
  80. }
  81. /// <summary>
  82. /// Adds the artist.
  83. /// </summary>
  84. /// <param name="name">The name.</param>
  85. /// <exception cref="System.ArgumentNullException">name</exception>
  86. public void AddArtist(string name)
  87. {
  88. if (string.IsNullOrWhiteSpace(name))
  89. {
  90. throw new ArgumentNullException("name");
  91. }
  92. if (!Artists.Contains(name, StringComparer.OrdinalIgnoreCase))
  93. {
  94. Artists.Add(name);
  95. }
  96. }
  97. /// <summary>
  98. /// Creates the name of the sort.
  99. /// </summary>
  100. /// <returns>System.String.</returns>
  101. protected override string CreateSortName()
  102. {
  103. return (ProductionYear != null ? ProductionYear.Value.ToString("000-") : "")
  104. + (IndexNumber != null ? IndexNumber.Value.ToString("0000 - ") : "") + Name;
  105. }
  106. /// <summary>
  107. /// Determines whether the specified name has artist.
  108. /// </summary>
  109. /// <param name="name">The name.</param>
  110. /// <returns><c>true</c> if the specified name has artist; otherwise, <c>false</c>.</returns>
  111. public bool HasArtist(string name)
  112. {
  113. return Artists.Contains(name, StringComparer.OrdinalIgnoreCase) || string.Equals(AlbumArtist, name, StringComparison.OrdinalIgnoreCase);
  114. }
  115. }
  116. }