Skip to content

Commit

Permalink
live tv fix
Browse files Browse the repository at this point in the history
  • Loading branch information
LukePulverenti committed Mar 31, 2015
1 parent 370d9d7 commit fd590cb
Show file tree
Hide file tree
Showing 20 changed files with 207 additions and 66 deletions.
23 changes: 0 additions & 23 deletions MediaBrowser.Api/Playback/MediaInfoService.cs
Expand Up @@ -39,29 +39,6 @@ public class GetPlaybackInfo : IReturn<PlaybackInfoResponse>
[Route("/Items/{Id}/PlaybackInfo", "POST", Summary = "Gets live playback media info for an item")]
public class GetPostedPlaybackInfo : PlaybackInfoRequest, IReturn<PlaybackInfoResponse>
{
[ApiMember(Name = "Id", Description = "Item Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
public string Id { get; set; }

[ApiMember(Name = "UserId", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "POST")]
public string UserId { get; set; }

[ApiMember(Name = "MaxStreamingBitrate", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "POST")]
public int? MaxStreamingBitrate { get; set; }

[ApiMember(Name = "StartTimeTicks", Description = "Optional. Specify a starting offset, in ticks. 1 tick = 10000 ms", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "POST")]
public long? StartTimeTicks { get; set; }

[ApiMember(Name = "AudioStreamIndex", Description = "Optional. The index of the audio stream to use. If omitted the first audio stream will be used.", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "POST")]
public int? AudioStreamIndex { get; set; }

[ApiMember(Name = "SubtitleStreamIndex", Description = "Optional. The index of the subtitle stream to use. If omitted no subtitles will be used.", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "POST")]
public int? SubtitleStreamIndex { get; set; }

[ApiMember(Name = "MediaSourceId", Description = "The media version id, if playing an alternate version", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
public string MediaSourceId { get; set; }

[ApiMember(Name = "LiveStreamId", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
public string LiveStreamId { get; set; }
}

[Route("/LiveStreams/Open", "POST", Summary = "Opens a media source")]
Expand Down
2 changes: 1 addition & 1 deletion MediaBrowser.Api/Playback/TranscodingThrottler.cs
Expand Up @@ -42,7 +42,7 @@ private void TimerCallback(object state)

var options = GetOptions();

if (/*options.EnableThrottling &&*/ IsThrottleAllowed(_job, options.ThrottleThresholdSeconds))
if (options.EnableThrottling && IsThrottleAllowed(_job, options.ThrottleThresholdSeconds))
{
PauseTranscoding();
}
Expand Down
Expand Up @@ -107,30 +107,40 @@ private HttpClientInfo GetHttpClient(string host, bool enableHttpCompression)

private WebRequest GetRequest(HttpRequestOptions options, string method, bool enableHttpCompression)
{
var request = (HttpWebRequest)WebRequest.Create(options.Url);
var request = WebRequest.Create(options.Url);
var httpWebRequest = request as HttpWebRequest;

AddRequestHeaders(request, options);
if (httpWebRequest != null)
{
AddRequestHeaders(httpWebRequest, options);

request.AutomaticDecompression = enableHttpCompression ? DecompressionMethods.Deflate : DecompressionMethods.None;
httpWebRequest.AutomaticDecompression = enableHttpCompression ? DecompressionMethods.Deflate : DecompressionMethods.None;
}

request.CachePolicy = new RequestCachePolicy(RequestCacheLevel.BypassCache);

if (options.EnableKeepAlive)
if (httpWebRequest != null)
{
request.KeepAlive = true;
if (options.EnableKeepAlive)
{
httpWebRequest.KeepAlive = true;
}
}

request.Method = method;
request.Timeout = options.TimeoutMs;

if (!string.IsNullOrEmpty(options.Host))
if (httpWebRequest != null)
{
request.Host = options.Host;
}
if (!string.IsNullOrEmpty(options.Host))
{
httpWebRequest.Host = options.Host;
}

if (!string.IsNullOrEmpty(options.Referer))
{
request.Referer = options.Referer;
if (!string.IsNullOrEmpty(options.Referer))
{
httpWebRequest.Referer = options.Referer;
}
}

//request.ServicePoint.BindIPEndPointDelegate = BindIPEndPointCallback;
Expand Down
6 changes: 6 additions & 0 deletions MediaBrowser.Controller/LiveTv/LiveTvProgram.cs
Expand Up @@ -34,6 +34,12 @@ protected override string CreateUserDataKey()
/// <value>The channel identifier.</value>
public string ExternalChannelId { get; set; }

/// <summary>
/// Gets or sets the original air date.
/// </summary>
/// <value>The original air date.</value>
public DateTime? OriginalAirDate { get; set; }

/// <summary>
/// Gets or sets the type of the channel.
/// </summary>
Expand Down
16 changes: 16 additions & 0 deletions MediaBrowser.Controller/Sync/ISyncDataProvider.cs
Expand Up @@ -14,6 +14,14 @@ public interface ISyncDataProvider
/// <returns>Task&lt;List&lt;System.String&gt;&gt;.</returns>
Task<List<string>> GetServerItemIds(SyncTarget target, string serverId);

/// <summary>
/// Gets the synchronize job item ids.
/// </summary>
/// <param name="target">The target.</param>
/// <param name="serverId">The server identifier.</param>
/// <returns>Task&lt;List&lt;System.String&gt;&gt;.</returns>
Task<List<string>> GetSyncJobItemIds(SyncTarget target, string serverId);

/// <summary>
/// Adds the or update.
/// </summary>
Expand Down Expand Up @@ -46,5 +54,13 @@ public interface ISyncDataProvider
/// <param name="itemId">The item identifier.</param>
/// <returns>Task&lt;LocalItem&gt;.</returns>
Task<List<LocalItem>> GetCachedItems(SyncTarget target, string serverId, string itemId);
/// <summary>
/// Gets the cached items by synchronize job item identifier.
/// </summary>
/// <param name="target">The target.</param>
/// <param name="serverId">The server identifier.</param>
/// <param name="syncJobItemId">The synchronize job item identifier.</param>
/// <returns>Task&lt;List&lt;LocalItem&gt;&gt;.</returns>
Task<List<LocalItem>> GetCachedItemsBySyncJobItemId(SyncTarget target, string serverId, string syncJobItemId);
}
}
5 changes: 2 additions & 3 deletions MediaBrowser.Model/ApiClient/IApiClient.cs
Expand Up @@ -248,10 +248,9 @@ Task<T> GetAsync<T>(string url, CancellationToken cancellationToken = default(Ca
/// <summary>
/// Gets the playback information.
/// </summary>
/// <param name="itemId">The item identifier.</param>
/// <param name="userId">The user identifier.</param>
/// <param name="request">The request.</param>
/// <returns>Task&lt;LiveMediaInfoResult&gt;.</returns>
Task<PlaybackInfoResponse> GetPlaybackInfo(string itemId, string userId);
Task<PlaybackInfoResponse> GetPlaybackInfo(PlaybackInfoRequest request);

/// <summary>
/// Gets the users async.
Expand Down
16 changes: 16 additions & 0 deletions MediaBrowser.Model/MediaInfo/PlaybackInfoRequest.cs
Expand Up @@ -4,6 +4,22 @@ namespace MediaBrowser.Model.MediaInfo
{
public class PlaybackInfoRequest
{
public string Id { get; set; }

public string UserId { get; set; }

public int? MaxStreamingBitrate { get; set; }

public long? StartTimeTicks { get; set; }

public int? AudioStreamIndex { get; set; }

public int? SubtitleStreamIndex { get; set; }

public string MediaSourceId { get; set; }

public string LiveStreamId { get; set; }

public DeviceProfile DeviceProfile { get; set; }
}
}
5 changes: 5 additions & 0 deletions MediaBrowser.Model/Sync/LocalItem.cs
Expand Up @@ -31,6 +31,11 @@ public class LocalItem
/// <value>The item identifier.</value>
public string ItemId { get; set; }
/// <summary>
/// Gets or sets the synchronize job item identifier.
/// </summary>
/// <value>The synchronize job item identifier.</value>
public string SyncJobItemId { get; set; }
/// <summary>
/// Gets or sets the user ids with access.
/// </summary>
/// <value>The user ids with access.</value>
Expand Down
1 change: 1 addition & 0 deletions MediaBrowser.Model/Sync/SyncDataRequest.cs
Expand Up @@ -6,6 +6,7 @@ public class SyncDataRequest
{
public List<string> LocalItemIds { get; set; }
public List<string> OfflineUserIds { get; set; }
public List<string> SyncJobItemIds { get; set; }

public string TargetId { get; set; }

Expand Down
Expand Up @@ -2,7 +2,6 @@
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
Expand Down
Expand Up @@ -129,6 +129,11 @@ private IEnumerable<MediaStream> GetMediaStreamsForItem(IEnumerable<MediaStream>
return list;
}

public Task<IEnumerable<MediaSourceInfo>> GetPlayackMediaSources(string id, bool enablePathSubstitution, CancellationToken cancellationToken)
{
return GetPlayackMediaSources(id, null, enablePathSubstitution, cancellationToken);
}

public async Task<IEnumerable<MediaSourceInfo>> GetPlayackMediaSources(string id, string userId, bool enablePathSubstitution, CancellationToken cancellationToken)
{
var item = _libraryManager.GetItemById(id);
Expand Down Expand Up @@ -225,11 +230,6 @@ private void SetKeyProperties(IMediaSourceProvider provider, MediaSourceInfo med
}
}

public Task<IEnumerable<MediaSourceInfo>> GetPlayackMediaSources(string id, bool enablePathSubstitution, CancellationToken cancellationToken)
{
return GetPlayackMediaSources(id, null, enablePathSubstitution, cancellationToken);
}

public MediaSourceInfo GetStaticMediaSource(IHasMediaSources item, string mediaSourceId, bool enablePathSubstitution)
{
return GetStaticMediaSources(item, enablePathSubstitution).FirstOrDefault(i => string.Equals(i.Id, mediaSourceId, StringComparison.OrdinalIgnoreCase));
Expand Down
Expand Up @@ -373,7 +373,7 @@ public ProgramInfoDto GetProgramInfoDto(LiveTvProgram item, LiveTvChannel channe
StartDate = item.StartDate,
OfficialRating = item.OfficialRating,
IsHD = item.IsHD,
OriginalAirDate = item.PremiereDate,
OriginalAirDate = item.OriginalAirDate,
Audio = item.Audio,
CommunityRating = GetClientCommunityRating(item.CommunityRating),
IsRepeat = item.IsRepeat,
Expand Down
6 changes: 4 additions & 2 deletions MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs
Expand Up @@ -589,13 +589,15 @@ private async Task<LiveTvProgram> GetProgram(ProgramInfo info, ChannelType chann
item.Name = info.Name;
item.OfficialRating = info.OfficialRating;
item.Overview = info.Overview;
item.PremiereDate = info.OriginalAirDate;
item.OriginalAirDate = info.OriginalAirDate;
item.ProviderImagePath = info.ImagePath;
item.ProviderImageUrl = info.ImageUrl;
item.RunTimeTicks = (info.EndDate - info.StartDate).Ticks;
item.StartDate = info.StartDate;
item.ProductionYear = info.ProductionYear;

item.ProductionYear = info.ProductionYear;
item.PremiereDate = item.PremiereDate ?? info.OriginalAirDate;

await item.UpdateToRepository(ItemUpdateType.MetadataImport, cancellationToken).ConfigureAwait(false);

return item;
Expand Down
11 changes: 6 additions & 5 deletions MediaBrowser.Server.Implementations/Sync/MediaSync.cs
Expand Up @@ -67,12 +67,12 @@ public MediaSync(ILogger logger, ISyncManager syncManager, IServerApplicationHos
SyncTarget target,
CancellationToken cancellationToken)
{
var localIds = await dataProvider.GetServerItemIds(target, serverId).ConfigureAwait(false);
var jobItemIds = await dataProvider.GetSyncJobItemIds(target, serverId).ConfigureAwait(false);

var result = await _syncManager.SyncData(new SyncDataRequest
{
TargetId = target.Id,
LocalItemIds = localIds
SyncJobItemIds = jobItemIds

}).ConfigureAwait(false);

Expand Down Expand Up @@ -285,11 +285,11 @@ private string GetSubtitleSaveFileName(LocalItem item, string language, bool isF
private async Task RemoveItem(IServerSyncProvider provider,
ISyncDataProvider dataProvider,
string serverId,
string itemId,
string syncJobItemId,
SyncTarget target,
CancellationToken cancellationToken)
{
var localItems = await dataProvider.GetCachedItems(target, serverId, itemId);
var localItems = await dataProvider.GetCachedItemsBySyncJobItemId(target, serverId, syncJobItemId);

foreach (var localItem in localItems)
{
Expand Down Expand Up @@ -350,7 +350,8 @@ public LocalItem CreateLocalItem(IServerSyncProvider provider, SyncedItem synced
ItemId = libraryItem.Id,
ServerId = serverId,
LocalPath = localPath,
Id = GetLocalId(syncedItem.SyncJobItemId, libraryItem.Id)
Id = GetLocalId(syncedItem.SyncJobItemId, libraryItem.Id),
SyncJobItemId = syncedItem.SyncJobItemId
};
}

Expand Down

0 comments on commit fd590cb

Please sign in to comment.