2
0
Эх сурвалжийг харах

add ability to create timer

Luke Pulverenti 11 жил өмнө
parent
commit
533a7b218d

+ 61 - 1
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<TimerInfoDto>
+    {
+    }
+
     [Route("/LiveTv/Timers", "GET")]
     [Api(Description = "Gets live tv timers")]
     public class GetTimers : IReturn<QueryResult<TimerInfoDto>>
@@ -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<ProgramInfoDto>
+    {
+        [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<TimerInfoDto>
@@ -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);
+        }
     }
 }

+ 32 - 0
MediaBrowser.Controller/LiveTv/ILiveTvManager.cs

@@ -31,6 +31,13 @@ namespace MediaBrowser.Controller.LiveTv
         /// <returns>Task.</returns>
         Task ScheduleRecording(string programId);
 
+        /// <summary>
+        /// Gets the new timer defaults asynchronous.
+        /// </summary>
+        /// <param name="cancellationToken">The cancellation token.</param>
+        /// <returns>Task{TimerInfo}.</returns>
+        Task<TimerInfoDto> GetNewTimerDefaults(CancellationToken cancellationToken);
+        
         /// <summary>
         /// Deletes the recording.
         /// </summary>
@@ -131,6 +138,15 @@ namespace MediaBrowser.Controller.LiveTv
         /// <returns>Channel.</returns>
         Channel GetChannel(string id);
 
+        /// <summary>
+        /// Gets the program.
+        /// </summary>
+        /// <param name="id">The identifier.</param>
+        /// <param name="cancellationToken">The cancellation token.</param>
+        /// <param name="user">The user.</param>
+        /// <returns>Task{ProgramInfoDto}.</returns>
+        Task<ProgramInfoDto> GetProgram(string id, CancellationToken cancellationToken, User user = null);
+        
         /// <summary>
         /// Gets the programs.
         /// </summary>
@@ -154,5 +170,21 @@ namespace MediaBrowser.Controller.LiveTv
         /// <param name="cancellationToken">The cancellation token.</param>
         /// <returns>Task.</returns>
         Task UpdateSeriesTimer(SeriesTimerInfoDto timer, CancellationToken cancellationToken);
+
+        /// <summary>
+        /// Creates the timer.
+        /// </summary>
+        /// <param name="timer">The timer.</param>
+        /// <param name="cancellationToken">The cancellation token.</param>
+        /// <returns>Task.</returns>
+        Task CreateTimer(TimerInfoDto timer, CancellationToken cancellationToken);
+
+        /// <summary>
+        /// Creates the series timer.
+        /// </summary>
+        /// <param name="timer">The timer.</param>
+        /// <param name="cancellationToken">The cancellation token.</param>
+        /// <returns>Task.</returns>
+        Task CreateSeriesTimer(SeriesTimerInfoDto timer, CancellationToken cancellationToken);
     }
 }

+ 7 - 0
MediaBrowser.Controller/LiveTv/ILiveTvService.cs

@@ -116,6 +116,13 @@ namespace MediaBrowser.Controller.LiveTv
         /// <returns>Task{IEnumerable{RecordingInfo}}.</returns>
         Task<IEnumerable<TimerInfo>> GetTimersAsync(CancellationToken cancellationToken);
 
+        /// <summary>
+        /// Gets the timer defaults asynchronous.
+        /// </summary>
+        /// <param name="cancellationToken">The cancellation token.</param>
+        /// <returns>Task{TimerInfo}.</returns>
+        Task<TimerInfo> GetNewTimerDefaultsAsync(CancellationToken cancellationToken);
+        
         /// <summary>
         /// Gets the series timers asynchronous.
         /// </summary>

+ 6 - 0
MediaBrowser.Model/LiveTv/ChannelInfoDto.cs

@@ -22,6 +22,12 @@ namespace MediaBrowser.Model.LiveTv
         /// <value>The identifier.</value>
         public string Id { get; set; }
 
