Core refactoring (app doesn't work)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user