PowerToys/Wox.Plugin.SystemPlugins/SuggestionSources/Google.cs

41 lines
1.2 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Serialization;
using Wox.Infrastructure;
2014-12-21 22:03:03 +08:00
using Wox.Infrastructure.Http;
using YAMP.Numerics;
namespace Wox.Plugin.SystemPlugins.SuggestionSources
{
public class Google : AbstractSuggestionSource
{
public override List<string> GetSuggestions(string query)
{
2014-12-21 22:03:03 +08:00
var result = HttpRequest.Get("https://www.google.com/complete/search?output=chrome&q=" + Uri.EscapeUriString(query));
if (string.IsNullOrEmpty(result)) return new List<string>();
try
{
2014-12-21 22:03:03 +08:00
JContainer json = JsonConvert.DeserializeObject(result) as JContainer;
if (json != null)
{
2014-12-21 22:03:03 +08:00
var results = json[1] as JContainer;
if (results != null)
{
2014-12-21 22:03:03 +08:00
return results.OfType<JValue>().Select(o => o.Value).OfType<string>().ToList();
}
}
}
2014-12-21 22:03:03 +08:00
catch { }
return new List<string>();
}
}
}