The Free Software Media System - Server Backend & API
re-org scripts
Luke Pulverentiad52df6be098
diff --git a/MediaBrowser.Api/ApiEntryPoint.cs b/MediaBrowser.Api/ApiEntryPoint.csindex a21fc22fe3..a6958b95d3 100644--- a/MediaBrowser.Api/ApiEntryPoint.cs+++ b/MediaBrowser.Api/ApiEntryPoint.cs@@ -274,32 +274,37 @@ namespace MediaBrowser.Apireturn null;}- job.ActiveRequestCount++;-- job.DisposeKillTimer();+ OnTranscodeBeginRequest(job);return job;}}+ public void OnTranscodeBeginRequest(TranscodingJob job)+ {+ job.ActiveRequestCount++;++ job.DisposeKillTimer();+ }+public void OnTranscodeEndRequest(TranscodingJob job){job.ActiveRequestCount--;if (job.ActiveRequestCount == 0){- if (job.Type == TranscodingJobType.Progressive)- {- const int timerDuration = 1000;+ // TODO: Lower this hls timeout+ var timerDuration = job.Type == TranscodingJobType.Progressive ?+ 1000 :+ 14400000;- if (job.KillTimer == null)- {- job.KillTimer = new Timer(OnTranscodeKillTimerStopped, job, timerDuration, Timeout.Infinite);- }- else- {- job.KillTimer.Change(timerDuration, Timeout.Infinite);- }+ if (job.KillTimer == null)+ {+ job.KillTimer = new Timer(OnTranscodeKillTimerStopped, job, timerDuration, Timeout.Infinite);+ }+ else+ {+ job.KillTimer.Change(timerDuration, Timeout.Infinite);}}}@@ -498,7 +503,7 @@ namespace MediaBrowser.Api.ToList();Exception e = null;-+foreach (var file in filesToDelete){trydiff --git a/MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs b/MediaBrowser.Api/Playback/Hls/DynamicHlsService.csindex c9ae6669b6..48523e2556 100644--- a/MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs+++ b/MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs@@ -114,7 +114,7 @@ namespace MediaBrowser.Api.Playback.Hlsif (File.Exists(segmentPath)){- job = ApiEntryPoint.Instance.GetTranscodingJob(playlistPath, TranscodingJobType);+ job = ApiEntryPoint.Instance.OnTranscodeBeginRequest(playlistPath, TranscodingJobType);return await GetSegmentResult(playlistPath, segmentPath, requestedIndex, segmentLength, job, cancellationToken).ConfigureAwait(false);}@@ -123,7 +123,7 @@ namespace MediaBrowser.Api.Playback.Hls{if (File.Exists(segmentPath)){- job = ApiEntryPoint.Instance.GetTranscodingJob(playlistPath, TranscodingJobType);+ job = ApiEntryPoint.Instance.OnTranscodeBeginRequest(playlistPath, TranscodingJobType);return await GetSegmentResult(playlistPath, segmentPath, requestedIndex, segmentLength, job, cancellationToken).ConfigureAwait(false);}else@@ -145,6 +145,7 @@ namespace MediaBrowser.Api.Playback.Hlsrequest.StartTimeTicks = GetSeekPositionTicks(state, requestedIndex);job = await StartFfMpeg(state, playlistPath, cancellationTokenSource).ConfigureAwait(false);+ ApiEntryPoint.Instance.OnTranscodeBeginRequest(job);}catch{@@ -168,7 +169,7 @@ namespace MediaBrowser.Api.Playback.Hls}Logger.Info("returning {0}", segmentPath);- job = job ?? ApiEntryPoint.Instance.GetTranscodingJob(playlistPath, TranscodingJobType);+ job = job ?? ApiEntryPoint.Instance.OnTranscodeBeginRequest(playlistPath, TranscodingJobType);return await GetSegmentResult(playlistPath, segmentPath, requestedIndex, segmentLength, job, cancellationToken).ConfigureAwait(false);}@@ -368,8 +369,8 @@ namespace MediaBrowser.Api.Playback.Hlsif (transcodingJob != null){transcodingJob.DownloadPositionTicks = Math.Max(transcodingJob.DownloadPositionTicks ?? segmentEndingPositionTicks, segmentEndingPositionTicks);+ ApiEntryPoint.Instance.OnTranscodeEndRequest(transcodingJob);}-}});}diff --git a/MediaBrowser.Api/Playback/Hls/HlsSegmentService.cs b/MediaBrowser.Api/Playback/Hls/HlsSegmentService.csindex da4ffb55dc..1fe0661d9f 100644--- a/MediaBrowser.Api/Playback/Hls/HlsSegmentService.cs+++ b/MediaBrowser.Api/Playback/Hls/HlsSegmentService.cs@@ -1,6 +1,10 @@using MediaBrowser.Controller;+using MediaBrowser.Controller.Configuration;+using MediaBrowser.Controller.Net;using ServiceStack;+using System;using System.IO;+using System.Linq;namespace MediaBrowser.Api.Playback.Hls{@@ -32,6 +36,8 @@ namespace MediaBrowser.Api.Playback.Hls[Api(Description = "Gets an Http live streaming segment file. Internal use only.")]public class GetHlsPlaylist{+ // TODO: Deprecate with new iOS app+/// <summary>/// Gets or sets the id./// </summary>@@ -52,22 +58,39 @@ namespace MediaBrowser.Api.Playback.Hlspublic string StreamId { get; set; }}+ /// <summary>+ /// Class GetHlsVideoSegment+ /// </summary>+ [Route("/Videos/{Id}/hls/{PlaylistId}/{SegmentId}.ts", "GET")]+ [Api(Description = "Gets an Http live streaming segment file. Internal use only.")]+ public class GetHlsVideoSegment : VideoStreamRequest+ {+ public string PlaylistId { get; set; }++ /// <summary>+ /// Gets or sets the segment id.+ /// </summary>+ /// <value>The segment id.</value>+ public string SegmentId { get; set; }+ }+public class HlsSegmentService : BaseApiService{private readonly IServerApplicationPaths _appPaths;+ private readonly IServerConfigurationManager _config;- public HlsSegmentService(IServerApplicationPaths appPaths)+ public HlsSegmentService(IServerApplicationPaths appPaths, IServerConfigurationManager config){_appPaths = appPaths;+ _config = config;}public object Get(GetHlsPlaylist request){var file = request.PlaylistId + Path.GetExtension(Request.PathInfo);-file = Path.Combine(_appPaths.TranscodingTempPath, file);- return ResultFactory.GetStaticFileResult(Request, file, FileShare.ReadWrite);+ return GetFileResult(file, file);}public void Delete(StopEncodingProcess request)@@ -80,13 +103,49 @@ namespace MediaBrowser.Api.Playback.Hls/// </summary>/// <param name="request">The request.</param>/// <returns>System.Object.</returns>- public object Get(GetHlsAudioSegment request)+ public object Get(GetHlsVideoSegment request){var file = request.SegmentId + Path.GetExtension(Request.PathInfo);+ file = Path.Combine(_config.ApplicationPaths.TranscodingTempPath, file);++ var normalizedPlaylistId = request.PlaylistId.Replace("-low", string.Empty);++ var playlistPath = Directory.EnumerateFiles(_config.ApplicationPaths.TranscodingTempPath, "*")+ .FirstOrDefault(i => string.Equals(Path.GetExtension(i), ".m3u8", StringComparison.OrdinalIgnoreCase) && i.IndexOf(normalizedPlaylistId, StringComparison.OrdinalIgnoreCase) != -1);++ return GetFileResult(file, playlistPath);+ }+ /// <summary>+ /// Gets the specified request.+ /// </summary>+ /// <param name="request">The request.</param>+ /// <returns>System.Object.</returns>+ public object Get(GetHlsAudioSegment request)+ {+ // TODO: Deprecate with new iOS app+ var file = request.SegmentId + Path.GetExtension(Request.PathInfo);file = Path.Combine(_appPaths.TranscodingTempPath, file);return ResultFactory.GetStaticFileResult(Request, file, FileShare.ReadWrite);}++ private object GetFileResult(string path, string playlistPath)+ {+ var transcodingJob = ApiEntryPoint.Instance.OnTranscodeBeginRequest(playlistPath, TranscodingJobType.Hls);++ return ResultFactory.GetStaticFileResult(Request, new StaticFileResultOptions+ {+ Path = path,+ FileShare = FileShare.ReadWrite,+ OnComplete = () =>+ {+ if (transcodingJob != null)+ {+ ApiEntryPoint.Instance.OnTranscodeEndRequest(transcodingJob);+ }+ }+ });+ }}}diff --git a/MediaBrowser.Api/Playback/Hls/VideoHlsService.cs b/MediaBrowser.Api/Playback/Hls/VideoHlsService.csindex 69e86777b3..e1baf8c121 100644--- a/MediaBrowser.Api/Playback/Hls/VideoHlsService.cs+++ b/MediaBrowser.Api/Playback/Hls/VideoHlsService.cs@@ -19,6 +19,8 @@ namespace MediaBrowser.Api.Playback.Hls[Api(Description = "Gets a video stream using HTTP live streaming.")]public class GetHlsVideoStream : VideoStreamRequest{+ // TODO: Deprecate with new iOS app+[ApiMember(Name = "BaselineStreamAudioBitRate", Description = "Optional. Specify the audio bitrate for the baseline stream.", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")]public int? BaselineStreamAudioBitRate { get; set; }@@ -35,22 +37,6 @@ namespace MediaBrowser.Api.Playback.Hls{}- /// <summary>- /// Class GetHlsVideoSegment- /// </summary>- [Route("/Videos/{Id}/hls/{PlaylistId}/{SegmentId}.ts", "GET")]- [Api(Description = "Gets an Http live streaming segment file. Internal use only.")]- public class GetHlsVideoSegment : VideoStreamRequest- {- public string PlaylistId { get; set; }-- /// <summary>- /// Gets or sets the segment id.- /// </summary>- /// <value>The segment id.</value>- public string SegmentId { get; set; }- }-/// <summary>/// Class VideoHlsService/// </summary>@@ -60,20 +46,6 @@ namespace MediaBrowser.Api.Playback.Hls{}- /// <summary>- /// Gets the specified request.- /// </summary>- /// <param name="request">The request.</param>- /// <returns>System.Object.</returns>- public object Get(GetHlsVideoSegment request)- {- var file = request.SegmentId + Path.GetExtension(Request.PathInfo);-- file = Path.Combine(ServerConfigurationManager.ApplicationPaths.TranscodingTempPath, file);-- return ResultFactory.GetStaticFileResult(Request, file);- }-/// <summary>/// Gets the specified request./// </summary>diff --git a/MediaBrowser.WebDashboard/Api/PackageCreator.cs b/MediaBrowser.WebDashboard/Api/PackageCreator.csindex 4262a314dc..0a995a8455 100644--- a/MediaBrowser.WebDashboard/Api/PackageCreator.cs+++ b/MediaBrowser.WebDashboard/Api/PackageCreator.cs@@ -288,7 +288,7 @@ namespace MediaBrowser.WebDashboard.Api"thirdparty/apiclient/ajax.js","thirdparty/apiclient/events.js","thirdparty/apiclient/deferred.js",- "thirdparty/apiclient/mediabrowser.apiclient.js",+ "thirdparty/apiclient/apiclient.js","thirdparty/apiclient/connectservice.js","thirdparty/apiclient/serverdiscovery.js","thirdparty/apiclient/connectionmanager.js"diff --git a/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj b/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csprojindex d8ab31551d..4dcc0c6a2e 100644--- a/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj+++ b/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj@@ -190,7 +190,7 @@<Content Include="dashboard-ui\thirdparty\apiclient\deferred.js"><CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory></Content>- <Content Include="dashboard-ui\thirdparty\apiclient\deferredAlt.js">+ <Content Include="dashboard-ui\thirdparty\apiclient\alt\deferred.js"><CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory></Content><Content Include="dashboard-ui\thirdparty\apiclient\device.js">@@ -202,7 +202,7 @@<Content Include="dashboard-ui\thirdparty\apiclient\logger.js"><CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory></Content>- <Content Include="dashboard-ui\thirdparty\apiclient\mediabrowser.apiclient.js">+ <Content Include="dashboard-ui\thirdparty\apiclient\apiclient.js"><CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory></Content><Content Include="dashboard-ui\channelitems.html">