Audio.cs 3.9 KB

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