Пример #1
0
        private MalMessageModel ParseInboxHtmlToMalMessage(HtmlNode msgNode, bool read)
        {
            var current = new MalMessageModel();
            current.Sender = msgNode.FirstOfDescendantsWithClass("div", "mym mym_user").InnerText.Trim();
            current.Target = Credentials.UserName;
            var contentNode = msgNode.FirstOfDescendantsWithClass("div", "mym mym_subject");
            current.Subject =
                WebUtility.HtmlDecode(contentNode.Descendants("a").First().ChildNodes[0].InnerText.Trim().Trim('-'));
            current.Content = WebUtility.HtmlDecode(contentNode.Descendants("span").First().InnerText.Trim());
            current.Id =
                contentNode.FirstOfDescendantsWithClass("a", "subject-link").Attributes["href"].Value.Split('=')
                    .Last();
            current.Date = msgNode.FirstOfDescendantsWithClass("span", "mym_date").InnerText.Trim();
            current.IsRead = read;

            var ids =
                msgNode.FirstOfDescendantsWithClass("span", "mym_actions").Descendants("a").First().Attributes["href"]
                    .Value.Split('=');
            current.ThreadId = ids[3].Substring(0, ids[3].IndexOf('&'));
            current.ReplyId = ids[2].Substring(0, ids[3].IndexOf('&'));
            return current;
        }
Пример #2
0
        public static SeasonalAnimeData ParseFromHtml(HtmlNode htmlNode,int index,bool parseDate = true)
        {
            if (htmlNode.Attributes["class"]?.Value != HtmlClassMgr.ClassDefs["#Seasonal:entryNode:class"])
                return null;

            var imageNode =
                htmlNode.FirstOfDescendantsWithClass("div", "image lazyload");
            var link = imageNode.ChildNodes.First(node => node.Name == "a").Attributes["href"].Value;
            var img = imageNode.Attributes["data-bg"].Value;
            var scoreTxt =
                htmlNode.Descendants("span")
                    .First(
                        node =>
                            node.Attributes.Contains("class") &&
                            node.Attributes["class"].Value ==
                            HtmlClassMgr.ClassDefs["#Seasonal:entryNode:score:class"])
                    .InnerText;
            var infoNode =
                htmlNode.Descendants("div")
                    .First(
                        node =>
                            node.Attributes.Contains("class") &&
                            node.Attributes["class"].Value ==
                            HtmlClassMgr.ClassDefs["#Seasonal:entryNode:info:class"]);
            int day = -1;
            string airStartDate = null;
            if(parseDate)
                try
                {
                    var date = infoNode.ChildNodes[1].InnerText.Trim().Substring(0, 13).Replace(",", "");
                    var dateObj = DateTime.Parse(date);
                    day = (int)dateObj.DayOfWeek;
                    airStartDate = dateObj.ToString("yyyy-MM-dd");
                    day++;
                }
                catch (Exception)
                {
                    day = -1;
                }

            float score;
            if (!float.TryParse(scoreTxt, out score))
                score = 0;
            return new SeasonalAnimeData
            {
                Title = WebUtility.HtmlDecode(imageNode.InnerText.Trim()),
                //there are some \n that we need to get rid of
                Id = int.Parse(link.Substring(8).Split('/')[2]), //extracted from anime link
                ImgUrl = img, // from image style attr it's between ( )
                Score = score, //0 for N/A
                Episodes =
                    htmlNode.Descendants("div")
                        .First(
                            node =>
                                node.Attributes.Contains("class") &&
                                node.Attributes["class"].Value ==
                                HtmlClassMgr.ClassDefs["#Seasonal:entryNode:eps:class"])
                        .Descendants("a")
                        .First()
                        .InnerText.Split(new[] {" "}, StringSplitOptions.RemoveEmptyEntries)[0],
                Index = index,
                Genres = htmlNode.Descendants("div").First(node =>
                        node.Attributes.Contains("class") &&
                        node.Attributes["class"].Value ==
                        HtmlClassMgr.ClassDefs["#Seasonal:entryNode:genres:class"])
                    .InnerText
                    .Replace('\n', ';')
                    .Split(new[] {';'}, StringSplitOptions.RemoveEmptyEntries)
                    .Where(s => !string.IsNullOrWhiteSpace(s)).Select(s => s.Trim())
                    .ToList(),
                AirDay = day,
                AirStartDate = airStartDate
            };
        }
Пример #3
0
 private MalMessageModel ParseOutboxHtmlToMalMessage(HtmlNode msgNode)
 {
     var current = new MalMessageModel();
     current.Target = msgNode.FirstOfDescendantsWithClass("div", "mym mym_user").InnerText.Trim();
     current.Sender = Credentials.UserName;
     var contentNode = msgNode.FirstOfDescendantsWithClass("div", "mym mym_subject");
     current.Subject =
         WebUtility.HtmlDecode(contentNode.Descendants("a").First().ChildNodes[0].InnerText.Trim().Trim('-'));
     current.Content = WebUtility.HtmlDecode(contentNode.Descendants("span").First().InnerText.Trim());
     current.Date = msgNode.FirstOfDescendantsWithClass("span", "mym_date").InnerText.Trim();
     current.IsMine = true;
     return current;
 }