The Free Software Media System - Server Backend & API
update live tv return object
Luke Pulverentib7ed4df4fa11
diff --git a/MediaBrowser.Api/Playback/BaseStreamingService.cs b/MediaBrowser.Api/Playback/BaseStreamingService.csindex c188376fe6..919e51eccf 100644--- a/MediaBrowser.Api/Playback/BaseStreamingService.cs+++ b/MediaBrowser.Api/Playback/BaseStreamingService.cs@@ -859,19 +859,12 @@ namespace MediaBrowser.Api.Playbackstate.LiveTvStreamId = streamInfo.Id;- if (!string.IsNullOrEmpty(streamInfo.Path))- {- state.MediaPath = streamInfo.Path;- }- else if (!string.IsNullOrEmpty(streamInfo.Url))- {- state.MediaPath = streamInfo.Url;- }+ state.MediaPath = streamInfo.Path;+ state.InputProtocol = streamInfo.Protocol;await Task.Delay(1500, cancellationTokenSource.Token).ConfigureAwait(false);-- state.InputProtocol = GetProtocol(state.MediaPath);- AttachMediaStreamInfo(state, streamInfo.MediaStreams, state.VideoRequest, state.RequestedUrl);++ AttachMediaStreamInfo(state, streamInfo, state.VideoRequest, state.RequestedUrl);checkCodecs = true;}@@ -882,19 +875,12 @@ namespace MediaBrowser.Api.Playbackstate.LiveTvStreamId = streamInfo.Id;- if (!string.IsNullOrEmpty(streamInfo.Path))- {- state.MediaPath = streamInfo.Path;- }- else if (!string.IsNullOrEmpty(streamInfo.Url))- {- state.MediaPath = streamInfo.Url;- }+ state.MediaPath = streamInfo.Path;+ state.InputProtocol = streamInfo.Protocol;await Task.Delay(1500, cancellationTokenSource.Token).ConfigureAwait(false);- state.InputProtocol = GetProtocol(state.MediaPath);- AttachMediaStreamInfo(state, streamInfo.MediaStreams, state.VideoRequest, state.RequestedUrl);+ AttachMediaStreamInfo(state, streamInfo, state.VideoRequest, state.RequestedUrl);checkCodecs = true;}@@ -1006,7 +992,7 @@ namespace MediaBrowser.Api.Playbackawait Task.Delay(100, cancellationTokenSource.Token).ConfigureAwait(false);}- if (state.IsInputVideo && transcodingJob.Type == Api.TranscodingJobType.Progressive)+ if (state.IsInputVideo && transcodingJob.Type == TranscodingJobType.Progressive){await Task.Delay(1000, cancellationTokenSource.Token).ConfigureAwait(false);@@ -1712,6 +1698,23 @@ namespace MediaBrowser.Api.Playbackreturn state;}+ private void AttachMediaStreamInfo(StreamState state,+ ChannelMediaInfo mediaInfo,+ VideoStreamRequest videoRequest,+ string requestedUrl)+ {+ var mediaSource = mediaInfo.ToMediaSource();++ state.InputProtocol = mediaSource.Protocol;+ state.MediaPath = mediaSource.Path;+ state.RunTimeTicks = mediaSource.RunTimeTicks;+ state.RemoteHttpHeaders = mediaSource.RequiredHttpHeaders;+ state.InputBitrate = mediaSource.Bitrate;+ state.InputFileSize = mediaSource.Size;++ AttachMediaStreamInfo(state, mediaSource.MediaStreams, videoRequest, requestedUrl);+ }+private void AttachMediaStreamInfo(StreamState state,List<MediaStream> mediaStreams,VideoStreamRequest videoRequest,diff --git a/MediaBrowser.Api/Playback/Hls/MpegDashService.cs b/MediaBrowser.Api/Playback/Hls/MpegDashService.csindex 1150220158..baa6233809 100644--- a/MediaBrowser.Api/Playback/Hls/MpegDashService.cs+++ b/MediaBrowser.Api/Playback/Hls/MpegDashService.cs@@ -103,7 +103,9 @@ namespace MediaBrowser.Api.Playback.Hlsvar builder = new StringBuilder();- var duration = "PT0H02M11.00S";+ var time = TimeSpan.FromTicks(state.RunTimeTicks.Value);++ var duration = "PT" + time.Hours.ToString("00", UsCulture) + "H" + time.Minutes.ToString("00", UsCulture) + "M" + time.Seconds.ToString("00", UsCulture) + ".00S";builder.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");builder.AppendFormat(@@ -239,16 +241,17 @@ namespace MediaBrowser.Api.Playback.Hls{var seconds = TimeSpan.FromTicks(state.RunTimeTicks ?? 0).TotalSeconds;- builder.Append("<SegmentList timescale=\"1000\" duration=\"10000\">");-var queryStringIndex = Request.RawUrl.IndexOf('?');var queryString = queryStringIndex == -1 ? string.Empty : Request.RawUrl.Substring(queryStringIndex);var index = 0;+ builder.Append("<SegmentList timescale=\"1000\" duration=\"10000\">");while (seconds > 0){- builder.AppendFormat("<SegmentURL media=\"{0}.ts{1}\"/>", index.ToString(UsCulture), SecurityElement.Escape(queryString));+ var segmentUrl = string.Format("{0}.ts{1}", index.ToString(UsCulture), SecurityElement.Escape(queryString));++ builder.AppendFormat("<SegmentURL media=\"{0}\"/>", segmentUrl);seconds -= state.SegmentLength;index++;diff --git a/MediaBrowser.Controller/Channels/ChannelMediaInfo.cs b/MediaBrowser.Controller/Channels/ChannelMediaInfo.csindex f16fd11205..64a4f355c3 100644--- a/MediaBrowser.Controller/Channels/ChannelMediaInfo.cs+++ b/MediaBrowser.Controller/Channels/ChannelMediaInfo.cs@@ -1,6 +1,10 @@-using MediaBrowser.Model.MediaInfo;+using MediaBrowser.Common.Extensions;+using MediaBrowser.Model.Dto;+using MediaBrowser.Model.Entities;+using MediaBrowser.Model.MediaInfo;using System;using System.Collections.Generic;+using System.Linq;namespace MediaBrowser.Controller.Channels{@@ -31,6 +35,8 @@ namespace MediaBrowser.Controller.Channelspublic long? RunTimeTicks { get; set; }+ public string Id { get; set; }+public ChannelMediaInfo(){RequiredHttpHeaders = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);@@ -38,5 +44,67 @@ namespace MediaBrowser.Controller.Channels// This is most commonProtocol = MediaProtocol.Http;}++ public MediaSourceInfo ToMediaSource()+ {+ var id = Path.GetMD5().ToString("N");++ var source = new MediaSourceInfo+ {+ MediaStreams = GetMediaStreams(this).ToList(),++ Container = Container,+ Protocol = Protocol,+ Path = Path,+ RequiredHttpHeaders = RequiredHttpHeaders,+ RunTimeTicks = RunTimeTicks,+ Name = id,+ Id = id+ };++ var bitrate = (AudioBitrate ?? 0) + (VideoBitrate ?? 0);++ if (bitrate > 0)+ {+ source.Bitrate = bitrate;+ }++ return source;+ }++ private IEnumerable<MediaStream> GetMediaStreams(ChannelMediaInfo info)+ {+ var list = new List<MediaStream>();++ if (!string.IsNullOrWhiteSpace(info.VideoCodec) &&+ !string.IsNullOrWhiteSpace(info.AudioCodec))+ {+ list.Add(new MediaStream+ {+ Type = MediaStreamType.Video,+ Width = info.Width,+ RealFrameRate = info.Framerate,+ Profile = info.VideoProfile,+ Level = info.VideoLevel,+ Index = -1,+ Height = info.Height,+ Codec = info.VideoCodec,+ BitRate = info.VideoBitrate,+ AverageFrameRate = info.Framerate+ });++ list.Add(new MediaStream+ {+ Type = MediaStreamType.Audio,+ Index = -1,+ Codec = info.AudioCodec,+ BitRate = info.AudioBitrate,+ Channels = info.AudioChannels,+ SampleRate = info.AudioSampleRate+ });+ }++ return list;+ }}}\ No newline at end of filediff --git a/MediaBrowser.Controller/LiveTv/ILiveTvManager.cs b/MediaBrowser.Controller/LiveTv/ILiveTvManager.csindex 370ac2e756..fcd973ec29 100644--- a/MediaBrowser.Controller/LiveTv/ILiveTvManager.cs+++ b/MediaBrowser.Controller/LiveTv/ILiveTvManager.cs@@ -1,4 +1,5 @@-using MediaBrowser.Controller.Entities;+using MediaBrowser.Controller.Channels;+using MediaBrowser.Controller.Entities;using MediaBrowser.Model.Dto;using MediaBrowser.Model.LiveTv;using MediaBrowser.Model.Querying;@@ -154,7 +155,7 @@ namespace MediaBrowser.Controller.LiveTv/// <param name="id">The identifier.</param>/// <param name="cancellationToken">The cancellation token.</param>/// <returns>Task{Stream}.</returns>- Task<LiveStreamInfo> GetRecordingStream(string id, CancellationToken cancellationToken);+ Task<ChannelMediaInfo> GetRecordingStream(string id, CancellationToken cancellationToken);/// <summary>/// Gets the channel stream.@@ -162,7 +163,7 @@ namespace MediaBrowser.Controller.LiveTv/// <param name="id">The identifier.</param>/// <param name="cancellationToken">The cancellation token.</param>/// <returns>Task{StreamResponseInfo}.</returns>- Task<LiveStreamInfo> GetChannelStream(string id, CancellationToken cancellationToken);+ Task<ChannelMediaInfo> GetChannelStream(string id, CancellationToken cancellationToken);/// <summary>/// Gets the program.diff --git a/MediaBrowser.Controller/LiveTv/ILiveTvService.cs b/MediaBrowser.Controller/LiveTv/ILiveTvService.csindex 3abbe500fc..eda69b164e 100644--- a/MediaBrowser.Controller/LiveTv/ILiveTvService.cs+++ b/MediaBrowser.Controller/LiveTv/ILiveTvService.cs@@ -2,6 +2,7 @@using System.Collections.Generic;using System.Threading;using System.Threading.Tasks;+using MediaBrowser.Controller.Channels;namespace MediaBrowser.Controller.LiveTv{@@ -172,7 +173,7 @@ namespace MediaBrowser.Controller.LiveTv/// <param name="recordingId">The recording identifier.</param>/// <param name="cancellationToken">The cancellation token.</param>/// <returns>Task{Stream}.</returns>- Task<LiveStreamInfo> GetRecordingStream(string recordingId, CancellationToken cancellationToken);+ Task<ChannelMediaInfo> GetRecordingStream(string recordingId, CancellationToken cancellationToken);/// <summary>/// Gets the channel stream.@@ -180,7 +181,7 @@ namespace MediaBrowser.Controller.LiveTv/// <param name="channelId">The channel identifier.</param>/// <param name="cancellationToken">The cancellation token.</param>/// <returns>Task{Stream}.</returns>- Task<LiveStreamInfo> GetChannelStream(string channelId, CancellationToken cancellationToken);+ Task<ChannelMediaInfo> GetChannelStream(string channelId, CancellationToken cancellationToken);/// <summary>/// Closes the live stream.diff --git a/MediaBrowser.Controller/LiveTv/LiveStreamInfo.cs b/MediaBrowser.Controller/LiveTv/LiveStreamInfo.csdeleted file mode 100644index 019c9d31a5..0000000000--- a/MediaBrowser.Controller/LiveTv/LiveStreamInfo.cs+++ /dev/null@@ -1,43 +0,0 @@-using MediaBrowser.Model.Entities;-using System.Collections.Generic;--namespace MediaBrowser.Controller.LiveTv-{- public class LiveStreamInfo- {- /// <summary>- /// Gets or sets the path.- /// </summary>- /// <value>The path.</value>- public string Path { get; set; }-- /// <summary>- /// Gets or sets the URL.- /// </summary>- /// <value>The URL.</value>- public string Url { get; set; }-- /// <summary>- /// Gets or sets the identifier.- /// </summary>- /// <value>The identifier.</value>- public string Id { get; set; }-- /// <summary>- /// Gets or sets the media container.- /// </summary>- /// <value>The media container.</value>- public string MediaContainer { get; set; }-- /// <summary>- /// Gets or sets the media streams.- /// </summary>- /// <value>The media streams.</value>- public List<MediaStream> MediaStreams { get; set; }-- public LiveStreamInfo()- {- MediaStreams = new List<MediaStream>();- }- }-}diff --git a/MediaBrowser.Controller/MediaBrowser.Controller.csproj b/MediaBrowser.Controller/MediaBrowser.Controller.csprojindex 8ae605b629..7039a00eb2 100644--- a/MediaBrowser.Controller/MediaBrowser.Controller.csproj+++ b/MediaBrowser.Controller/MediaBrowser.Controller.csproj@@ -181,7 +181,6 @@<Compile Include="LiveTv\RecordingGroup.cs" /><Compile Include="LiveTv\RecordingStatusChangedEventArgs.cs" /><Compile Include="LiveTv\ILiveTvRecording.cs" />- <Compile Include="LiveTv\LiveStreamInfo.cs" /><Compile Include="LiveTv\LiveTvAudioRecording.cs" /><Compile Include="LiveTv\LiveTvChannel.cs" /><Compile Include="LiveTv\ChannelInfo.cs" />diff --git a/MediaBrowser.Model/Connect/ConnectAuthenticationResult.cs b/MediaBrowser.Model/Connect/ConnectAuthenticationResult.csindex 4dcbf69041..0df035e575 100644--- a/MediaBrowser.Model/Connect/ConnectAuthenticationResult.cs+++ b/MediaBrowser.Model/Connect/ConnectAuthenticationResult.cs@@ -4,10 +4,10 @@ namespace MediaBrowser.Model.Connectpublic class ConnectAuthenticationResult{/// <summary>- /// Gets or sets the user identifier.+ /// Gets or sets the user./// </summary>- /// <value>The user identifier.</value>- public string UserId { get; set; }+ /// <value>The user.</value>+ public ConnectUser User { get; set; }/// <summary>/// Gets or sets the access token./// </summary>diff --git a/MediaBrowser.Server.Implementations/Channels/ChannelManager.cs b/MediaBrowser.Server.Implementations/Channels/ChannelManager.csindex b9d2182150..f1075f77de 100644--- a/MediaBrowser.Server.Implementations/Channels/ChannelManager.cs+++ b/MediaBrowser.Server.Implementations/Channels/ChannelManager.cs@@ -359,71 +359,13 @@ namespace MediaBrowser.Server.Implementations.Channelsprivate MediaSourceInfo GetMediaSource(IChannelMediaItem item, ChannelMediaInfo info){- var id = info.Path.GetMD5().ToString("N");+ var source = info.ToMediaSource();- var source = new MediaSourceInfo- {- MediaStreams = GetMediaStreams(info).ToList(),-- Container = info.Container,- Protocol = info.Protocol,- Path = info.Path,- RequiredHttpHeaders = info.RequiredHttpHeaders,- RunTimeTicks = item.RunTimeTicks,- Name = id,- Id = id- };-- var bitrate = (info.AudioBitrate ?? 0) + (info.VideoBitrate ?? 0);-- if (bitrate > 0)- {- source.Bitrate = bitrate;- }-- if (item is ChannelVideoItem && info.Protocol != MediaProtocol.Rtmp)- {-- }+ source.RunTimeTicks = source.RunTimeTicks ?? item.RunTimeTicks;return source;}- private IEnumerable<MediaStream> GetMediaStreams(ChannelMediaInfo info)- {- var list = new List<MediaStream>();-- if (!string.IsNullOrWhiteSpace(info.VideoCodec) &&- !string.IsNullOrWhiteSpace(info.AudioCodec))- {- list.Add(new MediaStream- {- Type = MediaStreamType.Video,- Width = info.Width,- RealFrameRate = info.Framerate,- Profile = info.VideoProfile,- Level = info.VideoLevel,- Index = -1,- Height = info.Height,- Codec = info.VideoCodec,- BitRate = info.VideoBitrate,- AverageFrameRate = info.Framerate- });-- list.Add(new MediaStream- {- Type = MediaStreamType.Audio,- Index = -1,- Codec = info.AudioCodec,- BitRate = info.AudioBitrate,- Channels = info.AudioChannels,- SampleRate = info.AudioSampleRate- });- }-- return list;- }-private IEnumerable<ChannelMediaInfo> SortMediaInfoResults(IEnumerable<ChannelMediaInfo> channelMediaSources){var list = channelMediaSources.ToList();diff --git a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.csindex 64f7a3373f..23a2da4fd0 100644--- a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs+++ b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs@@ -2,6 +2,7 @@using MediaBrowser.Common.Extensions;using MediaBrowser.Common.IO;using MediaBrowser.Common.ScheduledTasks;+using MediaBrowser.Controller.Channels;using MediaBrowser.Controller.Configuration;using MediaBrowser.Controller.Drawing;using MediaBrowser.Controller.Dto;@@ -344,24 +345,24 @@ namespace MediaBrowser.Server.Implementations.LiveTvprivate readonly SemaphoreSlim _liveStreamSemaphore = new SemaphoreSlim(1, 1);- public async Task<LiveStreamInfo> GetRecordingStream(string id, CancellationToken cancellationToken)+ public async Task<ChannelMediaInfo> GetRecordingStream(string id, CancellationToken cancellationToken){return await GetLiveStream(id, false, cancellationToken).ConfigureAwait(false);}- public async Task<LiveStreamInfo> GetChannelStream(string id, CancellationToken cancellationToken)+ public async Task<ChannelMediaInfo> GetChannelStream(string id, CancellationToken cancellationToken){return await GetLiveStream(id, true, cancellationToken).ConfigureAwait(false);}- private async Task<LiveStreamInfo> GetLiveStream(string id, bool isChannel, CancellationToken cancellationToken)+ private async Task<ChannelMediaInfo> GetLiveStream(string id, bool isChannel, CancellationToken cancellationToken){await _liveStreamSemaphore.WaitAsync(cancellationToken).ConfigureAwait(false);try{var service = ActiveService;- LiveStreamInfo info;+ ChannelMediaInfo info;if (isChannel){@@ -406,55 +407,41 @@ namespace MediaBrowser.Server.Implementations.LiveTv}}- private void Sanitize(LiveStreamInfo info)+ private void Sanitize(ChannelMediaInfo info){// Clean some bad data coming from providers- foreach (var stream in info.MediaStreams)+ if (info.AudioBitrate.HasValue && info.AudioBitrate <= 0){- if (stream.BitDepth.HasValue && stream.BitDepth <= 0)- {- stream.BitDepth = null;- }- if (stream.BitRate.HasValue && stream.BitRate <= 0)- {- stream.BitRate = null;- }- if (stream.Channels.HasValue && stream.Channels <= 0)- {- stream.Channels = null;- }- if (stream.AverageFrameRate.HasValue && stream.AverageFrameRate <= 0)- {- stream.AverageFrameRate = null;- }- if (stream.RealFrameRate.HasValue && stream.RealFrameRate <= 0)- {- stream.RealFrameRate = null;- }- if (stream.Width.HasValue && stream.Width <= 0)- {- stream.Width = null;- }- if (stream.Height.HasValue && stream.Height <= 0)- {- stream.Height = null;- }- if (stream.SampleRate.HasValue && stream.SampleRate <= 0)- {- stream.SampleRate = null;- }- if (stream.Level.HasValue && stream.Level <= 0)- {- stream.Level = null;- }- if (stream.PacketLength.HasValue && stream.PacketLength <= 0)- {- stream.PacketLength = null;- }-- // Don't trust the provider values- stream.Index = -1;+ info.AudioBitrate = null;+ }+ if (info.VideoBitrate.HasValue && info.VideoBitrate <= 0)+ {+ info.VideoBitrate = null;+ }+ if (info.AudioChannels.HasValue && info.AudioChannels <= 0)+ {+ info.AudioChannels = null;+ }+ if (info.Framerate.HasValue && info.Framerate <= 0)+ {+ info.Framerate = null;+ }+ if (info.Width.HasValue && info.Width <= 0)+ {+ info.Width = null;+ }+ if (info.Height.HasValue && info.Height <= 0)+ {+ info.Height = null;+ }+ if (info.AudioSampleRate.HasValue && info.AudioSampleRate <= 0)+ {+ info.AudioSampleRate = null;+ }+ if (info.VideoLevel.HasValue && info.VideoLevel <= 0)+ {+ info.VideoLevel = null;}}@@ -1702,7 +1689,7 @@ namespace MediaBrowser.Server.Implementations.LiveTvclass LiveStreamData{- internal LiveStreamInfo Info;+ internal ChannelMediaInfo Info;internal int ConsumerCount;internal string ItemId;internal bool IsChannel;diff --git a/Nuget/MediaBrowser.Common.Internal.nuspec b/Nuget/MediaBrowser.Common.Internal.nuspecindex 6f280c45af..a776cd0599 100644--- a/Nuget/MediaBrowser.Common.Internal.nuspec+++ b/Nuget/MediaBrowser.Common.Internal.nuspec@@ -2,7 +2,7 @@<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd"><metadata><id>MediaBrowser.Common.Internal</id>- <version>3.0.484</version>+ <version>3.0.486</version><title>MediaBrowser.Common.Internal</title><authors>Luke</authors><owners>ebr,Luke,scottisafool</owners>@@ -12,7 +12,7 @@<description>Contains common components shared by Media Browser Theater and Media Browser Server. Not intended for plugin developer consumption.</description><copyright>Copyright © Media Browser 2013</copyright><dependencies>- <dependency id="MediaBrowser.Common" version="3.0.484" />+ <dependency id="MediaBrowser.Common" version="3.0.486" /><dependency id="NLog" version="3.1.0.0" /><dependency id="SimpleInjector" version="2.5.2" /><dependency id="sharpcompress" version="0.10.2" />diff --git a/Nuget/MediaBrowser.Common.nuspec b/Nuget/MediaBrowser.Common.nuspecindex 95197afc68..faeb5b0cf1 100644--- a/Nuget/MediaBrowser.Common.nuspec+++ b/Nuget/MediaBrowser.Common.nuspec@@ -2,7 +2,7 @@<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd"><metadata><id>MediaBrowser.Common</id>- <version>3.0.484</version>+ <version>3.0.486</version><title>MediaBrowser.Common</title><authors>Media Browser Team</authors><owners>ebr,Luke,scottisafool</owners>diff --git a/Nuget/MediaBrowser.Model.Signed.nuspec b/Nuget/MediaBrowser.Model.Signed.nuspecindex 4264b28500..b73d4a80f7 100644--- a/Nuget/MediaBrowser.Model.Signed.nuspec+++ b/Nuget/MediaBrowser.Model.Signed.nuspec@@ -2,7 +2,7 @@<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd"><metadata><id>MediaBrowser.Model.Signed</id>- <version>3.0.484</version>+ <version>3.0.486</version><title>MediaBrowser.Model - Signed Edition</title><authors>Media Browser Team</authors><owners>ebr,Luke,scottisafool</owners>diff --git a/Nuget/MediaBrowser.Server.Core.nuspec b/Nuget/MediaBrowser.Server.Core.nuspecindex 2820c4f9d3..fa1a9aa62e 100644--- a/Nuget/MediaBrowser.Server.Core.nuspec+++ b/Nuget/MediaBrowser.Server.Core.nuspec@@ -2,7 +2,7 @@<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd"><metadata><id>MediaBrowser.Server.Core</id>- <version>3.0.484</version>+ <version>3.0.486</version><title>Media Browser.Server.Core</title><authors>Media Browser Team</authors><owners>ebr,Luke,scottisafool</owners>@@ -12,7 +12,7 @@<description>Contains core components required to build plugins for Media Browser Server.</description><copyright>Copyright © Media Browser 2013</copyright><dependencies>- <dependency id="MediaBrowser.Common" version="3.0.484" />+ <dependency id="MediaBrowser.Common" version="3.0.486" /></dependencies></metadata><files>