live tv updates

pull/702/head
Luke Pulverenti 11 years ago
parent 7e8d11cb2a
commit cb9b570a2a

@ -260,20 +260,10 @@ namespace MediaBrowser.Api.Playback
{
var quality = ServerConfigurationManager.Configuration.EncodingQuality;
if (quality == EncodingQuality.Auto)
{
var cpuCount = Environment.ProcessorCount;
if (cpuCount >= 4)
{
return 0;
}
return cpuCount;
}
switch (quality)
{
case EncodingQuality.Auto:
return 0;
case EncodingQuality.HighSpeed:
return 2;
case EncodingQuality.HighQuality:

@ -132,7 +132,7 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
#if __MonoCS__
return GetMonoRequest(options, method, enableHttpCompression);
#endif
var request = HttpWebRequest.CreateHttp(options.Url);
if (!string.IsNullOrEmpty(options.AcceptHeader))
@ -172,9 +172,64 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
/// <returns>Task{HttpResponseInfo}.</returns>
/// <exception cref="HttpException">
/// </exception>
public async Task<HttpResponseInfo> GetResponse(HttpRequestOptions options)
public Task<HttpResponseInfo> GetResponse(HttpRequestOptions options)
{
return SendAsync(options, "GET");
}
/// <summary>
/// Performs a GET request and returns the resulting stream
/// </summary>
/// <param name="options">The options.</param>
/// <returns>Task{Stream}.</returns>
/// <exception cref="HttpException"></exception>
/// <exception cref="MediaBrowser.Model.Net.HttpException"></exception>
public async Task<Stream> Get(HttpRequestOptions options)
{
var response = await GetResponse(options).ConfigureAwait(false);
return response.Content;
}
/// <summary>
/// Performs a GET request and returns the resulting stream
/// </summary>
/// <param name="url">The URL.</param>
/// <param name="resourcePool">The resource pool.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task{Stream}.</returns>
public Task<Stream> Get(string url, SemaphoreSlim resourcePool, CancellationToken cancellationToken)
{
ValidateParams(options.Url, options.CancellationToken);
return Get(new HttpRequestOptions
{
Url = url,
ResourcePool = resourcePool,
CancellationToken = cancellationToken,
});
}
/// <summary>
/// Gets the specified URL.
/// </summary>
/// <param name="url">The URL.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task{Stream}.</returns>
public Task<Stream> Get(string url, CancellationToken cancellationToken)
{
return Get(url, null, cancellationToken);
}
/// <summary>
/// send as an asynchronous operation.
/// </summary>
/// <param name="options">The options.</param>
/// <param name="httpMethod">The HTTP method.</param>
/// <returns>Task{HttpResponseInfo}.</returns>
/// <exception cref="HttpException">
/// </exception>
private async Task<HttpResponseInfo> SendAsync(HttpRequestOptions options, string httpMethod)
{
ValidateParams(options);
options.CancellationToken.ThrowIfCancellationRequested();
@ -185,7 +240,17 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
throw new HttpException(string.Format("Cancelling connection to {0} due to a previous timeout.", options.Url)) { IsTimedOut = true };
}
var httpWebRequest = GetRequest(options, "GET", options.EnableHttpCompression);
var httpWebRequest = GetRequest(options, httpMethod, options.EnableHttpCompression);
if (!string.IsNullOrEmpty(options.RequestContent) || string.Equals(httpMethod, "post", StringComparison.OrdinalIgnoreCase))
{
var content = options.RequestContent ?? string.Empty;
var bytes = Encoding.UTF8.GetBytes(content);
httpWebRequest.ContentType = options.RequestContentType ?? "application/x-www-form-urlencoded";
httpWebRequest.ContentLength = bytes.Length;
httpWebRequest.GetRequestStream().Write(bytes, 0, bytes.Length);
}
if (options.ResourcePool != null)
{
@ -202,7 +267,7 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
throw new HttpException(string.Format("Connection to {0} timed out", options.Url)) { IsTimedOut = true };
}
_logger.Info("HttpClientManager.GET url: {0}", options.Url);
_logger.Info("HttpClientManager {0}: {1}", httpMethod.ToUpper(), options.Url);
try
{
@ -275,46 +340,9 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
}
}
/// <summary>
/// Performs a GET request and returns the resulting stream
/// </summary>
/// <param name="options">The options.</param>
/// <returns>Task{Stream}.</returns>
/// <exception cref="HttpException"></exception>
/// <exception cref="MediaBrowser.Model.Net.HttpException"></exception>
public async Task<Stream> Get(HttpRequestOptions options)
public Task<HttpResponseInfo> Post(HttpRequestOptions options)
{
var response = await GetResponse(options).ConfigureAwait(false);
return response.Content;
}
/// <summary>
/// Performs a GET request and returns the resulting stream
/// </summary>
/// <param name="url">The URL.</param>
/// <param name="resourcePool">The resource pool.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task{Stream}.</returns>
public Task<Stream> Get(string url, SemaphoreSlim resourcePool, CancellationToken cancellationToken)
{
return Get(new HttpRequestOptions
{
Url = url,
ResourcePool = resourcePool,
CancellationToken = cancellationToken,
});
}
/// <summary>
/// Gets the specified URL.
/// </summary>
/// <param name="url">The URL.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task{Stream}.</returns>
public Task<Stream> Get(string url, CancellationToken cancellationToken)
{
return Get(url, null, cancellationToken);
return SendAsync(options, "POST");
}
/// <summary>
@ -329,82 +357,15 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
/// <exception cref="MediaBrowser.Model.Net.HttpException"></exception>
public async Task<Stream> Post(HttpRequestOptions options, Dictionary<string, string> postData)
{
ValidateParams(options.Url, options.CancellationToken);
options.CancellationToken.ThrowIfCancellationRequested();
var httpWebRequest = GetRequest(options, "POST", options.EnableHttpCompression);
var strings = postData.Keys.Select(key => string.Format("{0}={1}", key, postData[key]));
var postContent = string.Join("&", strings.ToArray());
var bytes = Encoding.UTF8.GetBytes(postContent);
httpWebRequest.ContentType = "application/x-www-form-urlencoded";
httpWebRequest.ContentLength = bytes.Length;
httpWebRequest.GetRequestStream().Write(bytes, 0, bytes.Length);
if (options.ResourcePool != null)
{
await options.ResourcePool.WaitAsync(options.CancellationToken).ConfigureAwait(false);
}
_logger.Info("HttpClientManager.POST url: {0}", options.Url);
try
{
options.CancellationToken.ThrowIfCancellationRequested();
using (var response = await httpWebRequest.GetResponseAsync().ConfigureAwait(false))
{
var httpResponse = (HttpWebResponse)response;
EnsureSuccessStatusCode(httpResponse);
options.CancellationToken.ThrowIfCancellationRequested();
using (var stream = httpResponse.GetResponseStream())
{
var memoryStream = new MemoryStream();
await stream.CopyToAsync(memoryStream).ConfigureAwait(false);
memoryStream.Position = 0;
options.RequestContent = postContent;
options.RequestContentType = "application/x-www-form-urlencoded";
return memoryStream;
}
}
}
catch (OperationCanceledException ex)
{
var exception = GetCancellationException(options.Url, options.CancellationToken, ex);
var response = await Post(options).ConfigureAwait(false);
throw exception;
}
catch (HttpRequestException ex)
{
_logger.ErrorException("Error getting response from " + options.Url, ex);
throw new HttpException(ex.Message, ex);
}
catch (WebException ex)
{
_logger.ErrorException("Error getting response from " + options.Url, ex);
throw new HttpException(ex.Message, ex);
}
catch (Exception ex)
{
_logger.ErrorException("Error getting response from " + options.Url, ex);
throw;
}
finally
{
if (options.ResourcePool != null)
{
options.ResourcePool.Release();
}
}
return response.Content;
}
/// <summary>
@ -443,7 +404,7 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
public async Task<HttpResponseInfo> GetTempFileResponse(HttpRequestOptions options)
{
ValidateParams(options.Url, options.CancellationToken);
ValidateParams(options);
Directory.CreateDirectory(_appPaths.TempDirectory);
@ -592,7 +553,7 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
{
return new HttpException(ex.Message, ex);
}
return ex;
}
@ -608,17 +569,11 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
}
}
/// <summary>
/// Validates the params.
/// </summary>
/// <param name="url">The URL.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <exception cref="System.ArgumentNullException">url</exception>
private void ValidateParams(string url, CancellationToken cancellationToken)
private void ValidateParams(HttpRequestOptions options)
{
if (string.IsNullOrEmpty(url))
if (string.IsNullOrEmpty(options.Url))
{
throw new ArgumentNullException("url");
throw new ArgumentNullException("options");
}
}

