787a6e9f48
UI navigation framework Related Work Items: #408, #414, #416
42 lines
1.1 KiB
C#
42 lines
1.1 KiB
C#
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<List<SearchSuggestion>> GetSuggestions(string term)
|
|
{
|
|
List<SearchSuggestion> suggestions = new List<SearchSuggestion>();
|
|
|
|
try
|
|
{
|
|
using HttpClient client = new HttpClient();
|
|
string results = await client.GetStringAsync($"http://suggestqueries.google.com/complete/search?" +
|
|
$"ds=yt&" +
|
|
$"client=toolbar&" +
|
|
$"q={term}&" +
|
|
$"hl={SettingsService.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;
|
|
}
|
|
}
|
|
}
|