public LyricsInfo SearchLyricsAsync(string artist, string song) { var geniusClient = new GeniusClient(); Song songInfo = geniusClient.Search($"{artist} {song}"); String uri = songInfo.Url; var client = new HttpClient(); var response = client.GetAsync(uri).GetAwaiter().GetResult(); LyricsInfo lyricsInfo = null; if (response.IsSuccessStatusCode) { lyricsInfo = new LyricsInfo(); lyricsInfo.Artist = songInfo.Artist; lyricsInfo.Song = songInfo.Title; lyricsInfo.ThumbnailUrl = songInfo.ThumbnailUrl; var body = response.Content.ReadAsStringAsync().GetAwaiter().GetResult(); HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(body); var lyricsDiv = doc.DocumentNode.SelectSingleNode("//div[@class='lyrics']"); lyricsInfo.Lyrics = lyricsDiv.InnerText.Trim(); } response.Dispose(); client.Dispose(); return(lyricsInfo); }
public LyricsInfo SearchLyricsAsync(String artist, String song) { String uri = $"https://mourits.xyz:2096/?a={artist}&s={song}"; var client = new HttpClient(); var response = client.GetAsync(uri).GetAwaiter().GetResult(); var body = response.Content.ReadAsStringAsync().GetAwaiter().GetResult(); JObject bodyJson = JObject.Parse(body); LyricsInfo info = null; if (bodyJson["success"] != null && (bool)bodyJson["success"]) { info = new LyricsInfo { Artist = (String)bodyJson["artist"], Song = (String)bodyJson["song"], Lyrics = (String)bodyJson["result"]["lyrics"] }; } client.Dispose(); return(info); }