From ca84909f4b186fcace650c213e34a3b4ef8b6ae1 Mon Sep 17 00:00:00 2001 From: RKrom Date: Fri, 9 Oct 2015 20:35:59 +0200 Subject: [PATCH] Added some fixes for the Imgur V3 API response parsing, the links were not correctly processed. --- GreenshotImgurPlugin/ImgurInfo.cs | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/GreenshotImgurPlugin/ImgurInfo.cs b/GreenshotImgurPlugin/ImgurInfo.cs index 6b65f48ef..fd8b61d20 100644 --- a/GreenshotImgurPlugin/ImgurInfo.cs +++ b/GreenshotImgurPlugin/ImgurInfo.cs @@ -166,16 +166,41 @@ namespace GreenshotImgurPlugin } nodes = doc.GetElementsByTagName("datetime"); if(nodes.Count > 0) { - imgurInfo.Timestamp = DateTime.Parse(nodes.Item(0).InnerText); + try + { + imgurInfo.Timestamp = DateTime.Parse(nodes.Item(0).InnerText); + } + catch (Exception) + { + // Version 3 has seconds since Epoch + double secondsSince; + if (double.TryParse(nodes.Item(0).InnerText, out secondsSince)) + { + var epoch = new DateTimeOffset(1970, 1, 1, 0, 0, 0, TimeSpan.Zero); + imgurInfo.Timestamp = epoch.AddSeconds(secondsSince).DateTime; + } + } } nodes = doc.GetElementsByTagName("original"); if(nodes.Count > 0) { imgurInfo.Original = nodes.Item(0).InnerText; } + // Version 3 API only has Link + nodes = doc.GetElementsByTagName("link"); + if (nodes.Count > 0) + { + imgurInfo.Original = nodes.Item(0).InnerText; + } nodes = doc.GetElementsByTagName("imgur_page"); - if(nodes.Count > 0) { + if (nodes.Count > 0) + { imgurInfo.Page = nodes.Item(0).InnerText; } + else + { + // Version 3 doesn't have a page link in the response + imgurInfo.Page = string.Format("http://imgur.com/{0}", imgurInfo.Hash); + } nodes = doc.GetElementsByTagName("small_square"); if(nodes.Count > 0) { imgurInfo.SmallSquare = nodes.Item(0).InnerText;