Browse Source

added recording status enum

Luke Pulverenti 11 years ago
parent
commit
6a9ed5f87f

+ 24 - 4
MediaBrowser.Api/LiveTv/LiveTvService.cs

@@ -26,7 +26,7 @@ namespace MediaBrowser.Api.LiveTv
         [ApiMember(Name = "Type", Description = "Optional filter by channel type.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
         public ChannelType? Type { get; set; }
 
-        [ApiMember(Name = "UserId", Description = "Optional filter by channel user id.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
+        [ApiMember(Name = "UserId", Description = "Optional filter by user id.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
         public string UserId { get; set; }
     }
 
@@ -40,8 +40,17 @@ namespace MediaBrowser.Api.LiveTv
         /// <value>The id.</value>
         [ApiMember(Name = "Id", Description = "Channel Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
         public string Id { get; set; }
+
+        [ApiMember(Name = "UserId", Description = "Optional user id.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
+        public string UserId { get; set; }
     }
 
+    [Route("/LiveTv/Recordings", "GET")]
+    [Api(Description = "Gets live tv recordings")]
+    public class GetRecordings : IReturn<QueryResult<RecordingInfoDto>>
+    {
+    }
+    
     [Route("/LiveTv/Programs", "GET")]
     [Api(Description = "Gets available live tv epgs..")]
     public class GetPrograms : IReturn<QueryResult<ProgramInfoDto>>
@@ -51,6 +60,9 @@ namespace MediaBrowser.Api.LiveTv
 
         [ApiMember(Name = "ChannelIds", Description = "The channels to return guide information for.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
         public string ChannelIds { get; set; }
+
+        [ApiMember(Name = "UserId", Description = "Optional filter by user id.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
+        public string UserId { get; set; }
     }
 
     public class LiveTvService : BaseApiService
@@ -106,9 +118,9 @@ namespace MediaBrowser.Api.LiveTv
 
         public object Get(GetChannel request)
         {
-            var result = _liveTvManager.GetChannel(request.Id);
+            var result = _liveTvManager.GetChannelInfoDto(request.Id, request.UserId);
 
-            return ToOptimizedResult(_liveTvManager.GetChannelInfoDto(result));
+            return ToOptimizedResult(result);
         }
 
         public object Get(GetPrograms request)
@@ -116,10 +128,18 @@ namespace MediaBrowser.Api.LiveTv
             var result = _liveTvManager.GetPrograms(new ProgramQuery
             {
                 ServiceName = request.ServiceName,
-                ChannelIdList = (request.ChannelIds ?? string.Empty).Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToArray()
+                ChannelIdList = (request.ChannelIds ?? string.Empty).Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToArray(),
+                UserId = request.UserId
             });
 
             return ToOptimizedResult(result);
         }
+
+        public object Get(GetRecordings request)
+        {
+            var result = _liveTvManager.GetRecordings();
+
+            return ToOptimizedResult(result);
+        }
     }
 }

+ 11 - 4
MediaBrowser.Controller/LiveTv/ILiveTvManager.cs

@@ -29,11 +29,10 @@ namespace MediaBrowser.Controller.LiveTv
         QueryResult<ChannelInfoDto> GetChannels(ChannelQuery query);
 
         /// <summary>
-        /// Gets the channel information dto.
+        /// Gets the recordings.
         /// </summary>
-        /// <param name="info">The information.</param>
-        /// <returns>ChannelInfoDto.</returns>
-        ChannelInfoDto GetChannelInfoDto(Channel info);
+        /// <returns>QueryResult{RecordingInfoDto}.</returns>
+        QueryResult<RecordingInfoDto> GetRecordings();
 
         /// <summary>
         /// Gets the channel.
@@ -42,6 +41,14 @@ namespace MediaBrowser.Controller.LiveTv
         /// <returns>Channel.</returns>
         Channel GetChannel(string id);
 
+        /// <summary>
+        /// Gets the channel.
+        /// </summary>
+        /// <param name="id">The identifier.</param>
+        /// <param name="userId">The user identifier.</param>
+        /// <returns>Channel.</returns>
+        ChannelInfoDto GetChannelInfoDto(string id, string userId);
+
         /// <summary>
         /// Gets the programs.
         /// </summary>

+ 25 - 0
MediaBrowser.Controller/LiveTv/ProgramInfo.cs

@@ -1,5 +1,6 @@
 using System;
 using System.Collections.Generic;
+using MediaBrowser.Model.LiveTv;
 
 namespace MediaBrowser.Controller.LiveTv
 {
@@ -21,6 +22,12 @@ namespace MediaBrowser.Controller.LiveTv
         /// </summary>
         public string Name { get; set; }
 
+        /// <summary>
+        /// Gets or sets the official rating.
+        /// </summary>
+        /// <value>The official rating.</value>
+        public string OfficialRating { get; set; }
+        
         /// <summary>
         /// Description of the progam.
         /// </summary>
@@ -41,6 +48,24 @@ namespace MediaBrowser.Controller.LiveTv
         /// </summary>
         public List<string> Genres { get; set; }
 
+        /// <summary>
+        /// Gets or sets the quality.
+        /// </summary>
+        /// <value>The quality.</value>
+        public ProgramVideoQuality Quality { 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 audio.
+        /// </summary>
+        /// <value>The audio.</value>
+        public ProgramAudio Audio { get; set; }
+        
         public ProgramInfo()
         {
             Genres = new List<string>();

+ 5 - 3
MediaBrowser.Controller/LiveTv/RecordingInfo.cs

@@ -1,4 +1,5 @@
-using System;
+using MediaBrowser.Model.LiveTv;
+using System;
 using System.Collections.Generic;
 
 namespace MediaBrowser.Controller.LiveTv
@@ -47,9 +48,10 @@ namespace MediaBrowser.Controller.LiveTv
         public DateTime EndDate { get; set; }
 
         /// <summary>
-        /// Status of the recording.
+        /// Gets or sets the status.
         /// </summary>
-        public string Status { get; set; } //TODO: Enum for status?? Difference NextPvr,Argus,...
+        /// <value>The status.</value>
+        public RecordingStatus Status { get; set; }
 
         /// <summary>
         /// Gets or sets a value indicating whether this instance is recurring.

+ 3 - 0
MediaBrowser.Model.Portable/MediaBrowser.Model.Portable.csproj

@@ -248,6 +248,9 @@
     <Compile Include="..\MediaBrowser.Model\LiveTv\RecordingQuery.cs">
       <Link>LiveTv\RecordingQuery.cs</Link>
     </Compile>
+    <Compile Include="..\MediaBrowser.Model\LiveTv\RecordingStatus.cs">
+      <Link>LiveTv\RecordingStatus.cs</Link>
+    </Compile>
     <Compile Include="..\MediaBrowser.Model\Logging\ILogger.cs">
       <Link>Logging\ILogger.cs</Link>
     </Compile>

+ 3 - 0
MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj

@@ -235,6 +235,9 @@
     <Compile Include="..\MediaBrowser.Model\LiveTv\RecordingQuery.cs">
       <Link>LiveTv\RecordingQuery.cs</Link>
     </Compile>
+    <Compile Include="..\MediaBrowser.Model\LiveTv\RecordingStatus.cs">
+      <Link>LiveTv\RecordingStatus.cs</Link>
+    </Compile>
     <Compile Include="..\MediaBrowser.Model\Logging\ILogger.cs">
       <Link>Logging\ILogger.cs</Link>
     </Compile>

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

@@ -1,4 +1,5 @@
 using System;
+using MediaBrowser.Model.Dto;
 
 namespace MediaBrowser.Model.LiveTv
 {
@@ -54,5 +55,11 @@ namespace MediaBrowser.Model.LiveTv
         /// </summary>
         /// <value>The type of the media.</value>
         public string MediaType { get; set; }
+
+        /// <summary>
+        /// Gets or sets the user data.
+        /// </summary>
+        /// <value>The user data.</value>
+        public UserItemDataDto UserData { get; set; }
     }
 }

+ 35 - 0
MediaBrowser.Model/LiveTv/ProgramInfoDto.cs

@@ -27,6 +27,12 @@ namespace MediaBrowser.Model.LiveTv
         /// </summary>
         /// <value>The recording identifier.</value>
         public string RecordingId { get; set; }
+
+        /// <summary>
+        /// Gets or sets the official rating.
+        /// </summary>
+        /// <value>The official rating.</value>
+        public string OfficialRating { get; set; }
         
         /// <summary>
         /// Gets or sets the name of the service.
@@ -59,9 +65,38 @@ namespace MediaBrowser.Model.LiveTv
         /// </summary>
         public List<string> Genres { get; set; }
 
+        /// <summary>
+        /// Gets or sets the quality.
+        /// </summary>
+        /// <value>The quality.</value>
+        public ProgramVideoQuality Quality { get; set; }
+
+        /// <summary>
+        /// Gets or sets the audio.
+        /// </summary>
+        /// <value>The audio.</value>
+        public ProgramAudio Audio { get; set; }
+        
+        /// <summary>
+        /// Gets or sets the original air date.
+        /// </summary>
+        /// <value>The original air date.</value>
+        public DateTime? OriginalAirDate { get; set; }
+        
         public ProgramInfoDto()
         {
             Genres = new List<string>();
         }
     }
+
+    public enum ProgramVideoQuality
+    {
+        StandardDefinition,
+        HighDefinition
+    }
+
+    public enum ProgramAudio
+    {
+        Stereo
+    }
 }

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

@@ -17,6 +17,12 @@
         /// <value>The channel identifier.</value>
         public string[] ChannelIdList { get; set; }
 
+        /// <summary>
+        /// Gets or sets the user identifier.
+        /// </summary>
+        /// <value>The user identifier.</value>
+        public string UserId { get; set; }
+
         public ProgramQuery()
         {
             ChannelIdList = new string[] { };

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

@@ -55,5 +55,11 @@ namespace MediaBrowser.Model.LiveTv
         /// IsRecurring recording?
         /// </summary>
         public bool IsRecurring { get; set; }
+
+        /// <summary>
+        /// Gets or sets the status.
+        /// </summary>
+        /// <value>The status.</value>
+        public RecordingStatus Status { get; set; }
     }
 }

+ 13 - 0
MediaBrowser.Model/LiveTv/RecordingStatus.cs

@@ -0,0 +1,13 @@
+
+namespace MediaBrowser.Model.LiveTv
+{
+    public enum RecordingStatus
+    {
+        Pending,
+        InProgress,
+        Completed,
+        CompletedWithError,
+        Conflicted,
+        Deleted
+    }
+}

+ 1 - 0
MediaBrowser.Model/MediaBrowser.Model.csproj

@@ -65,6 +65,7 @@
     <Compile Include="LiveTv\ProgramInfoDto.cs" />
     <Compile Include="LiveTv\ProgramQuery.cs" />
     <Compile Include="LiveTv\RecordingQuery.cs" />
+    <Compile Include="LiveTv\RecordingStatus.cs" />
     <Compile Include="Providers\ImageProviderInfo.cs" />
     <Compile Include="Providers\RemoteImageInfo.cs" />
     <Compile Include="Dto\StudioDto.cs" />

+ 76 - 9
MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs

@@ -2,7 +2,11 @@
 using MediaBrowser.Common.IO;
 using MediaBrowser.Controller;
 using MediaBrowser.Controller.Drawing;
+using MediaBrowser.Controller.Dto;
+using MediaBrowser.Controller.Entities;
+using MediaBrowser.Controller.Library;
 using MediaBrowser.Controller.LiveTv;
+using MediaBrowser.Controller.Localization;
 using MediaBrowser.Controller.Persistence;
 using MediaBrowser.Model.Entities;
 using MediaBrowser.Model.LiveTv;
@@ -28,6 +32,11 @@ namespace MediaBrowser.Server.Implementations.LiveTv
         private readonly IItemRepository _itemRepo;
         private readonly IImageProcessor _imageProcessor;
 
+        private readonly IUserManager _userManager;
+        private readonly ILocalizationManager _localization;
+        private readonly IUserDataManager _userDataManager;
+        private readonly IDtoService _dtoService;
+
         private readonly List<ILiveTvService> _services = new List<ILiveTvService>();
 
         private List<Channel> _channels = new List<Channel>();
@@ -36,13 +45,17 @@ namespace MediaBrowser.Server.Implementations.LiveTv
 
         private readonly SemaphoreSlim _updateSemaphore = new SemaphoreSlim(1, 1);
 
-        public LiveTvManager(IServerApplicationPaths appPaths, IFileSystem fileSystem, ILogger logger, IItemRepository itemRepo, IImageProcessor imageProcessor)
+        public LiveTvManager(IServerApplicationPaths appPaths, IFileSystem fileSystem, ILogger logger, IItemRepository itemRepo, IImageProcessor imageProcessor, IUserManager userManager, ILocalizationManager localization, IUserDataManager userDataManager, IDtoService dtoService)
         {
             _appPaths = appPaths;
             _fileSystem = fileSystem;
             _logger = logger;
             _itemRepo = itemRepo;
             _imageProcessor = imageProcessor;
+            _userManager = userManager;
+            _localization = localization;
+            _userDataManager = userDataManager;
+            _dtoService = dtoService;
         }
 
         /// <summary>
@@ -67,10 +80,11 @@ namespace MediaBrowser.Server.Implementations.LiveTv
         /// Gets the channel info dto.
         /// </summary>
         /// <param name="info">The info.</param>
+        /// <param name="user">The user.</param>
         /// <returns>ChannelInfoDto.</returns>
-        public ChannelInfoDto GetChannelInfoDto(Channel info)
+        public ChannelInfoDto GetChannelInfoDto(Channel info, User user)
         {
-            return new ChannelInfoDto
+            var dto = new ChannelInfoDto
             {
                 Name = info.Name,
                 ServiceName = info.ServiceName,
@@ -81,6 +95,13 @@ namespace MediaBrowser.Server.Implementations.LiveTv
                 Id = info.Id.ToString("N"),
                 MediaType = info.MediaType
             };
+
+            if (user != null)
+            {
+                dto.UserData = _dtoService.GetUserItemDataDto(_userDataManager.GetUserData(user.Id, info.GetUserDataKey()));
+            }
+
+            return dto;
         }
 
         private ILiveTvService GetService(ChannelInfo channel)
@@ -111,7 +132,28 @@ namespace MediaBrowser.Server.Implementations.LiveTv
 
         public QueryResult<ChannelInfoDto> GetChannels(ChannelQuery query)
         {
-            var channels = _channels.OrderBy(i =>
+            var user = string.IsNullOrEmpty(query.UserId) ? null : _userManager.GetUserById(new Guid(query.UserId));
+
+            IEnumerable<Channel> channels = _channels;
+
+            if (user != null)
+            {
+                channels = channels.Where(i => i.IsParentalAllowed(user, _localization))
+                    .OrderBy(i =>
+                    {
+                        double number = 0;
+
+                        if (!string.IsNullOrEmpty(i.ChannelNumber))
+                        {
+                            double.TryParse(i.ChannelNumber, out number);
+                        }
+
+                        return number;
+
+                    });
+            }
+
+            var returnChannels = channels.OrderBy(i =>
             {
                 double number = 0;
 
@@ -123,13 +165,13 @@ namespace MediaBrowser.Server.Implementations.LiveTv
                 return number;
 
             }).ThenBy(i => i.Name)
-            .Select(GetChannelInfoDto)
+            .Select(i => GetChannelInfoDto(i, user))
             .ToArray();
 
             return new QueryResult<ChannelInfoDto>
             {
-                Items = channels,
-                TotalRecordCount = channels.Length
+                Items = returnChannels,
+                TotalRecordCount = returnChannels.Length
             };
         }
 
@@ -140,6 +182,15 @@ namespace MediaBrowser.Server.Implementations.LiveTv
             return _channels.FirstOrDefault(i => i.Id == guid);
         }
 
+        public ChannelInfoDto GetChannelInfoDto(string id, string userId)
+        {
+            var channel = GetChannel(id);
+
+            var user = string.IsNullOrEmpty(userId) ? null : _userManager.GetUserById(new Guid(userId));
+
+            return channel == null ? null : GetChannelInfoDto(channel, user);
+        }
+
         private ProgramInfoDto GetProgramInfoDto(ProgramInfo program, Channel channel)
         {
             var id = GetInternalProgramIdId(channel.ServiceName, program.Id).ToString("N");
@@ -154,7 +205,11 @@ namespace MediaBrowser.Server.Implementations.LiveTv
                 Id = id,
                 Name = program.Name,
                 ServiceName = channel.ServiceName,
-                StartDate = program.StartDate
+                StartDate = program.StartDate,
+                OfficialRating = program.OfficialRating,
+                Quality = program.Quality,
+                OriginalAirDate = program.OriginalAirDate,
+                Audio = program.Audio
             };
         }
 
@@ -367,7 +422,8 @@ namespace MediaBrowser.Server.Implementations.LiveTv
                 StartDate = info.StartDate,
                 Id = id,
                 ExternalId = info.Id,
-                ChannelId = GetInternalChannelId(service.Name, info.ChannelId).ToString("N")
+                ChannelId = GetInternalChannelId(service.Name, info.ChannelId).ToString("N"),
+                Status = info.Status
             };
 
             if (!string.IsNullOrEmpty(info.ProgramId))
@@ -377,5 +433,16 @@ namespace MediaBrowser.Server.Implementations.LiveTv
 
             return dto;
         }
+
+        public QueryResult<RecordingInfoDto> GetRecordings()
+        {
+            var returnArray = _recordings.ToArray();
+
+            return new QueryResult<RecordingInfoDto>
+            {
+                Items = returnArray,
+                TotalRecordCount = returnArray.Length
+            };
+        }
     }
 }

+ 1 - 1
MediaBrowser.ServerApplication/ApplicationHost.cs

@@ -294,7 +294,7 @@ namespace MediaBrowser.ServerApplication
             DtoService = new DtoService(Logger, LibraryManager, UserManager, UserDataManager, ItemRepository, ImageProcessor);
             RegisterSingleInstance(DtoService);
 
-            LiveTvManager = new LiveTvManager(ApplicationPaths, FileSystemManager, Logger, ItemRepository, ImageProcessor);
+            LiveTvManager = new LiveTvManager(ApplicationPaths, FileSystemManager, Logger, ItemRepository, ImageProcessor, UserManager, LocalizationManager, UserDataManager, DtoService);
             RegisterSingleInstance(LiveTvManager);
 
             var displayPreferencesTask = Task.Run(async () => await ConfigureDisplayPreferencesRepositories().ConfigureAwait(false));