|
|
@ -105,7 +105,6 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
|
|
|
|
private class HdHomerunChannelInfo : ChannelInfo
|
|
|
|
private class HdHomerunChannelInfo : ChannelInfo
|
|
|
|
{
|
|
|
|
{
|
|
|
|
public bool IsLegacyTuner { get; set; }
|
|
|
|
public bool IsLegacyTuner { get; set; }
|
|
|
|
public string Url { get; set; }
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override async Task<List<ChannelInfo>> GetChannelsInternal(TunerHostInfo info, CancellationToken cancellationToken)
|
|
|
|
protected override async Task<List<ChannelInfo>> GetChannelsInternal(TunerHostInfo info, CancellationToken cancellationToken)
|
|
|
@ -124,7 +123,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
|
|
|
|
VideoCodec = i.VideoCodec,
|
|
|
|
VideoCodec = i.VideoCodec,
|
|
|
|
ChannelType = ChannelType.TV,
|
|
|
|
ChannelType = ChannelType.TV,
|
|
|
|
IsLegacyTuner = (i.URL ?? string.Empty).StartsWith("hdhomerun", StringComparison.OrdinalIgnoreCase),
|
|
|
|
IsLegacyTuner = (i.URL ?? string.Empty).StartsWith("hdhomerun", StringComparison.OrdinalIgnoreCase),
|
|
|
|
Url = i.URL
|
|
|
|
Path = i.URL
|
|
|
|
|
|
|
|
|
|
|
|
}).Cast<ChannelInfo>().ToList();
|
|
|
|
}).Cast<ChannelInfo>().ToList();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -148,7 +147,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
|
|
|
|
{
|
|
|
|
{
|
|
|
|
using (var response = await _httpClient.SendAsync(new HttpRequestOptions()
|
|
|
|
using (var response = await _httpClient.SendAsync(new HttpRequestOptions()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Url = string.Format("{0}/discover.json", GetApiUrl(info, false)),
|
|
|
|
Url = string.Format("{0}/discover.json", GetApiUrl(info)),
|
|
|
|
CancellationToken = cancellationToken,
|
|
|
|
CancellationToken = cancellationToken,
|
|
|
|
TimeoutMs = Convert.ToInt32(TimeSpan.FromSeconds(5).TotalMilliseconds),
|
|
|
|
TimeoutMs = Convert.ToInt32(TimeSpan.FromSeconds(5).TotalMilliseconds),
|
|
|
|
BufferContent = false
|
|
|
|
BufferContent = false
|
|
|
@ -195,13 +194,80 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private async Task<List<LiveTvTunerInfo>> GetTunerInfos(TunerHostInfo info, CancellationToken cancellationToken)
|
|
|
|
private async Task<List<LiveTvTunerInfo>> GetTunerInfosHttp(TunerHostInfo info, CancellationToken cancellationToken)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var model = await GetModelInfo(info, false, cancellationToken).ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using (var stream = await _httpClient.Get(new HttpRequestOptions()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Url = string.Format("{0}/tuners.html", GetApiUrl(info)),
|
|
|
|
|
|
|
|
CancellationToken = cancellationToken,
|
|
|
|
|
|
|
|
TimeoutMs = Convert.ToInt32(TimeSpan.FromSeconds(5).TotalMilliseconds),
|
|
|
|
|
|
|
|
BufferContent = false
|
|
|
|
|
|
|
|
}))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var tuners = new List<LiveTvTunerInfo>();
|
|
|
|
|
|
|
|
using (var sr = new StreamReader(stream, System.Text.Encoding.UTF8))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
while (!sr.EndOfStream)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
string line = StripXML(sr.ReadLine());
|
|
|
|
|
|
|
|
if (line.Contains("Channel"))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
LiveTvTunerStatus status;
|
|
|
|
|
|
|
|
var index = line.IndexOf("Channel", StringComparison.OrdinalIgnoreCase);
|
|
|
|
|
|
|
|
var name = line.Substring(0, index - 1);
|
|
|
|
|
|
|
|
var currentChannel = line.Substring(index + 7);
|
|
|
|
|
|
|
|
if (currentChannel != "none") { status = LiveTvTunerStatus.LiveTv; } else { status = LiveTvTunerStatus.Available; }
|
|
|
|
|
|
|
|
tuners.Add(new LiveTvTunerInfo
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Name = name,
|
|
|
|
|
|
|
|
SourceType = string.IsNullOrWhiteSpace(model.ModelNumber) ? Name : model.ModelNumber,
|
|
|
|
|
|
|
|
ProgramName = currentChannel,
|
|
|
|
|
|
|
|
Status = status
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return tuners;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static string StripXML(string source)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
char[] buffer = new char[source.Length];
|
|
|
|
|
|
|
|
int bufferIndex = 0;
|
|
|
|
|
|
|
|
bool inside = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < source.Length; i++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
char let = source[i];
|
|
|
|
|
|
|
|
if (let == '<')
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
inside = true;
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (let == '>')
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
inside = false;
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!inside)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
buffer[bufferIndex] = let;
|
|
|
|
|
|
|
|
bufferIndex++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return new string(buffer, 0, bufferIndex);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private async Task<List<LiveTvTunerInfo>> GetTunerInfosUdp(TunerHostInfo info, CancellationToken cancellationToken)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var model = await GetModelInfo(info, false, cancellationToken).ConfigureAwait(false);
|
|
|
|
var model = await GetModelInfo(info, false, cancellationToken).ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
|
|
var tuners = new List<LiveTvTunerInfo>();
|
|
|
|
var tuners = new List<LiveTvTunerInfo>();
|
|
|
|
|
|
|
|
|
|
|
|
var uri = new Uri(GetApiUrl(info, false));
|
|
|
|
var uri = new Uri(GetApiUrl(info));
|
|
|
|
|
|
|
|
|
|
|
|
using (var manager = new HdHomerunManager(_socketFactory, Logger))
|
|
|
|
using (var manager = new HdHomerunManager(_socketFactory, Logger))
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -246,7 +312,22 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
|
|
|
|
return list;
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private string GetApiUrl(TunerHostInfo info, bool isPlayback)
|
|
|
|
public async Task<List<LiveTvTunerInfo>> GetTunerInfos(TunerHostInfo info, CancellationToken cancellationToken)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// TODO Need faster way to determine UDP vs HTTP
|
|
|
|
|
|
|
|
var channels = await GetChannels(info, true, cancellationToken);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var hdHomerunChannelInfo = channels.FirstOrDefault() as HdHomerunChannelInfo;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (hdHomerunChannelInfo == null || hdHomerunChannelInfo.IsLegacyTuner)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return await GetTunerInfosUdp(info, cancellationToken).ConfigureAwait(false);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return await GetTunerInfosHttp(info, cancellationToken).ConfigureAwait(false);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private string GetApiUrl(TunerHostInfo info)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var url = info.Url;
|
|
|
|
var url = info.Url;
|
|
|
|
|
|
|
|
|
|
|
@ -260,16 +341,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
|
|
|
|
url = "http://" + url;
|
|
|
|
url = "http://" + url;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var uri = new Uri(url);
|
|
|
|
return new Uri(url).AbsoluteUri.TrimEnd('/');
|
|
|
|
|
|
|
|
|
|
|
|
if (isPlayback)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var builder = new UriBuilder(uri);
|
|
|
|
|
|
|
|
builder.Port = 5004;
|
|
|
|
|
|
|
|
uri = builder.Uri;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return uri.AbsoluteUri.TrimEnd('/');
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private class Channels
|
|
|
|
private class Channels
|
|
|
@ -392,7 +464,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
|
|
|
|
nal = "0";
|
|
|
|
nal = "0";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var url = GetApiUrl(info, false);
|
|
|
|
var url = GetApiUrl(info);
|
|
|
|
|
|
|
|
|
|
|
|
var id = profile;
|
|
|
|
var id = profile;
|
|
|
|
if (string.IsNullOrWhiteSpace(id))
|
|
|
|
if (string.IsNullOrWhiteSpace(id))
|
|
|
@ -526,7 +598,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
|
|
|
|
|
|
|
|
|
|
|
|
if (hdhomerunChannel != null && hdhomerunChannel.IsLegacyTuner)
|
|
|
|
if (hdhomerunChannel != null && hdhomerunChannel.IsLegacyTuner)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return new HdHomerunUdpStream(mediaSource, streamId, new LegacyHdHomerunChannelCommands(hdhomerunChannel.Url), modelInfo.TunerCount, FileSystem, _httpClient, Logger, Config.ApplicationPaths, _appHost, _socketFactory, _networkManager, _environment);
|
|
|
|
return new HdHomerunUdpStream(mediaSource, streamId, new LegacyHdHomerunChannelCommands(hdhomerunChannel.Path), modelInfo.TunerCount, FileSystem, _httpClient, Logger, Config.ApplicationPaths, _appHost, _socketFactory, _networkManager, _environment);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// The UDP method is not working reliably on OSX, and on BSD it hasn't been tested yet
|
|
|
|
// The UDP method is not working reliably on OSX, and on BSD it hasn't been tested yet
|
|
|
@ -537,7 +609,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
|
|
|
|
{
|
|
|
|
{
|
|
|
|
mediaSource.Protocol = MediaProtocol.Http;
|
|
|
|
mediaSource.Protocol = MediaProtocol.Http;
|
|
|
|
|
|
|
|
|
|
|
|
var httpUrl = GetApiUrl(info, true) + "/auto/v" + hdhrId;
|
|
|
|
var httpUrl = channelInfo.Path;
|
|
|
|
|
|
|
|
|
|
|
|
// If raw was used, the tuner doesn't support params
|
|
|
|
// If raw was used, the tuner doesn't support params
|
|
|
|
if (!string.IsNullOrWhiteSpace(profile) && !string.Equals(profile, "native", StringComparison.OrdinalIgnoreCase))
|
|
|
|
if (!string.IsNullOrWhiteSpace(profile) && !string.Equals(profile, "native", StringComparison.OrdinalIgnoreCase))
|
|
|
|