示例#1
0
        private Comment(CommentCollection owner, int id, HtmlNode commentNode)
        {
            this.Owner = owner;
            var culture  = System.Globalization.CultureInfo.InvariantCulture;
            var document = commentNode.OwnerDocument;

            this.Id = id;

            var contentHtml = document.GetElementbyId($"comment_{id}").OuterHtml.Replace("://forums.exhentai.org", "://forums.e-hentai.org");

            this.Content = HtmlNode.CreateNode(contentHtml);

            var editNode = commentNode.Descendants("div").FirstOrDefault(node => node.HasClass("c8"));

            if (editNode != null)
            {
                this.Edited = DateTimeOffset.ParseExact(editNode.Element("strong").InnerText, "dd MMMM yyyy, HH:mm 'UTC'", culture, System.Globalization.DateTimeStyles.AssumeUniversal);
            }

            var postedAndAuthorNode = commentNode.Descendants("div").First(node => node.HasClass("c3"));

            this.Author = postedAndAuthorNode.Element("a").GetInnerText();
            this.Posted = DateTimeOffset.ParseExact(postedAndAuthorNode.FirstChild.InnerText, "'Posted on' dd MMMM yyyy, HH:mm 'UTC by:  '", culture, System.Globalization.DateTimeStyles.AssumeUniversal | System.Globalization.DateTimeStyles.AllowWhiteSpaces);

            if (!this.IsUploaderComment)
            {
                this.score = int.Parse(document.GetElementbyId($"comment_score_{id}").InnerText);
                var actionNode = commentNode.Descendants("div").FirstOrDefault(node => node.HasClass("c4") && node.HasClass("nosel"));
                if (actionNode != null)
                {
                    var vuNode = document.GetElementbyId($"comment_vote_up_{id}");
                    var vdNode = document.GetElementbyId($"comment_vote_down_{id}");
                    if (vuNode != null && vdNode != null)
                    {
                        if (vuNode.GetAttribute("style", "").Contains("color:blue"))
                        {
                            this.status = CommentStatus.VotedUp;
                        }
                        else if (vdNode.GetAttribute("style", "").Contains("color:blue"))
                        {
                            this.status = CommentStatus.VotedDown;
                        }
                        else
                        {
                            this.status = CommentStatus.Votable;
                        }
                    }
                    else if (actionNode.InnerText == "[Edit]")
                    {
                        this.status = CommentStatus.Editable;
                    }
                }
            }
        }
示例#2
0
        internal static IEnumerable <Comment> AnalyzeDocument(CommentCollection owner, HtmlDocument document)
        {
            var commentNodes = document?.GetElementbyId("cdiv")?.ChildNodes;

            if (commentNodes is null)
            {
                yield break;
            }
            for (var i = 0; i < commentNodes.Count; i += 2)
            {
                var headerNode  = commentNodes[i];
                var commentNode = commentNodes[i + 1];
                if (headerNode.Name != "a" || commentNode.Name != "div")
                {
                    break;
                }
                var id = int.Parse(headerNode.GetAttribute("name", "c0").Substring(1));
                yield return(new Comment(owner, id, commentNode));
            }
        }