소스 검색

fixes #550 - Add internal interfaces for live tv

Luke Pulverenti 11 년 전
부모
커밋
98442402a5

+ 74 - 0
MediaBrowser.Api/LiveTv/LiveTvService.cs

@@ -0,0 +1,74 @@
+using MediaBrowser.Controller.LiveTv;
+using MediaBrowser.Model.LiveTv;
+using ServiceStack.ServiceHost;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading;
+using System.Threading.Tasks;
+
+namespace MediaBrowser.Api.LiveTv
+{
+    [Route("/LiveTv/Services", "GET")]
+    [Api(Description = "Gets available live tv services.")]
+    public class GetServices : IReturn<List<LiveTvServiceInfo>>
+    {
+    }
+
+    [Route("/LiveTv/Channels", "GET")]
+    [Api(Description = "Gets available live tv channels.")]
+    public class GetChannels : IReturn<List<ChannelInfoDto>>
+    {
+        // Add filter by service if needed, and/or other filters
+    }
+    
+    public class LiveTvService : BaseApiService
+    {
+        private readonly ILiveTvManager _liveTvManager;
+
+        public LiveTvService(ILiveTvManager liveTvManager)
+        {
+            _liveTvManager = liveTvManager;
+        }
+
+        public object Get(GetServices request)
+        {
+            var services = _liveTvManager.Services;
+
+            var result = services.Select(GetServiceInfo)
+                .ToList();
+
+            return ToOptimizedResult(result);
+        }
+
+        public object Get(GetChannels request)
+        {
+            var services = _liveTvManager.Services;
+
+            var result = services.Select(GetServiceInfo)
+                .ToList();
+
+            return ToOptimizedResult(result);
+        }
+
+        public async Task<IEnumerable<ChannelInfoDto>> GetChannelsAsync(GetChannels request)
+        {
+            var services = _liveTvManager.Services;
+
+            var channelTasks = services.Select(i => i.GetChannelsAsync(CancellationToken.None));
+
+            var channelLists = await Task.WhenAll(channelTasks).ConfigureAwait(false);
+
+            // Aggregate all channels from all services
+            return channelLists.SelectMany(i => i)
+                .Select(_liveTvManager.GetChannelInfoDto);
+        }
+        
+        private LiveTvServiceInfo GetServiceInfo(ILiveTvService service)
+        {
+            return new LiveTvServiceInfo
+            {
+                Name = service.Name
+            };
+        }
+    }
+}

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

@@ -81,6 +81,7 @@
     <Compile Include="Library\LibraryHelpers.cs" />
     <Compile Include="Library\LibraryHelpers.cs" />
     <Compile Include="Library\LibraryService.cs" />
     <Compile Include="Library\LibraryService.cs" />
     <Compile Include="Library\LibraryStructureService.cs" />
     <Compile Include="Library\LibraryStructureService.cs" />
+    <Compile Include="LiveTv\LiveTvService.cs" />
     <Compile Include="LocalizationService.cs" />
     <Compile Include="LocalizationService.cs" />
     <Compile Include="MoviesService.cs" />
     <Compile Include="MoviesService.cs" />
     <Compile Include="NotificationsService.cs" />
     <Compile Include="NotificationsService.cs" />

+ 21 - 0
MediaBrowser.Controller/LiveTv/ChannelInfo.cs

@@ -0,0 +1,21 @@
+
+namespace MediaBrowser.Controller.LiveTv
+{
+    /// <summary>
+    /// Class ChannelInfo
+    /// </summary>
+    public class ChannelInfo
+    {
+        /// <summary>
+        /// Gets or sets the name.
+        /// </summary>
+        /// <value>The name.</value>
+        public string Name { get; set; }
+
+        /// <summary>
+        /// Gets or sets the name of the service.
+        /// </summary>
+        /// <value>The name of the service.</value>
+        public string ServiceName { get; set; }
+    }
+}

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

