Audio.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. #nullable disable
  2. #pragma warning disable 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. /// <inheritdoc />
  26. [JsonIgnore]
  27. public IReadOnlyList<string> Artists { get; set; }
  28. /// <inheritdoc />
  29. [JsonIgnore]
  30. public IReadOnlyList<string> AlbumArtists { get; set; }
  31. public Audio()
  32. {
  33. Artists = Array.Empty<string>();
  34. AlbumArtists = Array.Empty<string>();
  35. }
  36. public override double GetDefaultPrimaryImageAspectRatio()
  37. {
  38. return 1;
  39. }
  40. [JsonIgnore]
  41. public override bool SupportsPlayedStatus => true;
  42. [JsonIgnore]
  43. public override bool SupportsPeople => false;
  44. [JsonIgnore]
  45. public override bool SupportsAddingToPlaylist => true;
  46. [JsonIgnore]
  47. public override bool SupportsInheritedParentImages => true;
  48. [JsonIgnore]
  49. protected override bool SupportsOwnedItems => false;
  50. [JsonIgnore]
  51. public override Folder LatestItemsIndexContainer => AlbumEntity;
  52. public override bool CanDownload()
  53. {
  54. return IsFileProtocol;
  55. }
  56. [JsonIgnore]
  57. public MusicAlbum AlbumEntity => FindParent<MusicAlbum>();
  58. /// <summary>
  59. /// Gets the type of the media.
  60. /// </summary>
  61. /// <value>The type of the media.</value>
  62. [JsonIgnore]
  63. public override string MediaType => Model.Entities.MediaType.Audio;
  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. }