@ -66,6 +66,10 @@ namespace MediaBrowser.Common.Net
public Dictionary<string, string> RequestHeaders { get; private set; }
public string RequestContentType { get; set; }
public string RequestContent { get; set; }
private string GetHeaderValue(string name)
{
string value;

@ -64,6 +64,13 @@ namespace MediaBrowser.Common.Net
/// <returns>Task{Stream}.</returns>
Task<Stream> Post(string url, Dictionary<string, string> postData, CancellationToken cancellationToken);
/// <summary>
/// Posts the specified options.
/// </summary>
/// <param name="options">The options.</param>
/// <returns>Task{HttpResponseInfo}.</returns>
Task<HttpResponseInfo> Post(HttpRequestOptions options);
/// <summary>
/// Downloads the contents of a given url into a temporary location
/// </summary>

@ -17,6 +17,12 @@ namespace MediaBrowser.Controller.LiveTv
/// <value>The channel identifier.</value>
public string ChannelId { get; set; }
/// <summary>
/// Gets or sets the name of the channel.
/// </summary>
/// <value>The name of the channel.</value>
public string ChannelName { get; set; }
/// <summary>
/// Name of the program
/// </summary>

@ -38,6 +38,12 @@ namespace MediaBrowser.Controller.LiveTv
/// <value>The path.</value>
public string Path { get; set; }
/// <summary>
/// Gets or sets the URL.
/// </summary>
/// <value>The URL.</value>
public string Url { get; set; }
/// <summary>
/// Gets or sets the overview.
/// </summary>

@ -48,11 +48,23 @@ namespace MediaBrowser.Controller.LiveTv
public DateTime EndDate { get; set; }
/// <summary>
/// Gets or sets the type of the recurrence.
/// Gets or sets a value indicating whether [record any time].
/// </summary>
/// <value>The type of the recurrence.</value>
public RecurrenceType RecurrenceType { get; set; }
/// <value><c>true</c> if [record any time]; otherwise, <c>false</c>.</value>
public bool RecordAnyTime { get; set; }
/// <summary>
/// Gets or sets a value indicating whether [record any channel].
/// </summary>
/// <value><c>true</c> if [record any channel]; otherwise, <c>false</c>.</value>
public bool RecordAnyChannel { get; set; }
/// <summary>
/// Gets or sets a value indicating whether [record new only].
/// </summary>
/// <value><c>true</c> if [record new only]; otherwise, <c>false</c>.</value>
public bool RecordNewOnly { get; set; }
/// <summary>
/// Gets or sets the days.
/// </summary>

@ -23,6 +23,12 @@ namespace MediaBrowser.Model.LiveTv
/// <value>The channel identifier.</value>
public string ChannelId { get; set; }
/// <summary>
/// Gets or sets the name of the channel.
/// </summary>
/// <value>The name of the channel.</value>
public string ChannelName { get; set; }
/// <summary>
/// Gets or sets the community rating.
/// </summary>

@ -50,6 +50,12 @@ namespace MediaBrowser.Model.LiveTv
/// <value>The path.</value>
public string Path { get; set; }
/// <summary>
/// Gets or sets the URL.
/// </summary>
/// <value>The URL.</value>
public string Url { get; set; }
/// <summary>
/// Overview of the recording.
/// </summary>

@ -14,15 +14,6 @@ namespace MediaBrowser.Model.LiveTv
Error
}
public enum RecurrenceType
{
Manual,
NewProgramEventsOneChannel,
AllProgramEventsOneChannel,
NewProgramEventsAllChannels,
AllProgramEventsAllChannels
}
public enum DayPattern
{
Daily,

@ -71,10 +71,22 @@ namespace MediaBrowser.Model.LiveTv
public DateTime EndDate { get; set; }
/// <summary>
/// Gets or sets the type of the recurrence.
/// Gets or sets a value indicating whether [record any time].
/// </summary>
/// <value>The type of the recurrence.</value>
public RecurrenceType RecurrenceType { get; set; }
/// <value><c>true</c> if [record any time]; otherwise, <c>false</c>.</value>
public bool RecordAnyTime { get; set; }
/// <summary>
/// Gets or sets a value indicating whether [record any channel].
/// </summary>
/// <value><c>true</c> if [record any channel]; otherwise, <c>false</c>.</value>
public bool RecordAnyChannel { get; set; }
/// <summary>
/// Gets or sets a value indicating whether [record new only].
/// </summary>
/// <value><c>true</c> if [record new only]; otherwise, <c>false</c>.</value>
public bool RecordNewOnly { get; set; }
/// <summary>
/// Gets or sets the days.

@ -43,6 +43,12 @@ namespace MediaBrowser.Model.LiveTv
/// <value>The program identifier.</value>
public string ProgramId { get; set; }
/// <summary>
/// Gets or sets the external program identifier.
/// </summary>
/// <value>The external program identifier.</value>
public string ExternalProgramId { get; set; }
/// <summary>
/// Name of the recording.
/// </summary>

@ -47,7 +47,8 @@ namespace MediaBrowser.Server.Implementations.LiveTv
RequiredPrePaddingSeconds = info.RequiredPrePaddingSeconds,
ExternalChannelId = info.ChannelId,
ExternalSeriesTimerId = info.SeriesTimerId,
ServiceName = service.Name
ServiceName = service.Name,
ExternalProgramId = info.ProgramId
};
var duration = info.EndDate - info.StartDate;
@ -78,7 +79,9 @@ namespace MediaBrowser.Server.Implementations.LiveTv
RequiredPrePaddingSeconds = info.RequiredPrePaddingSeconds,
Days = info.Days,
Priority = info.Priority,
RecurrenceType = info.RecurrenceType,
RecordAnyChannel = info.RecordAnyChannel,
RecordAnyTime = info.RecordAnyTime,
RecordNewOnly = info.RecordNewOnly,
ExternalChannelId = info.ChannelId,
ExternalProgramId = info.ProgramId,
ServiceName = service.Name
@ -146,7 +149,8 @@ namespace MediaBrowser.Server.Implementations.LiveTv
OfficialRating = info.OfficialRating,
Audio = info.Audio,
IsHD = info.IsHD,
ServiceName = service.Name
ServiceName = service.Name,
Url = info.Url
};
if (user != null)
@ -219,7 +223,8 @@ namespace MediaBrowser.Server.Implementations.LiveTv
CommunityRating = program.CommunityRating,
AspectRatio = program.AspectRatio,
IsRepeat = program.IsRepeat,
EpisodeTitle = program.EpisodeTitle
EpisodeTitle = program.EpisodeTitle,
ChannelName = program.ChannelName
};
if (user != null)
@ -302,7 +307,8 @@ namespace MediaBrowser.Server.Implementations.LiveTv
RequestedPostPaddingSeconds = dto.RequestedPostPaddingSeconds,
RequestedPrePaddingSeconds = dto.RequestedPrePaddingSeconds,
RequiredPostPaddingSeconds = dto.RequiredPostPaddingSeconds,
RequiredPrePaddingSeconds = dto.RequiredPrePaddingSeconds
RequiredPrePaddingSeconds = dto.RequiredPrePaddingSeconds,
ProgramId = dto.ExternalProgramId
};
}
@ -323,8 +329,10 @@ namespace MediaBrowser.Server.Implementations.LiveTv
RequiredPrePaddingSeconds = dto.RequiredPrePaddingSeconds,
Days = dto.Days,
Priority = dto.Priority,
RecurrenceType = dto.RecurrenceType,
ProgramId = dto.ExternalProgramId
ProgramId = dto.ExternalProgramId,
RecordAnyChannel = dto.RecordAnyChannel,
RecordAnyTime = dto.RecordAnyTime,
RecordNewOnly = dto.RecordNewOnly
};
}
}

