From 05db0cde889c9f42f5b001f314aeb135e26f9284 Mon Sep 17 00:00:00 2001 From: Jose Alacan Date: Mon, 22 Feb 2016 19:48:30 -0500 Subject: [PATCH 1/2] Update M3U Parser Update parser to get correct info for SatIp M3U playlist. --- .../LiveTv/TunerHosts/M3uParser.cs | 63 ++++++++++++------- 1 file changed, 39 insertions(+), 24 deletions(-) diff --git a/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/M3uParser.cs b/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/M3uParser.cs index 9ec5809a9..ccca6a7fe 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/M3uParser.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/M3uParser.cs @@ -48,12 +48,9 @@ namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts private List GetChannels(StreamReader reader, string urlHash, string channelIdPrefix) { var channels = new List(); - - string channnelName = null; - string channelNumber = null; string line; - string imageUrl = null; - while ((line = reader.ReadLine()) != null) + string extInf = ""; + while ((line = reader.ReadLine()) != null) { line = line.Trim(); if (string.IsNullOrWhiteSpace(line)) @@ -68,30 +65,48 @@ namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts if (line.StartsWith("#EXTINF:", StringComparison.OrdinalIgnoreCase)) { - line = line.Substring(8); - _logger.Info("Found m3u channel: {0}", line); - var parts = line.Split(new[] { ',' }, 2); - channelNumber = parts[0].Trim().Split(' ')[0] ?? "0"; - channnelName = FindProperty("tvg-name", line, parts[1]); - imageUrl = FindProperty("tvg-logo", line, null); + extInf = line.Substring(8).Trim(); + _logger.Info("Found m3u channel: {0}", extInf); } - else if (!string.IsNullOrWhiteSpace(channelNumber)) - { - channels.Add(new M3UChannel - { - Name = channnelName, - Number = channelNumber, - Id = channelIdPrefix + urlHash + line.GetMD5().ToString("N"), - ImageUrl = imageUrl - }); - - imageUrl = null; - channelNumber = null; - channnelName = null; + else if (!string.IsNullOrWhiteSpace(extInf)) + { + var channel = GetChannelnfo(extInf); + channel.Id = line; + channels.Add(channel); + extInf = ""; } } return channels; } + public M3UChannel GetChannelnfo(string extInf) + { + var titleIndex = extInf.LastIndexOf(','); + var channel = new M3UChannel(); + + channel.Number = extInf.Trim().Split(' ')[0] ?? "0"; + channel.Name = extInf.Substring(titleIndex + 1); + + if(channel.Number == "-1") { channel.Number = "0"; } + + //Check for channel number with the format from SatIp + int number; + var numberIndex = channel.Name.IndexOf('.'); + if (numberIndex > 0) + { + if (int.TryParse(channel.Name.Substring(0, numberIndex), out number)) + { + channel.Number = number.ToString(); + channel.Name = channel.Name.Substring(numberIndex + 1); + } + } + channel.ImageUrl = FindProperty("tvg-logo", extInf, null); + channel.Number = FindProperty("tvg-id", extInf, channel.Number); + channel.Number = FindProperty("channel-id", extInf, channel.Number); + channel.Name = FindProperty("tvg-name", extInf, channel.Name); + channel.Name = FindProperty("tvg-id", extInf, channel.Name); + return channel; + + } public string FindProperty(string property, string properties, string defaultResult = "") { var reg = new Regex(@"([a-z0-9\-_]+)=\""([^""]+)\""", RegexOptions.IgnoreCase); From caaa10e2d6d01cc5d086e1848e17ec8022ad6fd5 Mon Sep 17 00:00:00 2001 From: Jose Alacan Date: Mon, 22 Feb 2016 20:09:08 -0500 Subject: [PATCH 2/2] Make to work with current channel id values --- .../LiveTv/TunerHosts/M3uParser.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/M3uParser.cs b/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/M3uParser.cs index ccca6a7fe..51c35caf4 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/M3uParser.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/M3uParser.cs @@ -71,7 +71,8 @@ namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts else if (!string.IsNullOrWhiteSpace(extInf)) { var channel = GetChannelnfo(extInf); - channel.Id = line; + channel.Id = channelIdPrefix + urlHash + line.GetMD5().ToString("N"); + channel.Path = line; channels.Add(channel); extInf = ""; }