Audio.cs 3.5 KB

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