jellyfin-server/MediaBrowser.Dlna/PlayTo/PlaylistItemFactory.cs

66 lines
2.0 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 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,
2014-03-23 00:48:34 +00:00
}
};
var directPlay = profile.DirectPlayProfiles
2014-04-18 05:03:01 +00:00
.FirstOrDefault(i => i.Type == DlnaProfileType.Photo && IsSupported(i, item));
if (directPlay != null)
{
2014-04-18 05:03:01 +00:00
playlistItem.StreamInfo.IsDirectStream = true;
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)
{
2014-04-18 05:03:01 +00:00
playlistItem.StreamInfo.IsDirectStream = true;
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;
}
}
}