diff --git a/Emby.Server.Implementations/Sorting/AlbumArtistComparer.cs b/Emby.Server.Implementations/Sorting/AlbumArtistComparer.cs
index 65c8599e7..59185cdb7 100644
--- a/Emby.Server.Implementations/Sorting/AlbumArtistComparer.cs
+++ b/Emby.Server.Implementations/Sorting/AlbumArtistComparer.cs
@@ -1,5 +1,4 @@
using System;
-using System.Linq;
using Jellyfin.Data.Enums;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Audio;
@@ -9,37 +8,35 @@ using MediaBrowser.Model.Querying;
namespace Emby.Server.Implementations.Sorting
{
///
- /// Class AlbumArtistComparer.
+ /// Allows comparing artists of albums. Only the first artist of each album is considered.
///
public class AlbumArtistComparer : IBaseItemComparer
{
///
- /// Gets the name.
+ /// Gets the item type this comparer compares.
///
- /// The name.
public ItemSortBy Type => ItemSortBy.AlbumArtist;
///
- /// Compares the specified x.
+ /// Compares the specified arguments on their primary artist.
///
- /// The x.
- /// The y.
- /// System.Int32.
+ /// First item to compare.
+ /// Second item to compare.
+ /// Zero if equal, else negative or positive number to indicate order.
public int Compare(BaseItem? x, BaseItem? y)
{
- return string.Compare(GetValue(x), GetValue(y), StringComparison.OrdinalIgnoreCase);
+ return string.Compare(GetFirstAlbumArtist(x), GetFirstAlbumArtist(y), StringComparison.OrdinalIgnoreCase);
}
- ///
- /// Gets the value.
- ///
- /// The x.
- /// System.String.
- private static string? GetValue(BaseItem? x)
+ private static string? GetFirstAlbumArtist(BaseItem? x)
{
- var audio = x as IHasAlbumArtist;
+ if (x is IHasAlbumArtist audio
+ && audio.AlbumArtists.Count != 0)
+ {
+ return audio.AlbumArtists[0];
+ }
- return audio?.AlbumArtists.FirstOrDefault();
+ return null;
}
}
}