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

101 lines
3.0 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-15 04:14:07 +00:00
public static PlaylistItem Create(BaseItem item, DeviceProfile 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;
2014-03-14 14:27:32 +00:00
playlistItem.FileFormat = Path.GetExtension(path);
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-14 14:27:32 +00:00
//Just to make sure we have a "." for the url, remove it in case a user adds it or not
playlistItem.FileFormat = "." + transcodingProfile.Container.TrimStart('.');
2014-03-13 19:08:02 +00:00
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)
{
2014-03-14 14:27:32 +00:00
var mediaContainer = Path.GetExtension(path);
2014-03-13 19:08:02 +00:00
2014-03-14 14:27:32 +00:00
if (!profile.Containers.Any(i => string.Equals("." + i.TrimStart('.'), mediaContainer, StringComparison.OrdinalIgnoreCase)))
2014-03-13 19:08:02 +00:00
{
return false;
}
// Placeholder for future conditions
2014-03-13 21:36:19 +00:00
// TODO: Support codec list as additional restriction
2014-03-13 19:08:02 +00:00
return true;
}
2014-03-15 04:14:07 +00:00
private static bool IsSupported(DeviceProfile profile, TranscodingProfile transcodingProfile, string path)
2014-03-13 19:08:02 +00:00
{
// Placeholder for future conditions
return true;
}
2014-02-26 21:31:47 +00:00
}
2014-03-14 14:27:32 +00:00
}