@ -336,7 +336,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv
.ToList();
}
var returnArray = list.OrderByDescending(i => i.StartDate)
var returnArray = list.OrderBy(i => i.StartDate)
.ToArray();
return new QueryResult<TimerInfoDto>

@ -275,7 +275,9 @@ namespace MediaBrowser.WebDashboard.Api
// Don't cache if not configured to do so
// But always cache images to simulate production
if (!_serverConfigurationManager.Configuration.EnableDashboardResponseCaching && !contentType.StartsWith("image/", StringComparison.OrdinalIgnoreCase))
if (!_serverConfigurationManager.Configuration.EnableDashboardResponseCaching &&
!contentType.StartsWith("image/", StringComparison.OrdinalIgnoreCase) &&
!contentType.StartsWith("font/", StringComparison.OrdinalIgnoreCase))
{
return ResultFactory.GetResult(GetResourceStream(path).Result, contentType);
}
@ -284,7 +286,7 @@ namespace MediaBrowser.WebDashboard.Api
// Cache images unconditionally - updates to image files will require new filename
// If there's a version number in the query string we can cache this unconditionally
if (contentType.StartsWith("image/", StringComparison.OrdinalIgnoreCase) || !string.IsNullOrEmpty(request.V))
if (contentType.StartsWith("image/", StringComparison.OrdinalIgnoreCase) || contentType.StartsWith("font/", StringComparison.OrdinalIgnoreCase) || !string.IsNullOrEmpty(request.V))
{
cacheDuration = TimeSpan.FromDays(365);
}

