VideoBitRateComparer.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using MediaBrowser.Controller.Entities;
  2. using MediaBrowser.Controller.Sorting;
  3. using MediaBrowser.Model.Entities;
  4. using MediaBrowser.Model.Querying;
  5. using System.Linq;
  6. namespace MediaBrowser.Server.Implementations.Sorting
  7. {
  8. class VideoBitRateComparer : IBaseItemComparer
  9. {
  10. /// <summary>
  11. /// Compares the specified x.
  12. /// </summary>
  13. /// <param name="x">The x.</param>
  14. /// <param name="y">The y.</param>
  15. /// <returns>System.Int32.</returns>
  16. public int Compare(BaseItem x, BaseItem y)
  17. {
  18. return GetValue(x).CompareTo(GetValue(y));
  19. }
  20. private int GetValue(BaseItem item)
  21. {
  22. var video = item as IHasMediaStreams;
  23. if (video != null)
  24. {
  25. var videoStream = video.MediaStreams
  26. .FirstOrDefault(i => i.Type == MediaStreamType.Video);
  27. if (videoStream != null)
  28. {
  29. return videoStream.BitRate ?? 0;
  30. }
  31. }
  32. return 0;
  33. }
  34. /// <summary>
  35. /// Gets the name.
  36. /// </summary>
  37. /// <value>The name.</value>
  38. public string Name
  39. {
  40. get { return ItemSortBy.VideoBitRate; }
  41. }
  42. }
  43. }