@@ -0,0 +1,30 @@
+using MediaBrowser.Model.LiveTv;
+using System.Collections.Generic;
+
+namespace MediaBrowser.Controller.LiveTv
+{
+    /// <summary>
+    /// Manages all live tv services installed on the server
+    /// </summary>
+    public interface ILiveTvManager
+    {
+        /// <summary>
+        /// Gets the services.
+        /// </summary>
+        /// <value>The services.</value>
+        IReadOnlyList<ILiveTvService> Services { get; }
+
+        /// <summary>
+        /// Adds the parts.
+        /// </summary>
+        /// <param name="services">The services.</param>
+        void AddParts(IEnumerable<ILiveTvService> services);
+
+        /// <summary>
+        /// Gets the channel info dto.
+        /// </summary>
+        /// <param name="info">The info.</param>
+        /// <returns>ChannelInfoDto.</returns>
+        ChannelInfoDto GetChannelInfoDto(ChannelInfo info);
+    }
+}

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

@@ -0,0 +1,25 @@
+using System.Collections.Generic;
+using System.Threading;
+using System.Threading.Tasks;
+
+namespace MediaBrowser.Controller.LiveTv
+{
+    /// <summary>
+    /// Represents a single live tv back end (next pvr, media portal, etc).
+    /// </summary>
+    public interface ILiveTvService
+    {
+        /// <summary>
+        /// Gets the name.
+        /// </summary>
+        /// <value>The name.</value>
+        string Name { get; }
+
+        /// <summary>
+        /// Gets the channels async.
+        /// </summary>
+        /// <param name="cancellationToken">The cancellation token.</param>
+        /// <returns>Task{IEnumerable{ChannelInfo}}.</returns>
+        Task<IEnumerable<ChannelInfo>> GetChannelsAsync(CancellationToken cancellationToken);
+    }
+}

+ 3 - 0
MediaBrowser.Controller/MediaBrowser.Controller.csproj

@@ -96,6 +96,9 @@
     <Compile Include="Library\ILibraryPrescanTask.cs" />
     <Compile Include="Library\ILibraryPrescanTask.cs" />
     <Compile Include="Library\IMetadataSaver.cs" />
     <Compile Include="Library\IMetadataSaver.cs" />
     <Compile Include="Library\ItemUpdateType.cs" />
     <Compile Include="Library\ItemUpdateType.cs" />
+    <Compile Include="LiveTv\ChannelInfo.cs" />
+    <Compile Include="LiveTv\ILiveTvManager.cs" />
+    <Compile Include="LiveTv\ILiveTvService.cs" />
     <Compile Include="Localization\ILocalizationManager.cs" />
     <Compile Include="Localization\ILocalizationManager.cs" />
     <Compile Include="Notifications\INotificationsRepository.cs" />
     <Compile Include="Notifications\INotificationsRepository.cs" />
     <Compile Include="Notifications\NotificationUpdateEventArgs.cs" />
     <Compile Include="Notifications\NotificationUpdateEventArgs.cs" />

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

@@ -215,6 +215,12 @@
     <Compile Include="..\MediaBrowser.Model\IO\IZipClient.cs">
     <Compile Include="..\MediaBrowser.Model\IO\IZipClient.cs">
       <Link>IO\IZipClient.cs</Link>
       <Link>IO\IZipClient.cs</Link>
     </Compile>
     </Compile>
+    <Compile Include="..\MediaBrowser.Model\LiveTv\ChannelInfoDto.cs">
+      <Link>LiveTv\ChannelInfoDto.cs</Link>
+    </Compile>
+    <Compile Include="..\MediaBrowser.Model\LiveTv\LiveTvServiceInfo.cs">
+      <Link>LiveTv\LiveTvServiceInfo.cs</Link>
+    </Compile>
     <Compile Include="..\MediaBrowser.Model\Logging\ILogger.cs">
     <Compile Include="..\MediaBrowser.Model\Logging\ILogger.cs">
       <Link>Logging\ILogger.cs</Link>
       <Link>Logging\ILogger.cs</Link>
     </Compile>
     </Compile>

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

@@ -199,6 +199,12 @@
     <Compile Include="..\MediaBrowser.Model\IO\IZipClient.cs">
     <Compile Include="..\MediaBrowser.Model\IO\IZipClient.cs">
       <Link>IO\IZipClient.cs</Link>
       <Link>IO\IZipClient.cs</Link>
     </Compile>
     </Compile>
