Merge pull request #17 from daullmer/json

Use System.Text.Json
This commit is contained in:
K3rnelPan1c 2021-10-15 21:12:17 +02:00 committed by GitHub
commit bbe883af89
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 119 additions and 109 deletions

View File

@ -6,8 +6,6 @@ using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Entities;
using Microsoft.Extensions.Logging;
using MediaBrowser.Model.MediaInfo;
using MediaBrowser.Model.Net;
using MediaBrowser.Model.Serialization;
using Jellyfin.Plugin.NextPVR.Helpers;
using Jellyfin.Plugin.NextPVR.Responses;
using System;
@ -31,7 +29,6 @@ namespace Jellyfin.Plugin.NextPVR
public class LiveTvService : ILiveTvService
{
private readonly IHttpClientFactory _httpClientFactory;
private readonly IJsonSerializer _jsonSerializer;
private readonly CultureInfo _usCulture = new CultureInfo("en-US");
private readonly ILogger<LiveTvService> _logger;
private int _liveStreams;
@ -44,10 +41,9 @@ namespace Jellyfin.Plugin.NextPVR
public DateTimeOffset LastRecordingChange = DateTimeOffset.MinValue;
public LiveTvService(IHttpClientFactory httpClientFactory, IJsonSerializer jsonSerializer, ILogger<LiveTvService> logger, ICryptoProvider cryptoProvider, IFileSystem fileSystem)
public LiveTvService(IHttpClientFactory httpClientFactory, ILogger<LiveTvService> logger, ICryptoProvider cryptoProvider, IFileSystem fileSystem)
{
_httpClientFactory = httpClientFactory;
_jsonSerializer = jsonSerializer;
_logger = logger;
LastUpdatedSidDateTime = DateTime.UtcNow;
_fileSystem = fileSystem;
@ -89,7 +85,7 @@ namespace Jellyfin.Plugin.NextPVR
var baseUrl = Plugin.Instance.Configuration.WebServiceUrl;
var httpClient = _httpClientFactory.CreateClient(NamedClient.Default);
await using var stream = await httpClient.GetStreamAsync(string.Format("{0}/service?method=session.initiate&ver=1.0&device=jellyfin", baseUrl), cancellationToken).ConfigureAwait(false);
var clientKeys = new InstantiateResponse().GetClientKeys(stream, _jsonSerializer, _logger);
var clientKeys = await new InstantiateResponse().GetClientKeys(stream, _logger).ConfigureAwait(false);
var sid = clientKeys.sid;
var salt = clientKeys.salt;
@ -132,7 +128,7 @@ namespace Jellyfin.Plugin.NextPVR
var httpClient = _httpClientFactory.CreateClient(NamedClient.Default);
await using var stream = await httpClient.GetStreamAsync(string.Format("{0}/service?method=session.login&md5={1}&sid={2}", baseUrl, md5Result, sid));
{
return new InitializeResponse().LoggedIn(stream, _jsonSerializer, _logger);
return await new InitializeResponse().LoggedIn(stream, _logger).ConfigureAwait(false);
}
}
@ -158,7 +154,7 @@ namespace Jellyfin.Plugin.NextPVR
await using var stream = await _httpClientFactory.CreateClient(NamedClient.Default)
.GetStreamAsync(string.Format("{0}/service?method=channel.list&sid={1}", baseUrl, Sid), cancellationToken);
return new ChannelResponse(Plugin.Instance.Configuration.WebServiceUrl).GetChannels(stream, _jsonSerializer, _logger).ToList();
return await new ChannelResponse(Plugin.Instance.Configuration.WebServiceUrl).GetChannels(stream, _logger).ConfigureAwait(false);
}
@ -181,7 +177,7 @@ namespace Jellyfin.Plugin.NextPVR
await using var stream = await _httpClientFactory.CreateClient(NamedClient.Default)
.GetStreamAsync(string.Format("{0}/service?method=recording.list&filter=ready&sid={1}", baseUrl, Sid), cancellationToken);
return new RecordingResponse(baseUrl, _fileSystem, _logger).GetRecordings(stream, _jsonSerializer);
return await new RecordingResponse(baseUrl, _fileSystem, _logger).GetRecordings(stream).ConfigureAwait(false);
}
/// <summary>
@ -201,7 +197,7 @@ namespace Jellyfin.Plugin.NextPVR
.GetStreamAsync(string.Format("{0}/service?method=recording.delete&recording_id={1}&sid={2}", baseUrl, recordingId, Sid), cancellationToken);
LastRecordingChange = DateTimeOffset.UtcNow;
bool? error = new CancelDeleteRecordingResponse().RecordingError(stream, _jsonSerializer, _logger);
bool? error = await new CancelDeleteRecordingResponse().RecordingError(stream, _logger).ConfigureAwait(false);
if (error == null || error == true)
{
@ -237,7 +233,7 @@ namespace Jellyfin.Plugin.NextPVR
.GetStreamAsync(string.Format("{0}/service?method=recording.delete&recording_id={1}&sid={2}", baseUrl, timerId, Sid), cancellationToken);
LastRecordingChange = DateTimeOffset.UtcNow;
bool? error = new CancelDeleteRecordingResponse().RecordingError(stream, _jsonSerializer, _logger);
bool? error = await new CancelDeleteRecordingResponse().RecordingError(stream, _logger).ConfigureAwait(false);
if (error == null || error == true)
{
@ -268,7 +264,7 @@ namespace Jellyfin.Plugin.NextPVR
info.PostPaddingSeconds / 60,
info.Id), cancellationToken);
bool? error = new CancelDeleteRecordingResponse().RecordingError(stream, _jsonSerializer, _logger);
bool? error = await new CancelDeleteRecordingResponse().RecordingError(stream, _logger).ConfigureAwait(false);
if (error == null || error == true)
{
_logger.LogError(string.Format("[NextPVR] Failed to create the timer with programId: {0}", info.ProgramId));
@ -292,7 +288,7 @@ namespace Jellyfin.Plugin.NextPVR
await using var stream = await _httpClientFactory.CreateClient(NamedClient.Default)
.GetStreamAsync(string.Format("{0}/service?method=recording.list&filter=pending&sid={1}", baseUrl, Sid), cancellationToken);
return new RecordingResponse(baseUrl, _fileSystem, _logger).GetTimers(stream, _jsonSerializer);
return await new RecordingResponse(baseUrl, _fileSystem, _logger).GetTimers(stream).ConfigureAwait(false);
}
/// <summary>
@ -308,7 +304,7 @@ namespace Jellyfin.Plugin.NextPVR
await using var stream = await _httpClientFactory.CreateClient(NamedClient.Default)
.GetStreamAsync(string.Format("{0}/service?method=recording.recurring.list&sid={1}", baseUrl, Sid), cancellationToken);
return new RecurringResponse(baseUrl, _fileSystem, _logger).GetSeriesTimers(stream, _jsonSerializer);
return await new RecurringResponse(baseUrl, _fileSystem, _logger).GetSeriesTimers(stream).ConfigureAwait(false);
}
/// <summary>
@ -358,7 +354,7 @@ namespace Jellyfin.Plugin.NextPVR
await using var stream = await _httpClientFactory.CreateClient(NamedClient.Default)
.GetStreamAsync(url, cancellationToken);
bool? error = new CancelDeleteRecordingResponse().RecordingError(stream, _jsonSerializer, _logger);
bool? error = await new CancelDeleteRecordingResponse().RecordingError(stream, _logger).ConfigureAwait(false);
if (error == null || error == true)
{
_logger.LogError("[NextPVR] Failed to create or update the timer with Recurring ID: {0}", info.Id);
@ -442,7 +438,7 @@ namespace Jellyfin.Plugin.NextPVR
info.Id,
info.ProgramId), cancellationToken);
bool? error = new CancelDeleteRecordingResponse().RecordingError(stream, _jsonSerializer, _logger);
bool? error = await new CancelDeleteRecordingResponse().RecordingError(stream, _logger).ConfigureAwait(false);
if (error == null || error == true)
{
_logger.LogError("[NextPVR] Failed to update the timer with ID: {0}", info.Id);
@ -467,7 +463,7 @@ namespace Jellyfin.Plugin.NextPVR
await using var stream = await _httpClientFactory.CreateClient(NamedClient.Default)
.GetStreamAsync(string.Format("{0}/service?method=recording.recurring.delete&recurring_id={1}&sid={2}", baseUrl, timerId, Sid), cancellationToken);
bool? error = new CancelDeleteRecordingResponse().RecordingError(stream, _jsonSerializer, _logger);
bool? error = await new CancelDeleteRecordingResponse().RecordingError(stream, _logger).ConfigureAwait(false);
if (error == null || error == true)
{
@ -615,7 +611,7 @@ namespace Jellyfin.Plugin.NextPVR
var baseUrl = Plugin.Instance.Configuration.WebServiceUrl;
await using var stream = await _httpClientFactory.CreateClient(NamedClient.Default)
.GetStreamAsync(string.Format("{0}/service?method=setting.list&sid={1}", baseUrl, Sid), cancellationToken);
return new SettingResponse().GetDefaultSettings(stream, _jsonSerializer, _logger);
return await new SettingResponse().GetDefaultSettings(stream, _logger).ConfigureAwait(false);
}
public async Task<IEnumerable<ProgramInfo>> GetProgramsAsync(string channelId, DateTime startDateUtc, DateTime endDateUtc, CancellationToken cancellationToken)
@ -629,7 +625,7 @@ namespace Jellyfin.Plugin.NextPVR
((DateTimeOffset) startDateUtc).ToUnixTimeSeconds(),
((DateTimeOffset) endDateUtc).ToUnixTimeSeconds(),
channelId), cancellationToken);
return new ListingsResponse(baseUrl).GetPrograms(stream, _jsonSerializer, channelId, _logger).ToList();
return await new ListingsResponse(baseUrl).GetPrograms(stream, channelId, _logger).ConfigureAwait(false);
}
public Task RecordLiveStream(string id, CancellationToken cancellationToken)
@ -654,10 +650,10 @@ namespace Jellyfin.Plugin.NextPVR
await using (var stream = await httpClient.GetStreamAsync(string.Format("{0}/service?method=setting.version&sid={1}", baseUrl, Sid), cancellationToken))
{
var versionCheckResponse = new VersionCheckResponse(stream, _jsonSerializer);
var versionCheckResponse = new VersionCheckResponse();
upgradeAvailable = versionCheckResponse.UpdateAvailable();
serverVersion = versionCheckResponse.ServerVersion();
upgradeAvailable = await versionCheckResponse.UpdateAvailable(stream).ConfigureAwait(false);
serverVersion = await versionCheckResponse.ServerVersion(stream).ConfigureAwait(false);
}
@ -666,8 +662,7 @@ namespace Jellyfin.Plugin.NextPVR
using (var stream = await httpClient.GetStreamAsync(string.Format("{0}/service/method=system.status?sid={1}", baseUrl, Sid), cancellationToken).ConfigureAwait(false))
{
var tuners = new TunerResponse(stream, _jsonSerializer);
tvTunerInfos = tuners.LiveTvTunerInfos();
tvTunerInfos = await new TunerResponse().LiveTvTunerInfos(stream).ConfigureAwait(false);
}
return new LiveTvServiceStatusInfo
@ -688,7 +683,7 @@ namespace Jellyfin.Plugin.NextPVR
{
await using var stream = await _httpClientFactory.CreateClient(NamedClient.Default)
.GetStreamAsync(string.Format("{0}/service?method=recording.lastupdated&ignore_resume=true&sid={1}", baseUrl, Sid));
retTime = new LastUpdateResponse().GetUpdateTime(stream, _jsonSerializer, _logger);
retTime = await new LastUpdateResponse().GetUpdateTime(stream, _logger).ConfigureAwait(false);
if (retTime == DateTimeOffset.FromUnixTimeSeconds(0))
{
LastUpdatedSidDateTime = DateTimeOffset.MinValue;
@ -716,7 +711,7 @@ namespace Jellyfin.Plugin.NextPVR
await using var stream = await _httpClientFactory.CreateClient(NamedClient.Default)
.GetStreamAsync(string.Format("{0}/service?method=setting.get&key={1}&sid={2}", baseUrl, key, Sid), cancellationToken);
return new SettingResponse().GetSetting(stream, _jsonSerializer, _logger);
return await new SettingResponse().GetSetting(stream, _logger).ConfigureAwait(false);
}
public string HomePageUrl

View File

@ -3,10 +3,8 @@ using System.Collections.Generic;
using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.Plugins;
using MediaBrowser.Model.Plugins;
using MediaBrowser.Model.Serialization;
using Jellyfin.Plugin.NextPVR.Configuration;
using System.IO;
using MediaBrowser.Model.Drawing;
using MediaBrowser.Model.Serialization;
namespace Jellyfin.Plugin.NextPVR
{

View File

@ -5,20 +5,23 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using MediaBrowser.Model.Serialization;
using Jellyfin.Plugin.NextPVR.Helpers;
using System.Text.Json;
using MediaBrowser.Common.Json;
namespace Jellyfin.Plugin.NextPVR.Responses
{
public class CancelDeleteRecordingResponse
{
public bool? RecordingError(Stream stream, IJsonSerializer json, ILogger<LiveTvService> logger)
private readonly JsonSerializerOptions _jsonOptions = JsonDefaults.GetOptions();
public async Task<bool?> RecordingError(Stream stream, ILogger<LiveTvService> logger)
{
var root = json.DeserializeFromStream<RootObject>(stream);
var root = await JsonSerializer.DeserializeAsync<RootObject>(stream, _jsonOptions).ConfigureAwait(false);
if (root.stat != "ok")
{
UtilsHelper.DebugInformation(logger, string.Format("[NextPVR] RecordingError Response: {0}", json.SerializeToString(root)));
UtilsHelper.DebugInformation(logger, string.Format("[NextPVR] RecordingError Response: {0}", JsonSerializer.Serialize(root, _jsonOptions)));
return true;
}
return false;

View File

@ -5,8 +5,10 @@ using System.IO;
using System.Linq;
using MediaBrowser.Controller.LiveTv;
using Microsoft.Extensions.Logging;
using MediaBrowser.Model.Serialization;
using Jellyfin.Plugin.NextPVR.Helpers;
using System.Threading.Tasks;
using System.Text.Json;
using MediaBrowser.Common.Json;
namespace Jellyfin.Plugin.NextPVR.Responses
{
@ -14,15 +16,16 @@ namespace Jellyfin.Plugin.NextPVR.Responses
{
private readonly CultureInfo _usCulture = new CultureInfo("en-US");
private readonly string _baseUrl;
private readonly JsonSerializerOptions _jsonOptions = JsonDefaults.GetOptions();
public ChannelResponse(string baseUrl)
{
_baseUrl = baseUrl;
}
public IEnumerable<ChannelInfo> GetChannels(Stream stream, IJsonSerializer json,ILogger<LiveTvService> logger)
public async Task<IEnumerable<ChannelInfo>> GetChannels(Stream stream, ILogger<LiveTvService> logger)
{
var root = json.DeserializeFromStream<RootObject>(stream);
var root = await JsonSerializer.DeserializeAsync<RootObject>(stream, _jsonOptions).ConfigureAwait(false);
if (root == null)
{
@ -32,7 +35,7 @@ namespace Jellyfin.Plugin.NextPVR.Responses
if (root.channels != null)
{
UtilsHelper.DebugInformation(logger, string.Format("[NextPVR] ChannelResponse: {0}", json.SerializeToString(root)));
UtilsHelper.DebugInformation(logger, string.Format("[NextPVR] ChannelResponse: {0}", JsonSerializer.Serialize(root, _jsonOptions)));
return root.channels.Select(i => new ChannelInfo
{
Name = i.channelName,

View File

@ -1,20 +1,24 @@
using System;
using System.IO;
using Microsoft.Extensions.Logging;
using MediaBrowser.Model.Serialization;
using Jellyfin.Plugin.NextPVR.Helpers;
using MediaBrowser.Common.Json;
using System.Text.Json;
using System.Threading.Tasks;
namespace Jellyfin.Plugin.NextPVR.Responses
{
public class InitializeResponse
{
public bool LoggedIn(Stream stream, IJsonSerializer json, ILogger<LiveTvService> logger)
private readonly JsonSerializerOptions _jsonOptions = JsonDefaults.GetOptions();
public async Task<bool> LoggedIn(Stream stream, ILogger<LiveTvService> logger)
{
var root = json.DeserializeFromStream<RootObject>(stream);
var root = await JsonSerializer.DeserializeAsync<RootObject>(stream, _jsonOptions).ConfigureAwait(false);
if (root.stat != "")
{
UtilsHelper.DebugInformation(logger, string.Format("[NextPVR] Connection validation: {0}", json.SerializeToString(root)));
UtilsHelper.DebugInformation(logger, string.Format("[NextPVR] Connection validation: {0}", JsonSerializer.Serialize(root, _jsonOptions)));
return root.stat == "ok";
}
logger.LogError("[NextPVR] Failed to validate your connection with NextPVR.");

View File

@ -1,22 +1,26 @@
using System;
using System.IO;
using Microsoft.Extensions.Logging;
using MediaBrowser.Model.Serialization;
using Jellyfin.Plugin.NextPVR.Helpers;
using System.Threading.Tasks;
using System.Text.Json;
using MediaBrowser.Common.Json;
namespace Jellyfin.Plugin.NextPVR.Responses
{
public class InstantiateResponse
{
public ClientKeys GetClientKeys(Stream stream, IJsonSerializer json, ILogger<LiveTvService> logger)
private readonly JsonSerializerOptions _jsonOptions = JsonDefaults.GetOptions();
public async Task<ClientKeys> GetClientKeys(Stream stream, ILogger<LiveTvService> logger)
{
try
{
var root = json.DeserializeFromStream<ClientKeys>(stream);
var root = await JsonSerializer.DeserializeAsync<ClientKeys>(stream, _jsonOptions).ConfigureAwait(false);
if (root.sid != null && root.salt != null)
{
UtilsHelper.DebugInformation(logger, string.Format("[NextPVR] ClientKeys: {0}", json.SerializeToString(root)));
UtilsHelper.DebugInformation(logger, string.Format("[NextPVR] ClientKeys: {0}", JsonSerializer.Serialize(root, _jsonOptions)));
return root;
}
logger.LogError("[NextPVR] Failed to validate the ClientKeys from NextPVR.");

View File

@ -3,17 +3,20 @@ using System.IO;
using System;
using MediaBrowser.Controller.LiveTv;
using Microsoft.Extensions.Logging;
using MediaBrowser.Model.Serialization;
using Jellyfin.Plugin.NextPVR.Helpers;
using System.Threading.Tasks;
using MediaBrowser.Common.Json;
using System.Text.Json;
namespace Jellyfin.Plugin.NextPVR.Responses
{
public class LastUpdateResponse
{
public DateTimeOffset GetUpdateTime(Stream stream, IJsonSerializer json, ILogger<LiveTvService> logger)
private readonly JsonSerializerOptions _jsonOptions = JsonDefaults.GetOptions();
public async Task<DateTimeOffset> GetUpdateTime(Stream stream, ILogger<LiveTvService> logger)
{
var root = json.DeserializeFromStream<RootObject>(stream);
UtilsHelper.DebugInformation(logger, string.Format("[NextPVR] LastUpdate Response: {0}", json.SerializeToString(root)));
var root = await JsonSerializer.DeserializeAsync<RootObject>(stream, _jsonOptions).ConfigureAwait(false);
UtilsHelper.DebugInformation(logger, string.Format("[NextPVR] LastUpdate Response: {0}", JsonSerializer.Serialize(root, _jsonOptions)));
return DateTimeOffset.FromUnixTimeSeconds(root.last_update);
}
}

View File

@ -6,8 +6,10 @@ using System.Linq;
using MediaBrowser.Controller.LiveTv;
using MediaBrowser.Model.LiveTv;
using Microsoft.Extensions.Logging;
using MediaBrowser.Model.Serialization;
using Jellyfin.Plugin.NextPVR.Helpers;
using System.Threading.Tasks;
using System.Text.Json;
using MediaBrowser.Common.Json;
namespace Jellyfin.Plugin.NextPVR.Responses
{
@ -16,16 +18,17 @@ namespace Jellyfin.Plugin.NextPVR.Responses
private readonly CultureInfo _usCulture = new CultureInfo("en-US");
private readonly string _baseUrl;
private string _channelId;
private readonly JsonSerializerOptions _jsonOptions = JsonDefaults.GetOptions();
public ListingsResponse(string baseUrl)
{
_baseUrl = baseUrl;
}
public IEnumerable<ProgramInfo> GetPrograms(Stream stream, IJsonSerializer json, string channelId, ILogger<LiveTvService> logger)
public async Task<IEnumerable<ProgramInfo>> GetPrograms(Stream stream, string channelId, ILogger<LiveTvService> logger)
{
var root = json.DeserializeFromStream<RootObject>(stream);
UtilsHelper.DebugInformation(logger, string.Format("[NextPVR] GetPrograms Response: {0}", json.SerializeToString(root)));
var root = await JsonSerializer.DeserializeAsync<RootObject>(stream, _jsonOptions).ConfigureAwait(false);
UtilsHelper.DebugInformation(logger, string.Format("[NextPVR] GetPrograms Response: {0}", JsonSerializer.Serialize(root, _jsonOptions)));
/*

View File

@ -7,8 +7,10 @@ using MediaBrowser.Controller.LiveTv;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.LiveTv;
using Microsoft.Extensions.Logging;
using MediaBrowser.Model.Serialization;
using Jellyfin.Plugin.NextPVR.Helpers;
using System.Threading.Tasks;
using MediaBrowser.Common.Json;
using System.Text.Json;
namespace Jellyfin.Plugin.NextPVR.Responses
{
@ -18,6 +20,7 @@ namespace Jellyfin.Plugin.NextPVR.Responses
private readonly string _baseUrl;
private IFileSystem _fileSystem;
private readonly ILogger<LiveTvService> _logger;
private readonly JsonSerializerOptions _jsonOptions = JsonDefaults.GetOptions();
public RecordingResponse(string baseUrl, IFileSystem fileSystem, ILogger<LiveTvService> logger)
{
@ -26,7 +29,7 @@ namespace Jellyfin.Plugin.NextPVR.Responses
_logger = logger;
}
public IEnumerable<MyRecordingInfo> GetRecordings(Stream stream, IJsonSerializer json)
public async Task<IEnumerable<MyRecordingInfo>> GetRecordings(Stream stream)
{
if (stream == null)
{
@ -34,8 +37,8 @@ namespace Jellyfin.Plugin.NextPVR.Responses
throw new ArgumentNullException("stream");
}
var root = json.DeserializeFromStream<RootObject>(stream);
UtilsHelper.DebugInformation(_logger, string.Format("[NextPVR] GetRecordings Response: {0}", json.SerializeToString(root)));
var root = await JsonSerializer.DeserializeAsync<RootObject>(stream, _jsonOptions).ConfigureAwait(false);
UtilsHelper.DebugInformation(_logger, string.Format("[NextPVR] GetRecordings Response: {0}", JsonSerializer.Serialize(root, _jsonOptions)));
IEnumerable<MyRecordingInfo> Recordings;
try
@ -53,7 +56,7 @@ namespace Jellyfin.Plugin.NextPVR.Responses
return Recordings;
}
public IEnumerable<TimerInfo> GetTimers(Stream stream, IJsonSerializer json)
public async Task<IEnumerable<TimerInfo>> GetTimers(Stream stream)
{
if (stream == null)
{
@ -61,8 +64,8 @@ namespace Jellyfin.Plugin.NextPVR.Responses
throw new ArgumentNullException("stream");
}
var root = json.DeserializeFromStream<RootObject>(stream);
UtilsHelper.DebugInformation(_logger, string.Format("[NextPVR] GetTimers Response: {0}", json.SerializeToString(root)));
var root = await JsonSerializer.DeserializeAsync<RootObject>(stream, _jsonOptions).ConfigureAwait(false);
UtilsHelper.DebugInformation(_logger, string.Format("[NextPVR] GetTimers Response: {0}", JsonSerializer.Serialize(root, _jsonOptions)));
IEnumerable<TimerInfo> Timers;
try
{

View File

@ -7,9 +7,10 @@ using MediaBrowser.Controller.LiveTv;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.LiveTv;
using Microsoft.Extensions.Logging;
using MediaBrowser.Model.Serialization;
using Jellyfin.Plugin.NextPVR.Helpers;
using System.Text.Json;
using MediaBrowser.Common.Json;
using System.Threading.Tasks;
namespace Jellyfin.Plugin.NextPVR.Responses
{
@ -19,6 +20,7 @@ namespace Jellyfin.Plugin.NextPVR.Responses
private readonly string _baseUrl;
private IFileSystem _fileSystem;
private readonly ILogger<LiveTvService> _logger;
private readonly JsonSerializerOptions _jsonOptions = JsonDefaults.GetOptions();
public RecurringResponse(string baseUrl, IFileSystem fileSystem, ILogger<LiveTvService> logger)
{
@ -26,7 +28,7 @@ namespace Jellyfin.Plugin.NextPVR.Responses
_fileSystem = fileSystem;
_logger = logger;
}
public IEnumerable<SeriesTimerInfo> GetSeriesTimers(Stream stream, IJsonSerializer json)
public async Task<IEnumerable<SeriesTimerInfo>> GetSeriesTimers(Stream stream)
{
if (stream == null)
{
@ -34,8 +36,8 @@ namespace Jellyfin.Plugin.NextPVR.Responses
throw new ArgumentNullException("stream");
}
var root = json.DeserializeFromStream<RootObject>(stream);
UtilsHelper.DebugInformation(_logger, string.Format("[NextPVR] GetSeriesTimers Response: {0}", json.SerializeToString(root)));
var root = await JsonSerializer.DeserializeAsync<RootObject>(stream, _jsonOptions).ConfigureAwait(false);
UtilsHelper.DebugInformation(_logger, string.Format("[NextPVR] GetSeriesTimers Response: {0}", JsonSerializer.Serialize(root, _jsonOptions)));
return root.recurrings
.Select(i => i)
.Select(GetSeriesTimerInfo);

View File

@ -2,34 +2,32 @@
using System.IO;
using MediaBrowser.Controller.LiveTv;
using Microsoft.Extensions.Logging;
using MediaBrowser.Model.Serialization;
using Jellyfin.Plugin.NextPVR.Helpers;
using System.Threading.Tasks;
using System.Text.Json;
using MediaBrowser.Common.Json;
namespace Jellyfin.Plugin.NextPVR.Responses
{
public class SettingResponse
{
private readonly CultureInfo _usCulture = new CultureInfo("en-US");
private readonly JsonSerializerOptions _jsonOptions = JsonDefaults.GetOptions();
public bool GetDefaultSettings(Stream stream, IJsonSerializer json, ILogger<LiveTvService> logger)
public async Task<bool> GetDefaultSettings(Stream stream, ILogger<LiveTvService> logger)
{
ScheduleSettings root = GetScheduleSettings(stream, json);
UtilsHelper.DebugInformation(logger, string.Format("[NextPVR] GetDefaultTimerInfo Response: {0}", json.SerializeToString(root)));
var root = await JsonSerializer.DeserializeAsync<ScheduleSettings>(stream, _jsonOptions).ConfigureAwait(false);
UtilsHelper.DebugInformation(logger, string.Format("[NextPVR] GetDefaultTimerInfo Response: {0}", JsonSerializer.Serialize(root, _jsonOptions)));
Plugin.Instance.Configuration.PostPaddingSeconds = int.Parse(root.postPadding) * 60;
Plugin.Instance.Configuration.PrePaddingSeconds = int.Parse(root.prePadding) * 60;
Plugin.Instance.Configuration.ShowRepeat = root.showNewInGuide;
return true;
}
private ScheduleSettings GetScheduleSettings(Stream stream, IJsonSerializer json)
public async Task<string> GetSetting(Stream stream, ILogger<LiveTvService> logger)
{
return json.DeserializeFromStream<ScheduleSettings>(stream);
}
public string GetSetting(Stream stream, IJsonSerializer json, ILogger<LiveTvService> logger)
{
SettingValue root = json.DeserializeFromStream<SettingValue>(stream);
UtilsHelper.DebugInformation(logger, string.Format("[NextPVR] GetSetting Response: {0}", json.SerializeToString(root)));
var root = await JsonSerializer.DeserializeAsync<SettingValue>(stream, _jsonOptions).ConfigureAwait(false);
UtilsHelper.DebugInformation(logger, string.Format("[NextPVR] GetSetting Response: {0}", JsonSerializer.Serialize(root, _jsonOptions)));
return root.value;
}

View File

@ -2,19 +2,22 @@
using System.IO;
using MediaBrowser.Controller.LiveTv;
using Microsoft.Extensions.Logging;
using MediaBrowser.Model.Serialization;
using Jellyfin.Plugin.NextPVR.Helpers;
using System.Threading.Tasks;
using System.Text.Json;
using MediaBrowser.Common.Json;
namespace Jellyfin.Plugin.NextPVR.Responses
{
public class TimerDefaultsResponse
{
private readonly CultureInfo _usCulture = new CultureInfo("en-US");
private readonly JsonSerializerOptions _jsonOptions = JsonDefaults.GetOptions();
public SeriesTimerInfo GetDefaultTimerInfo(Stream stream, IJsonSerializer json, ILogger<LiveTvService> logger)
public async Task<SeriesTimerInfo> GetDefaultTimerInfo(Stream stream, ILogger<LiveTvService> logger)
{
var root = GetScheduleSettings(stream, json);
UtilsHelper.DebugInformation(logger,string.Format("[NextPVR] GetDefaultTimerInfo Response: {0}", json.SerializeToString(root)));
var root = await JsonSerializer.DeserializeAsync<ScheduleSettings>(stream, _jsonOptions).ConfigureAwait(false);
UtilsHelper.DebugInformation(logger,string.Format("[NextPVR] GetDefaultTimerInfo Response: {0}", JsonSerializer.Serialize(root, _jsonOptions)));
return new SeriesTimerInfo
{
@ -25,11 +28,6 @@ namespace Jellyfin.Plugin.NextPVR.Responses
RecordNewOnly = root.onlyNew
};
}
public ScheduleSettings GetScheduleSettings(Stream stream, IJsonSerializer json)
{
return json.DeserializeFromStream<ScheduleSettings>(stream);
}
}
// Classes created with http://json2csharp.com/

View File

@ -1,25 +1,22 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.Json;
using System.Threading.Tasks;
using MediaBrowser.Common.Json;
using MediaBrowser.Controller.LiveTv;
using MediaBrowser.Model.Drawing;
using MediaBrowser.Model.LiveTv;
using MediaBrowser.Model.Serialization;
namespace Jellyfin.Plugin.NextPVR.Responses
{
public class TunerResponse
{
private readonly RootObject _root;
private readonly JsonSerializerOptions _jsonOptions = JsonDefaults.GetOptions();
public TunerResponse(Stream stream, IJsonSerializer json)
public async Task<List<LiveTvTunerInfo>> LiveTvTunerInfos(Stream stream)
{
_root = json.DeserializeFromStream<RootObject>(stream);
}
public List<LiveTvTunerInfo> LiveTvTunerInfos()
{
return _root.Tuners.Select(GetTunerInformation).ToList();
var root = await JsonSerializer.DeserializeAsync<RootObject>(stream, _jsonOptions).ConfigureAwait(false);
return root.Tuners.Select(GetTunerInformation).ToList();
}
private LiveTvTunerInfo GetTunerInformation(Tuner i)

View File

@ -1,33 +1,32 @@
using System;
using System.IO;
using MediaBrowser.Model.Serialization;
using System.Text.Json;
using System.Threading.Tasks;
using MediaBrowser.Common.Json;
namespace Jellyfin.Plugin.NextPVR.Responses
{
public class VersionCheckResponse
{
private readonly RootObject _root;
private readonly JsonSerializerOptions _jsonOptions = JsonDefaults.GetOptions();
public VersionCheckResponse(Stream stream, IJsonSerializer json)
public async Task<bool> UpdateAvailable(Stream stream)
{
_root = json.DeserializeFromStream<RootObject>(stream);
}
public Boolean UpdateAvailable()
var root = await JsonSerializer.DeserializeAsync<RootObject>(stream, _jsonOptions).ConfigureAwait(false);
if (root.versionCheck != null)
{
if (_root.versionCheck != null)
{
return _root.versionCheck.upgradeAvailable;
return root.versionCheck.upgradeAvailable;
}
throw new Exception("Failed to get the Update Status from NextPVR.");
}
public string ServerVersion()
public async Task<string> ServerVersion(Stream stream)
{
if (_root.versionCheck != null)
var root = await JsonSerializer.DeserializeAsync<RootObject>(stream, _jsonOptions).ConfigureAwait(false);
if (root.versionCheck != null)
{
return _root.versionCheck.serverVer;
return root.versionCheck.serverVer;
}
throw new Exception("Failed to get the Server Version from NextPVR.");