diff --git a/Jellyfin.Plugin.NextPVR/LiveTvService.cs b/Jellyfin.Plugin.NextPVR/LiveTvService.cs index a8d491e..2d99803 100644 --- a/Jellyfin.Plugin.NextPVR/LiveTvService.cs +++ b/Jellyfin.Plugin.NextPVR/LiveTvService.cs @@ -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 _logger; private int _liveStreams; @@ -44,10 +41,9 @@ namespace Jellyfin.Plugin.NextPVR public DateTimeOffset LastRecordingChange = DateTimeOffset.MinValue; - public LiveTvService(IHttpClientFactory httpClientFactory, IJsonSerializer jsonSerializer, ILogger logger, ICryptoProvider cryptoProvider, IFileSystem fileSystem) + public LiveTvService(IHttpClientFactory httpClientFactory, ILogger 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); } /// @@ -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); } /// @@ -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); } /// @@ -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> 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 diff --git a/Jellyfin.Plugin.NextPVR/Plugin.cs b/Jellyfin.Plugin.NextPVR/Plugin.cs index bb7bded..56629f0 100644 --- a/Jellyfin.Plugin.NextPVR/Plugin.cs +++ b/Jellyfin.Plugin.NextPVR/Plugin.cs @@ -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 { diff --git a/Jellyfin.Plugin.NextPVR/Responses/CancelRecordingResponse.cs b/Jellyfin.Plugin.NextPVR/Responses/CancelRecordingResponse.cs index b9381db..6ea5df6 100644 --- a/Jellyfin.Plugin.NextPVR/Responses/CancelRecordingResponse.cs +++ b/Jellyfin.Plugin.NextPVR/Responses/CancelRecordingResponse.cs @@ -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 logger) + private readonly JsonSerializerOptions _jsonOptions = JsonDefaults.GetOptions(); + + public async Task RecordingError(Stream stream, ILogger logger) { - var root = json.DeserializeFromStream(stream); + var root = await JsonSerializer.DeserializeAsync(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; diff --git a/Jellyfin.Plugin.NextPVR/Responses/ChannelResponse.cs b/Jellyfin.Plugin.NextPVR/Responses/ChannelResponse.cs index d4212d6..d748ace 100644 --- a/Jellyfin.Plugin.NextPVR/Responses/ChannelResponse.cs +++ b/Jellyfin.Plugin.NextPVR/Responses/ChannelResponse.cs @@ -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 GetChannels(Stream stream, IJsonSerializer json,ILogger logger) + public async Task> GetChannels(Stream stream, ILogger logger) { - var root = json.DeserializeFromStream(stream); + var root = await JsonSerializer.DeserializeAsync(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, diff --git a/Jellyfin.Plugin.NextPVR/Responses/InitializeResponse.cs b/Jellyfin.Plugin.NextPVR/Responses/InitializeResponse.cs index 365816c..a2ac711 100644 --- a/Jellyfin.Plugin.NextPVR/Responses/InitializeResponse.cs +++ b/Jellyfin.Plugin.NextPVR/Responses/InitializeResponse.cs @@ -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 logger) + private readonly JsonSerializerOptions _jsonOptions = JsonDefaults.GetOptions(); + + public async Task LoggedIn(Stream stream, ILogger logger) { - var root = json.DeserializeFromStream(stream); + var root = await JsonSerializer.DeserializeAsync(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."); diff --git a/Jellyfin.Plugin.NextPVR/Responses/InstantiateResponse.cs b/Jellyfin.Plugin.NextPVR/Responses/InstantiateResponse.cs index 7abc5c9..5cd4aa0 100644 --- a/Jellyfin.Plugin.NextPVR/Responses/InstantiateResponse.cs +++ b/Jellyfin.Plugin.NextPVR/Responses/InstantiateResponse.cs @@ -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 logger) + private readonly JsonSerializerOptions _jsonOptions = JsonDefaults.GetOptions(); + + public async Task GetClientKeys(Stream stream, ILogger logger) { try { - var root = json.DeserializeFromStream(stream); + var root = await JsonSerializer.DeserializeAsync(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."); diff --git a/Jellyfin.Plugin.NextPVR/Responses/LastUpdateResponse.cs b/Jellyfin.Plugin.NextPVR/Responses/LastUpdateResponse.cs index 5bda081..172b03d 100644 --- a/Jellyfin.Plugin.NextPVR/Responses/LastUpdateResponse.cs +++ b/Jellyfin.Plugin.NextPVR/Responses/LastUpdateResponse.cs @@ -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 logger) + private readonly JsonSerializerOptions _jsonOptions = JsonDefaults.GetOptions(); + public async Task GetUpdateTime(Stream stream, ILogger logger) { - var root = json.DeserializeFromStream(stream); - UtilsHelper.DebugInformation(logger, string.Format("[NextPVR] LastUpdate Response: {0}", json.SerializeToString(root))); + var root = await JsonSerializer.DeserializeAsync(stream, _jsonOptions).ConfigureAwait(false); + UtilsHelper.DebugInformation(logger, string.Format("[NextPVR] LastUpdate Response: {0}", JsonSerializer.Serialize(root, _jsonOptions))); return DateTimeOffset.FromUnixTimeSeconds(root.last_update); } } diff --git a/Jellyfin.Plugin.NextPVR/Responses/ListingsResponse.cs b/Jellyfin.Plugin.NextPVR/Responses/ListingsResponse.cs index e7a5598..e9e7b20 100644 --- a/Jellyfin.Plugin.NextPVR/Responses/ListingsResponse.cs +++ b/Jellyfin.Plugin.NextPVR/Responses/ListingsResponse.cs @@ -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 GetPrograms(Stream stream, IJsonSerializer json, string channelId, ILogger logger) + public async Task> GetPrograms(Stream stream, string channelId, ILogger logger) { - var root = json.DeserializeFromStream(stream); - UtilsHelper.DebugInformation(logger, string.Format("[NextPVR] GetPrograms Response: {0}", json.SerializeToString(root))); + var root = await JsonSerializer.DeserializeAsync(stream, _jsonOptions).ConfigureAwait(false); + UtilsHelper.DebugInformation(logger, string.Format("[NextPVR] GetPrograms Response: {0}", JsonSerializer.Serialize(root, _jsonOptions))); /* diff --git a/Jellyfin.Plugin.NextPVR/Responses/RecordingResponse.cs b/Jellyfin.Plugin.NextPVR/Responses/RecordingResponse.cs index c22d560..4b8e4ad 100644 --- a/Jellyfin.Plugin.NextPVR/Responses/RecordingResponse.cs +++ b/Jellyfin.Plugin.NextPVR/Responses/RecordingResponse.cs @@ -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 _logger; + private readonly JsonSerializerOptions _jsonOptions = JsonDefaults.GetOptions(); public RecordingResponse(string baseUrl, IFileSystem fileSystem, ILogger logger) { @@ -26,7 +29,7 @@ namespace Jellyfin.Plugin.NextPVR.Responses _logger = logger; } - public IEnumerable GetRecordings(Stream stream, IJsonSerializer json) + public async Task> GetRecordings(Stream stream) { if (stream == null) { @@ -34,8 +37,8 @@ namespace Jellyfin.Plugin.NextPVR.Responses throw new ArgumentNullException("stream"); } - var root = json.DeserializeFromStream(stream); - UtilsHelper.DebugInformation(_logger, string.Format("[NextPVR] GetRecordings Response: {0}", json.SerializeToString(root))); + var root = await JsonSerializer.DeserializeAsync(stream, _jsonOptions).ConfigureAwait(false); + UtilsHelper.DebugInformation(_logger, string.Format("[NextPVR] GetRecordings Response: {0}", JsonSerializer.Serialize(root, _jsonOptions))); IEnumerable Recordings; try @@ -53,7 +56,7 @@ namespace Jellyfin.Plugin.NextPVR.Responses return Recordings; } - public IEnumerable GetTimers(Stream stream, IJsonSerializer json) + public async Task> GetTimers(Stream stream) { if (stream == null) { @@ -61,8 +64,8 @@ namespace Jellyfin.Plugin.NextPVR.Responses throw new ArgumentNullException("stream"); } - var root = json.DeserializeFromStream(stream); - UtilsHelper.DebugInformation(_logger, string.Format("[NextPVR] GetTimers Response: {0}", json.SerializeToString(root))); + var root = await JsonSerializer.DeserializeAsync(stream, _jsonOptions).ConfigureAwait(false); + UtilsHelper.DebugInformation(_logger, string.Format("[NextPVR] GetTimers Response: {0}", JsonSerializer.Serialize(root, _jsonOptions))); IEnumerable Timers; try { diff --git a/Jellyfin.Plugin.NextPVR/Responses/RecurringResponse.cs b/Jellyfin.Plugin.NextPVR/Responses/RecurringResponse.cs index e598426..46d98d2 100644 --- a/Jellyfin.Plugin.NextPVR/Responses/RecurringResponse.cs +++ b/Jellyfin.Plugin.NextPVR/Responses/RecurringResponse.cs @@ -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 _logger; + private readonly JsonSerializerOptions _jsonOptions = JsonDefaults.GetOptions(); public RecurringResponse(string baseUrl, IFileSystem fileSystem, ILogger logger) { @@ -26,7 +28,7 @@ namespace Jellyfin.Plugin.NextPVR.Responses _fileSystem = fileSystem; _logger = logger; } - public IEnumerable GetSeriesTimers(Stream stream, IJsonSerializer json) + public async Task> GetSeriesTimers(Stream stream) { if (stream == null) { @@ -34,8 +36,8 @@ namespace Jellyfin.Plugin.NextPVR.Responses throw new ArgumentNullException("stream"); } - var root = json.DeserializeFromStream(stream); - UtilsHelper.DebugInformation(_logger, string.Format("[NextPVR] GetSeriesTimers Response: {0}", json.SerializeToString(root))); + var root = await JsonSerializer.DeserializeAsync(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); diff --git a/Jellyfin.Plugin.NextPVR/Responses/SettingResponse.cs b/Jellyfin.Plugin.NextPVR/Responses/SettingResponse.cs index 47292d8..1e2cfaa 100644 --- a/Jellyfin.Plugin.NextPVR/Responses/SettingResponse.cs +++ b/Jellyfin.Plugin.NextPVR/Responses/SettingResponse.cs @@ -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 logger) + public async Task GetDefaultSettings(Stream stream, ILogger logger) { - ScheduleSettings root = GetScheduleSettings(stream, json); - UtilsHelper.DebugInformation(logger, string.Format("[NextPVR] GetDefaultTimerInfo Response: {0}", json.SerializeToString(root))); + var root = await JsonSerializer.DeserializeAsync(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 GetSetting(Stream stream, ILogger logger) { - return json.DeserializeFromStream(stream); - } - - public string GetSetting(Stream stream, IJsonSerializer json, ILogger logger) - { - SettingValue root = json.DeserializeFromStream(stream); - UtilsHelper.DebugInformation(logger, string.Format("[NextPVR] GetSetting Response: {0}", json.SerializeToString(root))); + var root = await JsonSerializer.DeserializeAsync(stream, _jsonOptions).ConfigureAwait(false); + UtilsHelper.DebugInformation(logger, string.Format("[NextPVR] GetSetting Response: {0}", JsonSerializer.Serialize(root, _jsonOptions))); return root.value; } diff --git a/Jellyfin.Plugin.NextPVR/Responses/TimerDefaultsResponse.cs b/Jellyfin.Plugin.NextPVR/Responses/TimerDefaultsResponse.cs index b304b03..2f9ee53 100644 --- a/Jellyfin.Plugin.NextPVR/Responses/TimerDefaultsResponse.cs +++ b/Jellyfin.Plugin.NextPVR/Responses/TimerDefaultsResponse.cs @@ -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 logger) + public async Task GetDefaultTimerInfo(Stream stream, ILogger logger) { - var root = GetScheduleSettings(stream, json); - UtilsHelper.DebugInformation(logger,string.Format("[NextPVR] GetDefaultTimerInfo Response: {0}", json.SerializeToString(root))); + var root = await JsonSerializer.DeserializeAsync(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(stream); - } } // Classes created with http://json2csharp.com/ diff --git a/Jellyfin.Plugin.NextPVR/Responses/TunerResponse.cs b/Jellyfin.Plugin.NextPVR/Responses/TunerResponse.cs index 3bf11c9..34bf969 100644 --- a/Jellyfin.Plugin.NextPVR/Responses/TunerResponse.cs +++ b/Jellyfin.Plugin.NextPVR/Responses/TunerResponse.cs @@ -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> LiveTvTunerInfos(Stream stream) { - _root = json.DeserializeFromStream(stream); - } - - public List LiveTvTunerInfos() - { - return _root.Tuners.Select(GetTunerInformation).ToList(); + var root = await JsonSerializer.DeserializeAsync(stream, _jsonOptions).ConfigureAwait(false); + return root.Tuners.Select(GetTunerInformation).ToList(); } private LiveTvTunerInfo GetTunerInformation(Tuner i) diff --git a/Jellyfin.Plugin.NextPVR/Responses/VersionCheckResponse.cs b/Jellyfin.Plugin.NextPVR/Responses/VersionCheckResponse.cs index ddd48c3..5a3451d 100644 --- a/Jellyfin.Plugin.NextPVR/Responses/VersionCheckResponse.cs +++ b/Jellyfin.Plugin.NextPVR/Responses/VersionCheckResponse.cs @@ -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 UpdateAvailable(Stream stream) { - _root = json.DeserializeFromStream(stream); - } - - public Boolean UpdateAvailable() - { - if (_root.versionCheck != null) + var root = await JsonSerializer.DeserializeAsync(stream, _jsonOptions).ConfigureAwait(false); + 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 ServerVersion(Stream stream) { - if (_root.versionCheck != null) + var root = await JsonSerializer.DeserializeAsync(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.");