jellyfin/MediaBrowser.Dlna/PlayTo/PlaylistItemFactory.cs

70 lines
2.1 KiB
C#
Raw Normal View History

2014-04-18 05:03:01 +00:00
using MediaBrowser.Controller.Entities;
2014-04-01 22:23:07 +00:00
using MediaBrowser.Model.Dlna;
using MediaBrowser.Model.Session;
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)
{
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,
2015-02-05 05:29:37 +00:00
DeviceProfile = profile
2014-04-23 02:47:46 +00:00
},
Profile = profile
};
var directPlay = profile.DirectPlayProfiles
2014-04-18 05:03:01 +00:00
.FirstOrDefault(i => i.Type == DlnaProfileType.Photo && IsSupported(i, item));
if (directPlay != null)
{
playlistItem.StreamInfo.PlayMethod = PlayMethod.DirectStream;
2014-04-18 05:03:01 +00:00
playlistItem.StreamInfo.Container = Path.GetExtension(item.Path);
return playlistItem;
}
var transcodingProfile = profile.TranscodingProfiles
2014-04-18 05:03:01 +00:00
.FirstOrDefault(i => i.Type == DlnaProfileType.Photo);
if (transcodingProfile != null)
{
playlistItem.StreamInfo.PlayMethod = PlayMethod.Transcode;
2014-04-18 05:03:01 +00:00
playlistItem.StreamInfo.Container = "." + transcodingProfile.Container.TrimStart('.');
}
2014-03-24 17:54:45 +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 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;
}
}
return true;
}
}
}