2014-04-18 05:03:01 +00:00
|
|
|
|
using MediaBrowser.Controller.Entities;
|
2014-04-01 22:23:07 +00:00
|
|
|
|
using MediaBrowser.Model.Dlna;
|
2014-08-05 23:59:24 +00:00
|
|
|
|
using MediaBrowser.Model.Session;
|
2014-03-22 18:25:03 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Globalization;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Dlna.PlayTo
|
|
|
|
|
{
|
|
|
|
|
public class PlaylistItemFactory
|
|
|
|
|
{
|
|
|
|
|
private readonly CultureInfo _usCulture = new CultureInfo("en-US");
|
|
|
|
|
|
2014-04-18 05:03:01 +00:00
|
|
|
|
public PlaylistItem Create(Photo item, DeviceProfile profile)
|
2014-03-22 18:25:03 +00:00
|
|
|
|
{
|
|
|
|
|
var playlistItem = new PlaylistItem
|
|
|
|
|
{
|
2014-04-18 05:03:01 +00:00
|
|
|
|
StreamInfo = new StreamInfo
|
2014-03-23 00:48:34 +00:00
|
|
|
|
{
|
2014-04-18 05:03:01 +00:00
|
|
|
|
ItemId = item.Id.ToString("N"),
|
|
|
|
|
MediaType = DlnaProfileType.Photo,
|
2014-04-23 02:47:46 +00:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
Profile = profile
|
2014-03-22 18:25:03 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var directPlay = profile.DirectPlayProfiles
|
2014-04-18 05:03:01 +00:00
|
|
|
|
.FirstOrDefault(i => i.Type == DlnaProfileType.Photo && IsSupported(i, item));
|
2014-03-22 18:25:03 +00:00
|
|
|
|
|
|
|
|
|
if (directPlay != null)
|
|
|
|
|
{
|
2014-08-05 23:59:24 +00:00
|
|
|
|
playlistItem.StreamInfo.PlayMethod = PlayMethod.DirectStream;
|
2014-04-18 05:03:01 +00:00
|
|
|
|
playlistItem.StreamInfo.Container = Path.GetExtension(item.Path);
|
2014-03-22 18:25:03 +00:00
|
|
|
|
|
|
|
|
|
return playlistItem;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var transcodingProfile = profile.TranscodingProfiles
|
2014-04-18 05:03:01 +00:00
|
|
|
|
.FirstOrDefault(i => i.Type == DlnaProfileType.Photo);
|
2014-03-22 18:25:03 +00:00
|
|
|
|
|
|
|
|
|
if (transcodingProfile != null)
|
|
|
|
|
{
|
2014-08-05 23:59:24 +00:00
|
|
|
|
playlistItem.StreamInfo.PlayMethod = PlayMethod.Transcode;
|
2014-04-18 05:03:01 +00:00
|
|
|
|
playlistItem.StreamInfo.Container = "." + transcodingProfile.Container.TrimStart('.');
|
2014-03-22 18:25:03 +00:00
|
|
|
|
}
|
2014-03-24 17:54:45 +00:00
|
|
|
|
|
2014-03-22 18:25:03 +00:00
|
|
|
|
return playlistItem;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool IsSupported(DirectPlayProfile profile, Photo item)
|
|
|
|
|
{
|
|
|
|
|
var mediaPath = item.Path;
|
|
|
|
|
|
2014-03-23 06:07:43 +00:00
|
|
|
|
if (profile.Container.Length > 0)
|
2014-03-22 18:25:03 +00:00
|
|
|
|
{
|
2014-03-22 20:02:10 +00:00
|
|
|
|
// Check container type
|
|
|
|
|
var mediaContainer = Path.GetExtension(mediaPath);
|
2014-03-23 06:07:43 +00:00
|
|
|
|
if (!profile.GetContainers().Any(i => string.Equals("." + i.TrimStart('.'), mediaContainer, StringComparison.OrdinalIgnoreCase)))
|
2014-03-22 20:02:10 +00:00
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2014-03-22 18:25:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|