StreamInfoSorter.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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)
  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. }).ToList();
  40. }
  41. }
  42. }