The Free Software Media System - Server Backend & API
update m3u channel mapping
Luke Pulverentic33b12ba7daf
diff --git a/Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs b/Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.csindex 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.EmbyTVpublic ChannelInfo GetEpgChannelFromTunerChannel(List<NameValuePair> mappings, ChannelInfo tunerChannel, List<ChannelInfo> 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.csindex 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.LiveTvvar 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.LiveTvresult.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.csindex 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.TunerHostsMediaEncoder = mediaEncoder;}- protected abstract Task<IEnumerable<ChannelInfo>> GetChannelsInternal(TunerHostInfo tuner, CancellationToken cancellationToken);+ protected abstract Task<List<ChannelInfo>> GetChannelsInternal(TunerHostInfo tuner, CancellationToken cancellationToken);public abstract string Type { get; }- public async Task<IEnumerable<ChannelInfo>> GetChannels(TunerHostInfo tuner, bool enableCache, CancellationToken cancellationToken)+ public async Task<List<ChannelInfo>> 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<IEnumerable<ChannelInfo>> GetChannels(bool enableCache, CancellationToken cancellationToken)+ public async Task<List<ChannelInfo>> GetChannels(bool enableCache, CancellationToken cancellationToken){var list = new List<ChannelInfo>();diff --git a/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunHost.cs b/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunHost.csindex 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<IEnumerable<ChannelInfo>> GetChannelsInternal(TunerHostInfo info, CancellationToken cancellationToken)+ protected override async Task<List<ChannelInfo>> GetChannelsInternal(TunerHostInfo info, CancellationToken cancellationToken){var lineup = await GetLineup(info, cancellationToken).ConfigureAwait(false);@@ -99,7 +99,8 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerunAudioCodec = i.AudioCodec,VideoCodec = i.VideoCodec,ChannelType = ChannelType.TV- });++ }).ToList();}private readonly Dictionary<string, DiscoverResponse> _modelCache = new Dictionary<string, DiscoverResponse>();diff --git a/Emby.Server.Implementations/LiveTv/TunerHosts/M3UTunerHost.cs b/Emby.Server.Implementations/LiveTv/TunerHosts/M3UTunerHost.csindex 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.TunerHostsprivate const string ChannelIdPrefix = "m3u_";- protected override async Task<IEnumerable<ChannelInfo>> GetChannelsInternal(TunerHostInfo info, CancellationToken cancellationToken)+ protected override async Task<List<ChannelInfo>> 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<ChannelInfo>().ToList();}public Task<List<LiveTvTunerInfo>> GetTunerInfos(CancellationToken cancellationToken)diff --git a/Emby.Server.Implementations/LiveTv/TunerHosts/M3uParser.cs b/Emby.Server.Implementations/LiveTv/TunerHosts/M3uParser.csindex 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.TunerHostschannel.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<string>();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.TunerHostsreturn name;}- private string GetTunerChannelId(Dictionary<string, string> attributes)- {- var values = new List<string>();-- 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<string, string> ParseExtInf(string line, out string remaining){var dict = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);