Fixed: (FileList) Parse response with STJson

pull/1884/head
Bogdan 8 months ago
parent 2100e96570
commit c1b399be39

@ -0,0 +1,29 @@
using System;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace NzbDrone.Common.Serializer;
public class BooleanConverter : JsonConverter<bool>
{
public override bool Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
return reader.TokenType switch
{
JsonTokenType.True => true,
JsonTokenType.False => false,
JsonTokenType.Number => reader.GetInt64() switch
{
1 => true,
0 => false,
_ => throw new JsonException()
},
_ => throw new JsonException()
};
}
public override void Write(Utf8JsonWriter writer, bool value, JsonSerializerOptions options)
{
writer.WriteBooleanValue(value);
}
}

@ -1,28 +1,44 @@
using Newtonsoft.Json;
using System.Text.Json.Serialization;
using NzbDrone.Common.Serializer;
namespace NzbDrone.Core.Indexers.Definitions.FileList;
public class FileListTorrent
{
public string Id { get; set; }
public uint Id { get; set; }
public string Name { get; set; }
public long Size { get; set; }
public int Leechers { get; set; }
public int Seeders { get; set; }
[JsonProperty(PropertyName = "times_completed")]
[JsonPropertyName("times_completed")]
public uint TimesCompleted { get; set; }
public uint Comments { get; set; }
public uint Files { get; set; }
[JsonProperty(PropertyName = "imdb")]
[JsonPropertyName("imdb")]
public string ImdbId { get; set; }
[JsonConverter(typeof(BooleanConverter))]
public bool Internal { get; set; }
[JsonProperty(PropertyName = "freeleech")]
[JsonPropertyName("freeleech")]
[JsonConverter(typeof(BooleanConverter))]
public bool FreeLeech { get; set; }
[JsonProperty(PropertyName = "doubleup")]
[JsonPropertyName("doubleup")]
[JsonConverter(typeof(BooleanConverter))]
public bool DoubleUp { get; set; }
[JsonProperty(PropertyName = "upload_date")]
[JsonPropertyName("upload_date")]
public string UploadDate { get; set; }
public string Category { get; set; }
[JsonProperty(PropertyName = "small_description")]
[JsonPropertyName("small_description")]
public string SmallDescription { get; set; }
}

@ -3,8 +3,8 @@ using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Net;
using Newtonsoft.Json;
using NzbDrone.Common.Http;
using NzbDrone.Common.Serializer;
using NzbDrone.Core.Indexers.Exceptions;
using NzbDrone.Core.Parser.Model;
@ -35,7 +35,7 @@ public class FileListParser : IParseIndexerResponse
var releaseInfos = new List<ReleaseInfo>();
var results = JsonConvert.DeserializeObject<List<FileListTorrent>>(indexerResponse.Content);
var results = STJson.Deserialize<List<FileListTorrent>>(indexerResponse.Content);
foreach (var row in results)
{
@ -54,7 +54,7 @@ public class FileListParser : IParseIndexerResponse
}
var imdbId = 0;
if (row.ImdbId != null && row.ImdbId.Length > 2)
if (row.ImdbId is { Length: > 2 })
{
imdbId = int.Parse(row.ImdbId.Substring(2));
}
@ -64,7 +64,7 @@ public class FileListParser : IParseIndexerResponse
releaseInfos.Add(new TorrentInfo
{
Guid = string.Format("FileList-{0}", id),
Guid = $"FileList-{id}",
Title = row.Name,
Size = row.Size,
Categories = _categories.MapTrackerCatDescToNewznab(row.Category),
@ -91,21 +91,21 @@ public class FileListParser : IParseIndexerResponse
public Action<IDictionary<string, string>, DateTime?> CookiesUpdater { get; set; }
private string GetDownloadUrl(string torrentId)
private string GetDownloadUrl(uint torrentId)
{
var url = new HttpUri(_settings.BaseUrl)
.CombinePath("/download.php")
.AddQueryParam("id", torrentId)
.AddQueryParam("id", torrentId.ToString())
.AddQueryParam("passkey", _settings.Passkey);
return url.FullUri;
}
private string GetInfoUrl(string torrentId)
private string GetInfoUrl(uint torrentId)
{
var url = new HttpUri(_settings.BaseUrl)
.CombinePath("/details.php")
.AddQueryParam("id", torrentId);
.AddQueryParam("id", torrentId.ToString());
return url.FullUri;
}

Loading…
Cancel
Save