aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Pulverenti <luke.pulverenti@gmail.com>2016-02-21 12:22:13 -0500
committerLuke Pulverenti <luke.pulverenti@gmail.com>2016-02-21 12:22:13 -0500
commitfd3c6f7eccec2c10cdbadedc979042949b58f9a7 (patch)
treeb8536c246bcc213479124110334629ff5d35ef4d
parentad8b43cc3d04ce17139976ec91a45f4a2004a0c3 (diff)
support additional m3u fields
-rw-r--r--MediaBrowser.Server.Implementations/LiveTv/TunerHosts/M3uParser.cs31
1 files changed, 22 insertions, 9 deletions
diff --git a/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/M3uParser.cs b/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/M3uParser.cs
index 8f5a4a095..9ec5809a9 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.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()
- {
- }
}
-}
+} \ No newline at end of file