Audio.cs 4.1 KB

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