using Newtonsoft.Json; using NLog; using System; using System.Net.Http; using System.Threading.Tasks; namespace NadekoBot.Services.Searches { public class AnimeSearchService { private readonly Logger _log; public AnimeSearchService() { _log = LogManager.GetCurrentClassLogger(); } public async Task GetAnimeData(string query) { if (string.IsNullOrWhiteSpace(query)) throw new ArgumentNullException(nameof(query)); try { var link = "https://aniapi.nadekobot.me/anime/" + Uri.EscapeDataString(query.Replace("/", " ")); using (var http = new HttpClient()) { var res = await http.GetStringAsync(link).ConfigureAwait(false); return JsonConvert.DeserializeObject(res); } } catch { return null; } } public async Task GetMangaData(string query) { if (string.IsNullOrWhiteSpace(query)) throw new ArgumentNullException(nameof(query)); try { var link = "https://aniapi.nadekobot.me/manga/" + Uri.EscapeDataString(query.Replace("/", " ")); using (var http = new HttpClient()) { var res = await http.GetStringAsync(link).ConfigureAwait(false); return JsonConvert.DeserializeObject(res); } } catch { return null; } } } }