| | 1 | | using System; |
| | 2 | | using Jellyfin.Data.Enums; |
| | 3 | | using MediaBrowser.Controller.Entities; |
| | 4 | | using MediaBrowser.Controller.Entities.Audio; |
| | 5 | | using MediaBrowser.Controller.Sorting; |
| | 6 | | using MediaBrowser.Model.Querying; |
| | 7 | |
|
| | 8 | | namespace Emby.Server.Implementations.Sorting |
| | 9 | | { |
| | 10 | | /// <summary> |
| | 11 | | /// Allows comparing artists of albums. Only the first artist of each album is considered. |
| | 12 | | /// </summary> |
| | 13 | | public class AlbumArtistComparer : IBaseItemComparer |
| | 14 | | { |
| | 15 | | /// <summary> |
| | 16 | | /// Gets the item type this comparer compares. |
| | 17 | | /// </summary> |
| 1 | 18 | | public ItemSortBy Type => ItemSortBy.AlbumArtist; |
| | 19 | |
|
| | 20 | | /// <summary> |
| | 21 | | /// Compares the specified arguments on their primary artist. |
| | 22 | | /// </summary> |
| | 23 | | /// <param name="x">First item to compare.</param> |
| | 24 | | /// <param name="y">Second item to compare.</param> |
| | 25 | | /// <returns>Zero if equal, else negative or positive number to indicate order.</returns> |
| | 26 | | public int Compare(BaseItem? x, BaseItem? y) |
| | 27 | | { |
| 0 | 28 | | return string.Compare(GetFirstAlbumArtist(x), GetFirstAlbumArtist(y), StringComparison.OrdinalIgnoreCase); |
| | 29 | | } |
| | 30 | |
|
| | 31 | | private static string? GetFirstAlbumArtist(BaseItem? x) |
| | 32 | | { |
| 0 | 33 | | if (x is IHasAlbumArtist audio |
| 0 | 34 | | && audio.AlbumArtists.Count != 0) |
| | 35 | | { |
| 0 | 36 | | return audio.AlbumArtists[0]; |
| | 37 | | } |
| | 38 | |
|
| 0 | 39 | | return null; |
| | 40 | | } |
| | 41 | | } |
| | 42 | | } |