ThePirateBay: replace yml with c# and using TPB's API (#9593)

This commit is contained in:
Jonathan Trowbridge
2020-09-23 22:13:17 -04:00
committed by GitHub
parent 00d3a62cf1
commit 977279318d
4 changed files with 321 additions and 211 deletions

View File

@@ -0,0 +1,33 @@
using System;
using Newtonsoft.Json;
namespace Jackett.Common.Converters
{
/// <summary>
/// converts a string value to a long and vice-versa.
/// </summary>
public sealed class StringToLongConverter : JsonConverter
{
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
=> writer.WriteValue(value.ToString());
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
if (reader.Value == null)
{
return null;
}
if (reader.Value is long)
{
return reader.Value;
}
return long.TryParse((string)reader.Value, out var foo)
? foo
: (long?) null;
}
public override bool CanConvert(Type objectType) => objectType == typeof(string);
}
}