jellyfin-plugin-nextpvr/Jellyfin.Plugin.NextPVR/Responses/InitializeResponse.cs
2024-06-14 07:30:05 -06:00

35 lines
1.1 KiB
C#

using System.IO;
using System.Text.Json;
using System.Threading.Tasks;
using Jellyfin.Extensions.Json;
using Jellyfin.Plugin.NextPVR.Helpers;
using Microsoft.Extensions.Logging;
namespace Jellyfin.Plugin.NextPVR.Responses;
public class InitializeResponse
{
private readonly JsonSerializerOptions _jsonOptions = JsonDefaults.CamelCaseOptions;
public async Task<bool> LoggedIn(Stream stream, ILogger<LiveTvService> logger)
{
var root = await JsonSerializer.DeserializeAsync<RootObject>(stream, _jsonOptions).ConfigureAwait(false);
if (!string.IsNullOrEmpty(root.Stat))
{
UtilsHelper.DebugInformation(logger, $"Connection validation: {JsonSerializer.Serialize(root, _jsonOptions)}");
return root.Stat == "ok";
}
logger.LogError("Failed to validate your connection with NextPVR");
throw new JsonException("Failed to validate your connection with NextPVR.");
}
private sealed class RootObject
{
public string Stat { get; set; }
public string Sid { get; set; }
}
}