From 95ceddb7d9c817f2e9233bd5116e7cb8ee76fc49 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sat, 14 Jan 2017 14:57:08 -0500 Subject: [PATCH] update m3uparser --- .../LiveTv/TunerHosts/M3uParser.cs | 21 +++++++++---------- MediaBrowser.Tests/M3uParserTest.cs | 12 +++++++++++ 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/Emby.Server.Implementations/LiveTv/TunerHosts/M3uParser.cs b/Emby.Server.Implementations/LiveTv/TunerHosts/M3uParser.cs index 5be94b507..06a7a0c2d 100644 --- a/Emby.Server.Implementations/LiveTv/TunerHosts/M3uParser.cs +++ b/Emby.Server.Implementations/LiveTv/TunerHosts/M3uParser.cs @@ -14,6 +14,7 @@ using MediaBrowser.Controller; using MediaBrowser.Controller.IO; using MediaBrowser.Controller.LiveTv; using MediaBrowser.Model.Logging; +using MediaBrowser.Model.Extensions; namespace Emby.Server.Implementations.LiveTv.TunerHosts { @@ -273,20 +274,18 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts var reg = new Regex(@"([a-z0-9\-_]+)=\""([^""]+)\""", RegexOptions.IgnoreCase); var matches = reg.Matches(line); - var minIndex = int.MaxValue; - foreach (Match match in matches) - { - dict[match.Groups[1].Value] = match.Groups[2].Value; - minIndex = Math.Min(minIndex, match.Index); - } - - if (minIndex > 0 && minIndex < line.Length) - { - line = line.Substring(0, minIndex); - } remaining = line; + foreach (Match match in matches) + { + var key = match.Groups[1].Value; + var value = match.Groups[2].Value; + + dict[match.Groups[1].Value] = match.Groups[2].Value; + remaining = remaining.Replace(key + "=\"" + value + "\"", string.Empty, StringComparison.OrdinalIgnoreCase); + } + return dict; } } diff --git a/MediaBrowser.Tests/M3uParserTest.cs b/MediaBrowser.Tests/M3uParserTest.cs index be7708457..3285d0740 100644 --- a/MediaBrowser.Tests/M3uParserTest.cs +++ b/MediaBrowser.Tests/M3uParserTest.cs @@ -52,5 +52,17 @@ namespace MediaBrowser.Tests Assert.AreEqual("Movies!", result[0].Name); Assert.AreEqual("3.2", result[0].Number); } + + [TestMethod] + public void TestFormat4() + { + BaseExtensions.CryptographyProvider = new CryptographyProvider(); + + var result = new M3uParser(new NullLogger(), null, null, null).ParseString("#EXTINF:0 tvg-id=\"abckabclosangeles.path.to\" tvg-logo=\"path.to / channel_logos / abckabclosangeles.png\", ABC KABC Los Angeles\nhttp://mystream", "-", "-"); + Assert.AreEqual(1, result.Count); + + Assert.IsNull(result[0].Number); + Assert.AreEqual("ABC KABC Los Angeles", result[0].Name); + } } }