diff --git a/MediaBrowser.Api/LiveTv/LiveTvService.cs b/MediaBrowser.Api/LiveTv/LiveTvService.cs new file mode 100644 index 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> + { + } + + [Route("/LiveTv/Channels", "GET")] + [Api(Description = "Gets available live tv channels.")] + public class GetChannels : IReturn> + { + // 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> 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.csproj index 4f54b52498..21e73361c2 100644 --- a/MediaBrowser.Api/MediaBrowser.Api.csproj +++ b/MediaBrowser.Api/MediaBrowser.Api.csproj @@ -81,6 +81,7 @@ + diff --git a/MediaBrowser.Controller/LiveTv/ChannelInfo.cs b/MediaBrowser.Controller/LiveTv/ChannelInfo.cs new file mode 100644 index 0000000000..5f40134482 --- /dev/null +++ b/MediaBrowser.Controller/LiveTv/ChannelInfo.cs @@ -0,0 +1,21 @@ + +namespace MediaBrowser.Controller.LiveTv +{ + /// + /// Class ChannelInfo + /// + public class ChannelInfo + { + /// + /// Gets or sets the name. + /// + /// The name. + public string Name { get; set; } + + /// + /// Gets or sets the name of the service. + /// + /// The name of the service. + public string ServiceName { get; set; } + } +} diff --git a/MediaBrowser.Controller/LiveTv/ILiveTvManager.cs b/MediaBrowser.Controller/LiveTv/ILiveTvManager.cs new file mode 100644 index 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 +{ + /// + /// Manages all live tv services installed on the server + /// + public interface ILiveTvManager + { + /// + /// Gets the services. + /// + /// The services. + IReadOnlyList Services { get; } + + /// + /// Adds the parts. + /// + /// The services. + void AddParts(IEnumerable services); + + /// + /// Gets the channel info dto. + /// + /// The info. + /// ChannelInfoDto. + ChannelInfoDto GetChannelInfoDto(ChannelInfo info); + } +} diff --git a/MediaBrowser.Controller/LiveTv/ILiveTvService.cs b/MediaBrowser.Controller/LiveTv/ILiveTvService.cs new file mode 100644 index 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 +{ + /// + /// Represents a single live tv back end (next pvr, media portal, etc). + /// + public interface ILiveTvService + { + /// + /// Gets the name. + /// + /// The name. + string Name { get; } + + /// + /// Gets the channels async. + /// + /// The cancellation token. + /// Task{IEnumerable{ChannelInfo}}. + Task> GetChannelsAsync(CancellationToken cancellationToken); + } +} diff --git a/MediaBrowser.Controller/MediaBrowser.Controller.csproj b/MediaBrowser.Controller/MediaBrowser.Controller.csproj index 0b27a350bd..57219ae513 100644 --- a/MediaBrowser.Controller/MediaBrowser.Controller.csproj +++ b/MediaBrowser.Controller/MediaBrowser.Controller.csproj @@ -96,6 +96,9 @@ + + + diff --git a/MediaBrowser.Model.Portable/MediaBrowser.Model.Portable.csproj b/MediaBrowser.Model.Portable/MediaBrowser.Model.Portable.csproj index e0ff0fbc63..56e9c3f8e3 100644 --- a/MediaBrowser.Model.Portable/MediaBrowser.Model.Portable.csproj +++ b/MediaBrowser.Model.Portable/MediaBrowser.Model.Portable.csproj @@ -215,6 +215,12 @@ IO\IZipClient.cs + + LiveTv\ChannelInfoDto.cs + + + LiveTv\LiveTvServiceInfo.cs + Logging\ILogger.cs diff --git a/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj b/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj index 59b3af342c..92abac5cff 100644 --- a/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj +++ b/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj @@ -199,6 +199,12 @@ IO\IZipClient.cs + + LiveTv\ChannelInfoDto.cs + + + LiveTv\LiveTvServiceInfo.cs + Logging\ILogger.cs diff --git a/MediaBrowser.Model/LiveTv/ChannelInfoDto.cs b/MediaBrowser.Model/LiveTv/ChannelInfoDto.cs new file mode 100644 index 0000000000..5150897c3d --- /dev/null +++ b/MediaBrowser.Model/LiveTv/ChannelInfoDto.cs @@ -0,0 +1,21 @@ + +namespace MediaBrowser.Model.LiveTv +{ + /// + /// Class ChannelInfoDto + /// + public class ChannelInfoDto + { + /// + /// Gets or sets the name. + /// + /// The name. + public string Name { get; set; } + + /// + /// Gets or sets the name of the service. + /// + /// The name of the service. + public string ServiceName { get; set; } + } +} diff --git a/MediaBrowser.Model/LiveTv/LiveTvServiceInfo.cs b/MediaBrowser.Model/LiveTv/LiveTvServiceInfo.cs new file mode 100644 index 0000000000..87647738f3 --- /dev/null +++ b/MediaBrowser.Model/LiveTv/LiveTvServiceInfo.cs @@ -0,0 +1,15 @@ + +namespace MediaBrowser.Model.LiveTv +{ + /// + /// Class ServiceInfo + /// + public class LiveTvServiceInfo + { + /// + /// Gets or sets the name. + /// + /// The name. + public string Name { get; set; } + } +} diff --git a/MediaBrowser.Model/MediaBrowser.Model.csproj b/MediaBrowser.Model/MediaBrowser.Model.csproj index fa4fc29862..b317dbf0ee 100644 --- a/MediaBrowser.Model/MediaBrowser.Model.csproj +++ b/MediaBrowser.Model/MediaBrowser.Model.csproj @@ -66,6 +66,8 @@ + + diff --git a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs new file mode 100644 index 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 +{ + /// + /// Class LiveTvManager + /// + public class LiveTvManager : ILiveTvManager + { + private readonly List _services = new List(); + /// + /// Gets the services. + /// + /// The services. + public IReadOnlyList Services + { + get { return _services; } + } + + /// + /// Adds the parts. + /// + /// The services. + public void AddParts(IEnumerable services) + { + _services.AddRange(services); + } + + /// + /// Gets the channel info dto. + /// + /// The info. + /// ChannelInfoDto. + 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.csproj index 86e250fe42..27dc44ee5d 100644 --- a/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj +++ b/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj @@ -148,6 +148,7 @@ + diff --git a/MediaBrowser.ServerApplication/ApplicationHost.cs b/MediaBrowser.ServerApplication/ApplicationHost.cs index 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.ServerApplication private IIsoManager IsoManager { get; set; } private ISessionManager SessionManager { get; set; } + private ILiveTvManager LiveTvManager { get; set; } + private ILocalizationManager LocalizationManager { get; set; } /// @@ -285,6 +289,9 @@ namespace MediaBrowser.ServerApplication DtoService = 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));