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

101 lines
2.9 KiB
C#
Raw Normal View History

2014-03-13 19:08:02 +00:00
using MediaBrowser.Controller.Dlna;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Model.Entities;
2014-02-27 02:44:00 +00:00
using System;
2014-03-13 19:08:02 +00:00
using System.IO;
using System.Linq;
2014-02-27 02:44:00 +00:00
2014-02-26 21:31:47 +00:00
namespace MediaBrowser.Dlna.PlayTo
{
public class PlaylistItem
{
public string ItemId { get; set; }
public bool Transcode { get; set; }
public bool IsVideo { get; set; }
public bool IsAudio { get; set; }
public string FileFormat { get; set; }
2014-03-12 20:01:19 +00:00
public string MimeType { get; set; }
2014-02-26 21:31:47 +00:00
public int PlayState { get; set; }
public string StreamUrl { get; set; }
public string DlnaHeaders { get; set; }
public string Didl { get; set; }
public long StartPositionTicks { get; set; }
2014-03-13 19:08:02 +00:00
public static PlaylistItem Create(BaseItem item, DlnaProfile profile)
2014-02-27 02:44:00 +00:00
{
2014-03-13 19:08:02 +00:00
var playlistItem = new PlaylistItem
{
ItemId = item.Id.ToString()
};
2014-02-27 02:44:00 +00:00
2014-03-13 19:08:02 +00:00
DlnaProfileType profileType;
if (string.Equals(item.MediaType, MediaType.Video, StringComparison.OrdinalIgnoreCase))
2014-02-27 02:44:00 +00:00
{
playlistItem.IsVideo = true;
2014-03-13 19:08:02 +00:00
profileType = DlnaProfileType.Video;
2014-02-27 02:44:00 +00:00
}
else
{
playlistItem.IsAudio = true;
2014-03-13 19:08:02 +00:00
profileType = DlnaProfileType.Audio;
2014-02-27 02:44:00 +00:00
}
2014-03-13 19:08:02 +00:00
var path = item.Path;
2014-02-27 02:44:00 +00:00
2014-03-13 19:08:02 +00:00
var directPlay = profile.DirectPlayProfiles.FirstOrDefault(i => i.Type == profileType && IsSupported(i, path));
2014-02-27 02:44:00 +00:00
2014-03-13 19:08:02 +00:00
if (directPlay != null)
2014-02-27 02:44:00 +00:00
{
2014-03-13 19:08:02 +00:00
playlistItem.Transcode = false;
playlistItem.FileFormat = Path.GetExtension(path).TrimStart('.');
2014-03-13 20:21:42 +00:00
playlistItem.MimeType = directPlay.MimeType;
2014-03-13 19:08:02 +00:00
return playlistItem;
2014-02-27 02:44:00 +00:00
}
2014-03-13 19:08:02 +00:00
var transcodingProfile = profile.TranscodingProfiles.FirstOrDefault(i => i.Type == profileType && IsSupported(profile, i, path));
2014-02-27 02:44:00 +00:00
2014-03-13 19:08:02 +00:00
if (transcodingProfile != null)
2014-02-27 02:44:00 +00:00
{
playlistItem.Transcode = true;
2014-03-13 19:08:02 +00:00
playlistItem.FileFormat = transcodingProfile.Container;
playlistItem.MimeType = transcodingProfile.MimeType;
2014-02-27 02:44:00 +00:00
}
return playlistItem;
}
2014-03-13 19:08:02 +00:00
private static bool IsSupported(DirectPlayProfile profile, string path)
{
// TODO: Support codec list as additional restriction
var mediaContainer = Path.GetExtension(path).TrimStart('.');
if (!profile.Containers.Any(i => string.Equals("." + i.TrimStart('.'), mediaContainer, StringComparison.OrdinalIgnoreCase)))
{
return false;
}
// Placeholder for future conditions
return true;
}
private static bool IsSupported(DlnaProfile profile, TranscodingProfile transcodingProfile, string path)
{
// Placeholder for future conditions
return true;
}
2014-02-26 21:31:47 +00:00
}
}