Audio.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. #nullable disable
  2. #pragma warning disable CA1002, CA1724, CA1826, CS1591
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Globalization;
  6. using System.Linq;
  7. using System.Text.Json.Serialization;
  8. using Jellyfin.Data.Enums;
  9. using MediaBrowser.Controller.Persistence;
  10. using MediaBrowser.Controller.Providers;
  11. using MediaBrowser.Model.Dto;
  12. using MediaBrowser.Model.Entities;
  13. namespace MediaBrowser.Controller.Entities.Audio
  14. {
  15. /// <summary>
  16. /// Class Audio.
  17. /// </summary>
  18. public class Audio : BaseItem,
  19. IHasAlbumArtist,
  20. IHasArtist,
  21. IHasMusicGenres,
  22. IHasLookupInfo<SongInfo>,
  23. IHasMediaSources
  24. {
  25. public Audio()
  26. {
  27. Artists = Array.Empty<string>();
  28. AlbumArtists = Array.Empty<string>();
  29. }
  30. /// <inheritdoc />
  31. [JsonIgnore]
  32. public IReadOnlyList<string> Artists { get; set; }
  33. /// <inheritdoc />
  34. [JsonIgnore]
  35. public IReadOnlyList<string> AlbumArtists { get; set; }
  36. [JsonIgnore]
  37. public override bool SupportsPlayedStatus => true;
  38. [JsonIgnore]
  39. public override bool SupportsPeople => false;
  40. [JsonIgnore]
  41. public override bool SupportsAddingToPlaylist => true;
  42. [JsonIgnore]
  43. public override bool SupportsInheritedParentImages => true;
  44. [JsonIgnore]
  45. protected override bool SupportsOwnedItems => false;
  46. [JsonIgnore]
  47. public override Folder LatestItemsIndexContainer => AlbumEntity;
  48. [JsonIgnore]
  49. public MusicAlbum AlbumEntity => FindParent<MusicAlbum>();
  50. /// <summary>
  51. /// Gets the type of the media.
  52. /// </summary>
  53. /// <value>The type of the media.</value>
  54. [JsonIgnore]
  55. public override string MediaType => Model.Entities.MediaType.Audio;
  56. public override double GetDefaultPrimaryImageAspectRatio()
  57. {
  58. return 1;
  59. }
  60. public override bool CanDownload()
  61. {
  62. return IsFileProtocol;
  63. }
  64. /// <summary>
  65. /// Creates the name of the sort.
  66. /// </summary>
  67. /// <returns>System.String.</returns>
  68. protected override string CreateSortName()
  69. {
  70. return (ParentIndexNumber != null ? ParentIndexNumber.Value.ToString("0000 - ", CultureInfo.InvariantCulture) : string.Empty)
  71. + (IndexNumber != null ? IndexNumber.Value.ToString("0000 - ", CultureInfo.InvariantCulture) : string.Empty) + Name;
  72. }
  73. public override List<string> GetUserDataKeys()
  74. {
  75. var list = base.GetUserDataKeys();
  76. var songKey = IndexNumber.HasValue ? IndexNumber.Value.ToString("0000", CultureInfo.InvariantCulture) : string.Empty;
  77. if (ParentIndexNumber.HasValue)
  78. {
  79. songKey = ParentIndexNumber.Value.ToString("0000", CultureInfo.InvariantCulture) + "-" + songKey;
  80. }
  81. songKey += Name;
  82. if (!string.IsNullOrEmpty(Album))
  83. {
  84. songKey = Album + "-" + songKey;
  85. }
  86. var albumArtist = AlbumArtists.FirstOrDefault();
  87. if (!string.IsNullOrEmpty(albumArtist))
  88. {
  89. songKey = albumArtist + "-" + songKey;
  90. }
  91. list.Insert(0, songKey);
  92. return list;
  93. }
  94. public override UnratedItem GetBlockUnratedType()
  95. {
  96. if (SourceType == SourceType.Library)
  97. {
  98. return UnratedItem.Music;
  99. }
  100. return base.GetBlockUnratedType();
  101. }
  102. public List<MediaStream> GetMediaStreams(MediaStreamType type)
  103. {
  104. return MediaSourceManager.GetMediaStreams(new MediaStreamQuery
  105. {
  106. ItemId = Id,
  107. Type = type
  108. });
  109. }
  110. public SongInfo GetLookupInfo()
  111. {
  112. var info = GetItemLookupInfo<SongInfo>();
  113. info.AlbumArtists = AlbumArtists;
  114. info.Album = Album;
  115. info.Artists = Artists;
  116. return info;
  117. }
  118. protected override List<Tuple<BaseItem, MediaSourceType>> GetAllItemsForMediaSources()
  119. {
  120. var list = new List<Tuple<BaseItem, MediaSourceType>>();
  121. list.Add(new Tuple<BaseItem, MediaSourceType>(this, MediaSourceType.Default));
  122. return list;
  123. }
  124. }
  125. }