public EpisodesPageData GetEpisodesPage() { if (m_episodes != null) { return(m_episodes); } if (m_header.Episodes == null) { throw new Exception("There's no episodes page for this anime."); } m_episodes = Episodes.Parse(m_header.Link_Episodes.Path); return(m_episodes); }
public async Task <EpisodesPageData> GetEpisodesPageAsync() { if (m_episodes != null) { return(m_episodes); } if (m_header.Episodes == null) { throw new Exception("There's no episodes page for this anime."); } m_episodes = await Episodes.ParseAsync(m_header.Link_Episodes.Path); return(m_episodes); }
public void AnimeEpisodesPage_ParsedCorrectly() { string testLink = "https://myanimelist.net/anime/21/One_Piece/episode"; EpisodesPageData page = MALParser.AnimePage.Episodes.Parse(testLink); Assert.AreEqual(page.NextPageAvailable, true); Assert.AreEqual(page.PreviousPageAvailable, false); Assert.AreNotEqual(page.Episodes.Count, 0); page.Episodes.ForEach(x => { Assert.IsNotNull(x.EnglishTitle); Assert.IsNotNull(x.WatchLink); Assert.AreNotEqual(x.Number, -1); }); }
private static EpisodesPageData AnalyzeDocument(string HTMLCode, string link) { HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(HTMLCode); EpisodesPageData page = new EpisodesPageData(Header.AnalyzeHeader(HTMLCode)); try { if (!doc.DocumentNode.Descendants("table").Any(x => x.GetAttributeValue("class", "") == "mt8 episode_list js-watch-episode-list ascend")) { return(page); } var mainNode = doc.DocumentNode.Descendants("table").First(x => x.GetAttributeValue("class", "") == "mt8 episode_list js-watch-episode-list ascend") .Descendants("tr").Where(x => x.GetAttributeValue("class", "") == "episode-list-data"); for (int i = 0; i < mainNode.Count(); i++) { EpisodeInfo ep = new EpisodeInfo(); var episodeNum = mainNode.ElementAt(i).Descendants("td").First(x => x.GetAttributeValue("class", "") == "episode-number nowrap"); var episodeTitle = mainNode.ElementAt(i).Descendants("td").First(x => x.GetAttributeValue("class", "") == "episode-title"); var episodeAired = mainNode.ElementAt(i).Descendants("td").First(x => x.GetAttributeValue("class", "") == "episode-aired nowrap"); ep.Number = Utility.GetIntFromString(episodeNum.InnerText); ep.EnglishTitle = HtmlEntity.DeEntitize(episodeTitle.Descendants("a").First().InnerText); ep.WatchLink = new Dto.Utility.LinkInfo(episodeTitle.Descendants("a").First().GetAttributeValue("href", "")); DateTime date; DateTime.TryParse(episodeAired.InnerText, out date); ep.AirDate = date; page.Episodes.Add(ep); } if (doc.DocumentNode.Descendants().Any(x => x.GetAttributeValue("class", "") == "mt12 mb12")) { int currOffset = Utility.GetIntFromString(doc.DocumentNode.Descendants().First(x => x.GetAttributeValue("class", "") == "link current").GetAttributeValue("href", "").Split('=').Last()); var links = doc.DocumentNode.Descendants().Where(x => x.GetAttributeValue("class", "") == "link"); int minOffset = Utility.GetIntFromString(links.First().GetAttributeValue("href", "").Split('=').Last()); int maxOffset = Utility.GetIntFromString(links.Last().GetAttributeValue("href", "").Split('=').Last()); string newLink = ""; if (link.Contains("?offset=")) { newLink = link.Split('=')[0] + "="; } else { newLink = link + "?offset="; } if (currOffset > minOffset) { page.PreviousPageLink = new Dto.Utility.LinkInfo(newLink + (currOffset - 100)); } if (currOffset < maxOffset) { page.NextPageLink = new Dto.Utility.LinkInfo(newLink + (currOffset + 100)); } } } catch (Exception ex) { Console.WriteLine(ex.Message + ex.StackTrace); } return(page); }