aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Pulverenti <luke.pulverenti@gmail.com>2016-02-06 16:11:23 -0500
committerLuke Pulverenti <luke.pulverenti@gmail.com>2016-02-06 16:11:23 -0500
commitc7684178ce51acc72576346a22c14868996c0df6 (patch)
treec073551a6ba7e6f04ae177003af04a1ae62ee9ad
parentc135bb17f2ab66b2b362d04f11596fec3b70c3ae (diff)
fix m3u tuner host only finding one channel
-rw-r--r--MediaBrowser.Server.Implementations/LiveTv/TunerHosts/M3UTunerHost.cs80
1 files changed, 42 insertions, 38 deletions
diff --git a/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/M3UTunerHost.cs b/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/M3UTunerHost.cs
index ddbbb030d..f87d4f43f 100644
--- a/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/M3UTunerHost.cs
+++ b/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/M3UTunerHost.cs
@@ -46,53 +46,59 @@ namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts
protected override async Task<IEnumerable<ChannelInfo>> GetChannelsInternal(TunerHostInfo info, CancellationToken cancellationToken)
{
- var url = info.Url;
- var urlHash = url.GetMD5().ToString("N");
+ var urlHash = info.Url.GetMD5().ToString("N");
- string line;
// Read the file and display it line by line.
- using (var file = new StreamReader(await GetListingsStream(info, cancellationToken).ConfigureAwait(false)))
+ using (var reader = new StreamReader(await GetListingsStream(info, cancellationToken).ConfigureAwait(false)))
{
- var channels = new List<M3UChannel>();
+ return GetChannels(reader, urlHash);
+ }
+ }
+
+ private List<M3UChannel> GetChannels(StreamReader reader, string urlHash)
+ {
+ var channels = new List<M3UChannel>();
- string channnelName = null;
- string channelNumber = null;
+ string channnelName = null;
+ string channelNumber = null;
+ string line;
- while ((line = file.ReadLine()) != null)
+ while ((line = reader.ReadLine()) != null)
+ {
+ line = line.Trim();
+ if (string.IsNullOrWhiteSpace(line))
{
- line = line.Trim();
- if (string.IsNullOrWhiteSpace(line))
- {
- continue;
- }
+ continue;
+ }
- if (line.StartsWith("#EXTM3U", StringComparison.OrdinalIgnoreCase))
- {
- continue;
- }
+ if (line.StartsWith("#EXTM3U", StringComparison.OrdinalIgnoreCase))
+ {
+ continue;
+ }
- if (line.StartsWith("#EXTINF:", StringComparison.OrdinalIgnoreCase))
- {
- var parts = line.Split(new[] { ':' }, 2).Last().Split(new[] { ',' }, 2);
- channelNumber = parts[0];
- channnelName = parts[1];
- }
- else if (!string.IsNullOrWhiteSpace(channelNumber))
+ if (line.StartsWith("#EXTINF:", StringComparison.OrdinalIgnoreCase))
+ {
+ line = line.Substring(8);
+ Logger.Info("Found m3u channel: {0}", line);
+ var parts = line.Split(new[] { ',' }, 2);
+ channelNumber = parts[0];
+ channnelName = parts[1];
+ }
+ else if (!string.IsNullOrWhiteSpace(channelNumber))
+ {
+ channels.Add(new M3UChannel
{
- channels.Add(new M3UChannel
- {
- Name = channnelName,
- Number = channelNumber,
- Id = ChannelIdPrefix + urlHash + channelNumber,
- Path = line
- });
-
- channelNumber = null;
- channnelName = null;
- }
+ Name = channnelName,
+ Number = channelNumber,
+ Id = ChannelIdPrefix + urlHash + line.GetMD5().ToString("N"),
+ Path = line
+ });
+
+ channelNumber = null;
+ channnelName = null;
}
- return channels;
}
+ return channels;
}
public Task<List<LiveTvTunerInfo>> GetTunerInfos(CancellationToken cancellationToken)
@@ -159,8 +165,6 @@ namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts
return null;
}
- //channelId = channelId.Substring(prefix.Length);
-
var channels = await GetChannels(info, true, cancellationToken).ConfigureAwait(false);
var m3uchannels = channels.Cast<M3UChannel>();
var channel = m3uchannels.FirstOrDefault(c => string.Equals(c.Id, channelId, StringComparison.OrdinalIgnoreCase));