+    <Compile Include="..\MediaBrowser.Model\LiveTv\ChannelInfoDto.cs">
+      <Link>LiveTv\ChannelInfoDto.cs</Link>
+    </Compile>
+    <Compile Include="..\MediaBrowser.Model\LiveTv\LiveTvServiceInfo.cs">
+      <Link>LiveTv\LiveTvServiceInfo.cs</Link>
+    </Compile>
     <Compile Include="..\MediaBrowser.Model\Logging\ILogger.cs">
     <Compile Include="..\MediaBrowser.Model\Logging\ILogger.cs">
       <Link>Logging\ILogger.cs</Link>
       <Link>Logging\ILogger.cs</Link>
     </Compile>
     </Compile>

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

@@ -0,0 +1,21 @@
+
+namespace MediaBrowser.Model.LiveTv
+{
+    /// <summary>
+    /// Class ChannelInfoDto
+    /// </summary>
+    public class ChannelInfoDto
+    {
+        /// <summary>
+        /// Gets or sets the name.
+        /// </summary>
+        /// <value>The name.</value>
+        public string Name { get; set; }
+
+        /// <summary>
+        /// Gets or sets the name of the service.
+        /// </summary>
+        /// <value>The name of the service.</value>
+        public string ServiceName { get; set; }
+    }
+}

+ 15 - 0
MediaBrowser.Model/LiveTv/LiveTvServiceInfo.cs

@@ -0,0 +1,15 @@
+
+namespace MediaBrowser.Model.LiveTv
+{
+    /// <summary>
+    /// Class ServiceInfo
+    /// </summary>
+    public class LiveTvServiceInfo
+    {
+        /// <summary>
+        /// Gets or sets the name.
+        /// </summary>
+        /// <value>The name.</value>
+        public string Name { get; set; }
+    }
+}

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

@@ -66,6 +66,8 @@
     <Compile Include="IO\IIsoManager.cs" />
     <Compile Include="IO\IIsoManager.cs" />
     <Compile Include="IO\IIsoMount.cs" />
     <Compile Include="IO\IIsoMount.cs" />
     <Compile Include="IO\IIsoMounter.cs" />
     <Compile Include="IO\IIsoMounter.cs" />
+    <Compile Include="LiveTv\ChannelInfoDto.cs" />
+    <Compile Include="LiveTv\LiveTvServiceInfo.cs" />
     <Compile Include="Net\WebSocketMessage.cs" />
     <Compile Include="Net\WebSocketMessage.cs" />
     <Compile Include="Net\WebSocketMessageType.cs" />
     <Compile Include="Net\WebSocketMessageType.cs" />
     <Compile Include="Net\WebSocketState.cs" />
     <Compile Include="Net\WebSocketState.cs" />

+ 45 - 0
MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs

@@ -0,0 +1,45 @@
+using MediaBrowser.Controller.LiveTv;
+using MediaBrowser.Model.LiveTv;
+using System.Collections.Generic;
+
+namespace MediaBrowser.Server.Implementations.LiveTv
+{
+    /// <summary>
+    /// Class LiveTvManager
+    /// </summary>
+    public class LiveTvManager : ILiveTvManager
+    {
+        private readonly List<ILiveTvService> _services = new List<ILiveTvService>();
+        /// <summary>
+        /// Gets the services.
+        /// </summary>
+        /// <value>The services.</value>
+        public IReadOnlyList<ILiveTvService> Services
+        {
+            get { return _services; }
+        }
+
+        /// <summary>
+        /// Adds the parts.
+        /// </summary>
+        /// <param name="services">The services.</param>
+        public void AddParts(IEnumerable<ILiveTvService> services)
+        {
+            _services.AddRange(services);
+        }
+
+        /// <summary>
+        /// Gets the channel info dto.
+        /// </summary>
+        /// <param name="info">The info.</param>
+        /// <returns>ChannelInfoDto.</returns>
+        public ChannelInfoDto GetChannelInfoDto(ChannelInfo info)
+        {
+            return new ChannelInfoDto
+            {
+                Name = info.Name,
+                ServiceName = info.ServiceName
+            };
+        }
+    }
+}

+ 1 - 0
MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj

