Skip to content

Commit fe15e99

Browse files
Merge branch 'dev' of https://github.com/MediaBrowser/Emby into dev
2 parents b1d410c + 1c50660 commit fe15e99

File tree

1 file changed

+40
-24
lines changed
  • MediaBrowser.Server.Implementations/LiveTv/TunerHosts

1 file changed

+40
-24
lines changed

MediaBrowser.Server.Implementations/LiveTv/TunerHosts/M3uParser.cs

+40-24
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,9 @@ public Task<Stream> GetListingsStream(string url, CancellationToken cancellation
4848
private List<M3UChannel> GetChannels(StreamReader reader, string urlHash, string channelIdPrefix)
4949
{
5050
var channels = new List<M3UChannel>();
51-
52-
string channnelName = null;
53-
string channelNumber = null;
5451
string line;
55-
string imageUrl = null;
56-
while ((line = reader.ReadLine()) != null)
52+
string extInf = "";
53+
while ((line = reader.ReadLine()) != null)
5754
{
5855
line = line.Trim();
5956
if (string.IsNullOrWhiteSpace(line))
@@ -68,30 +65,49 @@ private List<M3UChannel> GetChannels(StreamReader reader, string urlHash, string
6865

6966
if (line.StartsWith("#EXTINF:", StringComparison.OrdinalIgnoreCase))
7067
{
71-
line = line.Substring(8);
72-
_logger.Info("Found m3u channel: {0}", line);
73-
var parts = line.Split(new[] { ',' }, 2);
74-
channelNumber = parts[0].Trim().Split(' ')[0] ?? "0";
75-
channnelName = FindProperty("tvg-name", line, parts[1]);
76-
imageUrl = FindProperty("tvg-logo", line, null);
68+
extInf = line.Substring(8).Trim();
69+
_logger.Info("Found m3u channel: {0}", extInf);
7770
}
78-
else if (!string.IsNullOrWhiteSpace(channelNumber))
79-
{
80-
channels.Add(new M3UChannel
81-
{
82-
Name = channnelName,
83-
Number = channelNumber,
84-
Id = channelIdPrefix + urlHash + line.GetMD5().ToString("N"),
85-
ImageUrl = imageUrl
86-
});
87-
88-
imageUrl = null;
89-
channelNumber = null;
90-
channnelName = null;
71+
else if (!string.IsNullOrWhiteSpace(extInf))
72+
{
73+
var channel = GetChannelnfo(extInf);
74+
channel.Id = channelIdPrefix + urlHash + line.GetMD5().ToString("N");
75+
channel.Path = line;
76+
channels.Add(channel);
77+
extInf = "";
9178
}
9279
}
9380
return channels;
9481
}
82+
public M3UChannel GetChannelnfo(string extInf)
83+
{
84+
var titleIndex = extInf.LastIndexOf(',');
85+
var channel = new M3UChannel();
86+
87+
channel.Number = extInf.Trim().Split(' ')[0] ?? "0";
88+
channel.Name = extInf.Substring(titleIndex + 1);
89+
90+
if(channel.Number == "-1") { channel.Number = "0"; }
91+
92+
//Check for channel number with the format from SatIp
93+
int number;
94+
var numberIndex = channel.Name.IndexOf('.');
95+
if (numberIndex > 0)
96+
{
97+
if (int.TryParse(channel.Name.Substring(0, numberIndex), out number))
98+
{
99+
channel.Number = number.ToString();
100+
channel.Name = channel.Name.Substring(numberIndex + 1);
101+
}
102+
}
103+
channel.ImageUrl = FindProperty("tvg-logo", extInf, null);
104+
channel.Number = FindProperty("tvg-id", extInf, channel.Number);
105+
channel.Number = FindProperty("channel-id", extInf, channel.Number);
106+
channel.Name = FindProperty("tvg-name", extInf, channel.Name);
107+
channel.Name = FindProperty("tvg-id", extInf, channel.Name);
108+
return channel;
109+
110+
}
95111
public string FindProperty(string property, string properties, string defaultResult = "")
96112
{
97113
var reg = new Regex(@"([a-z0-9\-_]+)=\""([^""]+)\""", RegexOptions.IgnoreCase);

0 commit comments

Comments
 (0)