AlbumArtistComparer.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using System;
  2. using System.Linq;
  3. using Jellyfin.Data.Enums;
  4. using MediaBrowser.Controller.Entities;
  5. using MediaBrowser.Controller.Entities.Audio;
  6. using MediaBrowser.Controller.Sorting;
  7. using MediaBrowser.Model.Querying;
  8. namespace Emby.Server.Implementations.Sorting
  9. {
  10. /// <summary>
  11. /// Class AlbumArtistComparer.
  12. /// </summary>
  13. public class AlbumArtistComparer : IBaseItemComparer
  14. {
  15. /// <summary>
  16. /// Gets the name.
  17. /// </summary>
  18. /// <value>The name.</value>
  19. public ItemSortBy Type => ItemSortBy.AlbumArtist;
  20. /// <summary>
  21. /// Compares the specified x.
  22. /// </summary>
  23. /// <param name="x">The x.</param>
  24. /// <param name="y">The y.</param>
  25. /// <returns>System.Int32.</returns>
  26. public int Compare(BaseItem? x, BaseItem? y)
  27. {
  28. return string.Compare(GetValue(x), GetValue(y), StringComparison.OrdinalIgnoreCase);
  29. }
  30. /// <summary>
  31. /// Gets the value.
  32. /// </summary>
  33. /// <param name="x">The x.</param>
  34. /// <returns>System.String.</returns>
  35. private static string? GetValue(BaseItem? x)
  36. {
  37. var audio = x as IHasAlbumArtist;
  38. return audio?.AlbumArtists.FirstOrDefault();
  39. }
  40. }
  41. }