mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-07-09 03:04:24 -04:00
Merge pull request #10847 from barronpm/schedulesdirect-fix
SchedulesDirect fix
This commit is contained in:
commit
20f05f8103
@ -106,8 +106,7 @@ namespace Jellyfin.LiveTv.Listings
|
|||||||
using var options = new HttpRequestMessage(HttpMethod.Post, ApiUrl + "/schedules");
|
using var options = new HttpRequestMessage(HttpMethod.Post, ApiUrl + "/schedules");
|
||||||
options.Content = JsonContent.Create(requestList, options: _jsonOptions);
|
options.Content = JsonContent.Create(requestList, options: _jsonOptions);
|
||||||
options.Headers.TryAddWithoutValidation("token", token);
|
options.Headers.TryAddWithoutValidation("token", token);
|
||||||
using var response = await Send(options, true, info, cancellationToken).ConfigureAwait(false);
|
var dailySchedules = await Request<IReadOnlyList<DayDto>>(options, true, info, cancellationToken).ConfigureAwait(false);
|
||||||
var dailySchedules = await response.Content.ReadFromJsonAsync<IReadOnlyList<DayDto>>(_jsonOptions, cancellationToken).ConfigureAwait(false);
|
|
||||||
if (dailySchedules is null)
|
if (dailySchedules is null)
|
||||||
{
|
{
|
||||||
return Array.Empty<ProgramInfo>();
|
return Array.Empty<ProgramInfo>();
|
||||||
@ -121,8 +120,8 @@ namespace Jellyfin.LiveTv.Listings
|
|||||||
var programIds = dailySchedules.SelectMany(d => d.Programs.Select(s => s.ProgramId)).Distinct();
|
var programIds = dailySchedules.SelectMany(d => d.Programs.Select(s => s.ProgramId)).Distinct();
|
||||||
programRequestOptions.Content = JsonContent.Create(programIds, options: _jsonOptions);
|
programRequestOptions.Content = JsonContent.Create(programIds, options: _jsonOptions);
|
||||||
|
|
||||||
using var innerResponse = await Send(programRequestOptions, true, info, cancellationToken).ConfigureAwait(false);
|
var programDetails = await Request<IReadOnlyList<ProgramDetailsDto>>(programRequestOptions, true, info, cancellationToken)
|
||||||
var programDetails = await innerResponse.Content.ReadFromJsonAsync<IReadOnlyList<ProgramDetailsDto>>(_jsonOptions, cancellationToken).ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
if (programDetails is null)
|
if (programDetails is null)
|
||||||
{
|
{
|
||||||
return Array.Empty<ProgramInfo>();
|
return Array.Empty<ProgramInfo>();
|
||||||
@ -472,16 +471,13 @@ namespace Jellyfin.LiveTv.Listings
|
|||||||
str.Length--;
|
str.Length--;
|
||||||
str.Append(']');
|
str.Append(']');
|
||||||
|
|
||||||
using var message = new HttpRequestMessage(HttpMethod.Post, ApiUrl + "/metadata/programs")
|
using var message = new HttpRequestMessage(HttpMethod.Post, ApiUrl + "/metadata/programs");
|
||||||
{
|
|
||||||
Content = new StringContent(str.ToString(), Encoding.UTF8, MediaTypeNames.Application.Json)
|
|
||||||
};
|
|
||||||
message.Headers.TryAddWithoutValidation("token", token);
|
message.Headers.TryAddWithoutValidation("token", token);
|
||||||
|
message.Content = new StringContent(str.ToString(), Encoding.UTF8, MediaTypeNames.Application.Json);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using var innerResponse2 = await Send(message, true, info, cancellationToken).ConfigureAwait(false);
|
return await Request<IReadOnlyList<ShowImagesDto>>(message, true, info, cancellationToken).ConfigureAwait(false);
|
||||||
return await innerResponse2.Content.ReadFromJsonAsync<IReadOnlyList<ShowImagesDto>>(_jsonOptions, cancellationToken).ConfigureAwait(false);
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@ -507,8 +503,7 @@ namespace Jellyfin.LiveTv.Listings
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using var httpResponse = await Send(options, false, info, cancellationToken).ConfigureAwait(false);
|
var root = await Request<IReadOnlyList<HeadendsDto>>(options, false, info, cancellationToken).ConfigureAwait(false);
|
||||||
var root = await httpResponse.Content.ReadFromJsonAsync<IReadOnlyList<HeadendsDto>>(_jsonOptions, cancellationToken).ConfigureAwait(false);
|
|
||||||
if (root is not null)
|
if (root is not null)
|
||||||
{
|
{
|
||||||
foreach (HeadendsDto headend in root)
|
foreach (HeadendsDto headend in root)
|
||||||
@ -596,36 +591,42 @@ namespace Jellyfin.LiveTv.Listings
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<HttpResponseMessage> Send(
|
private async Task<T> Request<T>(
|
||||||
HttpRequestMessage options,
|
HttpRequestMessage message,
|
||||||
bool enableRetry,
|
bool enableRetry,
|
||||||
ListingsProviderInfo providerInfo,
|
ListingsProviderInfo providerInfo,
|
||||||
CancellationToken cancellationToken,
|
CancellationToken cancellationToken,
|
||||||
HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead)
|
HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead)
|
||||||
{
|
{
|
||||||
var response = await _httpClientFactory.CreateClient(NamedClient.Default)
|
using var response = await _httpClientFactory.CreateClient(NamedClient.Default)
|
||||||
.SendAsync(options, completionOption, cancellationToken).ConfigureAwait(false);
|
.SendAsync(message, completionOption, cancellationToken)
|
||||||
|
.ConfigureAwait(false);
|
||||||
if (response.IsSuccessStatusCode)
|
if (response.IsSuccessStatusCode)
|
||||||
{
|
{
|
||||||
return response;
|
return await response.Content.ReadFromJsonAsync<T>(_jsonOptions, cancellationToken).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Response is automatically disposed in the calling function,
|
|
||||||
// so dispose manually if not returning.
|
|
||||||
#pragma warning disable IDISP016, IDISP017
|
|
||||||
response.Dispose();
|
|
||||||
if (!enableRetry || (int)response.StatusCode >= 500)
|
if (!enableRetry || (int)response.StatusCode >= 500)
|
||||||
{
|
{
|
||||||
|
_logger.LogError(
|
||||||
|
"Request to {Url} failed with response {Response}",
|
||||||
|
message.RequestUri,
|
||||||
|
await response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false));
|
||||||
|
|
||||||
throw new HttpRequestException(
|
throw new HttpRequestException(
|
||||||
string.Format(CultureInfo.InvariantCulture, "Request failed: {0}", response.ReasonPhrase),
|
string.Format(CultureInfo.InvariantCulture, "Request failed: {0}", response.ReasonPhrase),
|
||||||
null,
|
null,
|
||||||
response.StatusCode);
|
response.StatusCode);
|
||||||
}
|
}
|
||||||
#pragma warning restore IDISP016, IDISP017
|
|
||||||
|
|
||||||
_tokens.Clear();
|
_tokens.Clear();
|
||||||
options.Headers.TryAddWithoutValidation("token", await GetToken(providerInfo, cancellationToken).ConfigureAwait(false));
|
using var retryMessage = new HttpRequestMessage(message.Method, message.RequestUri);
|
||||||
return await Send(options, false, providerInfo, cancellationToken).ConfigureAwait(false);
|
retryMessage.Content = message.Content;
|
||||||
|
retryMessage.Headers.TryAddWithoutValidation(
|
||||||
|
"token",
|
||||||
|
await GetToken(providerInfo, cancellationToken).ConfigureAwait(false));
|
||||||
|
|
||||||
|
return await Request<T>(retryMessage, false, providerInfo, cancellationToken).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<string> GetTokenInternal(
|
private async Task<string> GetTokenInternal(
|
||||||
@ -642,9 +643,7 @@ namespace Jellyfin.LiveTv.Listings
|
|||||||
string hashedPassword = Convert.ToHexString(hashedPasswordBytes).ToLowerInvariant();
|
string hashedPassword = Convert.ToHexString(hashedPasswordBytes).ToLowerInvariant();
|
||||||
options.Content = new StringContent("{\"username\":\"" + username + "\",\"password\":\"" + hashedPassword + "\"}", Encoding.UTF8, MediaTypeNames.Application.Json);
|
options.Content = new StringContent("{\"username\":\"" + username + "\",\"password\":\"" + hashedPassword + "\"}", Encoding.UTF8, MediaTypeNames.Application.Json);
|
||||||
|
|
||||||
using var response = await Send(options, false, null, cancellationToken).ConfigureAwait(false);
|
var root = await Request<TokenDto>(options, false, null, cancellationToken).ConfigureAwait(false);
|
||||||
response.EnsureSuccessStatusCode();
|
|
||||||
var root = await response.Content.ReadFromJsonAsync<TokenDto>(_jsonOptions, cancellationToken).ConfigureAwait(false);
|
|
||||||
if (string.Equals(root?.Message, "OK", StringComparison.Ordinal))
|
if (string.Equals(root?.Message, "OK", StringComparison.Ordinal))
|
||||||
{
|
{
|
||||||
_logger.LogInformation("Authenticated with Schedules Direct token: {Token}", root.Token);
|
_logger.LogInformation("Authenticated with Schedules Direct token: {Token}", root.Token);
|
||||||
@ -661,11 +660,21 @@ namespace Jellyfin.LiveTv.Listings
|
|||||||
ArgumentException.ThrowIfNullOrEmpty(token);
|
ArgumentException.ThrowIfNullOrEmpty(token);
|
||||||
ArgumentException.ThrowIfNullOrEmpty(info.ListingsId);
|
ArgumentException.ThrowIfNullOrEmpty(info.ListingsId);
|
||||||
|
|
||||||
_logger.LogInformation("Adding new LineUp ");
|
_logger.LogInformation("Adding new lineup {Id}", info.ListingsId);
|
||||||
|
|
||||||
using var options = new HttpRequestMessage(HttpMethod.Put, ApiUrl + "/lineups/" + info.ListingsId);
|
using var message = new HttpRequestMessage(HttpMethod.Put, ApiUrl + "/lineups/" + info.ListingsId);
|
||||||
options.Headers.TryAddWithoutValidation("token", token);
|
message.Headers.TryAddWithoutValidation("token", token);
|
||||||
using var response = await _httpClientFactory.CreateClient(NamedClient.Default).SendAsync(options, HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false);
|
|
||||||
|
using var response = await _httpClientFactory.CreateClient(NamedClient.Default)
|
||||||
|
.SendAsync(message, HttpCompletionOption.ResponseHeadersRead, cancellationToken)
|
||||||
|
.ConfigureAwait(false);
|
||||||
|
|
||||||
|
if (!response.IsSuccessStatusCode)
|
||||||
|
{
|
||||||
|
_logger.LogError(
|
||||||
|
"Error adding lineup to account: {Response}",
|
||||||
|
await response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<bool> HasLineup(ListingsProviderInfo info, CancellationToken cancellationToken)
|
private async Task<bool> HasLineup(ListingsProviderInfo info, CancellationToken cancellationToken)
|
||||||
@ -683,9 +692,7 @@ namespace Jellyfin.LiveTv.Listings
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using var httpResponse = await Send(options, false, null, cancellationToken).ConfigureAwait(false);
|
var root = await Request<LineupsDto>(options, false, null, cancellationToken).ConfigureAwait(false);
|
||||||
httpResponse.EnsureSuccessStatusCode();
|
|
||||||
var root = await httpResponse.Content.ReadFromJsonAsync<LineupsDto>(_jsonOptions, cancellationToken).ConfigureAwait(false);
|
|
||||||
return root?.Lineups.Any(i => string.Equals(info.ListingsId, i.Lineup, StringComparison.OrdinalIgnoreCase)) ?? false;
|
return root?.Lineups.Any(i => string.Equals(info.ListingsId, i.Lineup, StringComparison.OrdinalIgnoreCase)) ?? false;
|
||||||
}
|
}
|
||||||
catch (HttpRequestException ex)
|
catch (HttpRequestException ex)
|
||||||
@ -738,8 +745,7 @@ namespace Jellyfin.LiveTv.Listings
|
|||||||
using var options = new HttpRequestMessage(HttpMethod.Get, ApiUrl + "/lineups/" + listingsId);
|
using var options = new HttpRequestMessage(HttpMethod.Get, ApiUrl + "/lineups/" + listingsId);
|
||||||
options.Headers.TryAddWithoutValidation("token", token);
|
options.Headers.TryAddWithoutValidation("token", token);
|
||||||
|
|
||||||
using var httpResponse = await Send(options, true, info, cancellationToken).ConfigureAwait(false);
|
var root = await Request<ChannelDto>(options, true, info, cancellationToken).ConfigureAwait(false);
|
||||||
var root = await httpResponse.Content.ReadFromJsonAsync<ChannelDto>(_jsonOptions, cancellationToken).ConfigureAwait(false);
|
|
||||||
if (root is null)
|
if (root is null)
|
||||||
{
|
{
|
||||||
return new List<ChannelInfo>();
|
return new List<ChannelInfo>();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user