public async Task <MemeDto> GetRandomMemeAsync() { while (true) { string memeAsJson = await GetAsync("RandomMeme.php"); MemeDto meme = JsonConvert.DeserializeObject <MemeDto>(memeAsJson, new MemeConverter()); meme.Id = meme.GetMemeIdFromUrl(); if (meme.Title == null) { continue; } return(meme); } }
private static async Task<MemeDto> ExtractMemeFromMetaNodesAsync(IEnumerable<HtmlNode> collection) { MemeDto meme = new MemeDto(); foreach (HtmlNode htmlNode in collection) { string content = htmlNode.Attributes["content"].DeEntitizeValue; if (htmlNode.Attributes["property"].DeEntitizeValue == "og:title") meme.Title = content; else if (htmlNode.Attributes["property"].DeEntitizeValue == "og:url") meme.PageUrl = content; else if (htmlNode.Attributes["property"].DeEntitizeValue == "og:image") meme.ImageUrl = content; } meme.Id = meme.GetMemeIdFromUrl(); string videoUrl = NineGagPhotoCacheUrl + meme.Id + Mp4Tag; if (await HasVideoUrlAsync(videoUrl)) { meme.VideoUrl = videoUrl; } return meme; }