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