Browse Source

support additional m3u fields

Luke Pulverenti 9 years ago
parent
commit
fd3c6f7ecc
1 changed files with 22 additions and 9 deletions
  1. 22 9
      MediaBrowser.Server.Implementations/LiveTv/TunerHosts/M3uParser.cs

+ 22 - 9
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.TunerHosts
             string 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.TunerHosts
                     line = 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.TunerHosts
                         Name = 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()
-        {
-        }
     }
-}
+}