diff options
| author | Luke Pulverenti <luke.pulverenti@gmail.com> | 2015-08-19 12:43:23 -0400 |
|---|---|---|
| committer | Luke Pulverenti <luke.pulverenti@gmail.com> | 2015-08-19 12:43:23 -0400 |
| commit | e5aea2b622d36e38380ac7e97bfb653931253e77 (patch) | |
| tree | be3e843e6d2c93dd540ce1606b9cece2326bf655 /MediaBrowser.Server.Implementations | |
| parent | 615d1e2a53c9079e6b13789cbaa0410d9039f435 (diff) | |
pool tuners
Diffstat (limited to 'MediaBrowser.Server.Implementations')
3 files changed, 112 insertions, 19 deletions
diff --git a/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs b/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs index cd166ddd3..eb23fab80 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs @@ -88,11 +88,11 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV var status = new LiveTvServiceStatusInfo(); var list = new List<LiveTvTunerInfo>(); - foreach (var hostInstance in GetTunerHosts()) + foreach (var hostInstance in _liveTvManager.TunerHosts) { try { - var tuners = await hostInstance.Item1.GetTunerInfos(hostInstance.Item2, cancellationToken).ConfigureAwait(false); + var tuners = await hostInstance.GetTunerInfos(cancellationToken).ConfigureAwait(false); list.AddRange(tuners); } @@ -120,11 +120,11 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV var list = new List<ChannelInfo>(); - foreach (var hostInstance in GetTunerHosts()) + foreach (var hostInstance in _liveTvManager.TunerHosts) { try { - var channels = await hostInstance.Item1.GetChannels(hostInstance.Item2, cancellationToken).ConfigureAwait(false); + var channels = await hostInstance.GetChannels(cancellationToken).ConfigureAwait(false); list.AddRange(channels); } diff --git a/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunHost.cs b/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunHost.cs index 35f77abcb..7607d5b9d 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunHost.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunHost.cs @@ -49,7 +49,46 @@ namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts.HdHomerun private const string ChannelIdPrefix = "hdhr_"; - public async Task<IEnumerable<ChannelInfo>> GetChannels(TunerHostInfo info, CancellationToken cancellationToken) + private List<TunerHostInfo> GetTunerHosts() + { + return GetConfiguration().TunerHosts + .Where(i => i.IsEnabled && string.Equals(i.Type, Type, StringComparison.OrdinalIgnoreCase)) + .ToList(); + } + + public async Task<IEnumerable<ChannelInfo>> GetChannels(CancellationToken cancellationToken) + { + var list = new List<ChannelInfo>(); + + var hosts = GetTunerHosts(); + + var ipAddresses = new List<string>(); + + foreach (var host in hosts) + { + var ip = GetApiUrl(host, false); + + if (ipAddresses.Contains(ip, StringComparer.OrdinalIgnoreCase)) + { + continue; + } + + try + { + list.AddRange(await GetChannels(host, cancellationToken).ConfigureAwait(false)); + } + catch (Exception ex) + { + _logger.ErrorException("Error getting channel list", ex); + } + + ipAddresses.Add(ip); + } + + return list; + } + + private async Task<IEnumerable<ChannelInfo>> GetChannels(TunerHostInfo info, CancellationToken cancellationToken) { var options = new HttpRequestOptions { @@ -146,6 +185,26 @@ namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts.HdHomerun } } + public async Task<List<LiveTvTunerInfo>> GetTunerInfos(CancellationToken cancellationToken) + { + var list = new List<LiveTvTunerInfo>(); + + foreach (var host in GetConfiguration().TunerHosts + .Where(i => i.IsEnabled && string.Equals(i.Type, Type, StringComparison.OrdinalIgnoreCase))) + { + try + { + list.AddRange(await GetTunerInfos(host, cancellationToken).ConfigureAwait(false)); + } + catch (Exception ex) + { + _logger.ErrorException("Error getting tuner info", ex); + } + } + + return list; + } + private string GetApiUrl(TunerHostInfo info, bool isPlayback) { var url = info.Url; diff --git a/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/M3UTunerHost.cs b/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/M3UTunerHost.cs index 0755d2a39..ec05cefd5 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/M3UTunerHost.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/M3UTunerHost.cs @@ -4,6 +4,7 @@ using MediaBrowser.Controller.LiveTv; using MediaBrowser.Model.Dto; using MediaBrowser.Model.Entities; using MediaBrowser.Model.LiveTv; +using MediaBrowser.Model.Logging; using MediaBrowser.Model.MediaInfo; using System; using System.Collections.Generic; @@ -27,20 +28,52 @@ namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts } private readonly IConfigurationManager _config; + private readonly ILogger _logger; - public M3UTunerHost(IConfigurationManager config) + public M3UTunerHost(IConfigurationManager config, ILogger logger) { _config = config; + _logger = logger; } - public Task<IEnumerable<ChannelInfo>> GetChannels(TunerHostInfo info, CancellationToken cancellationToken) + private List<TunerHostInfo> GetTunerHosts() { - var urlHash = info.Url.GetMD5().ToString("N"); - + return GetConfiguration().TunerHosts + .Where(i => i.IsEnabled && string.Equals(i.Type, Type, StringComparison.OrdinalIgnoreCase)) + .ToList(); + } + + public async Task<IEnumerable<ChannelInfo>> GetChannels(CancellationToken cancellationToken) + { + var list = new List<ChannelInfo>(); + + var urls = GetTunerHosts().Select(i => i.Url) + .Where(i => !string.IsNullOrWhiteSpace(i)) + .Distinct(StringComparer.OrdinalIgnoreCase); + + foreach (var url in urls) + { + try + { + list.AddRange(await GetChannels(url, cancellationToken).ConfigureAwait(false)); + } + catch (Exception ex) + { + _logger.ErrorException("Error getting channel list", ex); + } + } + + return list; + } + + private Task<IEnumerable<ChannelInfo>> GetChannels(string url, CancellationToken cancellationToken) + { + var urlHash = url.GetMD5().ToString("N"); + int position = 0; string line; // Read the file and display it line by line. - var file = new StreamReader(info.Url); + var file = new StreamReader(url); var channels = new List<M3UChannel>(); while ((line = file.ReadLine()) != null) { @@ -105,19 +138,20 @@ namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts return Task.FromResult((IEnumerable<ChannelInfo>)channels); } - public Task<List<LiveTvTunerInfo>> GetTunerInfos(TunerHostInfo info, CancellationToken cancellationToken) + public Task<List<LiveTvTunerInfo>> GetTunerInfos(CancellationToken cancellationToken) { - var list = new List<LiveTvTunerInfo>(); - - list.Add(new LiveTvTunerInfo() + var list = GetConfiguration().TunerHosts + .Where(i => i.IsEnabled && string.Equals(i.Type, Type, StringComparison.OrdinalIgnoreCase)) + .Select(i => new LiveTvTunerInfo() { Name = Name, SourceType = Type, Status = LiveTvTunerStatus.Available, - Id = info.Url.GetMD5().ToString("N"), - Url = info.Url - }); - + Id = i.Url.GetMD5().ToString("N"), + Url = i.Url + }) + .ToList(); + return Task.FromResult(list); } @@ -136,7 +170,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts channelId = channelId.Substring(urlHash.Length); - var channels = await GetChannels(info, cancellationToken).ConfigureAwait(false); + var channels = await GetChannels(info.Url, cancellationToken).ConfigureAwait(false); var m3uchannels = channels.Cast<M3UChannel>(); var channel = m3uchannels.FirstOrDefault(c => c.Id == channelId); if (channel != null) |
