Archived
1
0

Core refactoring (app doesn't work)

This commit is contained in:
Michael Gordeev
2020-05-09 23:16:19 +03:00
parent 2b1f06dd93
commit 2a987e33a2
35 changed files with 1135 additions and 817 deletions
+36
View File
@@ -0,0 +1,36 @@
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={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;
}
}
}