From 4054846a6e2ac93a082a22e03f183296a27a0cba Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Mon, 25 Nov 2013 11:15:31 -0500 Subject: updated nuget for live tv --- .../LiveTv/LiveTvManager.cs | 47 ++++++++++++++++++++-- 1 file changed, 44 insertions(+), 3 deletions(-) (limited to 'MediaBrowser.Server.Implementations') diff --git a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs index 973fa54099..825c7d8ef8 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; + } } } -- cgit v1.2.3