public override async Task <AutoHintItems> GetAutoHintItemsAsync(SearchPara para, CancellationToken token) { var list = new AutoHintItems(); var client = new NetSwap(Settings).Client; switch (SiteType) { case SiteTypeEnum.Xml: { var xmlstr = await client.GetStringAsync(GetHintQuery(para)); var xml = new XmlDocument(); xml.LoadXml(xmlstr); var root = xml.SelectSingleNode("tags"); if (root == null) { return(list); } foreach (XmlElement child in root.ChildNodes) { list.Add(new AutoHintItem { Word = child.GetAttribute("name"), Count = child.GetAttribute("count") }); } return(list); } case SiteTypeEnum.Json: { var jsonstr = await client.GetStringAsync(GetHintQuery(para)); dynamic jsonlist = JsonConvert.DeserializeObject(jsonstr); foreach (var item in jsonlist) { list.Add(new AutoHintItem { Word = $"{item.name}", Count = $"{item.post_count}" }); } return(list); } default: return(null); } }
public override async Task <AutoHintItems> GetAutoHintItemsAsync(SearchPara para, CancellationToken token) { //type 1 tag 2 source 3 artist | chara no type var items = new AutoHintItems(); //chara without hint if (SubListIndex == 3) { return(items); } var url = $"{HomeUrl}/httpreq.php?mode=tag_search&tags={para.Keyword}&type={SubListIndex + 1}"; var txt = await Net.Client.GetStringAsync(url); var lines = txt.Split('\n'); for (var i = 0; i < lines.Length && i < 8; i++) { if (lines[i].Trim().Length > 0) { items.Add(new AutoHintItem { Word = lines[i].Trim() }); } } return(items); }
public override async Task <AutoHintItems> GetAutoHintItemsAsync(SearchPara para, CancellationToken token) { if (AutoHintNet == null) { AutoHintNet = new NetSwap(Settings, HomeUrl); AutoHintNet.SetReferer(HomeUrl); } var re = new AutoHintItems(); if (SubListIndex == 0 || SubListIndex == 5) { var url = $"{HomeUrl}/rpc/cps.php?keyword={ para.Keyword}"; var json = await AutoHintNet.Client.GetStringAsync(url); dynamic jlist = JsonConvert.DeserializeObject(json); if (jlist?.candidates != null) { foreach (var obj in jlist.candidates) { var item = new AutoHintItem(); item.Word = $"{obj.tag_name}"; re.Add(item); } } } return(re); }
public override async Task <AutoHintItems> GetAutoHintItemsAsync(SearchPara para, CancellationToken token) { //http://www.zerochan.net/suggest?q=tony&limit=8 var re = new AutoHintItems(); var url = $"{HomeUrl}/suggest?limit=8&q={para.Keyword}"; Net.Client.DefaultRequestHeaders.Referrer = new Uri(HomeUrl); var res = await Net.Client.GetAsync(url, token); var txt = await res.Content.ReadAsStringAsync(); var lines = txt.Split('\n'); for (var i = 0; i < lines.Length && i < 8; i++) { //Tony Taka|Mangaka| if (lines[i].Trim().Length > 0) { re.Add(new AutoHintItem { Word = lines[i].Substring(0, lines[i].IndexOf('|')).Trim() }); } } return(re); }
public override async Task <AutoHintItems> GetAutoHintItemsAsync(SearchPara para, CancellationToken token) { if (AutoHintNet == null) { AutoHintNet = new NetSwap(Settings, HomeUrl); } AutoHintNet.SetReferer(HomeUrl); //http://mjv-art.org/pictures/autocomplete_tag POST var re = new AutoHintItems(); //no result with length less than 3 if (para.Keyword.Length < 3) { return(re); } var mcontent = new MultipartFormDataContent("---------------" + DateTime.Now.Ticks.ToString("x")); mcontent.Add(new StringContent($"Content-Disposition: form-data; name=\"tag\"\r\n\r\n{para.Keyword}")); var url = $"{HomeUrl}/pictures/autocomplete_tag"; var response = await AutoHintNet.Client.PostAsync(url, mcontent, token); // todo 这里post数据失败,希望有大神能够解决 if (!response.IsSuccessStatusCode) { return(new AutoHintItems()); } var txt = await response.Content.ReadAsStringAsync(); //JSON format response //{"tags_list": [{"c": 3, "t": "suzumiya <b>haruhi</b> no yuutsu"}, {"c": 1, "t": "suzumiya <b>haruhi</b>"}]} var tagList = ((new System.Web.Script.Serialization.JavaScriptSerializer()).DeserializeObject(txt) as Dictionary <string, object>)?["tags_list"] as object[]; for (var i = 0; i < tagList.Length && i < 8; i++) { var tag = tagList[i] as Dictionary <string, object>; if (tag["t"].ToString().Trim().Length > 0) { re.Add(new AutoHintItem { Word = tag["t"].ToString().Trim().Replace("<b>", "").Replace("</b>", ""), Count = "N/A" }); } } return(re); }
public override async Task <AutoHintItems> GetAutoHintItemsAsync(SearchPara para, CancellationToken token) { var items = new AutoHintItems(); var url = $"{HomeUrl}/suggest?limit=8&q={para.Keyword}"; var txtres = await Net.Client.GetAsync(url, token); var txt = await txtres.Content.ReadAsStringAsync(); var lines = txt.Split('\n'); for (var i = 0; i < lines.Length && i < 8; i++) { //The Melancholy of Suzumiya Haruhi|Series|Noizi Ito if (lines[i].Trim().Length > 0) { items.Add(new AutoHintItem { Word = lines[i].Substring(0, lines[i].IndexOf('|')).Trim() }); } } return(items); }