update m3u tuners

pull/702/head
Luke Pulverenti 10 years ago
parent dcd0feee6e
commit f4c25b2471

@ -455,7 +455,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV
} }
} }
throw new ApplicationException("Tuner not found."); throw new NotImplementedException();
} }
public Task<List<MediaSourceInfo>> GetRecordingStreamMediaSources(string recordingId, CancellationToken cancellationToken) public Task<List<MediaSourceInfo>> GetRecordingStreamMediaSources(string recordingId, CancellationToken cancellationToken)

@ -39,68 +39,45 @@ namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts
var url = info.Url; var url = info.Url;
var urlHash = url.GetMD5().ToString("N"); var urlHash = url.GetMD5().ToString("N");
int position = 0;
string line; string line;
// Read the file and display it line by line. // Read the file and display it line by line.
var file = new StreamReader(url); var file = new StreamReader(url);
var channels = new List<M3UChannel>(); var channels = new List<M3UChannel>();
string channnelName = null;
string channelNumber = null;
while ((line = file.ReadLine()) != null) while ((line = file.ReadLine()) != null)
{ {
line = line.Trim(); line = line.Trim();
if (!String.IsNullOrWhiteSpace(line)) if (string.IsNullOrWhiteSpace(line))
{ {
if (position == 0 && !line.StartsWith("#EXTM3U")) continue;
{ }
throw new ApplicationException("wrong file");
} if (line.StartsWith("#EXTM3U", StringComparison.OrdinalIgnoreCase))
if (position % 2 == 0) {
{ continue;
if (position != 0) }
{
channels.Last().Path = line; if (line.StartsWith("#EXTINF:", StringComparison.OrdinalIgnoreCase))
} {
else var parts = line.Split(new[] { ':' }, 2).Last().Split(new[] { ',' }, 2);
{ channelNumber = parts[0];
line = line.Replace("#EXTM3U", ""); channnelName = parts[1];
line = line.Trim(); }
var vars = line.Split(' ').ToList(); else if (!string.IsNullOrWhiteSpace(channelNumber))
foreach (var variable in vars) {
{ channels.Add(new M3UChannel
var list = variable.Replace('"', ' ').Split('=');
switch (list[0])
{
case ("id"):
//_id = list[1];
break;
}
}
}
}
else
{ {
if (!line.StartsWith("#EXTINF:")) { throw new ApplicationException("Bad file"); } Name = channnelName,
line = line.Replace("#EXTINF:", ""); Number = channelNumber,
var nameStart = line.LastIndexOf(','); Id = ChannelIdPrefix + urlHash + channelNumber,
line = line.Substring(0, nameStart); Path = line
var vars = line.Split(' ').ToList(); });
vars.RemoveAt(0);
channels.Add(new M3UChannel()); channelNumber = null;
foreach (var variable in vars) channnelName = null;
{
var list = variable.Replace('"', ' ').Split('=');
switch (list[0])
{
case "tvg-id":
channels.Last().Id = ChannelIdPrefix + urlHash + list[1];
channels.Last().Number = list[1];
break;
case "tvg-name":
channels.Last().Name = list[1];
break;
}
}
}
position++;
} }
} }
file.Close(); file.Close();
@ -125,6 +102,35 @@ namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts
} }
protected override async Task<MediaSourceInfo> GetChannelStream(TunerHostInfo info, string channelId, string streamId, CancellationToken cancellationToken) protected override async Task<MediaSourceInfo> GetChannelStream(TunerHostInfo info, string channelId, string streamId, CancellationToken cancellationToken)
{
var sources = await GetChannelStreamMediaSources(info, channelId, cancellationToken).ConfigureAwait(false);
return sources.First();
}
class M3UChannel : ChannelInfo
{
public string Path { get; set; }
public M3UChannel()
{
}
}
public async Task Validate(TunerHostInfo info)
{
if (!File.Exists(info.Url))
{
throw new FileNotFoundException();
}
}
protected override bool IsValidChannelId(string channelId)
{
return channelId.StartsWith(ChannelIdPrefix, StringComparison.OrdinalIgnoreCase);
}
protected override async Task<List<MediaSourceInfo>> GetChannelStreamMediaSources(TunerHostInfo info, string channelId, CancellationToken cancellationToken)
{ {
var urlHash = info.Url.GetMD5().ToString("N"); var urlHash = info.Url.GetMD5().ToString("N");
var prefix = ChannelIdPrefix + urlHash; var prefix = ChannelIdPrefix + urlHash;
@ -133,29 +139,29 @@ namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts
return null; return null;
} }
channelId = channelId.Substring(prefix.Length); //channelId = channelId.Substring(prefix.Length);
var channels = await GetChannels(info, true, cancellationToken).ConfigureAwait(false); var channels = await GetChannels(info, true, cancellationToken).ConfigureAwait(false);
var m3uchannels = channels.Cast<M3UChannel>(); var m3uchannels = channels.Cast<M3UChannel>();
var channel = m3uchannels.FirstOrDefault(c => c.Id == channelId); var channel = m3uchannels.FirstOrDefault(c => string.Equals(c.Id, channelId, StringComparison.OrdinalIgnoreCase));
if (channel != null) if (channel != null)
{ {
var path = channel.Path; var path = channel.Path;
MediaProtocol protocol = MediaProtocol.File; MediaProtocol protocol = MediaProtocol.File;
if (path.StartsWith("http")) if (path.StartsWith("http", StringComparison.OrdinalIgnoreCase))
{ {
protocol = MediaProtocol.Http; protocol = MediaProtocol.Http;
} }
else if (path.StartsWith("rtmp")) else if (path.StartsWith("rtmp", StringComparison.OrdinalIgnoreCase))
{ {
protocol = MediaProtocol.Rtmp; protocol = MediaProtocol.Rtmp;
} }
else if (path.StartsWith("rtsp")) else if (path.StartsWith("rtsp", StringComparison.OrdinalIgnoreCase))
{ {
protocol = MediaProtocol.Rtsp; protocol = MediaProtocol.Rtsp;
} }
return new MediaSourceInfo var mediaSource = new MediaSourceInfo
{ {
Path = channel.Path, Path = channel.Path,
Protocol = protocol, Protocol = protocol,
@ -179,35 +185,10 @@ namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts
RequiresOpening = false, RequiresOpening = false,
RequiresClosing = false RequiresClosing = false
}; };
}
throw new ApplicationException("Host doesnt provide this channel");
}
class M3UChannel : ChannelInfo
{
public string Path { get; set; }
public M3UChannel()
{
}
}
public async Task Validate(TunerHostInfo info) return new List<MediaSourceInfo> { mediaSource };
{
if (!File.Exists(info.Url))
{
throw new FileNotFoundException();
} }
} return new List<MediaSourceInfo> { };
protected override bool IsValidChannelId(string channelId)
{
return channelId.StartsWith(ChannelIdPrefix, StringComparison.OrdinalIgnoreCase);
}
protected override Task<List<MediaSourceInfo>> GetChannelStreamMediaSources(TunerHostInfo info, string channelId, CancellationToken cancellationToken)
{
throw new NotImplementedException();
} }
protected override Task<bool> IsAvailableInternal(TunerHostInfo tuner, string channelId, CancellationToken cancellationToken) protected override Task<bool> IsAvailableInternal(TunerHostInfo tuner, string channelId, CancellationToken cancellationToken)

@ -1,4 +1,4 @@
using System.Reflection; using System.Reflection;
//[assembly: AssemblyVersion("3.0.*")] [assembly: AssemblyVersion("3.0.*")]
[assembly: AssemblyVersion("3.0.5713.4")] //[assembly: AssemblyVersion("3.0.5713.4")]

Loading…
Cancel
Save