From 60508e1dd8a25be58dea308e5f48ff0c596f97c8 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sat, 11 Jan 2014 22:29:47 -0500 Subject: reverting http result factory change --- .../HttpServer/HttpResultFactory.cs | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) (limited to 'MediaBrowser.Server.Implementations') diff --git a/MediaBrowser.Server.Implementations/HttpServer/HttpResultFactory.cs b/MediaBrowser.Server.Implementations/HttpServer/HttpResultFactory.cs index 2419320a5..9359261c5 100644 --- a/MediaBrowser.Server.Implementations/HttpServer/HttpResultFactory.cs +++ b/MediaBrowser.Server.Implementations/HttpServer/HttpResultFactory.cs @@ -360,19 +360,11 @@ namespace MediaBrowser.Server.Implementations.HttpServer var compress = ShouldCompressResponse(requestContext, contentType); - var hasOptions = GetStaticResult(requestContext, responseHeaders, contentType, factoryFn, compress, isHeadRequest); + var hasOptions = GetStaticResult(requestContext, responseHeaders, contentType, factoryFn, compress, isHeadRequest).Result; - return GetStaticResultTask(hasOptions, responseHeaders); - } - - private async Task GetStaticResultTask(Task optionsTask, - IEnumerable> responseHeaders) - { - var options = await optionsTask.ConfigureAwait(false); - - AddResponseHeaders(options, responseHeaders); + AddResponseHeaders(hasOptions, responseHeaders); - return options; + return hasOptions; } /// @@ -670,4 +662,4 @@ namespace MediaBrowser.Server.Implementations.HttpServer throw error; } } -} +} \ No newline at end of file -- cgit v1.2.3 From c8a106f485ff7e340ee8ca67adac3351ec6a31b6 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 12 Jan 2014 01:31:21 -0500 Subject: move media encoder to server project --- MediaBrowser.Api/Playback/BaseStreamingService.cs | 3 +- MediaBrowser.Api/Playback/Hls/AudioHlsService.cs | 2 +- MediaBrowser.Api/Playback/Hls/BaseHlsService.cs | 2 +- MediaBrowser.Api/Playback/Hls/VideoHlsService.cs | 2 +- .../Playback/Progressive/AudioService.cs | 2 +- .../Progressive/BaseProgressiveStreamingService.cs | 2 +- .../Playback/Progressive/VideoService.cs | 2 +- MediaBrowser.Common/MediaBrowser.Common.csproj | 2 - MediaBrowser.Common/MediaInfo/IMediaEncoder.cs | 109 -------- MediaBrowser.Common/MediaInfo/MediaInfoResult.cs | 311 --------------------- MediaBrowser.Controller/Entities/Audio/Audio.cs | 2 +- MediaBrowser.Controller/LiveTv/ILiveTvManager.cs | 3 +- .../MediaBrowser.Controller.csproj | 2 + MediaBrowser.Controller/MediaInfo/FFMpegManager.cs | 3 +- MediaBrowser.Controller/MediaInfo/IMediaEncoder.cs | 106 +++++++ .../MediaInfo/InternalMediaInfoResult.cs | 311 +++++++++++++++++++++ .../MediaInfo/MediaEncoderHelpers.cs | 21 +- MediaBrowser.Model/Entities/MediaStream.cs | 23 +- .../MediaInfo/AudioImageProvider.cs | 4 +- .../MediaInfo/BaseFFProbeProvider.cs | 9 +- .../MediaInfo/FFProbeAudioInfoProvider.cs | 5 +- .../MediaInfo/FFProbeVideoInfoProvider.cs | 7 +- .../MediaInfo/VideoImageProvider.cs | 3 +- .../LiveTv/LiveTvDtoService.cs | 2 +- .../LiveTv/LiveTvManager.cs | 62 +++- .../MediaEncoder/MediaEncoder.cs | 24 +- MediaBrowser.ServerApplication/ApplicationHost.cs | 7 +- 27 files changed, 551 insertions(+), 480 deletions(-) delete mode 100644 MediaBrowser.Common/MediaInfo/IMediaEncoder.cs delete mode 100644 MediaBrowser.Common/MediaInfo/MediaInfoResult.cs create mode 100644 MediaBrowser.Controller/MediaInfo/IMediaEncoder.cs create mode 100644 MediaBrowser.Controller/MediaInfo/InternalMediaInfoResult.cs (limited to 'MediaBrowser.Server.Implementations') diff --git a/MediaBrowser.Api/Playback/BaseStreamingService.cs b/MediaBrowser.Api/Playback/BaseStreamingService.cs index d9bd873cd..59fac5726 100644 --- a/MediaBrowser.Api/Playback/BaseStreamingService.cs +++ b/MediaBrowser.Api/Playback/BaseStreamingService.cs @@ -1,6 +1,5 @@ using MediaBrowser.Common.Extensions; using MediaBrowser.Common.IO; -using MediaBrowser.Common.MediaInfo; using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Dto; using MediaBrowser.Controller.Entities; @@ -733,7 +732,7 @@ namespace MediaBrowser.Api.Playback return "-"; } - var type = InputType.AudioFile; + var type = InputType.File; var inputPath = new[] { state.MediaPath }; diff --git a/MediaBrowser.Api/Playback/Hls/AudioHlsService.cs b/MediaBrowser.Api/Playback/Hls/AudioHlsService.cs index d5bf22362..a64cdb119 100644 --- a/MediaBrowser.Api/Playback/Hls/AudioHlsService.cs +++ b/MediaBrowser.Api/Playback/Hls/AudioHlsService.cs @@ -1,9 +1,9 @@ using MediaBrowser.Common.IO; -using MediaBrowser.Common.MediaInfo; using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Dto; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.LiveTv; +using MediaBrowser.Controller.MediaInfo; using MediaBrowser.Controller.Persistence; using MediaBrowser.Model.Dto; using MediaBrowser.Model.IO; diff --git a/MediaBrowser.Api/Playback/Hls/BaseHlsService.cs b/MediaBrowser.Api/Playback/Hls/BaseHlsService.cs index 8ac8dc9fc..1c4326928 100644 --- a/MediaBrowser.Api/Playback/Hls/BaseHlsService.cs +++ b/MediaBrowser.Api/Playback/Hls/BaseHlsService.cs @@ -1,11 +1,11 @@ using MediaBrowser.Common.Extensions; using MediaBrowser.Common.IO; -using MediaBrowser.Common.MediaInfo; using MediaBrowser.Common.Net; using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Dto; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.LiveTv; +using MediaBrowser.Controller.MediaInfo; using MediaBrowser.Controller.Persistence; using MediaBrowser.Model.Configuration; using MediaBrowser.Model.Dto; diff --git a/MediaBrowser.Api/Playback/Hls/VideoHlsService.cs b/MediaBrowser.Api/Playback/Hls/VideoHlsService.cs index 8fbb42f24..c87f61a1f 100644 --- a/MediaBrowser.Api/Playback/Hls/VideoHlsService.cs +++ b/MediaBrowser.Api/Playback/Hls/VideoHlsService.cs @@ -1,9 +1,9 @@ using MediaBrowser.Common.IO; -using MediaBrowser.Common.MediaInfo; using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Dto; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.LiveTv; +using MediaBrowser.Controller.MediaInfo; using MediaBrowser.Controller.Persistence; using MediaBrowser.Model.IO; using ServiceStack; diff --git a/MediaBrowser.Api/Playback/Progressive/AudioService.cs b/MediaBrowser.Api/Playback/Progressive/AudioService.cs index 050c06627..a7ef684a5 100644 --- a/MediaBrowser.Api/Playback/Progressive/AudioService.cs +++ b/MediaBrowser.Api/Playback/Progressive/AudioService.cs @@ -1,10 +1,10 @@ using MediaBrowser.Common.IO; -using MediaBrowser.Common.MediaInfo; using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Drawing; using MediaBrowser.Controller.Dto; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.LiveTv; +using MediaBrowser.Controller.MediaInfo; using MediaBrowser.Controller.Persistence; using MediaBrowser.Model.IO; using ServiceStack; diff --git a/MediaBrowser.Api/Playback/Progressive/BaseProgressiveStreamingService.cs b/MediaBrowser.Api/Playback/Progressive/BaseProgressiveStreamingService.cs index 0ae96effd..9c5acb7a0 100644 --- a/MediaBrowser.Api/Playback/Progressive/BaseProgressiveStreamingService.cs +++ b/MediaBrowser.Api/Playback/Progressive/BaseProgressiveStreamingService.cs @@ -1,12 +1,12 @@ using System; using MediaBrowser.Common.IO; -using MediaBrowser.Common.MediaInfo; using MediaBrowser.Common.Net; using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Drawing; using MediaBrowser.Controller.Dto; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.LiveTv; +using MediaBrowser.Controller.MediaInfo; using MediaBrowser.Controller.Persistence; using MediaBrowser.Model.Dto; using MediaBrowser.Model.IO; diff --git a/MediaBrowser.Api/Playback/Progressive/VideoService.cs b/MediaBrowser.Api/Playback/Progressive/VideoService.cs index c3ec02a59..f3ccaa244 100644 --- a/MediaBrowser.Api/Playback/Progressive/VideoService.cs +++ b/MediaBrowser.Api/Playback/Progressive/VideoService.cs @@ -1,10 +1,10 @@ using MediaBrowser.Common.IO; -using MediaBrowser.Common.MediaInfo; using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Drawing; using MediaBrowser.Controller.Dto; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.LiveTv; +using MediaBrowser.Controller.MediaInfo; using MediaBrowser.Controller.Persistence; using MediaBrowser.Model.IO; using ServiceStack; diff --git a/MediaBrowser.Common/MediaBrowser.Common.csproj b/MediaBrowser.Common/MediaBrowser.Common.csproj index 6098c4bb3..63819c5a9 100644 --- a/MediaBrowser.Common/MediaBrowser.Common.csproj +++ b/MediaBrowser.Common/MediaBrowser.Common.csproj @@ -65,8 +65,6 @@ - - diff --git a/MediaBrowser.Common/MediaInfo/IMediaEncoder.cs b/MediaBrowser.Common/MediaInfo/IMediaEncoder.cs deleted file mode 100644 index 82643779b..000000000 --- a/MediaBrowser.Common/MediaInfo/IMediaEncoder.cs +++ /dev/null @@ -1,109 +0,0 @@ -using System; -using System.Threading; -using System.Threading.Tasks; -using MediaBrowser.Model.Entities; - -namespace MediaBrowser.Common.MediaInfo -{ - /// - /// Interface IMediaEncoder - /// - public interface IMediaEncoder - { - /// - /// Gets the encoder path. - /// - /// The encoder path. - string EncoderPath { get; } - - /// - /// Gets the version. - /// - /// The version. - string Version { get; } - - /// - /// Extracts the image. - /// - /// The input files. - /// The type. - /// The threed format. - /// The offset. - /// The output path. - /// The cancellation token. - /// Task. - Task ExtractImage(string[] inputFiles, InputType type, Video3DFormat? threedFormat, TimeSpan? offset, string outputPath, CancellationToken cancellationToken); - - /// - /// Extracts the text subtitle. - /// - /// The input files. - /// The type. - /// Index of the subtitle stream. - /// The output path. - /// The cancellation token. - /// Task. - Task ExtractTextSubtitle(string[] inputFiles, InputType type, int subtitleStreamIndex, string outputPath, CancellationToken cancellationToken); - - /// - /// Converts the text subtitle to ass. - /// - /// The input path. - /// The output path. - /// The language. - /// The cancellation token. - /// Task. - Task ConvertTextSubtitleToAss(string inputPath, string outputPath, string language, CancellationToken cancellationToken); - - /// - /// Gets the media info. - /// - /// The input files. - /// The type. - /// The cancellation token. - /// Task. - Task GetMediaInfo(string[] inputFiles, InputType type, CancellationToken cancellationToken); - - /// - /// Gets the probe size argument. - /// - /// The type. - /// System.String. - string GetProbeSizeArgument(InputType type); - - /// - /// Gets the input argument. - /// - /// The input files. - /// The type. - /// System.String. - string GetInputArgument(string[] inputFiles, InputType type); - } - - /// - /// Enum InputType - /// - public enum InputType - { - /// - /// The audio file - /// - AudioFile, - /// - /// The video file - /// - VideoFile, - /// - /// The bluray - /// - Bluray, - /// - /// The DVD - /// - Dvd, - /// - /// The URL - /// - Url - } -} diff --git a/MediaBrowser.Common/MediaInfo/MediaInfoResult.cs b/MediaBrowser.Common/MediaInfo/MediaInfoResult.cs deleted file mode 100644 index d9a666f30..000000000 --- a/MediaBrowser.Common/MediaInfo/MediaInfoResult.cs +++ /dev/null @@ -1,311 +0,0 @@ -using MediaBrowser.Model.Entities; -using System.Collections.Generic; - -namespace MediaBrowser.Common.MediaInfo -{ - /// - /// Class MediaInfoResult - /// - public class MediaInfoResult - { - /// - /// Gets or sets the streams. - /// - /// The streams. - public MediaStreamInfo[] streams { get; set; } - - /// - /// Gets or sets the format. - /// - /// The format. - public MediaFormatInfo format { get; set; } - - /// - /// Gets or sets the chapters. - /// - /// The chapters. - public List Chapters { get; set; } - } - - /// - /// Represents a stream within the output - /// - public class MediaStreamInfo - { - /// - /// Gets or sets the index. - /// - /// The index. - public int index { get; set; } - - /// - /// Gets or sets the profile. - /// - /// The profile. - public string profile { get; set; } - - /// - /// Gets or sets the codec_name. - /// - /// The codec_name. - public string codec_name { get; set; } - - /// - /// Gets or sets the codec_long_name. - /// - /// The codec_long_name. - public string codec_long_name { get; set; } - - /// - /// Gets or sets the codec_type. - /// - /// The codec_type. - public string codec_type { get; set; } - - /// - /// Gets or sets the sample_rate. - /// - /// The sample_rate. - public string sample_rate { get; set; } - - /// - /// Gets or sets the channels. - /// - /// The channels. - public int channels { get; set; } - - /// - /// Gets or sets the channel_layout. - /// - /// The channel_layout. - public string channel_layout { get; set; } - - /// - /// Gets or sets the avg_frame_rate. - /// - /// The avg_frame_rate. - public string avg_frame_rate { get; set; } - - /// - /// Gets or sets the duration. - /// - /// The duration. - public string duration { get; set; } - - /// - /// Gets or sets the bit_rate. - /// - /// The bit_rate. - public string bit_rate { get; set; } - - /// - /// Gets or sets the width. - /// - /// The width. - public int width { get; set; } - - /// - /// Gets or sets the height. - /// - /// The height. - public int height { get; set; } - - /// - /// Gets or sets the display_aspect_ratio. - /// - /// The display_aspect_ratio. - public string display_aspect_ratio { get; set; } - - /// - /// Gets or sets the tags. - /// - /// The tags. - public Dictionary tags { get; set; } - - /// - /// Gets or sets the bits_per_sample. - /// - /// The bits_per_sample. - public int bits_per_sample { get; set; } - - /// - /// Gets or sets the r_frame_rate. - /// - /// The r_frame_rate. - public string r_frame_rate { get; set; } - - /// - /// Gets or sets the has_b_frames. - /// - /// The has_b_frames. - public int has_b_frames { get; set; } - - /// - /// Gets or sets the sample_aspect_ratio. - /// - /// The sample_aspect_ratio. - public string sample_aspect_ratio { get; set; } - - /// - /// Gets or sets the pix_fmt. - /// - /// The pix_fmt. - public string pix_fmt { get; set; } - - /// - /// Gets or sets the level. - /// - /// The level. - public int level { get; set; } - - /// - /// Gets or sets the time_base. - /// - /// The time_base. - public string time_base { get; set; } - - /// - /// Gets or sets the start_time. - /// - /// The start_time. - public string start_time { get; set; } - - /// - /// Gets or sets the codec_time_base. - /// - /// The codec_time_base. - public string codec_time_base { get; set; } - - /// - /// Gets or sets the codec_tag. - /// - /// The codec_tag. - public string codec_tag { get; set; } - - /// - /// Gets or sets the codec_tag_string. - /// - /// The codec_tag_string. - public string codec_tag_string { get; set; } - - /// - /// Gets or sets the sample_fmt. - /// - /// The sample_fmt. - public string sample_fmt { get; set; } - - /// - /// Gets or sets the dmix_mode. - /// - /// The dmix_mode. - public string dmix_mode { get; set; } - - /// - /// Gets or sets the start_pts. - /// - /// The start_pts. - public string start_pts { get; set; } - - /// - /// Gets or sets the is_avc. - /// - /// The is_avc. - public string is_avc { get; set; } - - /// - /// Gets or sets the nal_length_size. - /// - /// The nal_length_size. - public string nal_length_size { get; set; } - - /// - /// Gets or sets the ltrt_cmixlev. - /// - /// The ltrt_cmixlev. - public string ltrt_cmixlev { get; set; } - - /// - /// Gets or sets the ltrt_surmixlev. - /// - /// The ltrt_surmixlev. - public string ltrt_surmixlev { get; set; } - - /// - /// Gets or sets the loro_cmixlev. - /// - /// The loro_cmixlev. - public string loro_cmixlev { get; set; } - - /// - /// Gets or sets the loro_surmixlev. - /// - /// The loro_surmixlev. - public string loro_surmixlev { get; set; } - - /// - /// Gets or sets the disposition. - /// - /// The disposition. - public Dictionary disposition { get; set; } - } - - /// - /// Class MediaFormat - /// - public class MediaFormatInfo - { - /// - /// Gets or sets the filename. - /// - /// The filename. - public string filename { get; set; } - - /// - /// Gets or sets the nb_streams. - /// - /// The nb_streams. - public int nb_streams { get; set; } - - /// - /// Gets or sets the format_name. - /// - /// The format_name. - public string format_name { get; set; } - - /// - /// Gets or sets the format_long_name. - /// - /// The format_long_name. - public string format_long_name { get; set; } - - /// - /// Gets or sets the start_time. - /// - /// The start_time. - public string start_time { get; set; } - - /// - /// Gets or sets the duration. - /// - /// The duration. - public string duration { get; set; } - - /// - /// Gets or sets the size. - /// - /// The size. - public string size { get; set; } - - /// - /// Gets or sets the bit_rate. - /// - /// The bit_rate. - public string bit_rate { get; set; } - - /// - /// Gets or sets the tags. - /// - /// The tags. - public Dictionary tags { get; set; } - } -} diff --git a/MediaBrowser.Controller/Entities/Audio/Audio.cs b/MediaBrowser.Controller/Entities/Audio/Audio.cs index 028fc964d..9e4129cd1 100644 --- a/MediaBrowser.Controller/Entities/Audio/Audio.cs +++ b/MediaBrowser.Controller/Entities/Audio/Audio.cs @@ -109,7 +109,7 @@ namespace MediaBrowser.Controller.Entities.Audio /// System.String. public override string GetUserDataKey() { - var parent = Parent as MusicAlbum; + var parent = FindParent(); if (parent != null) { diff --git a/MediaBrowser.Controller/LiveTv/ILiveTvManager.cs b/MediaBrowser.Controller/LiveTv/ILiveTvManager.cs index d23c8c555..1856182da 100644 --- a/MediaBrowser.Controller/LiveTv/ILiveTvManager.cs +++ b/MediaBrowser.Controller/LiveTv/ILiveTvManager.cs @@ -1,5 +1,4 @@ -using System.IO; -using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Entities; using MediaBrowser.Model.LiveTv; using MediaBrowser.Model.Querying; using System.Collections.Generic; diff --git a/MediaBrowser.Controller/MediaBrowser.Controller.csproj b/MediaBrowser.Controller/MediaBrowser.Controller.csproj index 61de32e41..9082186fd 100644 --- a/MediaBrowser.Controller/MediaBrowser.Controller.csproj +++ b/MediaBrowser.Controller/MediaBrowser.Controller.csproj @@ -125,6 +125,8 @@ + + diff --git a/MediaBrowser.Controller/MediaInfo/FFMpegManager.cs b/MediaBrowser.Controller/MediaInfo/FFMpegManager.cs index 644222949..c1951038c 100644 --- a/MediaBrowser.Controller/MediaInfo/FFMpegManager.cs +++ b/MediaBrowser.Controller/MediaInfo/FFMpegManager.cs @@ -1,6 +1,5 @@ using MediaBrowser.Common.Extensions; using MediaBrowser.Common.IO; -using MediaBrowser.Common.MediaInfo; using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.Movies; @@ -178,7 +177,7 @@ namespace MediaBrowser.Controller.MediaInfo Directory.CreateDirectory(parentPath); - await _encoder.ExtractImage(inputPath, type, video.Video3DFormat, time, path, cancellationToken).ConfigureAwait(false); + await _encoder.ExtractImage(inputPath, type, false, video.Video3DFormat, time, path, cancellationToken).ConfigureAwait(false); chapter.ImagePath = path; changesMade = true; } diff --git a/MediaBrowser.Controller/MediaInfo/IMediaEncoder.cs b/MediaBrowser.Controller/MediaInfo/IMediaEncoder.cs new file mode 100644 index 000000000..8e0d696c9 --- /dev/null +++ b/MediaBrowser.Controller/MediaInfo/IMediaEncoder.cs @@ -0,0 +1,106 @@ +using System; +using System.Threading; +using System.Threading.Tasks; +using MediaBrowser.Model.Entities; + +namespace MediaBrowser.Controller.MediaInfo +{ + /// + /// Interface IMediaEncoder + /// + public interface IMediaEncoder + { + /// + /// Gets the encoder path. + /// + /// The encoder path. + string EncoderPath { get; } + + /// + /// Gets the version. + /// + /// The version. + string Version { get; } + + /// + /// Extracts the image. + /// + /// The input files. + /// The type. + /// if set to true [is audio]. + /// The threed format. + /// The offset. + /// The output path. + /// The cancellation token. + /// Task. + Task ExtractImage(string[] inputFiles, InputType type, bool isAudio, Video3DFormat? threedFormat, TimeSpan? offset, string outputPath, CancellationToken cancellationToken); + + /// + /// Extracts the text subtitle. + /// + /// The input files. + /// The type. + /// Index of the subtitle stream. + /// The output path. + /// The cancellation token. + /// Task. + Task ExtractTextSubtitle(string[] inputFiles, InputType type, int subtitleStreamIndex, string outputPath, CancellationToken cancellationToken); + + /// + /// Converts the text subtitle to ass. + /// + /// The input path. + /// The output path. + /// The language. + /// The cancellation token. + /// Task. + Task ConvertTextSubtitleToAss(string inputPath, string outputPath, string language, CancellationToken cancellationToken); + + /// + /// Gets the media info. + /// + /// The input files. + /// The type. + /// The cancellation token. + /// Task. + Task GetMediaInfo(string[] inputFiles, InputType type, CancellationToken cancellationToken); + + /// + /// Gets the probe size argument. + /// + /// The type. + /// System.String. + string GetProbeSizeArgument(InputType type); + + /// + /// Gets the input argument. + /// + /// The input files. + /// The type. + /// System.String. + string GetInputArgument(string[] inputFiles, InputType type); + } + + /// + /// Enum InputType + /// + public enum InputType + { + /// + /// The file + /// + File, + /// + /// The bluray + /// + Bluray, + /// + /// The DVD + /// + Dvd, + /// + /// The URL + /// + Url + } +} diff --git a/MediaBrowser.Controller/MediaInfo/InternalMediaInfoResult.cs b/MediaBrowser.Controller/MediaInfo/InternalMediaInfoResult.cs new file mode 100644 index 000000000..3ceec1b90 --- /dev/null +++ b/MediaBrowser.Controller/MediaInfo/InternalMediaInfoResult.cs @@ -0,0 +1,311 @@ +using System.Collections.Generic; +using MediaBrowser.Model.Entities; + +namespace MediaBrowser.Controller.MediaInfo +{ + /// + /// Class MediaInfoResult + /// + public class InternalMediaInfoResult + { + /// + /// Gets or sets the streams. + /// + /// The streams. + public MediaStreamInfo[] streams { get; set; } + + /// + /// Gets or sets the format. + /// + /// The format. + public MediaFormatInfo format { get; set; } + + /// + /// Gets or sets the chapters. + /// + /// The chapters. + public List Chapters { get; set; } + } + + /// + /// Represents a stream within the output + /// + public class MediaStreamInfo + { + /// + /// Gets or sets the index. + /// + /// The index. + public int index { get; set; } + + /// + /// Gets or sets the profile. + /// + /// The profile. + public string profile { get; set; } + + /// + /// Gets or sets the codec_name. + /// + /// The codec_name. + public string codec_name { get; set; } + + /// + /// Gets or sets the codec_long_name. + /// + /// The codec_long_name. + public string codec_long_name { get; set; } + + /// + /// Gets or sets the codec_type. + /// + /// The codec_type. + public string codec_type { get; set; } + + /// + /// Gets or sets the sample_rate. + /// + /// The sample_rate. + public string sample_rate { get; set; } + + /// + /// Gets or sets the channels. + /// + /// The channels. + public int channels { get; set; } + + /// + /// Gets or sets the channel_layout. + /// + /// The channel_layout. + public string channel_layout { get; set; } + + /// + /// Gets or sets the avg_frame_rate. + /// + /// The avg_frame_rate. + public string avg_frame_rate { get; set; } + + /// + /// Gets or sets the duration. + /// + /// The duration. + public string duration { get; set; } + + /// + /// Gets or sets the bit_rate. + /// + /// The bit_rate. + public string bit_rate { get; set; } + + /// + /// Gets or sets the width. + /// + /// The width. + public int width { get; set; } + + /// + /// Gets or sets the height. + /// + /// The height. + public int height { get; set; } + + /// + /// Gets or sets the display_aspect_ratio. + /// + /// The display_aspect_ratio. + public string display_aspect_ratio { get; set; } + + /// + /// Gets or sets the tags. + /// + /// The tags. + public Dictionary tags { get; set; } + + /// + /// Gets or sets the bits_per_sample. + /// + /// The bits_per_sample. + public int bits_per_sample { get; set; } + + /// + /// Gets or sets the r_frame_rate. + /// + /// The r_frame_rate. + public string r_frame_rate { get; set; } + + /// + /// Gets or sets the has_b_frames. + /// + /// The has_b_frames. + public int has_b_frames { get; set; } + + /// + /// Gets or sets the sample_aspect_ratio. + /// + /// The sample_aspect_ratio. + public string sample_aspect_ratio { get; set; } + + /// + /// Gets or sets the pix_fmt. + /// + /// The pix_fmt. + public string pix_fmt { get; set; } + + /// + /// Gets or sets the level. + /// + /// The level. + public int level { get; set; } + + /// + /// Gets or sets the time_base. + /// + /// The time_base. + public string time_base { get; set; } + + /// + /// Gets or sets the start_time. + /// + /// The start_time. + public string start_time { get; set; } + + /// + /// Gets or sets the codec_time_base. + /// + /// The codec_time_base. + public string codec_time_base { get; set; } + + /// + /// Gets or sets the codec_tag. + /// + /// The codec_tag. + public string codec_tag { get; set; } + + /// + /// Gets or sets the codec_tag_string. + /// + /// The codec_tag_string. + public string codec_tag_string { get; set; } + + /// + /// Gets or sets the sample_fmt. + /// + /// The sample_fmt. + public string sample_fmt { get; set; } + + /// + /// Gets or sets the dmix_mode. + /// + /// The dmix_mode. + public string dmix_mode { get; set; } + + /// + /// Gets or sets the start_pts. + /// + /// The start_pts. + public string start_pts { get; set; } + + /// + /// Gets or sets the is_avc. + /// + /// The is_avc. + public string is_avc { get; set; } + + /// + /// Gets or sets the nal_length_size. + /// + /// The nal_length_size. + public string nal_length_size { get; set; } + + /// + /// Gets or sets the ltrt_cmixlev. + /// + /// The ltrt_cmixlev. + public string ltrt_cmixlev { get; set; } + + /// + /// Gets or sets the ltrt_surmixlev. + /// + /// The ltrt_surmixlev. + public string ltrt_surmixlev { get; set; } + + /// + /// Gets or sets the loro_cmixlev. + /// + /// The loro_cmixlev. + public string loro_cmixlev { get; set; } + + /// + /// Gets or sets the loro_surmixlev. + /// + /// The loro_surmixlev. + public string loro_surmixlev { get; set; } + + /// + /// Gets or sets the disposition. + /// + /// The disposition. + public Dictionary disposition { get; set; } + } + + /// + /// Class MediaFormat + /// + public class MediaFormatInfo + { + /// + /// Gets or sets the filename. + /// + /// The filename. + public string filename { get; set; } + + /// + /// Gets or sets the nb_streams. + /// + /// The nb_streams. + public int nb_streams { get; set; } + + /// + /// Gets or sets the format_name. + /// + /// The format_name. + public string format_name { get; set; } + + /// + /// Gets or sets the format_long_name. + /// + /// The format_long_name. + public string format_long_name { get; set; } + + /// + /// Gets or sets the start_time. + /// + /// The start_time. + public string start_time { get; set; } + + /// + /// Gets or sets the duration. + /// + /// The duration. + public string duration { get; set; } + + /// + /// Gets or sets the size. + /// + /// The size. + public string size { get; set; } + + /// + /// Gets or sets the bit_rate. + /// + /// The bit_rate. + public string bit_rate { get; set; } + + /// + /// Gets or sets the tags. + /// + /// The tags. + public Dictionary tags { get; set; } + } +} diff --git a/MediaBrowser.Controller/MediaInfo/MediaEncoderHelpers.cs b/MediaBrowser.Controller/MediaInfo/MediaEncoderHelpers.cs index 261454f6d..300071b7b 100644 --- a/MediaBrowser.Controller/MediaInfo/MediaEncoderHelpers.cs +++ b/MediaBrowser.Controller/MediaInfo/MediaEncoderHelpers.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Globalization; using System.IO; using System.Linq; -using MediaBrowser.Common.MediaInfo; using MediaBrowser.Model.Entities; using MediaBrowser.Model.IO; @@ -29,7 +28,7 @@ namespace MediaBrowser.Controller.MediaInfo { var inputPath = isoMount == null ? new[] { videoPath } : new[] { isoMount.MountedPath }; - type = InputType.VideoFile; + type = InputType.File; switch (videoType) { @@ -87,7 +86,7 @@ namespace MediaBrowser.Controller.MediaInfo /// InputType. public static InputType GetInputType(VideoType? videoType, IsoType? isoType) { - var type = InputType.AudioFile; + var type = InputType.File; if (videoType.HasValue) { @@ -119,12 +118,22 @@ namespace MediaBrowser.Controller.MediaInfo return type; } - public static IEnumerable GetMediaStreams(MediaInfoResult data) + public static Model.Entities.MediaInfo GetMediaInfo(InternalMediaInfoResult data) { var internalStreams = data.streams ?? new MediaStreamInfo[] { }; - return internalStreams.Select(s => GetMediaStream(s, data.format)) - .Where(i => i != null); + var info = new Model.Entities.MediaInfo(); + + info.MediaStreams = internalStreams.Select(s => GetMediaStream(s, data.format)) + .Where(i => i != null) + .ToList(); + + if (data.format != null) + { + info.Format = data.format.format_name; + } + + return info; } private static readonly CultureInfo UsCulture = new CultureInfo("en-US"); diff --git a/MediaBrowser.Model/Entities/MediaStream.cs b/MediaBrowser.Model/Entities/MediaStream.cs index 133631649..59455889d 100644 --- a/MediaBrowser.Model/Entities/MediaStream.cs +++ b/MediaBrowser.Model/Entities/MediaStream.cs @@ -1,4 +1,5 @@ - +using System.Collections.Generic; + namespace MediaBrowser.Model.Entities { /// @@ -145,4 +146,24 @@ namespace MediaBrowser.Model.Entities /// Subtitle } + + public class MediaInfo + { + /// + /// Gets or sets the media streams. + /// + /// The media streams. + public List MediaStreams { get; set; } + + /// + /// Gets or sets the format. + /// + /// The format. + public string Format { get; set; } + + public MediaInfo() + { + MediaStreams = new List(); + } + } } diff --git a/MediaBrowser.Providers/MediaInfo/AudioImageProvider.cs b/MediaBrowser.Providers/MediaInfo/AudioImageProvider.cs index fd78a7565..8d768a6a0 100644 --- a/MediaBrowser.Providers/MediaInfo/AudioImageProvider.cs +++ b/MediaBrowser.Providers/MediaInfo/AudioImageProvider.cs @@ -1,9 +1,9 @@ using MediaBrowser.Common.Extensions; -using MediaBrowser.Common.MediaInfo; using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.Audio; using MediaBrowser.Controller.Library; +using MediaBrowser.Controller.MediaInfo; using MediaBrowser.Controller.Providers; using MediaBrowser.Model.Entities; using MediaBrowser.Model.Logging; @@ -163,7 +163,7 @@ namespace MediaBrowser.Providers.MediaInfo Directory.CreateDirectory(parentPath); - await _mediaEncoder.ExtractImage(new[] { item.Path }, InputType.AudioFile, null, null, path, cancellationToken).ConfigureAwait(false); + await _mediaEncoder.ExtractImage(new[] { item.Path }, InputType.File, true, null, null, path, cancellationToken).ConfigureAwait(false); } finally { diff --git a/MediaBrowser.Providers/MediaInfo/BaseFFProbeProvider.cs b/MediaBrowser.Providers/MediaInfo/BaseFFProbeProvider.cs index cd08f5828..95cbb3e4e 100644 --- a/MediaBrowser.Providers/MediaInfo/BaseFFProbeProvider.cs +++ b/MediaBrowser.Providers/MediaInfo/BaseFFProbeProvider.cs @@ -1,5 +1,4 @@ -using MediaBrowser.Common.MediaInfo; -using MediaBrowser.Controller.Configuration; +using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.MediaInfo; using MediaBrowser.Controller.Providers; @@ -104,11 +103,11 @@ namespace MediaBrowser.Providers.MediaInfo /// inputPath /// or /// cache - protected async Task GetMediaInfo(BaseItem item, IIsoMount isoMount, CancellationToken cancellationToken) + protected async Task GetMediaInfo(BaseItem item, IIsoMount isoMount, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); - var type = InputType.AudioFile; + var type = InputType.File; var inputPath = isoMount == null ? new[] { item.Path } : new[] { isoMount.MountedPath }; var video = item as Video; @@ -146,7 +145,7 @@ namespace MediaBrowser.Providers.MediaInfo /// Normalizes the FF probe result. /// /// The result. - protected void NormalizeFFProbeResult(MediaInfoResult result) + protected void NormalizeFFProbeResult(InternalMediaInfoResult result) { if (result.format != null && result.format.tags != null) { diff --git a/MediaBrowser.Providers/MediaInfo/FFProbeAudioInfoProvider.cs b/MediaBrowser.Providers/MediaInfo/FFProbeAudioInfoProvider.cs index a8432969b..d27b65e2a 100644 --- a/MediaBrowser.Providers/MediaInfo/FFProbeAudioInfoProvider.cs +++ b/MediaBrowser.Providers/MediaInfo/FFProbeAudioInfoProvider.cs @@ -1,5 +1,4 @@ using MediaBrowser.Common.Extensions; -using MediaBrowser.Common.MediaInfo; using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.Audio; @@ -58,9 +57,9 @@ namespace MediaBrowser.Providers.MediaInfo /// The cancellation token. /// The data. /// Task. - protected Task Fetch(Audio audio, CancellationToken cancellationToken, MediaInfoResult data) + protected Task Fetch(Audio audio, CancellationToken cancellationToken, InternalMediaInfoResult data) { - var mediaStreams = MediaEncoderHelpers.GetMediaStreams(data).ToList(); + var mediaStreams = MediaEncoderHelpers.GetMediaInfo(data).MediaStreams; audio.HasEmbeddedImage = mediaStreams.Any(i => i.Type == MediaStreamType.Video); diff --git a/MediaBrowser.Providers/MediaInfo/FFProbeVideoInfoProvider.cs b/MediaBrowser.Providers/MediaInfo/FFProbeVideoInfoProvider.cs index 4ce8cf069..fc2c5c370 100644 --- a/MediaBrowser.Providers/MediaInfo/FFProbeVideoInfoProvider.cs +++ b/MediaBrowser.Providers/MediaInfo/FFProbeVideoInfoProvider.cs @@ -1,5 +1,4 @@ using DvdLib.Ifo; -using MediaBrowser.Common.MediaInfo; using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Localization; @@ -310,7 +309,7 @@ namespace MediaBrowser.Providers.MediaInfo /// The data. /// The iso mount. /// Task. - protected async Task Fetch(Video video, bool force, BaseProviderInfo providerInfo, CancellationToken cancellationToken, MediaInfoResult data, IIsoMount isoMount) + protected async Task Fetch(Video video, bool force, BaseProviderInfo providerInfo, CancellationToken cancellationToken, InternalMediaInfoResult data, IIsoMount isoMount) { if (data.format != null) { @@ -323,7 +322,7 @@ namespace MediaBrowser.Providers.MediaInfo } } - var mediaStreams = MediaEncoderHelpers.GetMediaStreams(data).ToList(); + var mediaStreams = MediaEncoderHelpers.GetMediaInfo(data).MediaStreams; var chapters = data.Chapters ?? new List(); @@ -370,7 +369,7 @@ namespace MediaBrowser.Providers.MediaInfo /// The video. /// if set to true [force]. /// The data. - private void FetchWtvInfo(Video video, bool force, MediaInfoResult data) + private void FetchWtvInfo(Video video, bool force, InternalMediaInfoResult data) { if (data.format == null || data.format.tags == null) { diff --git a/MediaBrowser.Providers/MediaInfo/VideoImageProvider.cs b/MediaBrowser.Providers/MediaInfo/VideoImageProvider.cs index d5815690f..fc8826b61 100644 --- a/MediaBrowser.Providers/MediaInfo/VideoImageProvider.cs +++ b/MediaBrowser.Providers/MediaInfo/VideoImageProvider.cs @@ -1,5 +1,4 @@ using MediaBrowser.Common.Extensions; -using MediaBrowser.Common.MediaInfo; using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Library; @@ -255,7 +254,7 @@ namespace MediaBrowser.Providers.MediaInfo var inputPath = MediaEncoderHelpers.GetInputArgument(video.Path, video.LocationType == LocationType.Remote, video.VideoType, video.IsoType, isoMount, video.PlayableStreamFileNames, out type); - await _mediaEncoder.ExtractImage(inputPath, type, video.Video3DFormat, imageOffset, path, cancellationToken).ConfigureAwait(false); + await _mediaEncoder.ExtractImage(inputPath, type, false, video.Video3DFormat, imageOffset, path, cancellationToken).ConfigureAwait(false); video.PrimaryImagePath = path; } diff --git a/MediaBrowser.Server.Implementations/LiveTv/LiveTvDtoService.cs b/MediaBrowser.Server.Implementations/LiveTv/LiveTvDtoService.cs index 83da28b8f..c042e7750 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/LiveTvDtoService.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/LiveTvDtoService.cs @@ -368,7 +368,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv return null; } - private const string InternalVersionNumber = "2"; + private const string InternalVersionNumber = "3"; public Guid GetInternalChannelId(string serviceName, string externalId) { diff --git a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs index 3bc146bd4..17e17ab70 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs @@ -6,12 +6,14 @@ using MediaBrowser.Controller.Dto; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.LiveTv; +using MediaBrowser.Controller.MediaInfo; using MediaBrowser.Controller.Persistence; using MediaBrowser.Model.Entities; using MediaBrowser.Model.LiveTv; using MediaBrowser.Model.Logging; using MediaBrowser.Model.Querying; using System; +using System.Collections.Concurrent; using System.Collections.Generic; using System.IO; using System.Linq; @@ -23,7 +25,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv /// /// Class LiveTvManager /// - public class LiveTvManager : ILiveTvManager + public class LiveTvManager : ILiveTvManager, IDisposable { private readonly IServerApplicationPaths _appPaths; private readonly IFileSystem _fileSystem; @@ -31,15 +33,19 @@ namespace MediaBrowser.Server.Implementations.LiveTv private readonly IItemRepository _itemRepo; private readonly IUserManager _userManager; private readonly ILibraryManager _libraryManager; + private readonly IMediaEncoder _mediaEncoder; private readonly LiveTvDtoService _tvDtoService; private readonly List _services = new List(); + private readonly ConcurrentDictionary _openStreams = + new ConcurrentDictionary(); + private List _channelIdList = new List(); private Dictionary _programs = new Dictionary(); - public LiveTvManager(IServerApplicationPaths appPaths, IFileSystem fileSystem, ILogger logger, IItemRepository itemRepo, IImageProcessor imageProcessor, IUserDataManager userDataManager, IDtoService dtoService, IUserManager userManager, ILibraryManager libraryManager) + public LiveTvManager(IServerApplicationPaths appPaths, IFileSystem fileSystem, ILogger logger, IItemRepository itemRepo, IImageProcessor imageProcessor, IUserDataManager userDataManager, IDtoService dtoService, IUserManager userManager, ILibraryManager libraryManager, IMediaEncoder mediaEncoder) { _appPaths = appPaths; _fileSystem = fileSystem; @@ -47,6 +53,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv _itemRepo = itemRepo; _userManager = userManager; _libraryManager = libraryManager; + _mediaEncoder = mediaEncoder; _tvDtoService = new LiveTvDtoService(dtoService, userDataManager, imageProcessor, logger, _itemRepo); } @@ -180,7 +187,14 @@ namespace MediaBrowser.Server.Implementations.LiveTv var recording = recordings.First(i => _tvDtoService.GetInternalRecordingId(service.Name, i.Id) == new Guid(id)); - return await service.GetRecordingStream(recording.Id, cancellationToken).ConfigureAwait(false); + var result = await service.GetRecordingStream(recording.Id, cancellationToken).ConfigureAwait(false); + + if (!string.IsNullOrEmpty(result.Id)) + { + _openStreams.AddOrUpdate(result.Id, result, (key, info) => result); + } + + return result; } public async Task GetChannelStream(string id, CancellationToken cancellationToken) @@ -189,12 +203,19 @@ namespace MediaBrowser.Server.Implementations.LiveTv var channel = GetInternalChannel(id); - return await service.GetChannelStream(channel.ChannelInfo.Id, cancellationToken).ConfigureAwait(false); + var result = await service.GetChannelStream(channel.ChannelInfo.Id, cancellationToken).ConfigureAwait(false); + + if (!string.IsNullOrEmpty(result.Id)) + { + _openStreams.AddOrUpdate(result.Id, result, (key, info) => result); + } + + return result; } private async Task GetChannel(ChannelInfo channelInfo, string serviceName, CancellationToken cancellationToken) { - var path = Path.Combine(_appPaths.ItemsByNamePath, "channels", _fileSystem.GetValidFilename(serviceName), _fileSystem.GetValidFilename(channelInfo.Name)); + var path = Path.Combine(_appPaths.ItemsByNamePath, "channels", _fileSystem.GetValidFilename(channelInfo.Name)); var fileInfo = new DirectoryInfo(path); @@ -1047,5 +1068,36 @@ namespace MediaBrowser.Server.Implementations.LiveTv EndDate = endDate }; } + + /// + /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. + /// + public void Dispose() + { + Dispose(true); + } + + private readonly object _disposeLock = new object(); + /// + /// Releases unmanaged and - optionally - managed resources. + /// + /// true to release both managed and unmanaged resources; false to release only unmanaged resources. + protected virtual void Dispose(bool dispose) + { + if (dispose) + { + lock (_disposeLock) + { + foreach (var stream in _openStreams.Values.ToList()) + { + var task = CloseLiveStream(stream.Id, CancellationToken.None); + + Task.WaitAll(task); + } + + _openStreams.Clear(); + } + } + } } } diff --git a/MediaBrowser.Server.Implementations/MediaEncoder/MediaEncoder.cs b/MediaBrowser.Server.Implementations/MediaEncoder/MediaEncoder.cs index bcc857a80..6f956ba20 100644 --- a/MediaBrowser.Server.Implementations/MediaEncoder/MediaEncoder.cs +++ b/MediaBrowser.Server.Implementations/MediaEncoder/MediaEncoder.cs @@ -1,6 +1,6 @@ using MediaBrowser.Common.Configuration; using MediaBrowser.Common.IO; -using MediaBrowser.Common.MediaInfo; +using MediaBrowser.Controller.MediaInfo; using MediaBrowser.Model.Entities; using MediaBrowser.Model.Logging; using MediaBrowser.Model.Serialization; @@ -104,10 +104,10 @@ namespace MediaBrowser.Server.Implementations.MediaEncoder /// The type. /// The cancellation token. /// Task. - public Task GetMediaInfo(string[] inputFiles, InputType type, + public Task GetMediaInfo(string[] inputFiles, InputType type, CancellationToken cancellationToken) { - return GetMediaInfoInternal(GetInputArgument(inputFiles, type), type != InputType.AudioFile, + return GetMediaInfoInternal(GetInputArgument(inputFiles, type), type != InputType.File, GetProbeSizeArgument(type), cancellationToken); } @@ -125,8 +125,7 @@ namespace MediaBrowser.Server.Implementations.MediaEncoder switch (type) { case InputType.Dvd: - case InputType.VideoFile: - case InputType.AudioFile: + case InputType.File: inputPath = GetConcatInputArgument(inputFiles); break; case InputType.Bluray: @@ -173,7 +172,7 @@ namespace MediaBrowser.Server.Implementations.MediaEncoder /// The cancellation token. /// Task{MediaInfoResult}. /// - private async Task GetMediaInfoInternal(string inputPath, bool extractChapters, + private async Task GetMediaInfoInternal(string inputPath, bool extractChapters, string probeSizeArgument, CancellationToken cancellationToken) { @@ -206,7 +205,7 @@ namespace MediaBrowser.Server.Implementations.MediaEncoder await _ffProbeResourcePool.WaitAsync(cancellationToken).ConfigureAwait(false); - MediaInfoResult result; + InternalMediaInfoResult result; string standardError = null; try @@ -236,7 +235,7 @@ namespace MediaBrowser.Server.Implementations.MediaEncoder process.BeginErrorReadLine(); } - result = _jsonSerializer.DeserializeFromStream(process.StandardOutput.BaseStream); + result = _jsonSerializer.DeserializeFromStream(process.StandardOutput.BaseStream); if (extractChapters) { @@ -307,7 +306,7 @@ namespace MediaBrowser.Server.Implementations.MediaEncoder /// /// The result. /// The standard error. - private void AddChapters(MediaInfoResult result, string standardError) + private void AddChapters(InternalMediaInfoResult result, string standardError) { var lines = standardError.Split('\n').Select(l => l.TrimStart()); @@ -797,19 +796,20 @@ namespace MediaBrowser.Server.Implementations.MediaEncoder /// /// The input files. /// The type. + /// if set to true [is audio]. /// The threed format. /// The offset. /// The output path. /// The cancellation token. /// Task. /// Must use inputPath list overload - public async Task ExtractImage(string[] inputFiles, InputType type, Video3DFormat? threedFormat, TimeSpan? offset, string outputPath, CancellationToken cancellationToken) + public async Task ExtractImage(string[] inputFiles, InputType type, bool isAudio, Video3DFormat? threedFormat, TimeSpan? offset, string outputPath, CancellationToken cancellationToken) { - var resourcePool = type == InputType.AudioFile ? _audioImageResourcePool : _videoImageResourcePool; + var resourcePool = isAudio ? _audioImageResourcePool : _videoImageResourcePool; var inputArgument = GetInputArgument(inputFiles, type); - if (type != InputType.AudioFile) + if (!isAudio) { try { diff --git a/MediaBrowser.ServerApplication/ApplicationHost.cs b/MediaBrowser.ServerApplication/ApplicationHost.cs index a14ffc433..21efe8f9f 100644 --- a/MediaBrowser.ServerApplication/ApplicationHost.cs +++ b/MediaBrowser.ServerApplication/ApplicationHost.cs @@ -6,7 +6,6 @@ using MediaBrowser.Common.Extensions; using MediaBrowser.Common.Implementations; using MediaBrowser.Common.Implementations.ScheduledTasks; using MediaBrowser.Common.IO; -using MediaBrowser.Common.MediaInfo; using MediaBrowser.Common.Net; using MediaBrowser.Common.Progress; using MediaBrowser.Controller; @@ -284,9 +283,6 @@ namespace MediaBrowser.ServerApplication DtoService = new DtoService(Logger, LibraryManager, UserManager, UserDataManager, ItemRepository, ImageProcessor); RegisterSingleInstance(DtoService); - - LiveTvManager = new LiveTvManager(ApplicationPaths, FileSystemManager, Logger, ItemRepository, ImageProcessor, UserDataManager, DtoService, UserManager, LibraryManager); - RegisterSingleInstance(LiveTvManager); progress.Report(15); var innerProgress = new ActionableProgress(); @@ -295,6 +291,9 @@ namespace MediaBrowser.ServerApplication await RegisterMediaEncoder(innerProgress).ConfigureAwait(false); progress.Report(90); + LiveTvManager = new LiveTvManager(ApplicationPaths, FileSystemManager, Logger, ItemRepository, ImageProcessor, UserDataManager, DtoService, UserManager, LibraryManager, MediaEncoder); + RegisterSingleInstance(LiveTvManager); + var displayPreferencesTask = Task.Run(async () => await ConfigureDisplayPreferencesRepositories().ConfigureAwait(false)); var itemsTask = Task.Run(async () => await ConfigureItemRepositories().ConfigureAwait(false)); var userdataTask = Task.Run(async () => await ConfigureUserDataRepositories().ConfigureAwait(false)); -- cgit v1.2.3 From cc3e8dbbb942977d8f46a0a16e3802c0e5d0c94b Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 12 Jan 2014 10:58:47 -0500 Subject: added suggested live tv page --- MediaBrowser.Api/LiveTv/LiveTvService.cs | 32 +++++ MediaBrowser.Controller/LiveTv/ILiveTvManager.cs | 9 ++ MediaBrowser.Controller/LiveTv/ILiveTvService.cs | 25 ++-- MediaBrowser.Controller/LiveTv/LiveTvProgram.cs | 21 ++++ MediaBrowser.Model/LiveTv/ProgramQuery.cs | 27 ++++ .../LiveTv/LiveTvManager.cs | 140 ++++++++++++++++++++- MediaBrowser.WebDashboard/ApiClient.js | 13 +- MediaBrowser.WebDashboard/packages.config | 2 +- Nuget/MediaBrowser.Common.Internal.nuspec | 4 +- Nuget/MediaBrowser.Common.nuspec | 2 +- Nuget/MediaBrowser.Server.Core.nuspec | 4 +- 11 files changed, 263 insertions(+), 16 deletions(-) (limited to 'MediaBrowser.Server.Implementations') diff --git a/MediaBrowser.Api/LiveTv/LiveTvService.cs b/MediaBrowser.Api/LiveTv/LiveTvService.cs index 50e7319b9..f92c4932e 100644 --- a/MediaBrowser.Api/LiveTv/LiveTvService.cs +++ b/MediaBrowser.Api/LiveTv/LiveTvService.cs @@ -154,6 +154,23 @@ namespace MediaBrowser.Api.LiveTv public string MaxEndDate { get; set; } } + [Route("/LiveTv/Programs/Recommended", "GET")] + [Api(Description = "Gets available live tv epgs..")] + public class GetRecommendedPrograms : IReturn> + { + [ApiMember(Name = "UserId", Description = "Optional filter by user id.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET,POST")] + public string UserId { get; set; } + + [ApiMember(Name = "Limit", Description = "Optional. The maximum number of records to return", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")] + public int? Limit { get; set; } + + [ApiMember(Name = "IsAiring", Description = "Optional. Filter by programs that are currently airing, or not.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET")] + public bool? IsAiring { get; set; } + + [ApiMember(Name = "HasAired", Description = "Optional. Filter by programs that have completed airing, or not.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET")] + public bool? HasAired { get; set; } + } + [Route("/LiveTv/Programs/{Id}", "GET")] [Api(Description = "Gets a live tv program")] public class GetProgram : IReturn @@ -331,6 +348,21 @@ namespace MediaBrowser.Api.LiveTv return ToOptimizedResult(result); } + public object Get(GetRecommendedPrograms request) + { + var query = new RecommendedProgramQuery + { + UserId = request.UserId, + IsAiring = request.IsAiring, + Limit = request.Limit, + HasAired = request.HasAired + }; + + var result = _liveTvManager.GetRecommendedPrograms(query, CancellationToken.None).Result; + + return ToOptimizedResult(result); + } + public object Post(GetPrograms request) { return Get(request); diff --git a/MediaBrowser.Controller/LiveTv/ILiveTvManager.cs b/MediaBrowser.Controller/LiveTv/ILiveTvManager.cs index 1856182da..31c336932 100644 --- a/MediaBrowser.Controller/LiveTv/ILiveTvManager.cs +++ b/MediaBrowser.Controller/LiveTv/ILiveTvManager.cs @@ -240,5 +240,14 @@ namespace MediaBrowser.Controller.LiveTv /// /// GuideInfo. GuideInfo GetGuideInfo(); + + /// + /// Gets the recommended programs. + /// + /// The query. + /// The cancellation token. + /// Task{QueryResult{ProgramInfoDto}}. + Task> GetRecommendedPrograms(RecommendedProgramQuery query, + CancellationToken cancellationToken); } } diff --git a/MediaBrowser.Controller/LiveTv/ILiveTvService.cs b/MediaBrowser.Controller/LiveTv/ILiveTvService.cs index 1e535139c..81613c1df 100644 --- a/MediaBrowser.Controller/LiveTv/ILiveTvService.cs +++ b/MediaBrowser.Controller/LiveTv/ILiveTvService.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; @@ -37,7 +38,7 @@ namespace MediaBrowser.Controller.LiveTv /// The cancellation token. /// Task. Task CancelSeriesTimerAsync(string timerId, CancellationToken cancellationToken); - + /// /// Deletes the recording asynchronous. /// @@ -77,7 +78,7 @@ namespace MediaBrowser.Controller.LiveTv /// The cancellation token. /// Task. Task UpdateSeriesTimerAsync(SeriesTimerInfo info, CancellationToken cancellationToken); - + /// /// Gets the channel image asynchronous. This only needs to be implemented if an image path or url cannot be supplied to ChannelInfo /// @@ -102,7 +103,7 @@ namespace MediaBrowser.Controller.LiveTv /// The cancellation token. /// Task{ImageResponseInfo}. Task GetProgramImageAsync(string programId, string channelId, CancellationToken cancellationToken); - + /// /// Gets the recordings asynchronous. /// @@ -123,21 +124,23 @@ namespace MediaBrowser.Controller.LiveTv /// The cancellation token. /// Task{TimerInfo}. Task GetNewTimerDefaultsAsync(CancellationToken cancellationToken); - + /// /// Gets the series timers asynchronous. /// /// The cancellation token. /// Task{IEnumerable{SeriesTimerInfo}}. Task> GetSeriesTimersAsync(CancellationToken cancellationToken); - + /// /// Gets the programs asynchronous. /// /// The channel identifier. + /// The start date UTC. + /// The end date UTC. /// The cancellation token. /// Task{IEnumerable{ProgramInfo}}. - Task> GetProgramsAsync(string channelId, CancellationToken cancellationToken); + Task> GetProgramsAsync(string channelId, DateTime startDateUtc, DateTime endDateUtc, CancellationToken cancellationToken); /// /// Gets the recording stream. @@ -162,5 +165,13 @@ namespace MediaBrowser.Controller.LiveTv /// The cancellation token. /// Task. Task CloseLiveStream(string id, CancellationToken cancellationToken); + + /// + /// Records the live stream. + /// + /// The identifier. + /// The cancellation token. + /// Task. + Task RecordLiveStream(string id, CancellationToken cancellationToken); } } diff --git a/MediaBrowser.Controller/LiveTv/LiveTvProgram.cs b/MediaBrowser.Controller/LiveTv/LiveTvProgram.cs index abacc0c18..aceb32885 100644 --- a/MediaBrowser.Controller/LiveTv/LiveTvProgram.cs +++ b/MediaBrowser.Controller/LiveTv/LiveTvProgram.cs @@ -1,5 +1,6 @@ using MediaBrowser.Controller.Entities; using MediaBrowser.Model.LiveTv; +using System; namespace MediaBrowser.Controller.LiveTv { @@ -28,6 +29,26 @@ namespace MediaBrowser.Controller.LiveTv } } + public bool IsAiring + { + get + { + var now = DateTime.UtcNow; + + return now >= ProgramInfo.StartDate && now < ProgramInfo.EndDate; + } + } + + public bool HasAired + { + get + { + var now = DateTime.UtcNow; + + return now >= ProgramInfo.EndDate; + } + } + public override string GetClientTypeName() { return "Program"; diff --git a/MediaBrowser.Model/LiveTv/ProgramQuery.cs b/MediaBrowser.Model/LiveTv/ProgramQuery.cs index 36c06d4c0..a2a824994 100644 --- a/MediaBrowser.Model/LiveTv/ProgramQuery.cs +++ b/MediaBrowser.Model/LiveTv/ProgramQuery.cs @@ -32,4 +32,31 @@ namespace MediaBrowser.Model.LiveTv ChannelIdList = new string[] { }; } } + + public class RecommendedProgramQuery + { + /// + /// Gets or sets the user identifier. + /// + /// The user identifier. + public string UserId { get; set; } + + /// + /// Gets or sets a value indicating whether this instance is airing. + /// + /// true if this instance is airing; otherwise, false. + public bool? IsAiring { get; set; } + + /// + /// Gets or sets a value indicating whether this instance has aired. + /// + /// null if [has aired] contains no value, true if [has aired]; otherwise, false. + public bool? HasAired { get; set; } + + /// + /// The maximum number of items to return + /// + /// The limit. + public int? Limit { get; set; } + } } diff --git a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs index 17e17ab70..91766e0f8 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs @@ -32,6 +32,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv private readonly ILogger _logger; private readonly IItemRepository _itemRepo; private readonly IUserManager _userManager; + private readonly IUserDataManager _userDataManager; private readonly ILibraryManager _libraryManager; private readonly IMediaEncoder _mediaEncoder; @@ -54,6 +55,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv _userManager = userManager; _libraryManager = libraryManager; _mediaEncoder = mediaEncoder; + _userDataManager = userDataManager; _tvDtoService = new LiveTvDtoService(dtoService, userDataManager, imageProcessor, logger, _itemRepo); } @@ -428,7 +430,6 @@ namespace MediaBrowser.Server.Implementations.LiveTv } var returnArray = programs - .OrderBy(i => i.ProgramInfo.StartDate) .Select(i => { var channel = GetChannel(i); @@ -450,6 +451,138 @@ namespace MediaBrowser.Server.Implementations.LiveTv return result; } + public async Task> GetRecommendedPrograms(RecommendedProgramQuery query, CancellationToken cancellationToken) + { + IEnumerable programs = _programs.Values; + + var user = _userManager.GetUserById(new Guid(query.UserId)); + + // Avoid implicitly captured closure + var currentUser = user; + programs = programs.Where(i => i.IsParentalAllowed(currentUser)); + + if (query.IsAiring.HasValue) + { + var val = query.IsAiring.Value; + programs = programs.Where(i => i.IsAiring == val); + } + + if (query.HasAired.HasValue) + { + var val = query.HasAired.Value; + programs = programs.Where(i => i.HasAired == val); + } + + var serviceName = ActiveService.Name; + + var programList = programs.ToList(); + + var genres = programList.SelectMany(i => i.Genres) + .Distinct(StringComparer.OrdinalIgnoreCase) + .Select(i => _libraryManager.GetGenre(i)) + .ToDictionary(i => i.Name, StringComparer.OrdinalIgnoreCase); + + programs = programList.OrderByDescending(i => GetRecommendationScore(i.ProgramInfo, user.Id, serviceName, genres)) + .ThenBy(i => i.ProgramInfo.StartDate); + + if (query.Limit.HasValue) + { + programs = programs.Take(query.Limit.Value) + .OrderBy(i => i.ProgramInfo.StartDate); + } + + var returnArray = programs + .Select(i => + { + var channel = GetChannel(i); + + var channelName = channel == null ? null : channel.ChannelInfo.Name; + + return _tvDtoService.GetProgramInfoDto(i, channelName, user); + }) + .ToArray(); + + await AddRecordingInfo(returnArray, cancellationToken).ConfigureAwait(false); + + var result = new QueryResult + { + Items = returnArray, + TotalRecordCount = returnArray.Length + }; + + return result; + } + + private int GetRecommendationScore(ProgramInfo program, Guid userId, string serviceName, Dictionary genres) + { + var score = 0; + + if (program.IsLive) + { + score++; + } + + if (program.IsSeries && !program.IsRepeat) + { + score++; + } + + var internalChannelId = _tvDtoService.GetInternalChannelId(serviceName, program.ChannelId); + var channel = GetInternalChannel(internalChannelId); + + var channelUserdata = _userDataManager.GetUserData(userId, channel.GetUserDataKey()); + + if ((channelUserdata.Likes ?? false)) + { + score += 2; + } + else if (!(channelUserdata.Likes ?? true)) + { + score -= 2; + } + + if (channelUserdata.IsFavorite) + { + score += 3; + } + + score += GetGenreScore(program.Genres, userId, genres); + + return score; + } + + private int GetGenreScore(IEnumerable programGenres, Guid userId, Dictionary genres) + { + return programGenres.Select(i => + { + var score = 0; + + Genre genre; + + if (genres.TryGetValue(i, out genre)) + { + var genreUserdata = _userDataManager.GetUserData(userId, genre.GetUserDataKey()); + + if ((genreUserdata.Likes ?? false)) + { + score++; + } + else if (!(genreUserdata.Likes ?? true)) + { + score--; + } + + if (genreUserdata.IsFavorite) + { + score += 2; + } + } + + return score; + + }).Sum(); + } + private async Task AddRecordingInfo(IEnumerable programs, CancellationToken cancellationToken) { var timers = await ActiveService.GetTimersAsync(cancellationToken).ConfigureAwait(false); @@ -533,7 +666,10 @@ namespace MediaBrowser.Server.Implementations.LiveTv try { - var channelPrograms = await service.GetProgramsAsync(currentChannel.ChannelInfo.Id, cancellationToken).ConfigureAwait(false); + var start = DateTime.UtcNow; + var end = start.AddDays(3); + + var channelPrograms = await service.GetProgramsAsync(currentChannel.ChannelInfo.Id, start, end, cancellationToken).ConfigureAwait(false); var programTasks = channelPrograms.Select(program => GetProgram(program, currentChannel.ChannelInfo.ChannelType, service.Name, cancellationToken)); var programEntities = await Task.WhenAll(programTasks).ConfigureAwait(false); diff --git a/MediaBrowser.WebDashboard/ApiClient.js b/MediaBrowser.WebDashboard/ApiClient.js index fe0e5e541..b35341ebb 100644 --- a/MediaBrowser.WebDashboard/ApiClient.js +++ b/MediaBrowser.WebDashboard/ApiClient.js @@ -438,7 +438,7 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout, wi options = options || {}; - if (options.channelIds) { + if (options.channelIds && options.channelIds.length > 1800) { return self.ajax({ type: "POST", @@ -458,6 +458,17 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout, wi } }; + self.getLiveTvRecommendedPrograms = function (options) { + + options = options || {}; + + return self.ajax({ + type: "GET", + url: self.getUrl("LiveTv/Programs/Recommended", options), + dataType: "json" + }); + }; + self.getLiveTvRecordings = function (options) { var url = self.getUrl("LiveTv/Recordings", options || {}); diff --git a/MediaBrowser.WebDashboard/packages.config b/MediaBrowser.WebDashboard/packages.config index 6c512e8bb..b28f5655a 100644 --- a/MediaBrowser.WebDashboard/packages.config +++ b/MediaBrowser.WebDashboard/packages.config @@ -1,4 +1,4 @@  - + \ No newline at end of file diff --git a/Nuget/MediaBrowser.Common.Internal.nuspec b/Nuget/MediaBrowser.Common.Internal.nuspec index 534957de6..9c011b3f4 100644 --- a/Nuget/MediaBrowser.Common.Internal.nuspec +++ b/Nuget/MediaBrowser.Common.Internal.nuspec @@ -2,7 +2,7 @@ MediaBrowser.Common.Internal - 3.0.298 + 3.0.299 MediaBrowser.Common.Internal Luke ebr,Luke,scottisafool @@ -12,7 +12,7 @@ Contains common components shared by Media Browser Theater and Media Browser Server. Not intended for plugin developer consumption. Copyright © Media Browser 2013 - + diff --git a/Nuget/MediaBrowser.Common.nuspec b/Nuget/MediaBrowser.Common.nuspec index e6792e1df..d0cd3a306 100644 --- a/Nuget/MediaBrowser.Common.nuspec +++ b/Nuget/MediaBrowser.Common.nuspec @@ -2,7 +2,7 @@ MediaBrowser.Common - 3.0.298 + 3.0.299 MediaBrowser.Common Media Browser Team ebr,Luke,scottisafool diff --git a/Nuget/MediaBrowser.Server.Core.nuspec b/Nuget/MediaBrowser.Server.Core.nuspec index db48a2891..cc15b8c4d 100644 --- a/Nuget/MediaBrowser.Server.Core.nuspec +++ b/Nuget/MediaBrowser.Server.Core.nuspec @@ -2,7 +2,7 @@ MediaBrowser.Server.Core - 3.0.298 + 3.0.299 Media Browser.Server.Core Media Browser Team ebr,Luke,scottisafool @@ -12,7 +12,7 @@ Contains core components required to build plugins for Media Browser Server. Copyright © Media Browser 2013 - + -- cgit v1.2.3 From edd19f6c45eee0cb1ad247af7b2b223dd3c3fa5d Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 12 Jan 2014 11:55:38 -0500 Subject: added live tv settings page --- .../Configuration/ServerConfiguration.cs | 12 +++++++- .../LiveTv/LiveTvManager.cs | 32 ++++++++++++++++++---- MediaBrowser.ServerApplication/ApplicationHost.cs | 2 +- MediaBrowser.WebDashboard/Api/DashboardService.cs | 1 + .../MediaBrowser.WebDashboard.csproj | 6 ++++ 5 files changed, 45 insertions(+), 8 deletions(-) (limited to 'MediaBrowser.Server.Implementations') diff --git a/MediaBrowser.Model/Configuration/ServerConfiguration.cs b/MediaBrowser.Model/Configuration/ServerConfiguration.cs index bdf072b50..f7b4cf373 100644 --- a/MediaBrowser.Model/Configuration/ServerConfiguration.cs +++ b/MediaBrowser.Model/Configuration/ServerConfiguration.cs @@ -223,7 +223,10 @@ namespace MediaBrowser.Model.Configuration public string TranscodingTempPath { get; set; } public bool EnableAutomaticRestart { get; set; } - + + + public LiveTvOptions LiveTvOptions { get; set; } + /// /// Initializes a new instance of the class. /// @@ -287,6 +290,8 @@ namespace MediaBrowser.Model.Configuration { MaxBackdrops = 1 }; + + LiveTvOptions = new LiveTvOptions(); } } @@ -303,4 +308,9 @@ namespace MediaBrowser.Model.Configuration HighQuality, MaxQuality } + + public class LiveTvOptions + { + public int? GuideDays { get; set; } + } } diff --git a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs index 91766e0f8..ef8f515f5 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs @@ -1,6 +1,7 @@ using MediaBrowser.Common.Extensions; using MediaBrowser.Common.IO; using MediaBrowser.Controller; +using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Drawing; using MediaBrowser.Controller.Dto; using MediaBrowser.Controller.Entities; @@ -27,7 +28,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv /// public class LiveTvManager : ILiveTvManager, IDisposable { - private readonly IServerApplicationPaths _appPaths; + private readonly IServerConfigurationManager _config; private readonly IFileSystem _fileSystem; private readonly ILogger _logger; private readonly IItemRepository _itemRepo; @@ -46,9 +47,9 @@ namespace MediaBrowser.Server.Implementations.LiveTv private List _channelIdList = new List(); private Dictionary _programs = new Dictionary(); - public LiveTvManager(IServerApplicationPaths appPaths, IFileSystem fileSystem, ILogger logger, IItemRepository itemRepo, IImageProcessor imageProcessor, IUserDataManager userDataManager, IDtoService dtoService, IUserManager userManager, ILibraryManager libraryManager, IMediaEncoder mediaEncoder) + public LiveTvManager(IServerConfigurationManager config, IFileSystem fileSystem, ILogger logger, IItemRepository itemRepo, IImageProcessor imageProcessor, IUserDataManager userDataManager, IDtoService dtoService, IUserManager userManager, ILibraryManager libraryManager, IMediaEncoder mediaEncoder) { - _appPaths = appPaths; + _config = config; _fileSystem = fileSystem; _logger = logger; _itemRepo = itemRepo; @@ -217,7 +218,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv private async Task GetChannel(ChannelInfo channelInfo, string serviceName, CancellationToken cancellationToken) { - var path = Path.Combine(_appPaths.ItemsByNamePath, "channels", _fileSystem.GetValidFilename(channelInfo.Name)); + var path = Path.Combine(_config.ApplicationPaths.ItemsByNamePath, "channels", _fileSystem.GetValidFilename(channelInfo.Name)); var fileInfo = new DirectoryInfo(path); @@ -659,6 +660,8 @@ namespace MediaBrowser.Server.Implementations.LiveTv numComplete = 0; var programs = new List(); + var guideDays = GetGuideDays(list.Count); + foreach (var item in list) { // Avoid implicitly captured closure @@ -666,8 +669,8 @@ namespace MediaBrowser.Server.Implementations.LiveTv try { - var start = DateTime.UtcNow; - var end = start.AddDays(3); + var start = DateTime.UtcNow.AddHours(-1); + var end = start.AddDays(guideDays); var channelPrograms = await service.GetProgramsAsync(currentChannel.ChannelInfo.Id, start, end, cancellationToken).ConfigureAwait(false); @@ -695,6 +698,23 @@ namespace MediaBrowser.Server.Implementations.LiveTv _programs = programs.ToDictionary(i => i.Id); } + private double GetGuideDays(int channelCount) + { + if (_config.Configuration.LiveTvOptions.GuideDays.HasValue) + { + return _config.Configuration.LiveTvOptions.GuideDays.Value; + } + + var programsPerDay = channelCount * 48; + + const int maxPrograms = 32000; + + var days = Math.Round(((double)maxPrograms) / programsPerDay); + + // No less than 2, no more than 14 + return Math.Max(2, Math.Min(days, 14)); + } + private async Task>> GetChannels(ILiveTvService service, CancellationToken cancellationToken) { var channels = await service.GetChannelsAsync(cancellationToken).ConfigureAwait(false); diff --git a/MediaBrowser.ServerApplication/ApplicationHost.cs b/MediaBrowser.ServerApplication/ApplicationHost.cs index 21efe8f9f..27f874cb0 100644 --- a/MediaBrowser.ServerApplication/ApplicationHost.cs +++ b/MediaBrowser.ServerApplication/ApplicationHost.cs @@ -291,7 +291,7 @@ namespace MediaBrowser.ServerApplication await RegisterMediaEncoder(innerProgress).ConfigureAwait(false); progress.Report(90); - LiveTvManager = new LiveTvManager(ApplicationPaths, FileSystemManager, Logger, ItemRepository, ImageProcessor, UserDataManager, DtoService, UserManager, LibraryManager, MediaEncoder); + LiveTvManager = new LiveTvManager(ServerConfigurationManager, FileSystemManager, Logger, ItemRepository, ImageProcessor, UserDataManager, DtoService, UserManager, LibraryManager, MediaEncoder); RegisterSingleInstance(LiveTvManager); var displayPreferencesTask = Task.Run(async () => await ConfigureDisplayPreferencesRepositories().ConfigureAwait(false)); diff --git a/MediaBrowser.WebDashboard/Api/DashboardService.cs b/MediaBrowser.WebDashboard/Api/DashboardService.cs index 9d3e3e468..1a8871c28 100644 --- a/MediaBrowser.WebDashboard/Api/DashboardService.cs +++ b/MediaBrowser.WebDashboard/Api/DashboardService.cs @@ -505,6 +505,7 @@ namespace MediaBrowser.WebDashboard.Api "livetvtimer.js", "livetvseriestimer.js", "livetvseriestimers.js", + "livetvsettings.js", "livetvsuggested.js", "livetvtimers.js", "loginpage.js", diff --git a/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj b/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj index 50113c19f..8379503d4 100644 --- a/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj +++ b/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj @@ -184,6 +184,9 @@ PreserveNewest + + PreserveNewest + PreserveNewest @@ -433,6 +436,9 @@ PreserveNewest + + PreserveNewest + PreserveNewest -- cgit v1.2.3 From e4f5a3f005a240b013194d6a54edce29fef91e11 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 12 Jan 2014 16:32:13 -0500 Subject: added full m3u8 generation --- MediaBrowser.Api/BaseApiService.cs | 11 +- MediaBrowser.Api/Library/LibraryHelpers.cs | 70 ---------- MediaBrowser.Api/Playback/BaseStreamingService.cs | 2 + MediaBrowser.Api/Playback/Hls/BaseHlsService.cs | 27 ++-- MediaBrowser.Api/Playback/Hls/VideoHlsService.cs | 150 +++++++++++++++++++++ MediaBrowser.Api/Playback/StreamState.cs | 8 +- .../HttpServer/StreamWriter.cs | 8 ++ .../MediaBrowser.WebDashboard.csproj | 9 -- 8 files changed, 186 insertions(+), 99 deletions(-) (limited to 'MediaBrowser.Server.Implementations') diff --git a/MediaBrowser.Api/BaseApiService.cs b/MediaBrowser.Api/BaseApiService.cs index 62fcbd280..8febe4a65 100644 --- a/MediaBrowser.Api/BaseApiService.cs +++ b/MediaBrowser.Api/BaseApiService.cs @@ -1,13 +1,13 @@ -using System.IO; -using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.Audio; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Net; using MediaBrowser.Model.Logging; +using ServiceStack.Web; using System; using System.Collections.Generic; +using System.IO; using System.Linq; -using ServiceStack.Web; namespace MediaBrowser.Api { @@ -52,11 +52,6 @@ namespace MediaBrowser.Api return ResultFactory.GetOptimizedResult(Request, result); } - protected object ToStreamResult(Stream stream, string contentType) - { - return ResultFactory.GetResult(stream, contentType); - } - /// /// To the optimized result using cache. /// diff --git a/MediaBrowser.Api/Library/LibraryHelpers.cs b/MediaBrowser.Api/Library/LibraryHelpers.cs index e40cb7dd4..3836a0860 100644 --- a/MediaBrowser.Api/Library/LibraryHelpers.cs +++ b/MediaBrowser.Api/Library/LibraryHelpers.cs @@ -68,8 +68,6 @@ namespace MediaBrowser.Api.Library var rootFolderPath = user != null ? user.RootFolderPath : appPaths.DefaultUserViewsPath; var virtualFolderPath = Path.Combine(rootFolderPath, virtualFolderName); - ValidateNewMediaPath(fileSystem, rootFolderPath, path); - var shortcutFilename = Path.GetFileNameWithoutExtension(path); var lnk = Path.Combine(virtualFolderPath, shortcutFilename + ShortcutFileExtension); @@ -82,73 +80,5 @@ namespace MediaBrowser.Api.Library fileSystem.CreateShortcut(lnk, path); } - - /// - /// Validates that a new media path can be added - /// - /// The file system. - /// The current view root folder path. - /// The media path. - /// - /// - private static void ValidateNewMediaPath(IFileSystem fileSystem, string currentViewRootFolderPath, string mediaPath) - { - var pathsInCurrentVIew = Directory.EnumerateFiles(currentViewRootFolderPath, ShortcutFileSearch, SearchOption.AllDirectories) - .Select(fileSystem.ResolveShortcut) - .ToList(); - - // Don't allow duplicate sub-paths within the same user library, or it will result in duplicate items - // See comments in IsNewPathValid - var duplicate = pathsInCurrentVIew - .FirstOrDefault(p => !IsNewPathValid(fileSystem, mediaPath, p)); - - if (!string.IsNullOrEmpty(duplicate)) - { - throw new ArgumentException(string.Format("The path cannot be added to the library because {0} already exists.", duplicate)); - } - - // Make sure the current root folder doesn't already have a shortcut to the same path - duplicate = pathsInCurrentVIew - .FirstOrDefault(p => string.Equals(mediaPath, p, StringComparison.OrdinalIgnoreCase)); - - if (!string.IsNullOrEmpty(duplicate)) - { - throw new ArgumentException(string.Format("The path {0} already exists in the library", mediaPath)); - } - } - - /// - /// Validates that a new path can be added based on an existing path - /// - /// The file system. - /// The new path. - /// The existing path. - /// true if [is new path valid] [the specified new path]; otherwise, false. - private static bool IsNewPathValid(IFileSystem fileSystem, string newPath, string existingPath) - { - // Example: D:\Movies is the existing path - // D:\ cannot be added - // Neither can D:\Movies\Kids - // A D:\Movies duplicate is ok here since that will be caught later - - if (string.Equals(newPath, existingPath, StringComparison.OrdinalIgnoreCase)) - { - return true; - } - - // If enforceSubPathRestriction is true, validate the D:\Movies\Kids scenario - if (fileSystem.ContainsSubPath(existingPath, newPath)) - { - return false; - } - - // Validate the D:\ scenario - if (fileSystem.ContainsSubPath(newPath, existingPath)) - { - return false; - } - - return true; - } } } diff --git a/MediaBrowser.Api/Playback/BaseStreamingService.cs b/MediaBrowser.Api/Playback/BaseStreamingService.cs index 59fac5726..98d6e97a4 100644 --- a/MediaBrowser.Api/Playback/BaseStreamingService.cs +++ b/MediaBrowser.Api/Playback/BaseStreamingService.cs @@ -1042,6 +1042,7 @@ namespace MediaBrowser.Api.Playback } itemId = recording.Id; + //state.RunTimeTicks = recording.RunTimeTicks; state.SendInputOverStandardInput = recording.RecordingInfo.Status == RecordingStatus.InProgress; } else if (string.Equals(request.Type, "Channel", StringComparison.OrdinalIgnoreCase)) @@ -1090,6 +1091,7 @@ namespace MediaBrowser.Api.Playback : video.PlayableStreamFileNames.ToList(); } + state.RunTimeTicks = item.RunTimeTicks; itemId = item.Id; } diff --git a/MediaBrowser.Api/Playback/Hls/BaseHlsService.cs b/MediaBrowser.Api/Playback/Hls/BaseHlsService.cs index 1c4326928..f244886dc 100644 --- a/MediaBrowser.Api/Playback/Hls/BaseHlsService.cs +++ b/MediaBrowser.Api/Playback/Hls/BaseHlsService.cs @@ -75,18 +75,23 @@ namespace MediaBrowser.Api.Playback.Hls /// System.Object. protected object ProcessRequest(StreamRequest request) { - var state = GetState(request, CancellationToken.None).Result; - - return ProcessRequestAsync(state).Result; + return ProcessRequestAsync(request).Result; } /// /// Processes the request async. /// - /// The state. + /// The request. /// Task{System.Object}. - public async Task ProcessRequestAsync(StreamState state) + /// + /// A video bitrate is required + /// or + /// An audio bitrate is required + /// + private async Task ProcessRequestAsync(StreamRequest request) { + var state = GetState(request, CancellationToken.None).Result; + if (!state.VideoRequest.VideoBitRate.HasValue && (!state.VideoRequest.VideoCodec.HasValue || state.VideoRequest.VideoCodec.Value != VideoCodecs.Copy)) { throw new ArgumentException("A video bitrate is required"); @@ -155,7 +160,7 @@ namespace MediaBrowser.Api.Playback.Hls /// The state. /// The audio bitrate. /// The video bitrate. - private void GetPlaylistBitrates(StreamState state, out int audioBitrate, out int videoBitrate) + protected void GetPlaylistBitrates(StreamState state, out int audioBitrate, out int videoBitrate) { var audioBitrateParam = GetAudioBitrateParam(state); var videoBitrateParam = GetVideoBitrateParam(state); @@ -269,7 +274,7 @@ namespace MediaBrowser.Api.Playback.Hls var threads = GetNumberOfThreads(false); - var args = string.Format("{0}{1} {2} {3} -i {4}{5} -map_metadata -1 -threads {6} {7} {8} -sc_threshold 0 {9} -hls_time 10 -start_number 0 -hls_list_size 1440 \"{10}\"", + var args = string.Format("{0}{1} {2} {3} -i {4}{5} -map_metadata -1 -threads {6} {7} {8} -sc_threshold 0 {9} -hls_time {10} -start_number 0 -hls_list_size 1440 \"{11}\"", itsOffset, probeSize, GetUserAgentParam(state.MediaPath), @@ -280,6 +285,7 @@ namespace MediaBrowser.Api.Playback.Hls GetMapArgs(state), GetVideoArguments(state, performSubtitleConversions), GetAudioArguments(state), + state.SegmentLength.ToString(UsCulture), outputPath ).Trim(); @@ -291,10 +297,11 @@ namespace MediaBrowser.Api.Playback.Hls var bitrate = hlsVideoRequest.BaselineStreamAudioBitRate ?? 64000; - var lowBitrateParams = string.Format(" -threads {0} -vn -codec:a:0 libmp3lame -ac 2 -ab {2} -hls_time 10 -start_number 0 -hls_list_size 1440 \"{1}\"", + var lowBitrateParams = string.Format(" -threads {0} -vn -codec:a:0 libmp3lame -ac 2 -ab {1} -hls_time {2} -start_number 0 -hls_list_size 1440 \"{3}\"", threads, - lowBitratePath, - bitrate / 2); + bitrate / 2, + state.SegmentLength.ToString(UsCulture), + lowBitratePath); args += " " + lowBitrateParams; } diff --git a/MediaBrowser.Api/Playback/Hls/VideoHlsService.cs b/MediaBrowser.Api/Playback/Hls/VideoHlsService.cs index c87f61a1f..fae9e26c6 100644 --- a/MediaBrowser.Api/Playback/Hls/VideoHlsService.cs +++ b/MediaBrowser.Api/Playback/Hls/VideoHlsService.cs @@ -5,9 +5,14 @@ using MediaBrowser.Controller.Library; using MediaBrowser.Controller.LiveTv; using MediaBrowser.Controller.MediaInfo; using MediaBrowser.Controller.Persistence; +using MediaBrowser.Model.Dto; using MediaBrowser.Model.IO; using ServiceStack; using System; +using System.Collections.Generic; +using System.Text; +using System.Threading; +using System.Threading.Tasks; namespace MediaBrowser.Api.Playback.Hls { @@ -28,6 +33,29 @@ namespace MediaBrowser.Api.Playback.Hls public int TimeStampOffsetMs { get; set; } } + [Route("/Videos/{Id}/master.m3u8", "GET")] + [Api(Description = "Gets a video stream using HTTP live streaming.")] + public class GetMasterHlsVideoStream : VideoStreamRequest + { + [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; } + + [ApiMember(Name = "AppendBaselineStream", Description = "Optional. Whether or not to include a baseline audio-only stream in the master playlist.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET")] + public bool AppendBaselineStream { get; set; } + } + + [Route("/Videos/{Id}/main.m3u8", "GET")] + [Api(Description = "Gets a video stream using HTTP live streaming.")] + public class GetMainHlsVideoStream : VideoStreamRequest + { + } + + [Route("/Videos/{Id}/baseline.m3u8", "GET")] + [Api(Description = "Gets a video stream using HTTP live streaming.")] + public class GetBaselineHlsVideoStream : VideoStreamRequest + { + } + /// /// Class VideoHlsService /// @@ -38,6 +66,128 @@ namespace MediaBrowser.Api.Playback.Hls { } + public object Get(GetMasterHlsVideoStream request) + { + var result = GetAsync(request).Result; + + return result; + } + + public object Get(GetMainHlsVideoStream request) + { + var result = GetPlaylistAsync(request, "main").Result; + + return result; + } + + public object Get(GetBaselineHlsVideoStream request) + { + var result = GetPlaylistAsync(request, "baseline").Result; + + return result; + } + + private async Task GetPlaylistAsync(VideoStreamRequest request, string name) + { + var state = await GetState(request, CancellationToken.None).ConfigureAwait(false); + + var builder = new StringBuilder(); + + builder.AppendLine("#EXTM3U"); + builder.AppendLine("#EXT-X-VERSION:3"); + builder.AppendLine("#EXT-X-TARGETDURATION:" + state.SegmentLength.ToString(UsCulture)); + builder.AppendLine("#EXT-X-MEDIA-SEQUENCE:0"); + + var queryStringIndex = Request.RawUrl.IndexOf('?'); + var queryString = queryStringIndex == -1 ? string.Empty : Request.RawUrl.Substring(queryStringIndex); + + var seconds = TimeSpan.FromTicks(state.RunTimeTicks ?? 0).TotalSeconds; + + var index = 0; + + while (seconds > 0) + { + var length = seconds >= state.SegmentLength ? state.SegmentLength : seconds; + + builder.AppendLine("#EXTINF:" + length.ToString(UsCulture)); + + builder.AppendLine(string.Format("hls/{0}/{1}.ts{2}" , + + name, + index.ToString(UsCulture), + queryString)); + + seconds -= state.SegmentLength; + index++; + } + + builder.AppendLine("#EXT-X-ENDLIST"); + + var playlistText = builder.ToString(); + + return ResultFactory.GetResult(playlistText, MimeTypes.GetMimeType("playlist.m3u8"), new Dictionary()); + } + + private async Task GetAsync(GetMasterHlsVideoStream request) + { + var state = await GetState(request, CancellationToken.None).ConfigureAwait(false); + + if (!state.VideoRequest.VideoBitRate.HasValue && (!state.VideoRequest.VideoCodec.HasValue || state.VideoRequest.VideoCodec.Value != VideoCodecs.Copy)) + { + throw new ArgumentException("A video bitrate is required"); + } + if (!state.Request.AudioBitRate.HasValue && (!state.Request.AudioCodec.HasValue || state.Request.AudioCodec.Value != AudioCodecs.Copy)) + { + throw new ArgumentException("An audio bitrate is required"); + } + + int audioBitrate; + int videoBitrate; + GetPlaylistBitrates(state, out audioBitrate, out videoBitrate); + + var appendBaselineStream = false; + var baselineStreamBitrate = 64000; + + var hlsVideoRequest = state.VideoRequest as GetMasterHlsVideoStream; + if (hlsVideoRequest != null) + { + appendBaselineStream = hlsVideoRequest.AppendBaselineStream; + baselineStreamBitrate = hlsVideoRequest.BaselineStreamAudioBitRate ?? baselineStreamBitrate; + } + + var playlistText = GetMasterPlaylistFileText(videoBitrate + audioBitrate, appendBaselineStream, baselineStreamBitrate); + + return ResultFactory.GetResult(playlistText, MimeTypes.GetMimeType("playlist.m3u8"), new Dictionary()); + } + + private string GetMasterPlaylistFileText(int bitrate, bool includeBaselineStream, int baselineStreamBitrate) + { + var builder = new StringBuilder(); + + builder.AppendLine("#EXTM3U"); + + // Pad a little to satisfy the apple hls validator + var paddedBitrate = Convert.ToInt32(bitrate * 1.05); + + var queryStringIndex = Request.RawUrl.IndexOf('?'); + var queryString = queryStringIndex == -1 ? string.Empty : Request.RawUrl.Substring(queryStringIndex); + + // Main stream + builder.AppendLine("#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=" + paddedBitrate.ToString(UsCulture)); + var playlistUrl = "main.m3u8" + queryString; + builder.AppendLine(playlistUrl); + + // Low bitrate stream + if (includeBaselineStream) + { + builder.AppendLine("#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=" + baselineStreamBitrate.ToString(UsCulture)); + playlistUrl = "baseline.m3u8" + queryString; + builder.AppendLine(playlistUrl); + } + + return builder.ToString(); + } + /// /// Gets the specified request. /// diff --git a/MediaBrowser.Api/Playback/StreamState.cs b/MediaBrowser.Api/Playback/StreamState.cs index bf584c385..17a830380 100644 --- a/MediaBrowser.Api/Playback/StreamState.cs +++ b/MediaBrowser.Api/Playback/StreamState.cs @@ -1,8 +1,8 @@ -using System.Threading; -using MediaBrowser.Model.Entities; +using MediaBrowser.Model.Entities; using MediaBrowser.Model.IO; using System.Collections.Generic; using System.IO; +using System.Threading; namespace MediaBrowser.Api.Playback { @@ -54,5 +54,9 @@ namespace MediaBrowser.Api.Playback public CancellationTokenSource StandardInputCancellationTokenSource { get; set; } public string LiveTvStreamId { get; set; } + + public int SegmentLength = 10; + + public long? RunTimeTicks; } } diff --git a/MediaBrowser.Server.Implementations/HttpServer/StreamWriter.cs b/MediaBrowser.Server.Implementations/HttpServer/StreamWriter.cs index a4e6f18bb..a8774f1b7 100644 --- a/MediaBrowser.Server.Implementations/HttpServer/StreamWriter.cs +++ b/MediaBrowser.Server.Implementations/HttpServer/StreamWriter.cs @@ -2,6 +2,7 @@ using ServiceStack.Web; using System; using System.Collections.Generic; +using System.Globalization; using System.IO; using System.Threading.Tasks; @@ -13,6 +14,8 @@ namespace MediaBrowser.Server.Implementations.HttpServer public class StreamWriter : IStreamWriter, IHasOptions { private ILogger Logger { get; set; } + + private static readonly CultureInfo UsCulture = new CultureInfo("en-US"); /// /// Gets or sets the source stream. @@ -50,6 +53,11 @@ namespace MediaBrowser.Server.Implementations.HttpServer Logger = logger; Options["Content-Type"] = contentType; + + if (source.CanSeek) + { + Options["Content-Length"] = source.Length.ToString(UsCulture); + } } /// diff --git a/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj b/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj index 35ec2d6e7..8379503d4 100644 --- a/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj +++ b/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj @@ -157,15 +157,6 @@ PreserveNewest - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - PreserveNewest -- cgit v1.2.3