using FoxTube.Models; using System.Linq; using System.Collections.Generic; using System.Net.Http; using System.Threading.Tasks; using System.Xml; namespace FoxTube.Services { public static class Search { public static async Task> GetSuggestions(string term) { List suggestions = new List(); try { using HttpClient client = new HttpClient(); string results = await client.GetStringAsync($"http://suggestqueries.google.com/complete/search?ds=yt&client=toolbar&q={term}&hl={Settings.RelevanceLanguage}"); XmlDocument doc = new XmlDocument(); doc.LoadXml(results); for (int i = 0; i < doc["toplevel"].ChildNodes.Count && i < 5; i++) suggestions.Add(new SearchSuggestion(doc["toplevel"].ChildNodes[i]["suggestion"].GetAttribute("data"))); // Appending search history suggestions.AddRange(History.SearchHistory.Select(i => new SearchSuggestion(i, true))); return suggestions; } catch { } return suggestions; } } }