AlbumComparer.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. namespace Emby.Server.Implementations.Sorting
  8. {
  9. /// <summary>
  10. /// Class AlbumComparer.
  11. /// </summary>
  12. public class AlbumComparer : IBaseItemComparer
  13. {
  14. /// <summary>
  15. /// Gets the name.
  16. /// </summary>
  17. /// <value>The name.</value>
  18. public ItemSortBy Type => ItemSortBy.Album;
  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. return x is Audio audio ? audio.Album : string.Empty;
  37. }
  38. }
  39. }