aboutsummaryrefslogtreecommitdiff
path: root/Emby.Server.Implementations/LiveTv/TunerHosts/M3uParser.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Emby.Server.Implementations/LiveTv/TunerHosts/M3uParser.cs')
-rw-r--r--Emby.Server.Implementations/LiveTv/TunerHosts/M3uParser.cs54
1 files changed, 41 insertions, 13 deletions
diff --git a/Emby.Server.Implementations/LiveTv/TunerHosts/M3uParser.cs b/Emby.Server.Implementations/LiveTv/TunerHosts/M3uParser.cs
index 5e191ada9f..34d0dd8535 100644
--- a/Emby.Server.Implementations/LiveTv/TunerHosts/M3uParser.cs
+++ b/Emby.Server.Implementations/LiveTv/TunerHosts/M3uParser.cs
@@ -76,6 +76,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts
var channels = new List<M3UChannel>();
string line;
string extInf = "";
+
while ((line = reader.ReadLine()) != null)
{
line = line.Trim();
@@ -111,6 +112,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts
extInf = "";
}
}
+
return channels;
}
@@ -134,9 +136,11 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts
channel.Name = GetChannelName(extInf, attributes);
channel.Number = GetChannelNumber(extInf, attributes, mediaUrl);
- if (attributes.TryGetValue("tvg-id", out value))
+ var channelId = GetTunerChannelId(attributes);
+ if (!string.IsNullOrWhiteSpace(channelId))
{
- channel.Id = value;
+ channel.Id = channelId;
+ channel.TunerChannelId = channelId;
}
return channel;
@@ -172,9 +176,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts
numberString = numberString.Trim();
}
- if (string.IsNullOrWhiteSpace(numberString) ||
- string.Equals(numberString, "-1", StringComparison.OrdinalIgnoreCase) ||
- string.Equals(numberString, "0", StringComparison.OrdinalIgnoreCase))
+ if (!IsValidChannelNumber(numberString))
{
string value;
if (attributes.TryGetValue("tvg-id", out value))
@@ -192,9 +194,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts
numberString = numberString.Trim();
}
- if (string.IsNullOrWhiteSpace(numberString) ||
- string.Equals(numberString, "-1", StringComparison.OrdinalIgnoreCase) ||
- string.Equals(numberString, "0", StringComparison.OrdinalIgnoreCase))
+ if (!IsValidChannelNumber(numberString))
{
string value;
if (attributes.TryGetValue("channel-id", out value))
@@ -208,9 +208,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts
numberString = numberString.Trim();
}
- if (string.IsNullOrWhiteSpace(numberString) ||
- string.Equals(numberString, "-1", StringComparison.OrdinalIgnoreCase) ||
- string.Equals(numberString, "0", StringComparison.OrdinalIgnoreCase))
+ if (!IsValidChannelNumber(numberString))
{
numberString = null;
}
@@ -225,8 +223,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts
{
numberString = Path.GetFileNameWithoutExtension(mediaUrl.Split('/').Last());
- double value;
- if (!double.TryParse(numberString, NumberStyles.Any, CultureInfo.InvariantCulture, out value))
+ if (!IsValidChannelNumber(numberString))
{
numberString = null;
}
@@ -236,6 +233,24 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts
return numberString;
}
+ private bool IsValidChannelNumber(string numberString)
+ {
+ if (string.IsNullOrWhiteSpace(numberString) ||
+ string.Equals(numberString, "-1", StringComparison.OrdinalIgnoreCase) ||
+ string.Equals(numberString, "0", StringComparison.OrdinalIgnoreCase))
+ {
+ return false;
+ }
+
+ double value;
+ if (!double.TryParse(numberString, NumberStyles.Any, CultureInfo.InvariantCulture, out value))
+ {
+ return false;
+ }
+
+ return true;
+ }
+
private string GetChannelName(string extInf, Dictionary<string, string> attributes)
{
var nameParts = extInf.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
@@ -281,6 +296,19 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts
return name;
}
+ private string GetTunerChannelId(Dictionary<string, string> attributes)
+ {
+ string result;
+ attributes.TryGetValue("tvg-id", out result);
+
+ if (string.IsNullOrWhiteSpace(result))
+ {
+ attributes.TryGetValue("channel-id", out result);
+ }
+
+ return result;
+ }
+
private Dictionary<string, string> ParseExtInf(string line, out string remaining)
{
var dict = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);