@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>MediaBrowser.Common.Internal</id>
<version>3.0.273</version>
<version>3.0.275</version>
<title>MediaBrowser.Common.Internal</title>
<authors>Luke</authors>
<owners>ebr,Luke,scottisafool</owners>
@ -12,7 +12,7 @@
<description>Contains common components shared by Media Browser Theater and Media Browser Server. Not intended for plugin developer consumption.</description>
<copyright>Copyright © Media Browser 2013</copyright>
<dependencies>
<dependency id="MediaBrowser.Common" version="3.0.273" />
<dependency id="MediaBrowser.Common" version="3.0.275" />
<dependency id="NLog" version="2.1.0" />
<dependency id="SimpleInjector" version="2.4.0" />
<dependency id="sharpcompress" version="0.10.2" />

@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>MediaBrowser.Common</id>
<version>3.0.273</version>
<version>3.0.275</version>
<title>MediaBrowser.Common</title>
<authors>Media Browser Team</authors>
<owners>ebr,Luke,scottisafool</owners>

@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>MediaBrowser.Server.Core</id>
<version>3.0.273</version>
<version>3.0.275</version>
<title>Media Browser.Server.Core</title>
<authors>Media Browser Team</authors>
<owners>ebr,Luke,scottisafool</owners>
@ -12,7 +12,7 @@
<description>Contains core components required to build plugins for Media Browser Server.</description>
<copyright>Copyright © Media Browser 2013</copyright>
<dependencies>
<dependency id="MediaBrowser.Common" version="3.0.273" />
<dependency id="MediaBrowser.Common" version="3.0.275" />
</dependencies>
</metadata>
<files>

Loading…
Cancel
Save