mirror of
https://github.com/Prowlarr/Prowlarr.git
synced 2025-04-18 19:15:10 -04:00
Fixed: Handle wonky timestamps from Orpheus
This commit is contained in:
parent
4f83116413
commit
0e05d86a58
2 changed files with 43 additions and 0 deletions
|
@ -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…
Add table
Reference in a new issue