From a15bb3c4a92a6dd2148858e49dd27330b2311787 Mon Sep 17 00:00:00 2001 From: Master Kwoth Date: Wed, 27 Apr 2016 20:58:36 +0200 Subject: [PATCH] Fixed ~e621, closes #242 #243 --- NadekoBot/Classes/SearchHelper.cs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/NadekoBot/Classes/SearchHelper.cs b/NadekoBot/Classes/SearchHelper.cs index b8b7a8b5..ad78466f 100644 --- a/NadekoBot/Classes/SearchHelper.cs +++ b/NadekoBot/Classes/SearchHelper.cs @@ -263,12 +263,19 @@ namespace NadekoBot.Classes { try { - XDocument doc = await Task.Run(() => XDocument.Load(" http://e621.net/post/index.xml?tags=" + Uri.EscapeUriString(tags) + "%20order:random&limit=1")); - int id = Convert.ToInt32(doc.Root.Element("post").Element("id").Value); - return (doc.Root.Element("post").Element("file_url").Value); + var headers = new Dictionary() { + {"User-Agent", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.202 Safari/535.1"}, + {"Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" }, + }; + var data = await GetResponseStreamAsync( + "http://e621.net/post/index.xml?tags=" + Uri.EscapeUriString(tags) + "%20order:random&limit=1", + headers); + var doc = XDocument.Load(data); + return doc.Descendants("file_url").FirstOrDefault().Value; } - catch (Exception) + catch (Exception ex) { + Console.WriteLine("Error in e621 search: \n" + ex); return "Error, do you have too many tags?"; } }