From 1901af5a511fd8f37e152f0398539830d0dd2859 Mon Sep 17 00:00:00 2001 From: Bogdan Date: Wed, 4 Oct 2023 01:42:41 +0300 Subject: [PATCH] Fixed: (BeyondHD) Parse response with STJson --- .../Indexers/Definitions/BeyondHD.cs | 43 ++++++++++++------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/src/NzbDrone.Core/Indexers/Definitions/BeyondHD.cs b/src/NzbDrone.Core/Indexers/Definitions/BeyondHD.cs index 412f75c4b..6da765664 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/BeyondHD.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/BeyondHD.cs @@ -4,8 +4,8 @@ using System.Globalization; using System.Linq; using System.Net; using System.Net.Http; +using System.Text.Json.Serialization; using FluentValidation; -using Newtonsoft.Json; using NLog; using NzbDrone.Common.Extensions; using NzbDrone.Common.Http; @@ -19,6 +19,7 @@ using NzbDrone.Core.Messaging.Events; using NzbDrone.Core.Parser; using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Validation; +using static Newtonsoft.Json.Formatting; namespace NzbDrone.Core.Indexers.Definitions { @@ -163,7 +164,7 @@ namespace NzbDrone.Core.Indexers.Definitions Method = HttpMethod.Post }; request.SetContent(body.ToJson()); - request.ContentSummary = body.ToJson(Formatting.None); + request.ContentSummary = body.ToJson(None); yield return new IndexerRequest(request); } @@ -245,16 +246,16 @@ namespace NzbDrone.Core.Indexers.Definitions throw new IndexerAuthException("API Key invalid or not authorized"); } - var jsonResponse = new HttpResponse(indexerHttpResponse); + var jsonResponse = STJson.Deserialize(indexerResponse.Content); - if (jsonResponse.Resource.StatusCode == 0) + if (jsonResponse.StatusCode == 0) { - throw new IndexerException(indexerResponse, $"Indexer Error: {jsonResponse.Resource.StatusMessage}"); + throw new IndexerException(indexerResponse, $"Indexer Error: {jsonResponse.StatusMessage}"); } var releaseInfos = new List(); - foreach (var row in jsonResponse.Resource.Results) + foreach (var row in jsonResponse.Results) { var details = row.InfoUrl; var link = row.DownloadLink; @@ -412,10 +413,10 @@ namespace NzbDrone.Core.Indexers.Definitions public class BeyondHDResponse { - [JsonProperty(PropertyName = "status_code")] + [JsonPropertyName("status_code")] public int StatusCode { get; set; } - [JsonProperty(PropertyName = "status_message")] + [JsonPropertyName("status_message")] public string StatusMessage { get; set; } public List Results { get; set; } } @@ -424,36 +425,48 @@ namespace NzbDrone.Core.Indexers.Definitions { public string Name { get; set; } - [JsonProperty(PropertyName = "info_hash")] + [JsonPropertyName("info_hash")] public string InfoHash { get; set; } public string Category { get; set; } public string Type { get; set; } public long Size { get; set; } - [JsonProperty(PropertyName = "times_completed")] + [JsonPropertyName("times_completed")] public int Grabs { get; set; } public int Seeders { get; set; } public int Leechers { get; set; } - [JsonProperty(PropertyName = "created_at")] + [JsonPropertyName("created_at")] public string CreatedAt { get; set; } - [JsonProperty(PropertyName = "download_url")] + [JsonPropertyName("download_url")] public string DownloadLink { get; set; } - [JsonProperty(PropertyName = "url")] + [JsonPropertyName("url")] public string InfoUrl { get; set; } - [JsonProperty(PropertyName = "imdb_id")] + [JsonPropertyName("imdb_id")] public string ImdbId { get; set; } - [JsonProperty(PropertyName = "tmdb_id")] + [JsonPropertyName("tmdb_id")] public string TmdbId { get; set; } + + [JsonConverter(typeof(BooleanConverter))] public bool Freeleech { get; set; } + + [JsonConverter(typeof(BooleanConverter))] public bool Promo25 { get; set; } + + [JsonConverter(typeof(BooleanConverter))] public bool Promo50 { get; set; } + + [JsonConverter(typeof(BooleanConverter))] public bool Promo75 { get; set; } + + [JsonConverter(typeof(BooleanConverter))] public bool Limited { get; set; } + + [JsonConverter(typeof(BooleanConverter))] public bool Internal { get; set; } } }