+        /// <summary>
+        /// Gets or sets the external identifier.
+        /// </summary>
+        /// <value>The external identifier.</value>
+        public string ExternalId { get; set; }
+        
         /// <summary>
         /// Gets or sets the image tags.
         /// </summary>

+ 64 - 12
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<TimerInfo> 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<SeriesTimerInfo> 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;
         }
     }
 }

+ 54 - 22
MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs

@@ -178,7 +178,14 @@ namespace MediaBrowser.Server.Implementations.LiveTv
             return item;
         }
 
-        public async Task<QueryResult<ProgramInfoDto>> GetPrograms(ProgramQuery query, CancellationToken cancellationToken)
+        public Task<ProgramInfoDto> 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<QueryResult<ProgramInfoDto>> GetPrograms(ProgramQuery query, CancellationToken cancellationToken)
         {
             IEnumerable<ProgramInfoDto> programs = _programs
                 .OrderBy(i => i.StartDate)
@@ -193,11 +200,13 @@ namespace MediaBrowser.Server.Implementations.LiveTv
 
             var returnArray = programs.ToArray();
 
-            return new QueryResult<ProgramInfoDto>
+            var result = new QueryResult<ProgramInfoDto>
             {
                 Items = returnArray,
                 TotalRecordCount = returnArray.Length
             };
+
+            return Task.FromResult(result);
         }
 
         internal async Task RefreshChannels(IProgress<double> 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<QueryResult<SeriesTimerInfoDto>> GetSeriesTimers(SeriesTimerQuery query, CancellationToken cancellationToken)
         {
             var list = new List<SeriesTimerInfoDto>();
@@ -469,5 +458,48 @@ namespace MediaBrowser.Server.Implementations.LiveTv
 
             return results.Items.FirstOrDefault(i => string.Equals(i.Id, id, StringComparison.CurrentCulture));
         }
+
+        public async Task<TimerInfoDto> 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);
+        }
     }
 }

+ 1 - 0
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",

+ 54 - 4
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) {

+ 6 - 0
MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj

@@ -94,6 +94,9 @@
     <Content Include="dashboard-ui\livetvchannel.html">
       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
     </Content>
+    <Content Include="dashboard-ui\livetvnewrecording.html">
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </Content>
     <Content Include="dashboard-ui\livetvrecording.html">
       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
     </Content>
@@ -361,6 +364,9 @@
     <Content Include="dashboard-ui\livetvtimer.html">
       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
     </Content>
+    <Content Include="dashboard-ui\scripts\livetvnewrecording.js">
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </Content>
     <Content Include="dashboard-ui\scripts\livetvrecording.js">
       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
     </Content>

+ 1 - 1
MediaBrowser.WebDashboard/packages.config

@@ -1,4 +1,4 @@
 <?xml version="1.0" encoding="utf-8"?>
 <packages>
-  <package id="MediaBrowser.ApiClient.Javascript" version="3.0.206" targetFramework="net45" />
+  <package id="MediaBrowser.ApiClient.Javascript" version="3.0.209" targetFramework="net45" />
 </packages>

+ 2 - 2
Nuget/MediaBrowser.Common.Internal.nuspec

@@ -2,7 +2,7 @@
 <package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
     <metadata>
         <id>MediaBrowser.Common.Internal</id>
-        <version>3.0.275</version>
+        <version>3.0.276</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.275" />
+            <dependency id="MediaBrowser.Common" version="3.0.276" />
             <dependency id="NLog" version="2.1.0" />
             <dependency id="SimpleInjector" version="2.4.0" />
             <dependency id="sharpcompress" version="0.10.2" />

+ 1 - 1
Nuget/MediaBrowser.Common.nuspec

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

+ 2 - 2
Nuget/MediaBrowser.Server.Core.nuspec

@@ -2,7 +2,7 @@
 <package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
     <metadata>
         <id>MediaBrowser.Server.Core</id>
-        <version>3.0.275</version>
+        <version>3.0.276</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.275" />
+            <dependency id="MediaBrowser.Common" version="3.0.276" />
         </dependencies>
     </metadata>
     <files>