mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-07-09 03:04:24 -04:00
migrate to IHttpClientFactory in HdHomerunHost
This commit is contained in:
parent
97cc3d54bb
commit
96fdee38cb
@ -31,7 +31,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
|
|||||||
{
|
{
|
||||||
public class HdHomerunHost : BaseTunerHost, ITunerHost, IConfigurableTunerHost
|
public class HdHomerunHost : BaseTunerHost, ITunerHost, IConfigurableTunerHost
|
||||||
{
|
{
|
||||||
private readonly IHttpClient _httpClient;
|
private readonly IHttpClientFactory _httpClientFactory;
|
||||||
private readonly IServerApplicationHost _appHost;
|
private readonly IServerApplicationHost _appHost;
|
||||||
private readonly ISocketFactory _socketFactory;
|
private readonly ISocketFactory _socketFactory;
|
||||||
private readonly INetworkManager _networkManager;
|
private readonly INetworkManager _networkManager;
|
||||||
@ -43,7 +43,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
|
|||||||
IServerConfigurationManager config,
|
IServerConfigurationManager config,
|
||||||
ILogger<HdHomerunHost> logger,
|
ILogger<HdHomerunHost> logger,
|
||||||
IFileSystem fileSystem,
|
IFileSystem fileSystem,
|
||||||
IHttpClient httpClient,
|
IHttpClientFactory httpClientFactory,
|
||||||
IServerApplicationHost appHost,
|
IServerApplicationHost appHost,
|
||||||
ISocketFactory socketFactory,
|
ISocketFactory socketFactory,
|
||||||
INetworkManager networkManager,
|
INetworkManager networkManager,
|
||||||
@ -51,7 +51,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
|
|||||||
IMemoryCache memoryCache)
|
IMemoryCache memoryCache)
|
||||||
: base(config, logger, fileSystem, memoryCache)
|
: base(config, logger, fileSystem, memoryCache)
|
||||||
{
|
{
|
||||||
_httpClient = httpClient;
|
_httpClientFactory = httpClientFactory;
|
||||||
_appHost = appHost;
|
_appHost = appHost;
|
||||||
_socketFactory = socketFactory;
|
_socketFactory = socketFactory;
|
||||||
_networkManager = networkManager;
|
_networkManager = networkManager;
|
||||||
@ -78,8 +78,8 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
|
|||||||
BufferContent = false
|
BufferContent = false
|
||||||
};
|
};
|
||||||
|
|
||||||
using var response = await _httpClient.SendAsync(options, HttpMethod.Get).ConfigureAwait(false);
|
using var response = await _httpClientFactory.CreateClient(NamedClient.Default).GetAsync(model.LineupURL, cancellationToken).ConfigureAwait(false);
|
||||||
await using var stream = response.Content;
|
await using var stream = await response.Content.ReadAsStreamAsync();
|
||||||
var lineup = await JsonSerializer.DeserializeAsync<List<Channels>>(stream, cancellationToken: cancellationToken)
|
var lineup = await JsonSerializer.DeserializeAsync<List<Channels>>(stream, cancellationToken: cancellationToken)
|
||||||
.ConfigureAwait(false) ?? new List<Channels>();
|
.ConfigureAwait(false) ?? new List<Channels>();
|
||||||
|
|
||||||
@ -133,14 +133,10 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using var response = await _httpClient.SendAsync(
|
using var response = await _httpClientFactory.CreateClient(NamedClient.Default)
|
||||||
new HttpRequestOptions
|
.GetAsync(string.Format(CultureInfo.InvariantCulture, "{0}/discover.json", GetApiUrl(info)), cancellationToken)
|
||||||
{
|
.ConfigureAwait(false);
|
||||||
Url = string.Format(CultureInfo.InvariantCulture, "{0}/discover.json", GetApiUrl(info)),
|
await using var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
|
||||||
CancellationToken = cancellationToken,
|
|
||||||
BufferContent = false
|
|
||||||
}, HttpMethod.Get).ConfigureAwait(false);
|
|
||||||
await using var stream = response.Content;
|
|
||||||
var discoverResponse = await JsonSerializer.DeserializeAsync<DiscoverResponse>(stream, cancellationToken: cancellationToken)
|
var discoverResponse = await JsonSerializer.DeserializeAsync<DiscoverResponse>(stream, cancellationToken: cancellationToken)
|
||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
|
|
||||||
@ -183,48 +179,41 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
|
|||||||
{
|
{
|
||||||
var model = await GetModelInfo(info, false, cancellationToken).ConfigureAwait(false);
|
var model = await GetModelInfo(info, false, cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
using (var response = await _httpClient.SendAsync(
|
using var response = await _httpClientFactory.CreateClient(NamedClient.Default)
|
||||||
new HttpRequestOptions()
|
.GetAsync(string.Format(CultureInfo.InvariantCulture, "{0}/tuners.html", GetApiUrl(info)), cancellationToken)
|
||||||
{
|
.ConfigureAwait(false);
|
||||||
Url = string.Format(CultureInfo.InvariantCulture, "{0}/tuners.html", GetApiUrl(info)),
|
await using var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
|
||||||
CancellationToken = cancellationToken,
|
using var sr = new StreamReader(stream, System.Text.Encoding.UTF8);
|
||||||
BufferContent = false
|
var tuners = new List<LiveTvTunerInfo>();
|
||||||
},
|
while (!sr.EndOfStream)
|
||||||
HttpMethod.Get).ConfigureAwait(false))
|
|
||||||
using (var stream = response.Content)
|
|
||||||
using (var sr = new StreamReader(stream, System.Text.Encoding.UTF8))
|
|
||||||
{
|
{
|
||||||
var tuners = new List<LiveTvTunerInfo>();
|
string line = StripXML(sr.ReadLine());
|
||||||
while (!sr.EndOfStream)
|
if (line.Contains("Channel", StringComparison.Ordinal))
|
||||||
{
|
{
|
||||||
string line = StripXML(sr.ReadLine());
|
LiveTvTunerStatus status;
|
||||||
if (line.Contains("Channel", StringComparison.Ordinal))
|
var index = line.IndexOf("Channel", StringComparison.OrdinalIgnoreCase);
|
||||||
|
var name = line.Substring(0, index - 1);
|
||||||
|
var currentChannel = line.Substring(index + 7);
|
||||||
|
if (currentChannel != "none")
|
||||||
{
|
{
|
||||||
LiveTvTunerStatus status;
|
status = LiveTvTunerStatus.LiveTv;
|
||||||
var index = line.IndexOf("Channel", StringComparison.OrdinalIgnoreCase);
|
}
|
||||||
var name = line.Substring(0, index - 1);
|
else
|
||||||
var currentChannel = line.Substring(index + 7);
|
{
|
||||||
if (currentChannel != "none")
|
status = LiveTvTunerStatus.Available;
|
||||||
{
|
|
||||||
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;
|
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)
|
private static string StripXML(string source)
|
||||||
@ -634,7 +623,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
|
|||||||
info,
|
info,
|
||||||
streamId,
|
streamId,
|
||||||
FileSystem,
|
FileSystem,
|
||||||
_httpClient,
|
_httpClientFactory,
|
||||||
Logger,
|
Logger,
|
||||||
Config,
|
Config,
|
||||||
_appHost,
|
_appHost,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user