AlbumArtistComparer.cs 1.2 KB

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