@@ -148,6 +148,7 @@
     <Compile Include="Library\Validators\PeoplePostScanTask.cs" />
     <Compile Include="Library\Validators\PeoplePostScanTask.cs" />
     <Compile Include="Library\Validators\StudiosPostScanTask.cs" />
     <Compile Include="Library\Validators\StudiosPostScanTask.cs" />
     <Compile Include="Library\Validators\StudiosValidator.cs" />
     <Compile Include="Library\Validators\StudiosValidator.cs" />
+    <Compile Include="LiveTv\LiveTvManager.cs" />
     <Compile Include="Localization\LocalizationManager.cs" />
     <Compile Include="Localization\LocalizationManager.cs" />
     <Compile Include="MediaEncoder\MediaEncoder.cs" />
     <Compile Include="MediaEncoder\MediaEncoder.cs" />
     <Compile Include="Persistence\SqliteChapterRepository.cs" />
     <Compile Include="Persistence\SqliteChapterRepository.cs" />

+ 7 - 0
MediaBrowser.ServerApplication/ApplicationHost.cs

@@ -15,6 +15,7 @@ using MediaBrowser.Controller.Dto;
 using MediaBrowser.Controller.Entities;
 using MediaBrowser.Controller.Entities;
 using MediaBrowser.Controller.IO;
 using MediaBrowser.Controller.IO;
 using MediaBrowser.Controller.Library;
 using MediaBrowser.Controller.Library;
+using MediaBrowser.Controller.LiveTv;
 using MediaBrowser.Controller.Localization;
 using MediaBrowser.Controller.Localization;
 using MediaBrowser.Controller.MediaInfo;
 using MediaBrowser.Controller.MediaInfo;
 using MediaBrowser.Controller.Notifications;
 using MediaBrowser.Controller.Notifications;
@@ -39,6 +40,7 @@ using MediaBrowser.Server.Implementations.EntryPoints;
 using MediaBrowser.Server.Implementations.HttpServer;
 using MediaBrowser.Server.Implementations.HttpServer;
 using MediaBrowser.Server.Implementations.IO;
 using MediaBrowser.Server.Implementations.IO;
 using MediaBrowser.Server.Implementations.Library;
 using MediaBrowser.Server.Implementations.Library;
+using MediaBrowser.Server.Implementations.LiveTv;
 using MediaBrowser.Server.Implementations.Localization;
 using MediaBrowser.Server.Implementations.Localization;
 using MediaBrowser.Server.Implementations.MediaEncoder;
 using MediaBrowser.Server.Implementations.MediaEncoder;
 using MediaBrowser.Server.Implementations.Persistence;
 using MediaBrowser.Server.Implementations.Persistence;
@@ -154,6 +156,8 @@ namespace MediaBrowser.ServerApplication
         private IIsoManager IsoManager { get; set; }
         private IIsoManager IsoManager { get; set; }
         private ISessionManager SessionManager { get; set; }
         private ISessionManager SessionManager { get; set; }
 
 
+        private ILiveTvManager LiveTvManager { get; set; }
+        
         private ILocalizationManager LocalizationManager { get; set; }
         private ILocalizationManager LocalizationManager { get; set; }
 
 
         /// <summary>
         /// <summary>
@@ -285,6 +289,9 @@ namespace MediaBrowser.ServerApplication
             DtoService = new DtoService(Logger, LibraryManager, UserManager, UserDataRepository, ItemRepository, ImageProcessor);
             DtoService = new DtoService(Logger, LibraryManager, UserManager, UserDataRepository, ItemRepository, ImageProcessor);
             RegisterSingleInstance(DtoService);
             RegisterSingleInstance(DtoService);
 
 
+            LiveTvManager = new LiveTvManager();
+            RegisterSingleInstance(LiveTvManager);
+
             var displayPreferencesTask = Task.Run(async () => await ConfigureDisplayPreferencesRepositories().ConfigureAwait(false));
             var displayPreferencesTask = Task.Run(async () => await ConfigureDisplayPreferencesRepositories().ConfigureAwait(false));
             var itemsTask = Task.Run(async () => await ConfigureItemRepositories().ConfigureAwait(false));
             var itemsTask = Task.Run(async () => await ConfigureItemRepositories().ConfigureAwait(false));
             var userdataTask = Task.Run(async () => await ConfigureUserDataRepositories().ConfigureAwait(false));
             var userdataTask = Task.Run(async () => await ConfigureUserDataRepositories().ConfigureAwait(false));