From 01a9c07dd8bef8bb5d3abef4113d0449601b9ce5 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 24 Nov 2013 16:30:38 -0500 Subject: support display of channel images --- .../LiveTv/LiveTvManager.cs | 60 +++++++++++++--------- 1 file changed, 36 insertions(+), 24 deletions(-) (limited to 'MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs') diff --git a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs index 9e1c6c4acb..8ea4ff1d3f 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs @@ -70,9 +70,11 @@ namespace MediaBrowser.Server.Implementations.LiveTv Name = info.Name, ServiceName = info.ServiceName, ChannelType = info.ChannelType, - Id = info.ChannelId, + ChannelId = info.ChannelId, Number = info.ChannelNumber, - PrimaryImageTag = GetLogoImageTag(info) + PrimaryImageTag = GetLogoImageTag(info), + Type = info.GetType().Name, + Id = info.Id.ToString("N") }; } @@ -113,9 +115,11 @@ namespace MediaBrowser.Server.Implementations.LiveTv }).ThenBy(i => i.Name); } - public Channel GetChannel(string serviceName, string channelId) + public Channel GetChannel(string id) { - return _channels.FirstOrDefault(i => string.Equals(i.ServiceName, serviceName, StringComparison.OrdinalIgnoreCase) && string.Equals(i.ChannelId, channelId, StringComparison.OrdinalIgnoreCase)); + var guid = new Guid(id); + + return _channels.FirstOrDefault(i => i.Id == guid); } internal async Task RefreshChannels(IProgress progress, CancellationToken cancellationToken) @@ -125,36 +129,44 @@ namespace MediaBrowser.Server.Implementations.LiveTv var tasks = _services.Select(i => i.GetChannelsAsync(currentCancellationToken)); - var results = await Task.WhenAll(tasks).ConfigureAwait(false); + progress.Report(10); - var allChannels = results.SelectMany(i => i); + var results = await Task.WhenAll(tasks).ConfigureAwait(false); - var channnelTasks = allChannels.Select(i => GetChannel(i, cancellationToken)); + var allChannels = results.SelectMany(i => i).ToList(); - var channelEntities = await Task.WhenAll(channnelTasks).ConfigureAwait(false); + var list = new List(); - _channels = channelEntities.ToList(); - } + var numComplete = 0; - private async Task GetChannel(ChannelInfo channelInfo, CancellationToken cancellationToken) - { - try - { - return await GetChannelInternal(channelInfo, cancellationToken).ConfigureAwait(false); - } - catch (OperationCanceledException) - { - throw; - } - catch (Exception ex) + foreach (var channel in allChannels) { - _logger.ErrorException("Error getting channel information for {0}", ex, channelInfo.Name); + try + { + var item = await GetChannel(channel, cancellationToken).ConfigureAwait(false); - return null; + list.Add(item); + } + catch (OperationCanceledException) + { + throw; + } + catch (Exception ex) + { + _logger.ErrorException("Error getting channel information for {0}", ex, channel.Name); + } + + numComplete++; + double percent = numComplete; + percent /= allChannels.Count; + + progress.Report(90 * percent + 10); } + + _channels = list; } - private async Task GetChannelInternal(ChannelInfo channelInfo, CancellationToken cancellationToken) + private async Task GetChannel(ChannelInfo channelInfo, CancellationToken cancellationToken) { var path = Path.Combine(_appPaths.ItemsByNamePath, "channels", _fileSystem.GetValidFilename(channelInfo.ServiceName), _fileSystem.GetValidFilename(channelInfo.Name)); -- cgit v1.2.3