Kaynağa Gözat

update m3u channel mapping

Luke Pulverenti 8 yıl önce
ebeveyn
işleme
c33b12ba7d

+ 19 - 6
Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs

@@ -474,17 +474,30 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
 
         public 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));

+ 1 - 6
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)

+ 3 - 3
Emby.Server.Implementations/LiveTv/TunerHosts/BaseTunerHost.cs

@@ -35,10 +35,10 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts
             MediaEncoder = 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>();
 

+ 3 - 2
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.HdHomerun
                 AudioCodec = i.AudioCodec,
                 VideoCodec = i.VideoCodec,
                 ChannelType = ChannelType.TV
-            });
+
+            }).ToList();
         }
 
         private readonly Dictionary<string, DiscoverResponse> _modelCache = new Dictionary<string, DiscoverResponse>();

+ 4 - 2
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<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)

+ 18 - 21
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<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.TunerHosts
             return 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);