| | 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 | | /// Class ArtistComparer. |
| | 12 | | /// </summary> |
| | 13 | | public class ArtistComparer : IBaseItemComparer |
| | 14 | | { |
| | 15 | | /// <inheritdoc /> |
| 1 | 16 | | public ItemSortBy Type => ItemSortBy.Artist; |
| | 17 | |
|
| | 18 | | /// <inheritdoc /> |
| | 19 | | public int Compare(BaseItem? x, BaseItem? y) |
| | 20 | | { |
| 0 | 21 | | return string.Compare(GetValue(x), GetValue(y), StringComparison.OrdinalIgnoreCase); |
| | 22 | | } |
| | 23 | |
|
| | 24 | | /// <summary> |
| | 25 | | /// Gets the value. |
| | 26 | | /// </summary> |
| | 27 | | /// <param name="x">The x.</param> |
| | 28 | | /// <returns>System.String.</returns> |
| | 29 | | private static string? GetValue(BaseItem? x) |
| | 30 | | { |
| 0 | 31 | | if (x is not Audio audio) |
| | 32 | | { |
| 0 | 33 | | return string.Empty; |
| | 34 | | } |
| | 35 | |
|
| 0 | 36 | | return audio.Artists.Count == 0 ? null : audio.Artists[0]; |
| | 37 | | } |
| | 38 | | } |
| | 39 | | } |