Fixed: Handle wonky timestamps from Orpheus

fix-orpheus
ta264 3 years ago
parent 4f83116413
commit 0e05d86a58

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
namespace NzbDrone.Core.Indexers.Gazelle
{
@ -59,6 +60,7 @@ namespace NzbDrone.Core.Indexers.Gazelle
public int TotalSeeders { get; set; }
public int TotalSnatched { get; set; }
public long MaxSize { get; set; }
[JsonConverter(typeof(GazelleTimestampConverter))]
public long GroupTime { get; set; }
public List<GazelleTorrent> Torrents { get; set; }
public bool IsFreeLeech { get; set; }

@ -0,0 +1,41 @@
using System;
using Newtonsoft.Json;
namespace NzbDrone.Core.Indexers.Gazelle
{
public class GazelleTimestampConverter : JsonConverter
{
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
if (value == null)
{
writer.WriteNull();
}
else
{
writer.WriteValue(value);
}
}
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
if (objectType == typeof(long))
{
return Convert.ToInt64(reader.Value);
}
if (objectType == typeof(string))
{
var date = DateTimeOffset.Parse(reader.Value.ToString());
return date.ToUnixTimeSeconds();
}
throw new JsonSerializationException("Can't convert type " + existingValue.GetType().FullName + " to timestamp");
}
public override bool CanConvert(Type objectType)
{
return objectType == typeof(long) || objectType == typeof(string);
}
}
}
Loading…
Cancel
Save