jellyfin/MediaBrowser.Dlna/PlayTo/PlaylistItem.cs

101 lines
3.0 KiB
C#
Raw Normal View History

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