diff --git a/Emby.Server.Implementations/LiveTv/TunerHosts/M3uParser.cs b/Emby.Server.Implementations/LiveTv/TunerHosts/M3uParser.cs index e0f040281..9351922a4 100644 --- a/Emby.Server.Implementations/LiveTv/TunerHosts/M3uParser.cs +++ b/Emby.Server.Implementations/LiveTv/TunerHosts/M3uParser.cs @@ -43,6 +43,17 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts } } + public List ParseString(string text, string channelIdPrefix, string tunerHostId) + { + var urlHash = "text".GetMD5().ToString("N"); + + // Read the file and display it line by line. + using (var reader = new StringReader(text)) + { + return GetChannels(reader, urlHash, channelIdPrefix, tunerHostId); + } + } + public Task GetListingsStream(string url, CancellationToken cancellationToken) { if (url.StartsWith("http", StringComparison.OrdinalIgnoreCase)) @@ -59,7 +70,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts } const string ExtInfPrefix = "#EXTINF:"; - private List GetChannels(StreamReader reader, string urlHash, string channelIdPrefix, string tunerHostId) + private List GetChannels(TextReader reader, string urlHash, string channelIdPrefix, string tunerHostId) { var channels = new List(); string line; @@ -122,16 +133,17 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts var nameParts = extInf.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); var nameInExtInf = nameParts.Length > 1 ? nameParts.Last().Trim() : null; - var numberString = nameParts[0]; + string numberString = null; //Check for channel number with the format from SatIp - int number; + // #EXTINF:0,84. VOX Schweiz if (!string.IsNullOrWhiteSpace(nameInExtInf)) { var numberIndex = nameInExtInf.IndexOf('.'); if (numberIndex > 0) { - if (int.TryParse(nameInExtInf.Substring(0, numberIndex), out number)) + double number; + if (double.TryParse(nameInExtInf.Substring(0, numberIndex), NumberStyles.AllowCurrencySymbol, CultureInfo.InvariantCulture, out number)) { numberString = number.ToString(); } @@ -150,7 +162,11 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts string value; if (attributes.TryGetValue("tvg-id", out value)) { - numberString = value; + double doubleValue; + if (double.TryParse(value, NumberStyles.AllowCurrencySymbol, CultureInfo.InvariantCulture, out doubleValue)) + { + numberString = value; + } } } @@ -209,16 +225,16 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts var nameInExtInf = nameParts.Length > 1 ? nameParts.Last().Trim() : null; //Check for channel number with the format from SatIp - int number; if (!string.IsNullOrWhiteSpace(nameInExtInf)) { var numberIndex = nameInExtInf.IndexOf('.'); if (numberIndex > 0) { - if (int.TryParse(nameInExtInf.Substring(0, numberIndex), out number)) + double number; + if (double.TryParse(nameInExtInf.Substring(0, numberIndex), NumberStyles.AllowCurrencySymbol, CultureInfo.InvariantCulture, out number)) { //channel.Number = number.ToString(); - nameInExtInf = nameInExtInf.Substring(numberIndex + 1); + nameInExtInf = nameInExtInf.Substring(numberIndex + 1).Trim(); } } } diff --git a/MediaBrowser.Tests/M3uParserTest.cs b/MediaBrowser.Tests/M3uParserTest.cs new file mode 100644 index 000000000..a6f4c3bd8 --- /dev/null +++ b/MediaBrowser.Tests/M3uParserTest.cs @@ -0,0 +1,44 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Emby.Common.Implementations.Cryptography; +using Emby.Server.Implementations.LiveTv.TunerHosts; +using MediaBrowser.Common.Extensions; +using MediaBrowser.Model.Logging; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace MediaBrowser.Tests +{ + [TestClass] + public class M3uParserTest + { + [TestMethod] + public void TestFormat1() + { + BaseExtensions.CryptographyProvider = new CryptographyProvider(); + + var result = new M3uParser(new NullLogger(), null, null, null).ParseString("#EXTINF:0,84. VOX Schweiz\nhttp://mystream", "-", "-"); + Assert.AreEqual(1, result.Count); + + Assert.AreEqual("VOX Schweiz", result[0].Name); + Assert.AreEqual("84", result[0].Number); + } + [TestMethod] + public void TestFormat2() + { + BaseExtensions.CryptographyProvider = new CryptographyProvider(); + + var input = "#EXTINF:-1 tvg-id=\"\" tvg-name=\"ABC News 04\" tvg-logo=\"\" group-title=\"ABC Group\",ABC News 04"; + input += "\n"; + input += "http://mystream"; + + var result = new M3uParser(new NullLogger(), null, null, null).ParseString(input, "-", "-"); + Assert.AreEqual(1, result.Count); + + Assert.AreEqual("ABC News 04", result[0].Name); + Assert.IsNull(result[0].Number); + } + } +} diff --git a/MediaBrowser.Tests/MediaBrowser.Tests.csproj b/MediaBrowser.Tests/MediaBrowser.Tests.csproj index 4ea2cb0c0..8ba828d85 100644 --- a/MediaBrowser.Tests/MediaBrowser.Tests.csproj +++ b/MediaBrowser.Tests/MediaBrowser.Tests.csproj @@ -37,6 +37,9 @@ 4 + + ..\ThirdParty\emby\Emby.Common.Implementations.dll + @@ -58,12 +61,21 @@ + + + {e383961b-9356-4d5d-8233-9a1079d03055} + Emby.Server.Implementations + + + {9142eefa-7570-41e1-bfcc-468bb571af2f} + MediaBrowser.Common + {17e1f4e6-8abd-4fe5-9ecf-43d4b6087ba2} MediaBrowser.Controller