From fdca3bd9c407aab9b22b6d09b6f393fa49be4f3d Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Mon, 13 Jan 2014 00:41:00 -0500 Subject: [PATCH] live tv updates --- .../AuthorizationRequestFilterAttribute.cs | 1 - MediaBrowser.Api/BaseApiService.cs | 1 - MediaBrowser.Api/MediaBrowser.Api.csproj | 1 - .../Playback/Hls/HlsSegmentResponseFilter.cs | 53 --------------- .../Playback/Hls/HlsSegmentService.cs | 38 ----------- .../Playback/Hls/VideoHlsService.cs | 65 +++++++++++++++++++ .../LiveTv/RecordingInfo.cs | 6 ++ MediaBrowser.Model/LiveTv/RecordingInfoDto.cs | 6 ++ .../LiveTv/LiveTvDtoService.cs | 3 +- .../MediaEncoder/MediaEncoder.cs | 6 +- 10 files changed, 80 insertions(+), 100 deletions(-) delete mode 100644 MediaBrowser.Api/Playback/Hls/HlsSegmentResponseFilter.cs diff --git a/MediaBrowser.Api/AuthorizationRequestFilterAttribute.cs b/MediaBrowser.Api/AuthorizationRequestFilterAttribute.cs index 8f9babd06a..82df791ded 100644 --- a/MediaBrowser.Api/AuthorizationRequestFilterAttribute.cs +++ b/MediaBrowser.Api/AuthorizationRequestFilterAttribute.cs @@ -5,7 +5,6 @@ using MediaBrowser.Model.Logging; using ServiceStack.Web; using System; using System.Collections.Generic; -using System.Net.Http.Headers; namespace MediaBrowser.Api { diff --git a/MediaBrowser.Api/BaseApiService.cs b/MediaBrowser.Api/BaseApiService.cs index 8febe4a65d..556f3b57d5 100644 --- a/MediaBrowser.Api/BaseApiService.cs +++ b/MediaBrowser.Api/BaseApiService.cs @@ -6,7 +6,6 @@ using MediaBrowser.Model.Logging; using ServiceStack.Web; using System; using System.Collections.Generic; -using System.IO; using System.Linq; namespace MediaBrowser.Api diff --git a/MediaBrowser.Api/MediaBrowser.Api.csproj b/MediaBrowser.Api/MediaBrowser.Api.csproj index 409d152f79..a04aca2a03 100644 --- a/MediaBrowser.Api/MediaBrowser.Api.csproj +++ b/MediaBrowser.Api/MediaBrowser.Api.csproj @@ -99,7 +99,6 @@ - diff --git a/MediaBrowser.Api/Playback/Hls/HlsSegmentResponseFilter.cs b/MediaBrowser.Api/Playback/Hls/HlsSegmentResponseFilter.cs deleted file mode 100644 index 10ea6bc639..0000000000 --- a/MediaBrowser.Api/Playback/Hls/HlsSegmentResponseFilter.cs +++ /dev/null @@ -1,53 +0,0 @@ -using MediaBrowser.Controller; -using MediaBrowser.Model.Logging; -using ServiceStack.Text.Controller; -using ServiceStack.Web; -using System; -using System.IO; -using System.Linq; - -namespace MediaBrowser.Api.Playback.Hls -{ - public class HlsSegmentResponseFilter : Attribute, IHasResponseFilter - { - public ILogger Logger { get; set; } - public IServerApplicationPaths ApplicationPaths { get; set; } - - public void ResponseFilter(IRequest req, IResponse res, object response) - { - var pathInfo = PathInfo.Parse(req.PathInfo); - var itemId = pathInfo.GetArgumentValue(1); - var playlistId = pathInfo.GetArgumentValue(3); - - OnEndRequest(itemId, playlistId); - } - - public IHasResponseFilter Copy() - { - return this; - } - - public int Priority - { - get { return -1; } - } - - /// - /// Called when [end request]. - /// - /// The item id. - /// The playlist id. - protected void OnEndRequest(string itemId, string playlistId) - { - Logger.Info("OnEndRequest " + playlistId); - var normalizedPlaylistId = playlistId.Replace("-low", string.Empty); - - foreach (var playlist in Directory.EnumerateFiles(ApplicationPaths.TranscodingTempPath, "*.m3u8") - .Where(i => i.IndexOf(normalizedPlaylistId, StringComparison.OrdinalIgnoreCase) != -1) - .ToList()) - { - ApiEntryPoint.Instance.OnTranscodeEndRequest(playlist, TranscodingJobType.Hls); - } - } - } -} diff --git a/MediaBrowser.Api/Playback/Hls/HlsSegmentService.cs b/MediaBrowser.Api/Playback/Hls/HlsSegmentService.cs index 31583ac197..5d2dd07c7e 100644 --- a/MediaBrowser.Api/Playback/Hls/HlsSegmentService.cs +++ b/MediaBrowser.Api/Playback/Hls/HlsSegmentService.cs @@ -28,28 +28,6 @@ namespace MediaBrowser.Api.Playback.Hls public string SegmentId { get; set; } } - /// - /// Class GetHlsVideoSegment - /// - [Route("/Videos/{Id}/hls/{PlaylistId}/{SegmentId}.ts", "GET")] - [Api(Description = "Gets an Http live streaming segment file. Internal use only.")] - public class GetHlsVideoSegment - { - /// - /// Gets or sets the id. - /// - /// The id. - public string Id { get; set; } - - public string PlaylistId { get; set; } - - /// - /// Gets or sets the segment id. - /// - /// The segment id. - public string SegmentId { get; set; } - } - /// /// Class GetHlsVideoSegment /// @@ -99,22 +77,6 @@ namespace MediaBrowser.Api.Playback.Hls ApiEntryPoint.Instance.KillTranscodingJobs(request.DeviceId, true); } - /// - /// Gets the specified request. - /// - /// The request. - /// System.Object. - public object Get(GetHlsVideoSegment request) - { - var file = request.SegmentId + Path.GetExtension(Request.PathInfo); - - file = Path.Combine(_appPaths.TranscodingTempPath, file); - - OnBeginRequest(request.PlaylistId); - - return ResultFactory.GetStaticFileResult(Request, file); - } - /// /// Gets the specified request. /// diff --git a/MediaBrowser.Api/Playback/Hls/VideoHlsService.cs b/MediaBrowser.Api/Playback/Hls/VideoHlsService.cs index fae9e26c62..174cbe9ba0 100644 --- a/MediaBrowser.Api/Playback/Hls/VideoHlsService.cs +++ b/MediaBrowser.Api/Playback/Hls/VideoHlsService.cs @@ -10,6 +10,8 @@ using MediaBrowser.Model.IO; using ServiceStack; using System; using System.Collections.Generic; +using System.IO; +using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; @@ -56,6 +58,28 @@ namespace MediaBrowser.Api.Playback.Hls { } + /// + /// Class GetHlsVideoSegment + /// + [Route("/Videos/{Id}/hls/{PlaylistId}/{SegmentId}.ts", "GET")] + [Api(Description = "Gets an Http live streaming segment file. Internal use only.")] + public class GetHlsVideoSegment + { + /// + /// Gets or sets the id. + /// + /// The id. + public string Id { get; set; } + + public string PlaylistId { get; set; } + + /// + /// Gets or sets the segment id. + /// + /// The segment id. + public string SegmentId { get; set; } + } + /// /// Class VideoHlsService /// @@ -87,6 +111,22 @@ namespace MediaBrowser.Api.Playback.Hls return result; } + /// + /// Gets the specified request. + /// + /// The request. + /// System.Object. + public object Get(GetHlsVideoSegment request) + { + var file = request.SegmentId + Path.GetExtension(Request.PathInfo); + + file = Path.Combine(ServerConfigurationManager.ApplicationPaths.TranscodingTempPath, file); + + OnBeginRequest(request.PlaylistId); + + return ResultFactory.GetStaticFileResult(Request, file); + } + private async Task GetPlaylistAsync(VideoStreamRequest request, string name) { var state = await GetState(request, CancellationToken.None).ConfigureAwait(false); @@ -313,5 +353,30 @@ namespace MediaBrowser.Api.Playback.Hls { return ".ts"; } + + /// + /// Called when [begin request]. + /// + /// The playlist id. + protected void OnBeginRequest(string playlistId) + { + var normalizedPlaylistId = playlistId.Replace("-low", string.Empty); + + foreach (var playlist in Directory.EnumerateFiles(ServerConfigurationManager.ApplicationPaths.TranscodingTempPath, "*.m3u8") + .Where(i => i.IndexOf(normalizedPlaylistId, StringComparison.OrdinalIgnoreCase) != -1) + .ToList()) + { + ExtendPlaylistTimer(playlist); + } + } + + private async void ExtendPlaylistTimer(string playlist) + { + ApiEntryPoint.Instance.OnTranscodeBeginRequest(playlist, TranscodingJobType.Hls); + + await Task.Delay(20000).ConfigureAwait(false); + + ApiEntryPoint.Instance.OnTranscodeEndRequest(playlist, TranscodingJobType.Hls); + } } } diff --git a/MediaBrowser.Controller/LiveTv/RecordingInfo.cs b/MediaBrowser.Controller/LiveTv/RecordingInfo.cs index 6a0d135c83..bf453ccf4d 100644 --- a/MediaBrowser.Controller/LiveTv/RecordingInfo.cs +++ b/MediaBrowser.Controller/LiveTv/RecordingInfo.cs @@ -102,6 +102,12 @@ namespace MediaBrowser.Controller.LiveTv /// The audio. public ProgramAudio? Audio { get; set; } + /// + /// Gets or sets the original air date. + /// + /// The original air date. + public DateTime? OriginalAirDate { get; set; } + /// /// Gets or sets a value indicating whether this instance is movie. /// diff --git a/MediaBrowser.Model/LiveTv/RecordingInfoDto.cs b/MediaBrowser.Model/LiveTv/RecordingInfoDto.cs index 0ef5c9dc01..389df2248f 100644 --- a/MediaBrowser.Model/LiveTv/RecordingInfoDto.cs +++ b/MediaBrowser.Model/LiveTv/RecordingInfoDto.cs @@ -90,6 +90,12 @@ namespace MediaBrowser.Model.LiveTv /// public DateTime EndDate { get; set; } + /// + /// Gets or sets the original air date. + /// + /// The original air date. + public DateTime? OriginalAirDate { get; set; } + /// /// Gets or sets the status. /// diff --git a/MediaBrowser.Server.Implementations/LiveTv/LiveTvDtoService.cs b/MediaBrowser.Server.Implementations/LiveTv/LiveTvDtoService.cs index c042e7750d..ad9f769eb1 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/LiveTvDtoService.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/LiveTvDtoService.cs @@ -161,7 +161,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv return null; } - return val.Value * 2; + return val.Value; } public string GetStatusName(RecordingStatus status) @@ -222,6 +222,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv IsPremiere = info.IsPremiere, RunTimeTicks = (info.EndDate - info.StartDate).Ticks, LocationType = recording.LocationType, + OriginalAirDate = info.OriginalAirDate, MediaStreams = _itemRepo.GetMediaStreams(new MediaStreamQuery { diff --git a/MediaBrowser.Server.Implementations/MediaEncoder/MediaEncoder.cs b/MediaBrowser.Server.Implementations/MediaEncoder/MediaEncoder.cs index 6f956ba207..b09ff623e7 100644 --- a/MediaBrowser.Server.Implementations/MediaEncoder/MediaEncoder.cs +++ b/MediaBrowser.Server.Implementations/MediaEncoder/MediaEncoder.cs @@ -249,11 +249,7 @@ namespace MediaBrowser.Server.Implementations.MediaEncoder { process.Kill(); } - catch (InvalidOperationException ex1) - { - _logger.ErrorException("Error killing ffprobe", ex1); - } - catch (Win32Exception ex1) + catch (Exception ex1) { _logger.ErrorException("Error killing ffprobe", ex1); }