The Free Software Media System - Server Backend & API
support additional m3u fields
Luke Pulverentifd3c6f7eccec
diff --git a/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/M3uParser.cs b/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/M3uParser.csindex 8f5a4a0951..9ec5809a9e 100644--- a/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/M3uParser.cs+++ b/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/M3uParser.cs@@ -1,6 +1,7 @@using System;using System.Collections.Generic;using System.IO;+using System.Text.RegularExpressions;using System.Threading;using System.Threading.Tasks;using CommonIO;@@ -51,7 +52,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.TunerHostsstring channnelName = null;string channelNumber = null;string line;-+ string imageUrl = null;while ((line = reader.ReadLine()) != null){line = line.Trim();@@ -70,8 +71,9 @@ namespace MediaBrowser.Server.Implementations.LiveTv.TunerHostsline = line.Substring(8);_logger.Info("Found m3u channel: {0}", line);var parts = line.Split(new[] { ',' }, 2);- channelNumber = parts[0];- channnelName = parts[1];+ channelNumber = parts[0].Trim().Split(' ')[0] ?? "0";+ channnelName = FindProperty("tvg-name", line, parts[1]);+ imageUrl = FindProperty("tvg-logo", line, null);}else if (!string.IsNullOrWhiteSpace(channelNumber)){@@ -80,23 +82,34 @@ namespace MediaBrowser.Server.Implementations.LiveTv.TunerHostsName = channnelName,Number = channelNumber,Id = channelIdPrefix + urlHash + line.GetMD5().ToString("N"),- Path = line+ ImageUrl = imageUrl});+ imageUrl = null;channelNumber = null;channnelName = null;}}return channels;}+ public string FindProperty(string property, string properties, string defaultResult = "")+ {+ var reg = new Regex(@"([a-z0-9\-_]+)=\""([^""]+)\""", RegexOptions.IgnoreCase);+ var matches = reg.Matches(properties);+ foreach (Match match in matches)+ {+ if (match.Groups[1].Value == property)+ {+ return match.Groups[2].Value;+ }+ }+ return defaultResult;+ }}+public class M3UChannel : ChannelInfo{public string Path { get; set; }-- public M3UChannel()- {- }}-}+}\ No newline at end of file