The Free Software Media System - Server Backend & API
fixes #550 - Add internal interfaces for live tv
Luke Pulverenti98442402a5f8
diff --git a/MediaBrowser.Api/LiveTv/LiveTvService.cs b/MediaBrowser.Api/LiveTv/LiveTvService.csnew file mode 100644index 0000000000..a7a709aee5--- /dev/null+++ b/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+ };+ }+ }+}diff --git a/MediaBrowser.Api/MediaBrowser.Api.csproj b/MediaBrowser.Api/MediaBrowser.Api.csprojindex 4f54b52498..21e73361c2 100644--- a/MediaBrowser.Api/MediaBrowser.Api.csproj+++ b/MediaBrowser.Api/MediaBrowser.Api.csproj@@ -81,6 +81,7 @@<Compile Include="Library\LibraryHelpers.cs" /><Compile Include="Library\LibraryService.cs" /><Compile Include="Library\LibraryStructureService.cs" />+ <Compile Include="LiveTv\LiveTvService.cs" /><Compile Include="LocalizationService.cs" /><Compile Include="MoviesService.cs" /><Compile Include="NotificationsService.cs" />diff --git a/MediaBrowser.Controller/LiveTv/ChannelInfo.cs b/MediaBrowser.Controller/LiveTv/ChannelInfo.csnew file mode 100644index 0000000000..5f40134482--- /dev/null+++ b/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; }+ }+}diff --git a/MediaBrowser.Controller/LiveTv/ILiveTvManager.cs b/MediaBrowser.Controller/LiveTv/ILiveTvManager.csnew file mode 100644index 0000000000..de88d15620--- /dev/null+++ b/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);+ }+}diff --git a/MediaBrowser.Controller/LiveTv/ILiveTvService.cs b/MediaBrowser.Controller/LiveTv/ILiveTvService.csnew file mode 100644index 0000000000..4d9ec85311--- /dev/null+++ b/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);+ }+}diff --git a/MediaBrowser.Controller/MediaBrowser.Controller.csproj b/MediaBrowser.Controller/MediaBrowser.Controller.csprojindex 0b27a350bd..57219ae513 100644--- a/MediaBrowser.Controller/MediaBrowser.Controller.csproj+++ b/MediaBrowser.Controller/MediaBrowser.Controller.csproj@@ -96,6 +96,9 @@<Compile Include="Library\ILibraryPrescanTask.cs" /><Compile Include="Library\IMetadataSaver.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="Notifications\INotificationsRepository.cs" /><Compile Include="Notifications\NotificationUpdateEventArgs.cs" />diff --git a/MediaBrowser.Model.Portable/MediaBrowser.Model.Portable.csproj b/MediaBrowser.Model.Portable/MediaBrowser.Model.Portable.csprojindex e0ff0fbc63..56e9c3f8e3 100644--- a/MediaBrowser.Model.Portable/MediaBrowser.Model.Portable.csproj+++ b/MediaBrowser.Model.Portable/MediaBrowser.Model.Portable.csproj@@ -215,6 +215,12 @@<Compile Include="..\MediaBrowser.Model\IO\IZipClient.cs"><Link>IO\IZipClient.cs</Link></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"><Link>Logging\ILogger.cs</Link></Compile>diff --git a/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj b/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csprojindex 59b3af342c..92abac5cff 100644--- a/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj+++ b/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj@@ -199,6 +199,12 @@<Compile Include="..\MediaBrowser.Model\IO\IZipClient.cs"><Link>IO\IZipClient.cs</Link></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"><Link>Logging\ILogger.cs</Link></Compile>diff --git a/MediaBrowser.Model/LiveTv/ChannelInfoDto.cs b/MediaBrowser.Model/LiveTv/ChannelInfoDto.csnew file mode 100644index 0000000000..5150897c3d--- /dev/null+++ b/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; }+ }+}diff --git a/MediaBrowser.Model/LiveTv/LiveTvServiceInfo.cs b/MediaBrowser.Model/LiveTv/LiveTvServiceInfo.csnew file mode 100644index 0000000000..87647738f3--- /dev/null+++ b/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; }+ }+}diff --git a/MediaBrowser.Model/MediaBrowser.Model.csproj b/MediaBrowser.Model/MediaBrowser.Model.csprojindex fa4fc29862..b317dbf0ee 100644--- a/MediaBrowser.Model/MediaBrowser.Model.csproj+++ b/MediaBrowser.Model/MediaBrowser.Model.csproj@@ -66,6 +66,8 @@<Compile Include="IO\IIsoManager.cs" /><Compile Include="IO\IIsoMount.cs" /><Compile Include="IO\IIsoMounter.cs" />+ <Compile Include="LiveTv\ChannelInfoDto.cs" />+ <Compile Include="LiveTv\LiveTvServiceInfo.cs" /><Compile Include="Net\WebSocketMessage.cs" /><Compile Include="Net\WebSocketMessageType.cs" /><Compile Include="Net\WebSocketState.cs" />diff --git a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.csnew file mode 100644index 0000000000..87b02816f7--- /dev/null+++ b/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+ };+ }+ }+}diff --git a/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj b/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csprojindex 86e250fe42..27dc44ee5d 100644--- a/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj+++ b/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj@@ -148,6 +148,7 @@<Compile Include="Library\Validators\PeoplePostScanTask.cs" /><Compile Include="Library\Validators\StudiosPostScanTask.cs" /><Compile Include="Library\Validators\StudiosValidator.cs" />+ <Compile Include="LiveTv\LiveTvManager.cs" /><Compile Include="Localization\LocalizationManager.cs" /><Compile Include="MediaEncoder\MediaEncoder.cs" /><Compile Include="Persistence\SqliteChapterRepository.cs" />diff --git a/MediaBrowser.ServerApplication/ApplicationHost.cs b/MediaBrowser.ServerApplication/ApplicationHost.csindex d0f7da73de..f921f1c11a 100644--- a/MediaBrowser.ServerApplication/ApplicationHost.cs+++ b/MediaBrowser.ServerApplication/ApplicationHost.cs@@ -15,6 +15,7 @@ using MediaBrowser.Controller.Dto;using MediaBrowser.Controller.Entities;using MediaBrowser.Controller.IO;using MediaBrowser.Controller.Library;+using MediaBrowser.Controller.LiveTv;using MediaBrowser.Controller.Localization;using MediaBrowser.Controller.MediaInfo;using MediaBrowser.Controller.Notifications;@@ -39,6 +40,7 @@ using MediaBrowser.Server.Implementations.EntryPoints;using MediaBrowser.Server.Implementations.HttpServer;using MediaBrowser.Server.Implementations.IO;using MediaBrowser.Server.Implementations.Library;+using MediaBrowser.Server.Implementations.LiveTv;using MediaBrowser.Server.Implementations.Localization;using MediaBrowser.Server.Implementations.MediaEncoder;using MediaBrowser.Server.Implementations.Persistence;@@ -154,6 +156,8 @@ namespace MediaBrowser.ServerApplicationprivate IIsoManager IsoManager { get; set; }private ISessionManager SessionManager { get; set; }+ private ILiveTvManager LiveTvManager { get; set; }+private ILocalizationManager LocalizationManager { get; set; }/// <summary>@@ -285,6 +289,9 @@ namespace MediaBrowser.ServerApplicationDtoService = new DtoService(Logger, LibraryManager, UserManager, UserDataRepository, ItemRepository, ImageProcessor);RegisterSingleInstance(DtoService);+ LiveTvManager = new LiveTvManager();+ RegisterSingleInstance(LiveTvManager);+var displayPreferencesTask = Task.Run(async () => await ConfigureDisplayPreferencesRepositories().ConfigureAwait(false));var itemsTask = Task.Run(async () => await ConfigureItemRepositories().ConfigureAwait(false));var userdataTask = Task.Run(async () => await ConfigureUserDataRepositories().ConfigureAwait(false));