support srt in didl

pull/702/head
Luke Pulverenti 10 years ago
parent 3ff3d04284
commit e3c52b6f73

@ -1641,9 +1641,12 @@ namespace MediaBrowser.Api.Playback
// Can't stream copy if we're burning in subtitles // Can't stream copy if we're burning in subtitles
if (request.SubtitleStreamIndex.HasValue) if (request.SubtitleStreamIndex.HasValue)
{
if (request.SubtitleMethod == SubtitleDeliveryMethod.Encode)
{ {
return false; return false;
} }
}
// Source and target codecs must match // Source and target codecs must match
if (!string.Equals(request.VideoCodec, videoStream.Codec, StringComparison.OrdinalIgnoreCase)) if (!string.Equals(request.VideoCodec, videoStream.Codec, StringComparison.OrdinalIgnoreCase))

@ -25,8 +25,6 @@ namespace MediaBrowser.Api.Playback.Hls
{ {
public bool EnableAdaptiveBitrateStreaming { get; set; } public bool EnableAdaptiveBitrateStreaming { get; set; }
public SubtitleDeliveryMethod SubtitleMethod { get; set; }
public GetMasterHlsVideoStream() public GetMasterHlsVideoStream()
{ {
EnableAdaptiveBitrateStreaming = true; EnableAdaptiveBitrateStreaming = true;

@ -1,4 +1,5 @@
using ServiceStack; using MediaBrowser.Model.Dlna;
using ServiceStack;
namespace MediaBrowser.Api.Playback namespace MediaBrowser.Api.Playback
{ {
@ -160,6 +161,9 @@ namespace MediaBrowser.Api.Playback
[ApiMember(Name = "Level", Description = "Optional. Specify a level for the h264 profile, e.g. 3, 3.1.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")] [ApiMember(Name = "Level", Description = "Optional. Specify a level for the h264 profile, e.g. 3, 3.1.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
public string Level { get; set; } public string Level { get; set; }
[ApiMember(Name = "SubtitleDeliveryMethod", Description = "Optional. Specify the subtitle delivery method.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
public SubtitleDeliveryMethod SubtitleMethod { get; set; }
/// <summary> /// <summary>
/// Gets a value indicating whether this instance has fixed resolution. /// Gets a value indicating whether this instance has fixed resolution.
/// </summary> /// </summary>

@ -236,6 +236,11 @@ namespace MediaBrowser.Common.Net
return "text/vtt"; return "text/vtt";
} }
if (ext.Equals(".ttml", StringComparison.OrdinalIgnoreCase))
{
return "application/ttml+xml";
}
if (ext.Equals(".bif", StringComparison.OrdinalIgnoreCase)) if (ext.Equals(".bif", StringComparison.OrdinalIgnoreCase))
{ {
return "application/octet-stream"; return "application/octet-stream";

@ -183,19 +183,34 @@ namespace MediaBrowser.Dlna.ContentDirectory
//didl.SetAttribute("xmlns:sec", NS_SEC); //didl.SetAttribute("xmlns:sec", NS_SEC);
result.AppendChild(didl); result.AppendChild(didl);
var folder = (Folder)GetItemFromObjectId(id, user); var item = GetItemFromObjectId(id, user);
var childrenResult = (await GetChildrenSorted(folder, user, sortCriteria, start, requested).ConfigureAwait(false));
var totalCount = childrenResult.TotalRecordCount; var totalCount = 0;
if (string.Equals(flag, "BrowseMetadata")) if (string.Equals(flag, "BrowseMetadata"))
{ {
var folder = item as Folder;
if (folder == null)
{
result.DocumentElement.AppendChild(_didlBuilder.GetItemElement(result, item, deviceId, filter));
}
else
{
var childrenResult = (await GetChildrenSorted(folder, user, sortCriteria, start, requested).ConfigureAwait(false));
totalCount = childrenResult.TotalRecordCount;
result.DocumentElement.AppendChild(_didlBuilder.GetFolderElement(result, folder, totalCount, filter)); result.DocumentElement.AppendChild(_didlBuilder.GetFolderElement(result, folder, totalCount, filter));
}
provided++; provided++;
} }
else else
{ {
var folder = (Folder)item;
var childrenResult = (await GetChildrenSorted(folder, user, sortCriteria, start, requested).ConfigureAwait(false));
totalCount = childrenResult.TotalRecordCount;
provided = childrenResult.Items.Length; provided = childrenResult.Items.Length;
foreach (var i in childrenResult.Items) foreach (var i in childrenResult.Items)

@ -137,6 +137,23 @@ namespace MediaBrowser.Dlna.Didl
{ {
AddVideoResource(container, video, deviceId, filter, contentFeature, streamInfo); AddVideoResource(container, video, deviceId, filter, contentFeature, streamInfo);
} }
foreach (var subtitle in streamInfo.GetExternalSubtitles(_serverAddress))
{
AddSubtitleElement(container, subtitle);
}
}
private void AddSubtitleElement(XmlElement container, SubtitleStreamInfo info)
{
var res = container.OwnerDocument.CreateElement(string.Empty, "res", NS_DIDL);
res.InnerText = info.Url;
// TODO: Remove this hard-coding
res.SetAttribute("protocolInfo", "http-get:*:text/srt:*");
container.AppendChild(res);
} }
private void AddVideoResource(XmlElement container, Video video, string deviceId, Filter filter, string contentFeatures, StreamInfo streamInfo) private void AddVideoResource(XmlElement container, Video video, string deviceId, Filter filter, string contentFeatures, StreamInfo streamInfo)

@ -131,7 +131,7 @@ namespace MediaBrowser.Model.Dlna
return string.Format("Params={0}", string.Join(";", list.ToArray())); return string.Format("Params={0}", string.Join(";", list.ToArray()));
} }
public string ToSubtitleUrl(string baseUrl) public List<SubtitleStreamInfo> GetExternalSubtitles(string baseUrl)
{ {
if (SubtitleDeliveryMethod != SubtitleDeliveryMethod.External) if (SubtitleDeliveryMethod != SubtitleDeliveryMethod.External)
{ {
@ -148,13 +148,31 @@ namespace MediaBrowser.Model.Dlna
? 0 ? 0
: StartPositionTicks; : StartPositionTicks;
return string.Format("{0}/Videos/{1}/{2}/Subtitles/{3}/{4}/Stream.{5}", string url = string.Format("{0}/Videos/{1}/{2}/Subtitles/{3}/{4}/Stream.{5}",
baseUrl, baseUrl,
ItemId, ItemId,
MediaSourceId, MediaSourceId,
StringHelper.ToStringCultureInvariant(SubtitleStreamIndex.Value), StringHelper.ToStringCultureInvariant(SubtitleStreamIndex.Value),
StringHelper.ToStringCultureInvariant(startPositionTicks), StringHelper.ToStringCultureInvariant(startPositionTicks),
SubtitleFormat); SubtitleFormat);
List<SubtitleStreamInfo> list = new List<SubtitleStreamInfo>();
foreach (MediaStream stream in MediaSource.MediaStreams)
{
if (stream.Type == MediaStreamType.Subtitle && stream.Index == SubtitleStreamIndex.Value)
{
list.Add(new SubtitleStreamInfo
{
Url = url,
IsForced = stream.IsForced,
Language = stream.Language,
Name = stream.Language ?? "Unknown"
});
}
}
return list;
} }
/// <summary> /// <summary>
@ -482,4 +500,12 @@ namespace MediaBrowser.Model.Dlna
/// </summary> /// </summary>
Hls = 3 Hls = 3
} }
public class SubtitleStreamInfo
{
public string Url { get; set; }
public string Language { get; set; }
public string Name { get; set; }
public bool IsForced { get; set; }
}
} }

Loading…
Cancel
Save