From c33b12ba7daf7ada1cb644a76eb905e56873489c Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 23 Feb 2017 14:13:26 -0500 Subject: [PATCH] update m3u channel mapping --- .../LiveTv/EmbyTV/EmbyTV.cs | 25 +++++++++--- .../LiveTv/LiveTvManager.cs | 7 +--- .../LiveTv/TunerHosts/BaseTunerHost.cs | 6 +-- .../TunerHosts/HdHomerun/HdHomerunHost.cs | 5 ++- .../LiveTv/TunerHosts/M3UTunerHost.cs | 6 ++- .../LiveTv/TunerHosts/M3uParser.cs | 39 +++++++++---------- 6 files changed, 48 insertions(+), 40 deletions(-) diff --git a/Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs b/Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs index 82f32efa2d..926d82f94b 100644 --- a/Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs +++ b/Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs @@ -474,17 +474,30 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV public ChannelInfo GetEpgChannelFromTunerChannel(List mappings, ChannelInfo tunerChannel, List epgChannels) { - var tunerChannelId = string.IsNullOrWhiteSpace(tunerChannel.TunerChannelId) - ? tunerChannel.Id - : tunerChannel.TunerChannelId; + if (!string.IsNullOrWhiteSpace(tunerChannel.Id)) + { + var mappedTunerChannelId = GetMappedChannel(tunerChannel.Id, mappings); + + if (string.IsNullOrWhiteSpace(mappedTunerChannelId)) + { + mappedTunerChannelId = tunerChannel.Id; + } + + var channel = epgChannels.FirstOrDefault(i => string.Equals(mappedTunerChannelId, i.Id, StringComparison.OrdinalIgnoreCase)); + + if (channel != null) + { + return channel; + } + } - if (!string.IsNullOrWhiteSpace(tunerChannelId)) + if (!string.IsNullOrWhiteSpace(tunerChannel.TunerChannelId)) { - var mappedTunerChannelId = GetMappedChannel(tunerChannelId, mappings); + var mappedTunerChannelId = GetMappedChannel(tunerChannel.TunerChannelId, mappings); if (string.IsNullOrWhiteSpace(mappedTunerChannelId)) { - mappedTunerChannelId = tunerChannelId; + mappedTunerChannelId = tunerChannel.TunerChannelId; } var channel = epgChannels.FirstOrDefault(i => string.Equals(mappedTunerChannelId, i.Id, StringComparison.OrdinalIgnoreCase)); diff --git a/Emby.Server.Implementations/LiveTv/LiveTvManager.cs b/Emby.Server.Implementations/LiveTv/LiveTvManager.cs index 887784213b..654777b3c0 100644 --- a/Emby.Server.Implementations/LiveTv/LiveTvManager.cs +++ b/Emby.Server.Implementations/LiveTv/LiveTvManager.cs @@ -2926,7 +2926,7 @@ namespace Emby.Server.Implementations.LiveTv var result = new TunerChannelMapping { Name = tunerChannel.Name, - Id = tunerChannel.TunerChannelId + Id = tunerChannel.Id }; if (!string.IsNullOrWhiteSpace(tunerChannel.Number)) @@ -2934,11 +2934,6 @@ namespace Emby.Server.Implementations.LiveTv result.Name = tunerChannel.Number + " " + result.Name; } - if (string.IsNullOrWhiteSpace(result.Id)) - { - result.Id = tunerChannel.Id; - } - var providerChannel = EmbyTV.EmbyTV.Current.GetEpgChannelFromTunerChannel(mappings, tunerChannel, epgChannels); if (providerChannel != null) diff --git a/Emby.Server.Implementations/LiveTv/TunerHosts/BaseTunerHost.cs b/Emby.Server.Implementations/LiveTv/TunerHosts/BaseTunerHost.cs index 5fae3f666b..5ac3812b0a 100644 --- a/Emby.Server.Implementations/LiveTv/TunerHosts/BaseTunerHost.cs +++ b/Emby.Server.Implementations/LiveTv/TunerHosts/BaseTunerHost.cs @@ -35,10 +35,10 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts MediaEncoder = mediaEncoder; } - protected abstract Task> GetChannelsInternal(TunerHostInfo tuner, CancellationToken cancellationToken); + protected abstract Task> GetChannelsInternal(TunerHostInfo tuner, CancellationToken cancellationToken); public abstract string Type { get; } - public async Task> GetChannels(TunerHostInfo tuner, bool enableCache, CancellationToken cancellationToken) + public async Task> GetChannels(TunerHostInfo tuner, bool enableCache, CancellationToken cancellationToken) { ChannelCache cache = null; var key = tuner.Id; @@ -73,7 +73,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts .ToList(); } - public async Task> GetChannels(bool enableCache, CancellationToken cancellationToken) + public async Task> GetChannels(bool enableCache, CancellationToken cancellationToken) { var list = new List(); diff --git a/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunHost.cs b/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunHost.cs index bc9d01254b..2e70e1ac15 100644 --- a/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunHost.cs +++ b/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunHost.cs @@ -84,7 +84,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun } } - protected override async Task> GetChannelsInternal(TunerHostInfo info, CancellationToken cancellationToken) + protected override async Task> GetChannelsInternal(TunerHostInfo info, CancellationToken cancellationToken) { var lineup = await GetLineup(info, cancellationToken).ConfigureAwait(false); @@ -99,7 +99,8 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun AudioCodec = i.AudioCodec, VideoCodec = i.VideoCodec, ChannelType = ChannelType.TV - }); + + }).ToList(); } private readonly Dictionary _modelCache = new Dictionary(); diff --git a/Emby.Server.Implementations/LiveTv/TunerHosts/M3UTunerHost.cs b/Emby.Server.Implementations/LiveTv/TunerHosts/M3UTunerHost.cs index 601cb26661..8366c2d57f 100644 --- a/Emby.Server.Implementations/LiveTv/TunerHosts/M3UTunerHost.cs +++ b/Emby.Server.Implementations/LiveTv/TunerHosts/M3UTunerHost.cs @@ -48,9 +48,11 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts private const string ChannelIdPrefix = "m3u_"; - protected override async Task> GetChannelsInternal(TunerHostInfo info, CancellationToken cancellationToken) + protected override async Task> GetChannelsInternal(TunerHostInfo info, CancellationToken cancellationToken) { - return await new M3uParser(Logger, _fileSystem, _httpClient, _appHost).Parse(info.Url, ChannelIdPrefix, info.Id, !info.EnableTvgId, cancellationToken).ConfigureAwait(false); + var result = await new M3uParser(Logger, _fileSystem, _httpClient, _appHost).Parse(info.Url, ChannelIdPrefix, info.Id, !info.EnableTvgId, cancellationToken).ConfigureAwait(false); + + return result.Cast().ToList(); } public Task> GetTunerInfos(CancellationToken cancellationToken) diff --git a/Emby.Server.Implementations/LiveTv/TunerHosts/M3uParser.cs b/Emby.Server.Implementations/LiveTv/TunerHosts/M3uParser.cs index 073da48a02..8c4b9bf606 100644 --- a/Emby.Server.Implementations/LiveTv/TunerHosts/M3uParser.cs +++ b/Emby.Server.Implementations/LiveTv/TunerHosts/M3uParser.cs @@ -136,11 +136,26 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts channel.Name = GetChannelName(extInf, attributes); channel.Number = GetChannelNumber(extInf, attributes, mediaUrl); - var channelId = GetTunerChannelId(attributes); + string tvgId; + attributes.TryGetValue("tvg-id", out tvgId); + + string channelId; + attributes.TryGetValue("channel-id", out channelId); + + channel.TunerChannelId = string.IsNullOrWhiteSpace(tvgId) ? channelId : tvgId; + + var channelIdValues = new List(); if (!string.IsNullOrWhiteSpace(channelId)) { - channel.Id = channelId; - channel.TunerChannelId = channelId; + channelIdValues.Add(channelId); + } + if (!string.IsNullOrWhiteSpace(tvgId)) + { + channelIdValues.Add(tvgId); + } + if (channelIdValues.Count > 0) + { + channel.Id = string.Join("_", channelIdValues.ToArray()); } return channel; @@ -296,24 +311,6 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts return name; } - private string GetTunerChannelId(Dictionary attributes) - { - var values = new List(); - - string result; - if (attributes.TryGetValue("tvg-id", out result)) - { - values.Add(result); - } - - if (attributes.TryGetValue("channel-id", out result)) - { - values.Add(result); - } - - return values.Count == 0 ? null : string.Join("-", values.ToArray()); - } - private Dictionary ParseExtInf(string line, out string remaining) { var dict = new Dictionary(StringComparer.OrdinalIgnoreCase);