public async Task<List<MalMessageModel>> GetSentMessages(int page = 1) { try { var client = await MalHttpContextProvider.GetHttpContextAsync(); string path = $"/mymessages.php?go=sent"; var res = await client.GetAsync(path); var body = await res.Content.ReadAsStringAsync(); var output = new List<MalMessageModel>(); var doc = new HtmlDocument(); doc.LoadHtml(body); output.AddRange( doc.WhereOfDescendantsWithClass("div", "message read spot2 clearfix") .Select(ParseOutboxHtmlToMalMessage)); return output; } catch (WebException) { MalHttpContextProvider.ErrorMessage("Messages"); } return new List<MalMessageModel>(); }
public async Task<List<MalMessageModel>> GetMessages(int page = 1) { var client = await MalHttpContextProvider.GetHttpContextAsync(); string path = $"/mymessages.php?go=&show={page*20 - 20}"; var res = await client.GetAsync(path); var body = await res.Content.ReadAsStringAsync(); var output = new List<MalMessageModel>(); if (body.Contains("You have 0 messages")) return output; var doc = new HtmlDocument(); doc.LoadHtml(body); output.AddRange( doc.WhereOfDescendantsWithClass("div", "message unread spot1 clearfix") .Select(msgNode => ParseInboxHtmlToMalMessage(msgNode, false))); output.AddRange( doc.WhereOfDescendantsWithClass("div", "message read spot1 clearfix") .Select(msgNode => ParseInboxHtmlToMalMessage(msgNode, true))); return output; }
public async Task<List<AnimeVideoData>> GetVideos() { var output = new List<AnimeVideoData>(); var raw = await GetRequestResponse(false); if (string.IsNullOrEmpty(raw)) return output; var doc = new HtmlDocument(); doc.LoadHtml(raw); try { foreach (var videoNode in doc.WhereOfDescendantsWithClass("div", "video-list-outer-vertical")) { var current = new AnimeVideoData(); var link = videoNode.ChildNodes.First(node => node.Name == "a"); current.Thumb = link.Attributes["data-bg"].Value; if(current.Thumb.Contains("banned")) continue; current.AnimeId = int.Parse(link.Attributes["data-anime-id"].Value); var href = link.Attributes["href"].Value; var pos = href.IndexOf('?'); href = href.Substring(0, pos); current.YtLink = $"https://www.youtube.com/watch?v={href.Split('/').Last()}"; current.Name = WebUtility.HtmlDecode( videoNode.FirstOfDescendantsWithClass("div", "info-container").InnerText.Trim()); current.AnimeTitle = WebUtility.HtmlDecode(videoNode.Descendants("a").Last().InnerText.Trim()); output.Add(current); } } catch (Exception) { // } return output; }
public async Task<List<SeasonalAnimeData>> GetAnime() { var output = await DataCache.RetrieveData<List<SeasonalAnimeData>>( _genreMode ? $"genre_{_genre}_{_page}" : $"studio_{_studio}_{_page}", _genreMode ? "AnimesByGenre" : "AnimesByStudio", 7) ?? new List<SeasonalAnimeData>(); if (output.Count > 0) return output; var raw = await GetRequestResponse(); if (string.IsNullOrEmpty(raw)) return output; var doc = new HtmlDocument(); doc.LoadHtml(raw); int i = 0; try { foreach (var htmlNode in doc.WhereOfDescendantsWithClass("div", "seasonal-anime js-seasonal-anime")) { var model = AnimeSeasonalQuery.ParseFromHtml(htmlNode,i,false); if(model == null) continue; output.Add(model); i++; } } catch (Exception) { //ejchtiemel } if(_genreMode) DataCache.SaveData(output, $"genre_{_genre}_page{_page}", "AnimesByGenre"); else DataCache.SaveData(output, $"studio_{_studio}_page{_page}", "AnimesByStudio"); return output; }
public async Task<ForumIndexContent> GetPeekPosts() { var output = new ForumIndexContent(); var raw = await GetRequestResponse(); if (string.IsNullOrEmpty(raw)) return null; var doc = new HtmlDocument(); doc.LoadHtml(raw); var list = new List<ForumBoardEntryPeekPost>(2); int i = 0; foreach (var topics in doc.WhereOfDescendantsWithClass("ul", "topics")) { try { foreach (var post in topics.Descendants("li")) { i++; try { if (i == 5 || i == 6) //skip db midifiaction board continue; //if(i == 9) //add one more because suggestions have one post // list.Add(new ForumBoardEntryPeekPost()); var current = new ForumBoardEntryPeekPost(); current.PostTime = WebUtility.HtmlDecode(post.FirstOfDescendantsWithClass("span", "date di-ib pt4 fs10 fn-grey4").InnerText.TrimEnd('»')); var titleNode = post.FirstOfDescendantsWithClass("a", "topic-title-link"); current.Title = WebUtility.HtmlDecode(titleNode.InnerText); current.Id = titleNode.Attributes["href"].Value.Split('=').Last(); var img = post.Descendants("img").First(); current.User.ImgUrl = img.Attributes["src"].Value; current.User.Name = img.Attributes["alt"].Value; list.Add(current); if (list.Count == 2) //assume we have 2 for each board { output.ForumBoardEntryPeekPosts.Add(list); list = new List<ForumBoardEntryPeekPost>(); } } catch (Exception) { // } } } catch (Exception) { // } } try { int block = 0; var sideBlocks = doc.WhereOfDescendantsWithClass("div", "forum-side-block").Take(4); foreach (var sideBlock in sideBlocks) { var postList = new List<ForumPostEntry>(); foreach (var post in sideBlock.Descendants("li")) { var current = new ForumPostEntry(); var titleNode = post.FirstOfDescendantsWithClass("a", "title"); current.Id = titleNode.Attributes["href"].Value.Split('=').Last(); current.Title = WebUtility.HtmlDecode(titleNode.InnerText.Trim()); current.ImgUrl = post.Descendants("img").First().Attributes["src"].Value; var infoSpan = post.FirstOfDescendantsWithClass("span", "information di-ib fs10 fn-grey4"); current.Created = infoSpan.ChildNodes[0].InnerText.Trim(); current.Created = current.Created.Substring(0, current.Created.Length - 3); //remove "by" current.Op = infoSpan.Descendants("a").First().InnerText.Trim(); postList.Add(current); } switch (block) { case 0: output.PopularNewTopics = postList; break; case 1: output.RecentPosts = postList; break; case 2: output.AnimeSeriesDisc = postList; break; default: output.MangaSeriesDisc = postList; break; } block++; } } catch (Exception) { // } return output; }
public async Task<List<MalNewsUnitModel>> GetArticlesIndex(bool force = false) { if (!force) { if (_cachedData.ContainsKey(_mode)) return _cachedData[_mode]; var possibleData = await DataCache.RetrieveArticleIndexData(_mode); if (possibleData != null && possibleData.Count > 0) return possibleData; } var output = new List<MalNewsUnitModel>(); var raw = await GetRequestResponse(); if (string.IsNullOrEmpty(raw)) return null; var doc = new HtmlDocument(); doc.LoadHtml(raw); switch (_mode) { case ArticlePageWorkMode.Articles: foreach (var featuredNewsUnit in doc.WhereOfDescendantsWithClass("div", "featured-pickup-unit")) { try { var current = new MalNewsUnitModel(); var img = featuredNewsUnit.Descendants("a").First(); var imgUrl = img.Attributes["data-bg"].Value; if (!imgUrl.Contains("questionmark")) { imgUrl = Regex.Replace(imgUrl, @"\/r\/\d+x\d+", ""); current.ImgUrl = imgUrl.Substring(0, imgUrl.IndexOf('?')); } current.Url = img.Attributes["href"].Value; current.Highlight = WebUtility.HtmlDecode(featuredNewsUnit.Descendants("p").First().InnerText.Trim()); current.Title = WebUtility.HtmlDecode(img.InnerText.Trim()); if(current.Title.ToLower().Contains("giveaway")) // emm I'll pass on these continue; var infoDiv = featuredNewsUnit.FirstOfDescendantsWithClass("div", "information"); var infoDivsParagraphs = infoDiv.Descendants("p").ToList(); current.Author = WebUtility.HtmlDecode(infoDivsParagraphs[0].InnerText.Trim()); current.Views = WebUtility.HtmlDecode(infoDivsParagraphs[1].InnerText.Trim()); current.Tags = "New"; output.Add(current); } catch (Exception) { } } foreach (var newsUnit in doc.WhereOfDescendantsWithClass("div", "news-unit clearfix")) { try { var current = new MalNewsUnitModel(); var img = newsUnit.Descendants("a").First(); current.Url = img.Attributes["href"].Value; try { current.ImgUrl = img.Descendants("img").First().Attributes["data-src"].Value; } catch (Exception) { //html here is messy, there may be change here soon } var contentDivs = newsUnit.Descendants("div").ToList(); current.Title = WebUtility.HtmlDecode(contentDivs[0].Descendants("p").First().InnerText.Trim()); current.Highlight = WebUtility.HtmlDecode(contentDivs[1].InnerText.Trim()); var infos = contentDivs[2].Descendants("p").ToList(); current.Author = infos[0].InnerText.Trim(); current.Views = infos[1].InnerText.Trim(); try { current.Tags = string.Join(", ", contentDivs[3].Descendants("a").Select(node => node.InnerText.Trim())); } catch (Exception) { //no tags } current.Type = MalNewsType.Article; output.Add(current); } catch (Exception) { //hatml } } break; case ArticlePageWorkMode.News: foreach (var newsUnit in doc.WhereOfDescendantsWithClass("div", "news-unit clearfix rect")) { try { var current = new MalNewsUnitModel(); var img = newsUnit.Descendants("a").First(); current.Url = img.Attributes["href"].Value; try { current.ImgUrl = img.Descendants("img").First().Attributes["srcset"].Value.Split(' ', ' ')[2]; } catch (Exception) { try { current.ImgUrl = img.Descendants("img").First().Attributes["data-src"].Value; } catch (Exception) { //it may work this way, my predicition } //html here is messy, there may be change here soon } var contentDivs = newsUnit.Descendants("div").ToList(); current.Title = WebUtility.HtmlDecode(contentDivs[0].Descendants("p").First().InnerText.Trim()); current.Highlight = WebUtility.HtmlDecode(contentDivs[1].InnerText.Trim()); var infos = contentDivs[2].Descendants("p").ToList(); current.Author = "By: " + infos[0].ChildNodes[1].InnerText.Trim(); current.Views = infos[0].ChildNodes[3].InnerText.Trim(); try { current.Tags = string.Join(", ", contentDivs[2].ChildNodes[3].Descendants("a").Select(node => node.InnerText.Trim())); } catch (Exception) { //no tags } current.Type = MalNewsType.News; output.Add(current); } catch (Exception) { //hatml } } break; default: throw new ArgumentOutOfRangeException(); } _cachedData[_mode] = output; DataCache.SaveArticleIndexData(_mode, output); return output; }