2015-03-26 21:31:57 +01:00
|
|
|
|
using MediaBrowser.Model.MediaInfo;
|
|
|
|
|
using MediaBrowser.Model.Session;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Model.Dlna
|
|
|
|
|
{
|
|
|
|
|
public class StreamInfoSorter
|
|
|
|
|
{
|
2017-01-03 06:15:59 +01:00
|
|
|
|
public static List<StreamInfo> SortMediaSources(List<StreamInfo> streams, long? maxBitrate)
|
2015-03-26 21:31:57 +01:00
|
|
|
|
{
|
|
|
|
|
return streams.OrderBy(i =>
|
2015-03-27 00:10:34 +01:00
|
|
|
|
{
|
|
|
|
|
// Nothing beats direct playing a file
|
|
|
|
|
if (i.PlayMethod == PlayMethod.DirectPlay && i.MediaSource.Protocol == MediaProtocol.File)
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
}).ThenBy(i =>
|
2015-03-26 21:31:57 +01:00
|
|
|
|
{
|
|
|
|
|
switch (i.PlayMethod)
|
|
|
|
|
{
|
2015-03-27 00:10:34 +01:00
|
|
|
|
// Let's assume direct streaming a file is just as desirable as direct playing a remote url
|
|
|
|
|
case PlayMethod.DirectStream:
|
2015-03-26 21:31:57 +01:00
|
|
|
|
case PlayMethod.DirectPlay:
|
|
|
|
|
return 0;
|
|
|
|
|
default:
|
2015-03-27 21:55:31 +01:00
|
|
|
|
return 1;
|
2015-03-26 21:31:57 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}).ThenBy(i =>
|
|
|
|
|
{
|
|
|
|
|
switch (i.MediaSource.Protocol)
|
|
|
|
|
{
|
|
|
|
|
case MediaProtocol.File:
|
|
|
|
|
return 0;
|
|
|
|
|
default:
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-14 21:12:00 +02:00
|
|
|
|
}).ThenBy(i =>
|
|
|
|
|
{
|
|
|
|
|
if (maxBitrate.HasValue)
|
|
|
|
|
{
|
|
|
|
|
if (i.MediaSource.Bitrate.HasValue)
|
|
|
|
|
{
|
|
|
|
|
if (i.MediaSource.Bitrate.Value <= maxBitrate.Value)
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 2;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
2015-03-26 21:31:57 +01:00
|
|
|
|
}).ToList();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|