Archived
1
0
This repository has been archived on 2026-04-22. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
Michael Gordeev 787a6e9f48 Refactored core
UI navigation framework

Related Work Items: #408, #414, #416
2020-06-15 15:46:38 +03:00

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;
}
}
}