From 4054846a6e2ac93a082a22e03f183296a27a0cba Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Mon, 25 Nov 2013 11:15:31 -0500 Subject: [PATCH] updated nuget for live tv --- MediaBrowser.Api/Images/ImageService.cs | 4 +- MediaBrowser.Api/LiveTv/LiveTvService.cs | 29 +++++------- .../LiveTv/ILiveTvManager.cs | 7 +++ .../LiveTv/ILiveTvService.cs | 8 ++-- .../MediaBrowser.Model.Portable.csproj | 6 +-- .../MediaBrowser.Model.net35.csproj | 6 +-- MediaBrowser.Model/LiveTv/ChannelGuide.cs | 23 --------- MediaBrowser.Model/LiveTv/ProgramInfo.cs | 18 +++++++ MediaBrowser.Model/LiveTv/ProgramQuery.cs | 25 ++++++++++ MediaBrowser.Model/MediaBrowser.Model.csproj | 2 +- .../LiveTv/LiveTvManager.cs | 47 +++++++++++++++++-- Nuget/MediaBrowser.Common.Internal.nuspec | 4 +- Nuget/MediaBrowser.Common.nuspec | 2 +- Nuget/MediaBrowser.Server.Core.nuspec | 4 +- 14 files changed, 124 insertions(+), 61 deletions(-) delete mode 100644 MediaBrowser.Model/LiveTv/ChannelGuide.cs create mode 100644 MediaBrowser.Model/LiveTv/ProgramQuery.cs diff --git a/MediaBrowser.Api/Images/ImageService.cs b/MediaBrowser.Api/Images/ImageService.cs index e5603967b..9112518b8 100644 --- a/MediaBrowser.Api/Images/ImageService.cs +++ b/MediaBrowser.Api/Images/ImageService.cs @@ -80,8 +80,8 @@ namespace MediaBrowser.Api.Images public string Id { get; set; } } - [Route("/LiveTV/Channels/{Id}/Images/{Type}", "GET")] - [Route("/LiveTV/Channels/{Id}/Images/{Type}/{Index}", "GET")] + [Route("/LiveTv/Channels/{Id}/Images/{Type}", "GET")] + [Route("/LiveTv/Channels/{Id}/Images/{Type}/{Index}", "GET")] [Api(Description = "Gets an item image")] public class GetChannelImage : ImageRequest { diff --git a/MediaBrowser.Api/LiveTv/LiveTvService.cs b/MediaBrowser.Api/LiveTv/LiveTvService.cs index 68cfc9c44..b10d8d481 100644 --- a/MediaBrowser.Api/LiveTv/LiveTvService.cs +++ b/MediaBrowser.Api/LiveTv/LiveTvService.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Controller.LiveTv; +using System; +using MediaBrowser.Controller.LiveTv; using MediaBrowser.Model.LiveTv; using ServiceStack.ServiceHost; using System.Collections.Generic; @@ -41,7 +42,7 @@ namespace MediaBrowser.Api.LiveTv [ApiMember(Name = "Id", Description = "Channel Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")] public string Id { get; set; } } - + [Route("/LiveTv/Recordings", "GET")] [Api(Description = "Gets available live tv recordings.")] public class GetRecordings : IReturn> @@ -50,9 +51,9 @@ namespace MediaBrowser.Api.LiveTv public string ServiceName { get; set; } } - [Route("/LiveTv/Guide", "GET")] + [Route("/LiveTv/Programs", "GET")] [Api(Description = "Gets available live tv epgs..")] - public class GetGuide : IReturn> + public class GetPrograms : IReturn> { [ApiMember(Name = "ServiceName", Description = "Live tv service name", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")] public string ServiceName { get; set; } @@ -143,21 +144,15 @@ namespace MediaBrowser.Api.LiveTv return recordings.SelectMany(i => i); } - public object Get(GetGuide request) + public object Get(GetPrograms request) { - var result = GetGuideAsync(request).Result; + var result = _liveTvManager.GetPrograms(new ProgramQuery + { + ServiceName = request.ServiceName, + ChannelIdList = (request.ChannelIds ?? string.Empty).Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToArray() + }); - return ToOptimizedResult(result); - } - - private async Task> GetGuideAsync(GetGuide request) - { - var service = GetServices(request.ServiceName) - .First(); - - var channels = request.ChannelIds.Split(','); - - return await service.GetChannelGuidesAsync(channels, CancellationToken.None).ConfigureAwait(false); + return ToOptimizedResult(result.ToList()); } } } \ No newline at end of file diff --git a/MediaBrowser.Controller/LiveTv/ILiveTvManager.cs b/MediaBrowser.Controller/LiveTv/ILiveTvManager.cs index 5ec2f2c4a..339367c17 100644 --- a/MediaBrowser.Controller/LiveTv/ILiveTvManager.cs +++ b/MediaBrowser.Controller/LiveTv/ILiveTvManager.cs @@ -40,5 +40,12 @@ namespace MediaBrowser.Controller.LiveTv /// The identifier. /// Channel. Channel GetChannel(string id); + + /// + /// Gets the programs. + /// + /// The query. + /// IEnumerable{ProgramInfo}. + IEnumerable GetPrograms(ProgramQuery query); } } diff --git a/MediaBrowser.Controller/LiveTv/ILiveTvService.cs b/MediaBrowser.Controller/LiveTv/ILiveTvService.cs index 56d98d518..53cb514b5 100644 --- a/MediaBrowser.Controller/LiveTv/ILiveTvService.cs +++ b/MediaBrowser.Controller/LiveTv/ILiveTvService.cs @@ -61,11 +61,11 @@ namespace MediaBrowser.Controller.LiveTv Task> GetRecordingsAsync(RecordingQuery query, CancellationToken cancellationToken); /// - /// Gets the channel guides. + /// Gets the channel guide. /// - /// The channel identifier list. + /// The channel identifier. /// The cancellation token. - /// Task{IEnumerable{ChannelGuide}}. - Task> GetChannelGuidesAsync(IEnumerable channelIdList, CancellationToken cancellationToken); + /// Task{IEnumerable{ProgramInfo}}. + Task> GetChannelGuideAsync(string channelId, CancellationToken cancellationToken); } } diff --git a/MediaBrowser.Model.Portable/MediaBrowser.Model.Portable.csproj b/MediaBrowser.Model.Portable/MediaBrowser.Model.Portable.csproj index 6f72dc09b..2850d09ed 100644 --- a/MediaBrowser.Model.Portable/MediaBrowser.Model.Portable.csproj +++ b/MediaBrowser.Model.Portable/MediaBrowser.Model.Portable.csproj @@ -224,9 +224,6 @@ IO\IZipClient.cs - - LiveTv\ChannelGuide.cs - LiveTv\ChannelInfoDto.cs @@ -242,6 +239,9 @@ LiveTv\ProgramInfo.cs + + LiveTv\ProgramQuery.cs + LiveTv\RecordingInfo.cs diff --git a/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj b/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj index e49d0fb08..be6268184 100644 --- a/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj +++ b/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj @@ -211,9 +211,6 @@ IO\IZipClient.cs - - LiveTv\ChannelGuide.cs - LiveTv\ChannelInfoDto.cs @@ -229,6 +226,9 @@ LiveTv\ProgramInfo.cs + + LiveTv\ProgramQuery.cs + LiveTv\RecordingInfo.cs diff --git a/MediaBrowser.Model/LiveTv/ChannelGuide.cs b/MediaBrowser.Model/LiveTv/ChannelGuide.cs deleted file mode 100644 index d2bebac18..000000000 --- a/MediaBrowser.Model/LiveTv/ChannelGuide.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System.Collections.Generic; - -namespace MediaBrowser.Model.LiveTv -{ - public class ChannelGuide - { - /// - /// Gets or sets the name of the service. - /// - /// The name of the service. - public string ServiceName { get; set; } - - /// - /// ChannelId for the EPG. - /// - public string ChannelId { get; set; } - - /// - /// List of all the programs for a specific channel - /// - public List Programs { get; set; } - } -} diff --git a/MediaBrowser.Model/LiveTv/ProgramInfo.cs b/MediaBrowser.Model/LiveTv/ProgramInfo.cs index 6bf0e383f..75ec5df70 100644 --- a/MediaBrowser.Model/LiveTv/ProgramInfo.cs +++ b/MediaBrowser.Model/LiveTv/ProgramInfo.cs @@ -9,6 +9,24 @@ namespace MediaBrowser.Model.LiveTv /// public string Id { get; set; } + /// + /// Gets or sets the channel identifier. + /// + /// The channel identifier. + public string ChannelId { get; set; } + + /// + /// Gets or sets the name of the service. + /// + /// The name of the service. + public string ServiceName { get; set; } + + /// + /// Gets or sets the external channel identifier. + /// + /// The external channel identifier. + public string ExternalChannelId { get; set; } + /// /// Name of the program /// diff --git a/MediaBrowser.Model/LiveTv/ProgramQuery.cs b/MediaBrowser.Model/LiveTv/ProgramQuery.cs new file mode 100644 index 000000000..1276ddb9e --- /dev/null +++ b/MediaBrowser.Model/LiveTv/ProgramQuery.cs @@ -0,0 +1,25 @@ +namespace MediaBrowser.Model.LiveTv +{ + /// + /// Class ProgramQuery. + /// + public class ProgramQuery + { + /// + /// Gets or sets the name of the service. + /// + /// The name of the service. + public string ServiceName { get; set; } + + /// + /// Gets or sets the channel identifier. + /// + /// The channel identifier. + public string[] ChannelIdList { get; set; } + + public ProgramQuery() + { + ChannelIdList = new string[] { }; + } + } +} diff --git a/MediaBrowser.Model/MediaBrowser.Model.csproj b/MediaBrowser.Model/MediaBrowser.Model.csproj index dc0571b3e..05b4e9b7a 100644 --- a/MediaBrowser.Model/MediaBrowser.Model.csproj +++ b/MediaBrowser.Model/MediaBrowser.Model.csproj @@ -60,10 +60,10 @@ - + diff --git a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs index 973fa5409..825c7d8ef 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs @@ -29,6 +29,8 @@ namespace MediaBrowser.Server.Implementations.LiveTv private List _channels = new List(); + private Dictionary> _guide = new Dictionary>(); + private readonly List _services = new List(); public LiveTvManager(IServerApplicationPaths appPaths, IFileSystem fileSystem, ILogger logger, IItemRepository itemRepo, IImageProcessor imageProcessor) @@ -79,6 +81,11 @@ namespace MediaBrowser.Server.Implementations.LiveTv }; } + private ILiveTvService GetService(ChannelInfo channel) + { + return _services.FirstOrDefault(i => string.Equals(channel.ServiceName, i.Name, StringComparison.OrdinalIgnoreCase)); + } + private Guid? GetLogoImageTag(Channel info) { var path = info.PrimaryImagePath; @@ -137,16 +144,30 @@ namespace MediaBrowser.Server.Implementations.LiveTv var allChannels = results.SelectMany(i => i).ToList(); var list = new List(); + var guide = new Dictionary>(); var numComplete = 0; - foreach (var channel in allChannels) + foreach (var channelInfo in allChannels) { try { - var item = await GetChannel(channel, cancellationToken).ConfigureAwait(false); + var item = await GetChannel(channelInfo, cancellationToken).ConfigureAwait(false); + + var service = GetService(channelInfo); + + var programs = await service.GetChannelGuideAsync(channelInfo.Id, cancellationToken).ConfigureAwait(false); + var programList = programs.ToList(); + + foreach (var program in programList) + { + program.ExternalChannelId = channelInfo.Id; + program.ChannelId = item.Id.ToString("N"); + program.ServiceName = service.Name; + } list.Add(item); + guide[item.Id] = programList; } catch (OperationCanceledException) { @@ -154,7 +175,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv } catch (Exception ex) { - _logger.ErrorException("Error getting channel information for {0}", ex, channel.Name); + _logger.ErrorException("Error getting channel information for {0}", ex, channelInfo.Name); } numComplete++; @@ -164,6 +185,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv progress.Report(90 * percent + 10); } + _guide = guide; _channels = list; } @@ -218,5 +240,24 @@ namespace MediaBrowser.Server.Implementations.LiveTv return item; } + + public IEnumerable GetPrograms(ProgramQuery query) + { + var programs = _guide.Values.SelectMany(i => i); + + if (!string.IsNullOrEmpty(query.ServiceName)) + { + programs = programs.Where(i => string.Equals(i.ServiceName, query.ServiceName, StringComparison.OrdinalIgnoreCase)); + } + + if (query.ChannelIdList.Length > 0) + { + var guids = query.ChannelIdList.Select(i => new Guid(i)).ToList(); + + programs = programs.Where(i => guids.Contains(new Guid(i.ChannelId))); + } + + return programs; + } } } diff --git a/Nuget/MediaBrowser.Common.Internal.nuspec b/Nuget/MediaBrowser.Common.Internal.nuspec index 75b56d1e3..ea21fc39b 100644 --- a/Nuget/MediaBrowser.Common.Internal.nuspec +++ b/Nuget/MediaBrowser.Common.Internal.nuspec @@ -2,7 +2,7 @@ MediaBrowser.Common.Internal - 3.0.246 + 3.0.247 MediaBrowser.Common.Internal Luke ebr,Luke,scottisafool @@ -12,7 +12,7 @@ Contains common components shared by Media Browser Theater and Media Browser Server. Not intended for plugin developer consumption. Copyright © Media Browser 2013 - + diff --git a/Nuget/MediaBrowser.Common.nuspec b/Nuget/MediaBrowser.Common.nuspec index c24fe9dd6..1f2d32b5f 100644 --- a/Nuget/MediaBrowser.Common.nuspec +++ b/Nuget/MediaBrowser.Common.nuspec @@ -2,7 +2,7 @@ MediaBrowser.Common - 3.0.246 + 3.0.247 MediaBrowser.Common Media Browser Team ebr,Luke,scottisafool diff --git a/Nuget/MediaBrowser.Server.Core.nuspec b/Nuget/MediaBrowser.Server.Core.nuspec index 5bbed1f65..809cad71a 100644 --- a/Nuget/MediaBrowser.Server.Core.nuspec +++ b/Nuget/MediaBrowser.Server.Core.nuspec @@ -2,7 +2,7 @@ MediaBrowser.Server.Core - 3.0.246 + 3.0.247 Media Browser.Server.Core Media Browser Team ebr,Luke,scottisafool @@ -12,7 +12,7 @@ Contains core components required to build plugins for Media Browser Server. Copyright © Media Browser 2013 - +