StreamInfoSorter.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using MediaBrowser.Model.MediaInfo;
  2. using MediaBrowser.Model.Session;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. namespace MediaBrowser.Model.Dlna
  6. {
  7. public class StreamInfoSorter
  8. {
  9. public static List<StreamInfo> SortMediaSources(List<StreamInfo> streams, long? maxBitrate)
  10. {
  11. return streams.OrderBy(i =>
  12. {
  13. // Nothing beats direct playing a file
  14. if (i.PlayMethod == PlayMethod.DirectPlay && i.MediaSource.Protocol == MediaProtocol.File)
  15. {
  16. return 0;
  17. }
  18. return 1;
  19. }).ThenBy(i =>
  20. {
  21. switch (i.PlayMethod)
  22. {
  23. // Let's assume direct streaming a file is just as desirable as direct playing a remote url
  24. case PlayMethod.DirectStream:
  25. case PlayMethod.DirectPlay:
  26. return 0;
  27. default:
  28. return 1;
  29. }
  30. }).ThenBy(i =>
  31. {
  32. switch (i.MediaSource.Protocol)
  33. {
  34. case MediaProtocol.File:
  35. return 0;
  36. default:
  37. return 1;
  38. }
  39. }).ThenBy(i =>
  40. {
  41. if (maxBitrate.HasValue)
  42. {
  43. if (i.MediaSource.Bitrate.HasValue)
  44. {
  45. if (i.MediaSource.Bitrate.Value <= maxBitrate.Value)
  46. {
  47. return 0;
  48. }
  49. return 2;
  50. }
  51. }
  52. return 1;
  53. }).ToList();
  54. }
  55. }
  56. }