diff --git a/MediaBrowser.Api/LiveTv/LiveTvService.cs b/MediaBrowser.Api/LiveTv/LiveTvService.cs index 24d76c0d2b..e7b348eb7e 100644 --- a/MediaBrowser.Api/LiveTv/LiveTvService.cs +++ b/MediaBrowser.Api/LiveTv/LiveTvService.cs @@ -73,6 +73,12 @@ namespace MediaBrowser.Api.LiveTv public string Id { get; set; } } + [Route("/LiveTv/Timers/Defaults", "GET")] + [Api(Description = "Gets default values for a new timer")] + public class GetDefaultTimer : IReturn + { + } + [Route("/LiveTv/Timers", "GET")] [Api(Description = "Gets live tv timers")] public class GetTimers : IReturn> @@ -92,6 +98,18 @@ namespace MediaBrowser.Api.LiveTv public string UserId { get; set; } } + [Route("/LiveTv/Programs/{Id}", "GET")] + [Api(Description = "Gets a live tv program")] + public class GetProgram : IReturn + { + [ApiMember(Name = "Id", Description = "Program Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")] + public string Id { get; set; } + + [ApiMember(Name = "UserId", Description = "Optional attach user data.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")] + public string UserId { get; set; } + } + + [Route("/LiveTv/Recordings/{Id}", "DELETE")] [Api(Description = "Deletes a live tv recording")] public class DeleteRecording : IReturnVoid @@ -114,6 +132,12 @@ namespace MediaBrowser.Api.LiveTv { } + [Route("/LiveTv/Timers", "POST")] + [Api(Description = "Creates a live tv timer")] + public class CreateTimer : TimerInfoDto, IReturnVoid + { + } + [Route("/LiveTv/SeriesTimers/{Id}", "GET")] [Api(Description = "Gets a live tv series timer")] public class GetSeriesTimer : IReturn @@ -142,6 +166,12 @@ namespace MediaBrowser.Api.LiveTv { } + [Route("/LiveTv/SeriesTimers", "POST")] + [Api(Description = "Creates a live tv series timer")] + public class CreateSeriesTimer : SeriesTimerInfoDto, IReturnVoid + { + } + public class LiveTvService : BaseApiService { private readonly ILiveTvManager _liveTvManager; @@ -266,7 +296,7 @@ namespace MediaBrowser.Api.LiveTv public object Get(GetSeriesTimers request) { var result = _liveTvManager.GetSeriesTimers(new SeriesTimerQuery - { + { }, CancellationToken.None).Result; @@ -293,5 +323,35 @@ namespace MediaBrowser.Api.LiveTv Task.WaitAll(task); } + + public object Get(GetDefaultTimer request) + { + var result = _liveTvManager.GetNewTimerDefaults(CancellationToken.None).Result; + + return ToOptimizedResult(result); + } + + public object Get(GetProgram request) + { + var user = string.IsNullOrEmpty(request.UserId) ? null : _userManager.GetUserById(new Guid(request.UserId)); + + var result = _liveTvManager.GetProgram(request.Id, CancellationToken.None, user).Result; + + return ToOptimizedResult(result); + } + + public void Post(CreateSeriesTimer request) + { + var task = _liveTvManager.CreateSeriesTimer(request, CancellationToken.None); + + Task.WaitAll(task); + } + + public void Post(CreateTimer request) + { + var task = _liveTvManager.CreateTimer(request, CancellationToken.None); + + Task.WaitAll(task); + } } } \ No newline at end of file diff --git a/MediaBrowser.Controller/LiveTv/ILiveTvManager.cs b/MediaBrowser.Controller/LiveTv/ILiveTvManager.cs index d9e9298cec..10dfc08430 100644 --- a/MediaBrowser.Controller/LiveTv/ILiveTvManager.cs +++ b/MediaBrowser.Controller/LiveTv/ILiveTvManager.cs @@ -31,6 +31,13 @@ namespace MediaBrowser.Controller.LiveTv /// Task. Task ScheduleRecording(string programId); + /// + /// Gets the new timer defaults asynchronous. + /// + /// The cancellation token. + /// Task{TimerInfo}. + Task GetNewTimerDefaults(CancellationToken cancellationToken); + /// /// Deletes the recording. /// @@ -131,6 +138,15 @@ namespace MediaBrowser.Controller.LiveTv /// Channel. Channel GetChannel(string id); + /// + /// Gets the program. + /// + /// The identifier. + /// The cancellation token. + /// The user. + /// Task{ProgramInfoDto}. + Task GetProgram(string id, CancellationToken cancellationToken, User user = null); + /// /// Gets the programs. /// @@ -154,5 +170,21 @@ namespace MediaBrowser.Controller.LiveTv /// The cancellation token. /// Task. Task UpdateSeriesTimer(SeriesTimerInfoDto timer, CancellationToken cancellationToken); + + /// + /// Creates the timer. + /// + /// The timer. + /// The cancellation token. + /// Task. + Task CreateTimer(TimerInfoDto timer, CancellationToken cancellationToken); + + /// + /// Creates the series timer. + /// + /// The timer. + /// The cancellation token. + /// Task. + Task CreateSeriesTimer(SeriesTimerInfoDto timer, CancellationToken cancellationToken); } } diff --git a/MediaBrowser.Controller/LiveTv/ILiveTvService.cs b/MediaBrowser.Controller/LiveTv/ILiveTvService.cs index a5c91663ee..b88cadf238 100644 --- a/MediaBrowser.Controller/LiveTv/ILiveTvService.cs +++ b/MediaBrowser.Controller/LiveTv/ILiveTvService.cs @@ -116,6 +116,13 @@ namespace MediaBrowser.Controller.LiveTv /// Task{IEnumerable{RecordingInfo}}. Task> GetTimersAsync(CancellationToken cancellationToken); + /// + /// Gets the timer defaults asynchronous. + /// + /// The cancellation token. + /// Task{TimerInfo}. + Task GetNewTimerDefaultsAsync(CancellationToken cancellationToken); + /// /// Gets the series timers asynchronous. /// diff --git a/MediaBrowser.Model/LiveTv/ChannelInfoDto.cs b/MediaBrowser.Model/LiveTv/ChannelInfoDto.cs index 020771e5ee..89c92e6fdf 100644 --- a/MediaBrowser.Model/LiveTv/ChannelInfoDto.cs +++ b/MediaBrowser.Model/LiveTv/ChannelInfoDto.cs @@ -22,6 +22,12 @@ namespace MediaBrowser.Model.LiveTv /// The identifier. public string Id { get; set; } + /// + /// Gets or sets the external identifier. + /// + /// The external identifier. + public string ExternalId { get; set; } + /// /// Gets or sets the image tags. /// diff --git a/MediaBrowser.Server.Implementations/LiveTv/LiveTvDtoService.cs b/MediaBrowser.Server.Implementations/LiveTv/LiveTvDtoService.cs index ab98336626..ea85238879 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/LiveTvDtoService.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/LiveTvDtoService.cs @@ -1,4 +1,6 @@ -using MediaBrowser.Common.Extensions; +using System.Threading; +using System.Threading.Tasks; +using MediaBrowser.Common.Extensions; using MediaBrowser.Controller.Drawing; using MediaBrowser.Controller.Dto; using MediaBrowser.Controller.Entities; @@ -186,7 +188,8 @@ namespace MediaBrowser.Server.Implementations.LiveTv Number = info.ChannelNumber, Type = info.GetType().Name, Id = info.Id.ToString("N"), - MediaType = info.MediaType + MediaType = info.MediaType, + ExternalId = info.ChannelId }; if (user != null) @@ -292,50 +295,99 @@ namespace MediaBrowser.Server.Implementations.LiveTv return name.ToLower().GetMD5(); } - public TimerInfo GetTimerInfo(TimerInfoDto dto) + public async Task GetTimerInfo(TimerInfoDto dto, bool isNew, ILiveTvManager liveTv, CancellationToken cancellationToken) { - return new TimerInfo + var info = new TimerInfo { - Id = dto.ExternalId, ChannelName = dto.ChannelName, Overview = dto.Overview, EndDate = dto.EndDate, Name = dto.Name, StartDate = dto.StartDate, - ChannelId = dto.ExternalChannelId, Status = dto.Status, SeriesTimerId = dto.ExternalSeriesTimerId, RequestedPostPaddingSeconds = dto.RequestedPostPaddingSeconds, RequestedPrePaddingSeconds = dto.RequestedPrePaddingSeconds, RequiredPostPaddingSeconds = dto.RequiredPostPaddingSeconds, RequiredPrePaddingSeconds = dto.RequiredPrePaddingSeconds, - ProgramId = dto.ExternalProgramId, Priority = dto.Priority }; + + // Convert internal server id's to external tv provider id's + if (!isNew && !string.IsNullOrEmpty(dto.Id)) + { + var timer = await liveTv.GetTimer(dto.Id, cancellationToken).ConfigureAwait(false); + + info.Id = timer.ExternalId; + } + + if (!string.IsNullOrEmpty(dto.SeriesTimerId)) + { + var timer = await liveTv.GetSeriesTimer(dto.SeriesTimerId, cancellationToken).ConfigureAwait(false); + + info.SeriesTimerId = timer.ExternalId; + } + + if (!string.IsNullOrEmpty(dto.ChannelId)) + { + var channel = await liveTv.GetChannel(dto.ChannelId, cancellationToken).ConfigureAwait(false); + + info.ChannelId = channel.ExternalId; + } + + if (!string.IsNullOrEmpty(dto.ProgramId)) + { + var program = await liveTv.GetProgram(dto.ProgramId, cancellationToken).ConfigureAwait(false); + + info.ProgramId = program.ExternalId; + } + + return info; } - public SeriesTimerInfo GetSeriesTimerInfo(SeriesTimerInfoDto dto) + public async Task GetSeriesTimerInfo(SeriesTimerInfoDto dto, bool isNew, ILiveTvManager liveTv, CancellationToken cancellationToken) { - return new SeriesTimerInfo + var info = new SeriesTimerInfo { - Id = dto.ExternalId, ChannelName = dto.ChannelName, Overview = dto.Overview, EndDate = dto.EndDate, Name = dto.Name, StartDate = dto.StartDate, - ChannelId = dto.ExternalChannelId, RequestedPostPaddingSeconds = dto.RequestedPostPaddingSeconds, RequestedPrePaddingSeconds = dto.RequestedPrePaddingSeconds, RequiredPostPaddingSeconds = dto.RequiredPostPaddingSeconds, RequiredPrePaddingSeconds = dto.RequiredPrePaddingSeconds, Days = dto.Days, Priority = dto.Priority, - ProgramId = dto.ExternalProgramId, RecordAnyChannel = dto.RecordAnyChannel, RecordAnyTime = dto.RecordAnyTime, RecordNewOnly = dto.RecordNewOnly }; + + // Convert internal server id's to external tv provider id's + if (!isNew && !string.IsNullOrEmpty(dto.Id)) + { + var timer = await liveTv.GetSeriesTimer(dto.Id, cancellationToken).ConfigureAwait(false); + + info.Id = timer.ExternalId; + } + + if (!string.IsNullOrEmpty(dto.ChannelId)) + { + var channel = await liveTv.GetChannel(dto.ChannelId, cancellationToken).ConfigureAwait(false); + + info.ChannelId = channel.ExternalId; + } + + if (!string.IsNullOrEmpty(dto.ProgramId)) + { + var program = await liveTv.GetProgram(dto.ProgramId, cancellationToken).ConfigureAwait(false); + + info.ProgramId = program.ExternalId; + } + + return info; } } } diff --git a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs index b56f94a364..b9dfc1b48f 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs @@ -178,7 +178,14 @@ namespace MediaBrowser.Server.Implementations.LiveTv return item; } - public async Task> GetPrograms(ProgramQuery query, CancellationToken cancellationToken) + public Task GetProgram(string id, CancellationToken cancellationToken, User user = null) + { + var program = _programs.FirstOrDefault(i => string.Equals(i.Id, id, StringComparison.OrdinalIgnoreCase)); + + return Task.FromResult(program); + } + + public Task> GetPrograms(ProgramQuery query, CancellationToken cancellationToken) { IEnumerable programs = _programs .OrderBy(i => i.StartDate) @@ -193,11 +200,13 @@ namespace MediaBrowser.Server.Implementations.LiveTv var returnArray = programs.ToArray(); - return new QueryResult + var result = new QueryResult { Items = returnArray, TotalRecordCount = returnArray.Length }; + + return Task.FromResult(result); } internal async Task RefreshChannels(IProgress progress, CancellationToken cancellationToken) @@ -416,26 +425,6 @@ namespace MediaBrowser.Server.Implementations.LiveTv return results.Items.FirstOrDefault(i => string.Equals(i.Id, id, StringComparison.CurrentCulture)); } - public Task UpdateTimer(TimerInfoDto timer, CancellationToken cancellationToken) - { - var info = _tvDtoService.GetTimerInfo(timer); - - var service = GetServices(timer.ServiceName, null) - .First(); - - return service.UpdateTimerAsync(info, cancellationToken); - } - - public Task UpdateSeriesTimer(SeriesTimerInfoDto timer, CancellationToken cancellationToken) - { - var info = _tvDtoService.GetSeriesTimerInfo(timer); - - var service = GetServices(timer.ServiceName, null) - .First(); - - return service.UpdateSeriesTimerAsync(info, cancellationToken); - } - public async Task> GetSeriesTimers(SeriesTimerQuery query, CancellationToken cancellationToken) { var list = new List(); @@ -469,5 +458,48 @@ namespace MediaBrowser.Server.Implementations.LiveTv return results.Items.FirstOrDefault(i => string.Equals(i.Id, id, StringComparison.CurrentCulture)); } + + public async Task GetNewTimerDefaults(CancellationToken cancellationToken) + { + var info = await ActiveService.GetNewTimerDefaultsAsync(cancellationToken).ConfigureAwait(false); + + return _tvDtoService.GetTimerInfoDto(info, ActiveService); + } + + public async Task CreateTimer(TimerInfoDto timer, CancellationToken cancellationToken) + { + var service = string.IsNullOrEmpty(timer.ServiceName) ? ActiveService : GetServices(timer.ServiceName, null).First(); + + var info = await _tvDtoService.GetTimerInfo(timer, true, this, cancellationToken).ConfigureAwait(false); + + await service.CreateTimerAsync(info, cancellationToken).ConfigureAwait(false); + } + + public async Task CreateSeriesTimer(SeriesTimerInfoDto timer, CancellationToken cancellationToken) + { + var service = string.IsNullOrEmpty(timer.ServiceName) ? ActiveService : GetServices(timer.ServiceName, null).First(); + + var info = await _tvDtoService.GetSeriesTimerInfo(timer, true, this, cancellationToken).ConfigureAwait(false); + + await service.CreateSeriesTimerAsync(info, cancellationToken).ConfigureAwait(false); + } + + public async Task UpdateTimer(TimerInfoDto timer, CancellationToken cancellationToken) + { + var info = await _tvDtoService.GetTimerInfo(timer, false, this, cancellationToken).ConfigureAwait(false); + + var service = string.IsNullOrEmpty(timer.ServiceName) ? ActiveService : GetServices(timer.ServiceName, null).First(); + + await service.UpdateTimerAsync(info, cancellationToken).ConfigureAwait(false); + } + + public async Task UpdateSeriesTimer(SeriesTimerInfoDto timer, CancellationToken cancellationToken) + { + var info = await _tvDtoService.GetSeriesTimerInfo(timer, false, this, cancellationToken).ConfigureAwait(false); + + var service = string.IsNullOrEmpty(timer.ServiceName) ? ActiveService : GetServices(timer.ServiceName, null).First(); + + await service.UpdateSeriesTimerAsync(info, cancellationToken).ConfigureAwait(false); + } } } diff --git a/MediaBrowser.WebDashboard/Api/DashboardService.cs b/MediaBrowser.WebDashboard/Api/DashboardService.cs index 8088d35b70..805aec6e7f 100644 --- a/MediaBrowser.WebDashboard/Api/DashboardService.cs +++ b/MediaBrowser.WebDashboard/Api/DashboardService.cs @@ -495,6 +495,7 @@ namespace MediaBrowser.WebDashboard.Api "livetvchannel.js", "livetvchannels.js", "livetvguide.js", + "livetvnewrecording.js", "livetvrecording.js", "livetvrecordings.js", "livetvtimer.js", diff --git a/MediaBrowser.WebDashboard/ApiClient.js b/MediaBrowser.WebDashboard/ApiClient.js index 53f4fde2af..a42c27949e 100644 --- a/MediaBrowser.WebDashboard/ApiClient.js +++ b/MediaBrowser.WebDashboard/ApiClient.js @@ -389,13 +389,21 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout, wi }); }; - self.getLiveTvChannel = function (id) { + self.getLiveTvChannel = function (id, userId) { if (!id) { throw new Error("null id"); } - var url = self.getUrl("LiveTv/Channels/" + id); + var options = { + + }; + + if (userId) { + options.userId = userId; + } + + var url = self.getUrl("LiveTv/Channels/" + id, options); return self.ajax({ type: "GET", @@ -437,13 +445,44 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout, wi }); }; - self.getLiveTvRecording = function (id) { + self.getLiveTvRecording = function (id, userId) { if (!id) { throw new Error("null id"); } - var url = self.getUrl("LiveTv/Recordings/" + id); + var options = { + + }; + + if (userId) { + options.userId = userId; + } + + var url = self.getUrl("LiveTv/Recordings/" + id, options); + + return self.ajax({ + type: "GET", + url: url, + dataType: "json" + }); + }; + + self.getLiveTvProgram = function (id, userId) { + + if (!id) { + throw new Error("null id"); + } + + var options = { + + }; + + if (userId) { + options.userId = userId; + } + + var url = self.getUrl("LiveTv/Programs/" + id, options); return self.ajax({ type: "GET", @@ -506,6 +545,17 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout, wi }); }; + self.getNewLiveTvTimerDefaults = function () { + + var url = self.getUrl("LiveTv/Timers/Defaults"); + + return self.ajax({ + type: "GET", + url: url, + dataType: "json" + }); + }; + self.createLiveTvTimer = function (item) { if (!item) { diff --git a/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj b/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj index 8fbd6a6316..e04f59f943 100644 --- a/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj +++ b/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj @@ -94,6 +94,9 @@ PreserveNewest + + PreserveNewest + PreserveNewest @@ -361,6 +364,9 @@ PreserveNewest + + PreserveNewest + PreserveNewest diff --git a/MediaBrowser.WebDashboard/packages.config b/MediaBrowser.WebDashboard/packages.config index 808183a672..12f78c773a 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 7878753f24..ef156a2bfb 100644 --- a/Nuget/MediaBrowser.Common.Internal.nuspec +++ b/Nuget/MediaBrowser.Common.Internal.nuspec @@ -2,7 +2,7 @@ MediaBrowser.Common.Internal - 3.0.275 + 3.0.276 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 34133bf6e4..58ab614258 100644 --- a/Nuget/MediaBrowser.Common.nuspec +++ b/Nuget/MediaBrowser.Common.nuspec @@ -2,7 +2,7 @@ MediaBrowser.Common - 3.0.275 + 3.0.276 MediaBrowser.Common Media Browser Team ebr,Luke,scottisafool diff --git a/Nuget/MediaBrowser.Server.Core.nuspec b/Nuget/MediaBrowser.Server.Core.nuspec index 92bd239e4b..b94e775525 100644 --- a/Nuget/MediaBrowser.Server.Core.nuspec +++ b/Nuget/MediaBrowser.Server.Core.nuspec @@ -2,7 +2,7 @@ MediaBrowser.Server.Core - 3.0.275 + 3.0.276 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 - +