diff --git a/src/NzbDrone.Core/Indexers/Definitions/Gazelle/GazelleApi.cs b/src/NzbDrone.Core/Indexers/Definitions/Gazelle/GazelleApi.cs index 9dd0e8930..957798a57 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/Gazelle/GazelleApi.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/Gazelle/GazelleApi.cs @@ -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 Torrents { get; set; } public bool IsFreeLeech { get; set; } diff --git a/src/NzbDrone.Core/Indexers/Definitions/Gazelle/GazelleTimestampConverter.cs b/src/NzbDrone.Core/Indexers/Definitions/Gazelle/GazelleTimestampConverter.cs new file mode 100644 index 000000000..4ee833c22 --- /dev/null +++ b/src/NzbDrone.Core/Indexers/Definitions/Gazelle/GazelleTimestampConverter.cs @@ -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); + } + } +}